/// <summary> /// Execute the command within its own thread /// </summary> /// <param name="Elem"></param> /// public void Execute(MM_Element Elem) { //Thread.CurrentThread.SetApartmentState(ApartmentState.STA); String InCmd = Command; //Replace the {word} with the values for that element int Bracket = InCmd.IndexOf("{"); while (Bracket > -1) { String InWord = InCmd.Substring(Bracket + 1, InCmd.IndexOf("}", Bracket) - Bracket - 1); Object InValue = null; foreach (MemberInfo mI in Elem.GetType().GetMember(InWord)) { if (mI is FieldInfo) { InValue = (mI as FieldInfo).GetValue(Elem); } else if (mI is PropertyInfo) { InValue = (mI as PropertyInfo).GetValue(Elem, null); } } InCmd = InCmd.Substring(0, Bracket) + InValue.ToString() + InCmd.Substring(InCmd.IndexOf('}', Bracket) + 1); Bracket = InCmd.IndexOf("{"); } //Now, send our command if appropriate if (MM_Server_Interface.SendCommand(InCmd, "") == CheckState.Unchecked) { MessageBox.Show("Unable to send command. Please retry.", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error); } }
/// <summary> /// Handle the selection of an item /// </summary> /// <param name="SelectedElement"></param> private void srMain_ItemSelectionChanged(MM_Element SelectedElement) { try { this.SelectedElement = SelectedElement; NewViolation.ViolatedElement = SelectedElement; Button Trigger1 = new Button(), Trigger2 = new Button(); Trigger1.Text = Trigger2.Text = "Trigger Value Change"; Trigger1.AutoSize = Trigger2.AutoSize = true; Trigger1.Location = new Point(13, 8); Trigger1.Click += new EventHandler(TriggerUpdate); Trigger2.Click += new EventHandler(TriggerUpdate); ChangedValues.Clear(); int CurTop = Trigger1.Bottom + 5; SortedDictionary <String, MemberInfo> Members = new SortedDictionary <string, MemberInfo>(); if (SelectedElement != null) { foreach (MemberInfo mI in SelectedElement.GetType().GetMembers()) { if (mI is FieldInfo || (mI is PropertyInfo && (mI as PropertyInfo).CanRead && (mI as PropertyInfo).CanWrite)) { Members.Add(mI.Name, mI); } } } Label NewLabel; Control NewControl; List <Label> Labels = new List <Label>(); List <Control> Controls = new List <Control>(); if (SelectedElement != null) { Controls.Add(Trigger1); } foreach (MemberInfo mI in Members.Values) { if (mI.Name != "TEID") { Object inVal = null; Type inType = null; if (mI is PropertyInfo) { inVal = (mI as PropertyInfo).GetValue(SelectedElement, null); inType = (mI as PropertyInfo).PropertyType; } else if (mI is FieldInfo) { inVal = (mI as FieldInfo).GetValue(SelectedElement); inType = (mI as FieldInfo).FieldType; } if (inType.IsArray) { int ThisVal = 0; if (inVal != null) { foreach (Object inObj in inVal as System.Collections.IEnumerable) { if (ThisVal <= 10) { if (AddComponent(mI.Name + "[" + ThisVal++ + "]", inObj.GetType(), inObj, ref CurTop, out NewLabel, out NewControl)) { Labels.Add(NewLabel); Controls.Add(NewControl); } } } } } else if (inVal is System.Collections.IDictionary || inVal is System.Collections.IList) { } else if (AddComponent(mI.Name, inType, inVal, ref CurTop, out NewLabel, out NewControl)) { Labels.Add(NewLabel); Controls.Add(NewControl); } } } Trigger2.Top = CurTop; if (SelectedElement != null) { Controls.Add(Trigger2); } tabValueUpdates.Controls.Clear(); tabValueUpdates.SuspendLayout(); if (Labels.Count > 0) { tabValueUpdates.Controls.AddRange(Labels.ToArray()); } int MaxWidth = 0; foreach (Label lbl in Labels) { MaxWidth = Math.Max(MaxWidth, lbl.Width); } foreach (Control ctl in Controls) { ctl.Left = Labels[0].Left + MaxWidth + 5; ctl.Width = tabValueUpdates.ClientRectangle.Width - ctl.Left - 25; } tabValueUpdates.Controls.AddRange(Controls.ToArray()); tabValueUpdates.ResumeLayout(); } catch { } }
/// <summary> /// Assign a new element to the property page /// </summary> /// <param name="Element"></param> public void SetElement(MM_Element Element) { //Don't go through the work of reassigning the same element this.ImageList = MM_Repository.ViolationImages; if ((Element != null) && (this.Element == Element)) { return; } //Assign the element this.Element = Element; //Clear all tabs this.TabPages.Clear(); if (Element == null) { SetStyle(ControlStyles.UserPaint, true); } else { //Reset to our default style SetDefaultStyle(); //Now add in the information from our XML configuration file for this item. TabPage LocalPage = new TabPage(Element.ElemType.Name + " " + Element.Name); this.TabPages.Add(LocalPage); TreeView NewView = new TreeView(); NewView.NodeMouseClick += new TreeNodeMouseClickEventHandler(NewView_NodeMouseClick); NewView.Dock = DockStyle.Fill; SortedDictionary <String, Object> InValues = new SortedDictionary <string, object>(StringComparer.CurrentCultureIgnoreCase); InValues.Add("Name", Element.Name); if (Element.Substation != null) { InValues.Add("Substation", Element.Substation); } if (Element.KVLevel != null) { InValues.Add("KV Level", Element.KVLevel); } //Now, pull in all of the members MemberInfo[] inMembers = Element.GetType().GetMembers(); foreach (MemberInfo mI in inMembers) { try { if (mI.Name != "Coordinates" && !InValues.ContainsKey(mI.Name)) { if (mI is FieldInfo) { InValues.Add(mI.Name, ((FieldInfo)mI).GetValue(Element)); } else if (mI is PropertyInfo) { InValues.Add(mI.Name, ((PropertyInfo)mI).GetValue(Element, null)); } } } catch (Exception ex) { MM_System_Interfaces.LogError(ex); } } //Now, handle our information MM_AlarmViolation_Type ViolTmp; foreach (KeyValuePair <String, Object> kvp in InValues) { try { AddValue(kvp.Key, kvp.Value, NewView.Nodes, out ViolTmp); } catch (Exception ex) { } } if (Element is MM_Substation) { TreeNode LineNode = NewView.Nodes.Add("Lines"); Dictionary <MM_KVLevel, List <MM_Line> > Lines = new Dictionary <MM_KVLevel, List <MM_Line> >(); foreach (MM_Line TestLine in MM_Repository.Lines.Values) { if (TestLine.Permitted) { if (Array.IndexOf(TestLine.ConnectedStations, Element) != -1) { if (!Lines.ContainsKey(TestLine.KVLevel)) { Lines.Add(TestLine.KVLevel, new List <MM_Line>()); } Lines[TestLine.KVLevel].Add(TestLine); } } } foreach (KeyValuePair <MM_KVLevel, List <MM_Line> > kvp in Lines) { TreeNode KVNode = LineNode.Nodes.Add(kvp.Key.ToString()); foreach (MM_Line LineToAdd in kvp.Value) { (KVNode.Nodes.Add(LineToAdd.MenuDescription()) as TreeNode).Tag = LineToAdd; } } } if (Element.Violations.Count > 0) { TreeNode NewNode = NewView.Nodes.Add("Violations"); foreach (MM_AlarmViolation Viol in Element.Violations.Values) { TreeNode ViolNode = (NewNode.Nodes.Add(Viol.MenuDescription()) as TreeNode); ViolNode.Tag = Viol; ViolNode.ImageIndex = Viol.Type.ViolationIndex; } } LocalPage.Controls.Add(NewView); //Add in our tracking option TabPage TrackingPage = new TabPage(); TrackingPage.Text = "Tracking"; this.TabPages.Add(TrackingPage); FlowLayoutPanel flpTrack = new FlowLayoutPanel(); flpTrack.ForeColor = Color.White; flpTrack.BackColor = Color.Black; flpTrack.AutoScroll = true; flpTrack.Dock = DockStyle.Fill; TrackingPage.Controls.Add(flpTrack); foreach (MemberInfo mI in Element.GetType().GetMembers(BindingFlags.Instance | BindingFlags.Public | BindingFlags.FlattenHierarchy)) { if ((mI is FieldInfo && ((FieldInfo)mI).FieldType == typeof(float)) || (mI is PropertyInfo && ((PropertyInfo)mI).PropertyType == typeof(float))) { MM_LoadGen_Tracking_Operator Oper = new MM_LoadGen_Tracking_Operator(mI.Name, Element.ElemType, mI); Oper.Elements.Add(Element); flpTrack.Controls.Add(Oper); Oper.BeginTracking(); } } if (!string.IsNullOrWhiteSpace(Element.HistoricServerPath) && HistoricServerUrl != null && HistoricServerUrl.Length > 2) { try { if (!HistoricServerUrl.EndsWith("/")) { HistoricServerUrl += "/"; } TabPage historyPage = new TabPage(); historyPage.Text = "HistoricServer"; this.TabPages.Add(historyPage); string url = HistoricServerUrl + @"/#/Displays/Adhoc?DataItems=" + TranslateElementPath(Element.HistoricServerPath) + "&mode=kiosk&hideToolBar"; browser = new ChromiumWebBrowser(url); browser.RequestHandler = rh; historyPage.Controls.Add(browser); } catch (Exception ex) { MM_System_Interfaces.LogError(ex); } } //If we have historic data access, add a history tab if (MM_Server_Interface.Client != null) { TabPage NewPage = new TabPage(); NewPage.Text = "History"; this.TabPages.Add(NewPage); MM_Historic_Viewer hView = new MM_Historic_Viewer(MM_Historic_Viewer.GraphModeEnum.HistoricalOnly, MM_Historic_Viewer.GetMappings(Element), new string[] { }, ""); hView.Dock = DockStyle.Fill; NewPage.Controls.Add(hView); SelectedTab = NewPage; if (this.Parent.Controls.Count == 1) { TabPage NewPage2 = new TabPage(); NewPage2.Text = "Switch orientation"; this.TabPages.Add(NewPage2); } } if (((Element is MM_Unit && !string.IsNullOrWhiteSpace(((MM_Unit)Element).MarketResourceName)) || (Element is MM_Contingency && ((MM_Contingency)Element).Type == "Flowgate")) && FlowgateUrl != null && FlowgateUrl.Length > 2) { try { if (!FlowgateUrl.EndsWith("/")) { FlowgateUrl += "/"; } TabPage FlowgatePage = new TabPage(); FlowgatePage.Text = "Flowgate"; this.TabPages.Add(FlowgatePage); string url = ""; if (Element is MM_Unit) { url = FlowgateUrl + @"#/rc/gendetails?item=" + Element.Operator.Name.Replace("TOPOLOGY.", "") + "." + ((MM_Unit)Element).MarketResourceName; } else if (Element is MM_Contingency) { url = FlowgateUrl + @"#/rc/flowgatedetails?flowgate=" + ((MM_Contingency)Element).Name; } cbrowser = new ChromiumWebBrowser(url); cbrowser.RequestHandler = rh; cbrowser.LoadError += Cbrowser_LoadError; FlowgatePage.Controls.Add(cbrowser); SelectedTab = FlowgatePage; } catch (Exception ex) { MM_System_Interfaces.LogError(ex); } } this.Visible = true; this.BringToFront(); //If we're sharing this control with another, offer a back button if (this.Parent.Controls.Count != 1) { this.TabPages.Add("(back) "); } } }
/// <summary> /// Refresh the data for a data row /// </summary> /// <param name="RowToUpdate">The row to be modified</param> /// <param name="Elem">The element associated with the row</param> private void RefreshData(DataRow RowToUpdate, MM_Element Elem) { //Now go through, and pull in the unique characteristics for each item MemberInfo[] inMembers = Elem.GetType().GetMembers();//BindingFlags.Instance | BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.GetField | BindingFlags.GetProperty); foreach (MemberInfo mI in inMembers) { try { //First, pull in our values Type PropType = null; Object PropValue = null; if (mI is FieldInfo) { PropType = ((FieldInfo)mI).FieldType; PropValue = ((FieldInfo)mI).GetValue(Elem); } else if (mI is PropertyInfo) { PropType = ((PropertyInfo)mI).PropertyType; PropValue = ((PropertyInfo)mI).GetValue(Elem, null); } if (PropValue == null) { } else if (PropValue is PointF) { UpdateRowData(RowToUpdate, mI.Name + ".Latitude", typeof(Single), ((PointF)PropValue).Y); UpdateRowData(RowToUpdate, mI.Name + ".Longitude", typeof(Single), ((PointF)PropValue).X); } else if (PropValue is MM_Substation) { UpdateRowData(RowToUpdate, mI.Name, typeof(String), (PropValue as MM_Substation).LongName); } else if (PropValue is MM_Element) { UpdateRowData(RowToUpdate, mI.Name, typeof(String), (PropValue as MM_Element).Name); } else if (PropValue is MM_DisplayParameter) { UpdateRowData(RowToUpdate, mI.Name, typeof(String), (PropValue as MM_DisplayParameter).Name); } else if (PropValue is Single[]) { Single[] TSystemWiderse = (Single[])PropValue; String[] Descriptor = new string[TSystemWiderse.Length]; if (TSystemWiderse.Length == 2) { Descriptor[0] = mI.Name + " [From]"; Descriptor[1] = mI.Name + " [To]"; } else if (TSystemWiderse.Length == 3) { Descriptor[0] = mI.Name + " [Norm]"; Descriptor[1] = mI.Name + " [2 Hour]"; Descriptor[2] = mI.Name + " [15 Min]"; } else { for (int a = 0; a < TSystemWiderse.Length; a++) { Descriptor[a] = mI.Name + " [" + a.ToString("#,##0") + "]"; } } for (int a = 0; a < TSystemWiderse.Length; a++) { UpdateRowData(RowToUpdate, Descriptor[a], typeof(Single), TSystemWiderse[a]); } } else { UpdateRowData(RowToUpdate, mI.Name, PropType, PropValue); } } catch { } } }