/// <summary> /// Initialize a new reserve viewer /// </summary> public MM_Limit_Reserve_Viewer(XmlElement BaseElement) { InitializeComponent(); this.DoubleBuffered = true; foreach (MM_Reserve Reserve in Data_Integration.Reserves.Values) { Reserve.CreateDisplayItem(lv); } //Add in our historical viewer MM_Historic_Viewer hv = new MM_Historic_Viewer(MM_Historic_Viewer.GraphModeEnum.HistoricalOnly, BaseElement.Attributes["PIQueries"].Value.Split(','), new string[] { }, ""); hv.Dock = DockStyle.Fill; tpHistoric.Controls.Add(hv); }
/// <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) "); } } }