// Spludlow Software // Copyright © Samuel P. Ludlow 2020 All Rights Reserved // Distributed under the terms of the GNU General Public License version 3 // Distributed WITHOUT ANY WARRANTY; without implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE // https://www.spludlow.co.uk/LICENCE.TXT // The Spludlow logo is a registered trademark of Samuel P. Ludlow and may not be used without permission // v1.14 using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Data; using System.Drawing; public partial class Status : System.Web.UI.Page { private string _TaskType = null; private string _Host = null; private string _ApplicationId = null; private string _Hosted = null; private string _Thread = null; private string _QueueName = null; private int[] _ExtendedColumnIndexes = new int[] { 5, 15, 16, 18, 19, 20 }; private int _QueuePageSize = 50; private static List _GoodStatuses = new List(new string[] { "Started", "Running", "WaitSleepJoin", "Singleton", "SingleCall" }); protected void Page_Load(object sender, EventArgs e) { Spludlow.WebControls.DisableOnClick(this); } protected void ButtonQuery_Click(object sender, EventArgs e) { this._Display(); } private void _Display() { DataSet dataSet = Spludlow.Status.Query(); DataTable table = dataSet.Tables[0]; table.Columns.Add("HostColour", typeof(Color)); DataView view = new DataView(dataSet.Tables[0]); view.Sort = "OrganizationId, NetworkId, HostId, ApplicationId, Thread, TaskType, Type"; List hosts = new List(); foreach (DataRowView rowView in view) { DataRow row = rowView.Row; string host = (string)row["HostId"]; if (hosts.Contains(host) == false) hosts.Add(host); row["HostColour"] = IndexColour(hosts.IndexOf(host)); } foreach (int index in _ExtendedColumnIndexes) this.GridView1.Columns[index].Visible = this.CheckBoxExtended.Checked; this.GridView1.DataSource = view; this.GridView1.DataBind(); this._SelectedValues(true); } public Color IndexColour(int index) { int colIndex = (index % 8) + 1; return Color.FromArgb((colIndex & 1) * 32 + 191, ((colIndex & 2) >> 1) * 32 + 191, ((colIndex & 4) >> 2) * 32 + 191); } protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType != DataControlRowType.DataRow) return; Spludlow.SysTables.StatusRow row = (Spludlow.SysTables.StatusRow)((DataRowView)e.Row.DataItem).Row; bool problem = false; if (row.IsServiceStateNull() == true || (row.ServiceState != "Running" && row.ServiceState != "Started")) { problem = true; } else { if (row.IsTaskTypeNull() == true || (row.IsThreadStateNull() == false && _GoodStatuses.Contains(row.ThreadState) == false)) problem = true; } if (problem == true) { if ((e.Row.RowIndex % 2) == 0) e.Row.Cells[9].BackColor = Color.FromArgb(0xff, 0xd0, 0xd0); else e.Row.Cells[9].BackColor = Color.FromArgb(0xff, 0xc0, 0xc0); } e.Row.Cells[2].BackColor = (Color)row["HostColour"]; if (row.IsQueueLengthNull() == false && (int)row["QueueLength"] > 0) { if ((e.Row.RowIndex % 2) == 0) e.Row.Cells[17].BackColor = Color.FromArgb(0xff, 0xff, 0xd0); else e.Row.Cells[17].BackColor = Color.FromArgb(0xff, 0xff, 0xc0); } } private int _SelectedValues(bool displayQueue) { int index = this.GridView1.SelectedIndex; this.PanelQueue.Visible = false; if (index == -1) { return -1; } if (index >= this.GridView1.DataKeys.Count) { this.GridView1.SelectedIndex = -1; return -1; } this._TaskType = Spludlow.WebControls.KeyString(this.GridView1, index, "TaskType"); this._Host = Spludlow.WebControls.KeyString(this.GridView1, index, "HostId"); this._ApplicationId = Spludlow.WebControls.KeyString(this.GridView1, index, "ApplicationId"); this._Hosted = Spludlow.WebControls.KeyString(this.GridView1, index, "Hosted"); this._Thread = Spludlow.WebControls.KeyString(this.GridView1, index, "Thread"); this._QueueName = Spludlow.WebControls.KeyString(this.GridView1, index, "QueueName"); if (displayQueue == false) return index; if (this._TaskType != null) { if (this._TaskType == "Web") { this.PanelWebButtons.Visible = true; } else { this.PanelServiceButtons.Visible = true; if (this._TaskType == "Method" && this._Thread != null) { this.PanelThreadButtons.Visible = true; if (this._QueueName != null) { this.PanelQueue.Visible = true; int pageIndex = this._GetQueuePageIndex(); DataTable queueMessages = null; for (int pass = 0; pass < 2; ++pass) { queueMessages = Spludlow.MessageQueues.Query(this._Host, this._QueueName, pageIndex, this._QueuePageSize).Tables[0]; if (queueMessages.Rows.Count == 0 && pageIndex != 0) { pageIndex = 0; this._SetQueuePageIndex(pageIndex); } else { break; } } this.LiteralQueue.Text = "Queue: " + this._Host + " : " + this._QueueName + " (" + queueMessages.Rows.Count + ")"; this.GridViewQueueMessages.DataSource = queueMessages; this.GridViewQueueMessages.DataBind(); } } } } else { this.PanelServiceButtons.Visible = true; } return index; } private int _GetQueuePageIndex() { if (this.LiteralQueuePage.Text == "") this.LiteralQueuePage.Text = "1"; return Int32.Parse(this.LiteralQueuePage.Text) - 1; } private void _SetQueuePageIndex(int pageIndex) { this.LiteralQueuePage.Text = (pageIndex + 1).ToString(); } protected void GridView1_SelectedIndexChanged(object sender, EventArgs e) { this.LiteralQueuePage.Text = ""; this._SelectedValues(true); } protected void ButtonRecycleWeb_Click(object sender, EventArgs e) { this._SelectedValues(false); Spludlow.Admin.WebRecycle(this._Host, this._Hosted); this._Display(); } protected void ButtonStartWeb_Click(object sender, EventArgs e) { this._SelectedValues(false); Spludlow.Admin.WebStart(this._Host, this._Hosted); this._Display(); } protected void ButtonStopWeb_Click(object sender, EventArgs e) { this._SelectedValues(false); Spludlow.Admin.WebStop(this._Host, this._Hosted); this._Display(); } protected void ButtonStartService_Click(object sender, EventArgs e) { this._SelectedValues(false); Spludlow.Admin.ServiceStart(this._Host, this._Hosted); this._Display(); } protected void ButtonStopService_Click(object sender, EventArgs e) { this._SelectedValues(false); Spludlow.Admin.ServiceStop(this._Host, this._Hosted); this._Display(); } protected void ButtonStartThread_Click(object sender, EventArgs e) { this._SelectedValues(false); Spludlow.Service.StartThread(this._Host, this._ApplicationId, this._Thread); this._Display(); } protected void ButtonStopThread_Click(object sender, EventArgs e) { this._SelectedValues(false); Spludlow.Service.StopThread(this._Host, this._ApplicationId, this._Thread); this._Display(); } protected void ButtonParkThread_Click(object sender, EventArgs e) { this._SelectedValues(false); Spludlow.Service.ParkTask(this._Host, this._ApplicationId, this._Thread); this._Display(); } protected void ButtonUnParkThread_Click(object sender, EventArgs e) { this._SelectedValues(false); Spludlow.Service.UnParkTask(this._Host, this._ApplicationId, this._Thread); this._Display(); } protected void ButtonDeleteMessage_Click(object sender, EventArgs e) { string[] ids = Spludlow.WebControls.CheckedKeysString(this.GridViewQueueMessages, "CheckBoxMessage", "Id"); if (ids.Length == 0) { this.LabelError.Text = "Please select some messages to delete from the queue." + ids.Length; return; } if (this.CheckBoxSure.Checked == false) { this.LabelError.Text = "Please check 'Sure?' if you're sure."; return; } this._SelectedValues(false); Spludlow.MessageQueues.Delete(this._Host, this._QueueName, ids); this.CheckBoxSure.Checked = false; this._Display(); } protected void ButtonPurgeQueue_Click(object sender, EventArgs e) { if (this.CheckBoxSure.Checked == false) { this.LabelError.Text = "Please check 'Sure?' if you're sure."; return; } this._SelectedValues(false); Spludlow.MessageQueues.Purge(this._Host, this._QueueName); this.CheckBoxSure.Checked = false; this._Display(); } protected void ButtonToggle_Click(object sender, EventArgs e) { Spludlow.WebControls.ToggleCheckBoxes(this.GridViewQueueMessages, "CheckBoxMessage"); } protected void ButtonAutoStart_Click(object sender, EventArgs e) { try { Spludlow.Diagnostics.StartStoppedAllHosts(); } catch (Exception ee) { this.LabelError.Text = "Auto Start Error: " + ee.Message; } this._Display(); } protected void ButtonQueuePagePrev_Click(object sender, EventArgs e) { int pageIndex = this._GetQueuePageIndex() - 1; this._SetQueuePageIndex(pageIndex); this._Display(); } protected void ButtonQueuePageNext_Click(object sender, EventArgs e) { int pageIndex = this._GetQueuePageIndex() + 1; this._SetQueuePageIndex(pageIndex); this._Display(); } }