/// <summary> /// Assign a value that we've specified /// </summary> /// <param name="TargetObject"></param> /// <param name="FieldName"></param> /// <param name="TargetValue"></param> private void AssignValue(Object TargetObject, String FieldName, Object TargetValue) { if (TargetObject == null) { return; } try { if (TargetValue is DataRowView) { TargetValue = (TargetValue as DataRowView).Row[1]; } if (TargetValue is DBNull) { TargetValue = null; } ChangedValues.Add(FieldName); string[] splStr = FieldName.TrimEnd(']').Split('['); foreach (MemberInfo mI in TargetObject.GetType().GetMember(splStr[0])) { if (splStr.Length == 1 && mI is FieldInfo) { (mI as FieldInfo).SetValue(TargetObject, ChangeType(TargetValue, (mI as FieldInfo).FieldType)); } else if (splStr.Length == 1 && mI is PropertyInfo) { (mI as PropertyInfo).SetValue(TargetObject, ChangeType(TargetValue, (mI as PropertyInfo).PropertyType), null); } else { Array InVal; Type SingleType; if (mI is FieldInfo) { InVal = (Array)(mI as FieldInfo).GetValue(TargetObject); SingleType = (mI as FieldInfo).FieldType.GetElementType(); } else { InVal = (Array)(mI as PropertyInfo).GetValue(TargetObject, null); SingleType = (mI as PropertyInfo).PropertyType.GetElementType(); } InVal.SetValue(ChangeType(TargetValue, SingleType), int.Parse(splStr[1])); } } } catch (Exception ex) { MM_System_Interfaces.MessageBox("Error setting " + FieldName + " for " + TargetObject + "\n" + ex.ToString(), Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error); } }
/// <summary> /// This thread processes the pipe /// </summary> /// <param name="state"></param> private static void PipeHandler(object state) { //First, process any information, if it's passed via command line. if (!String.IsNullOrEmpty(CommandTSystemWiderse)) { String[] InCmd = CommandTSystemWiderse.Split(new string[] { "\\n" }, StringSplitOptions.RemoveEmptyEntries); CommandTSystemWiderse = null; ProcessCommand(InCmd); } SafeFileHandle clientPipeHandle; while (true) { //Try and create the pipe clientPipeHandle = CreateNamedPipe(PIPE_NAME, DUPLEX | FILE_FLAG_OVERLAPPED, 0, 255, BUFFER_SIZE, BUFFER_SIZE, 0, IntPtr.Zero); //failed to create named pipe if (clientPipeHandle.IsInvalid) { break; } //Indicate the success of the process if (ConnectNamedPipe(clientPipeHandle, IntPtr.Zero) != 1) { break; } //Open our stream and read everything in try { List <String> InLine = new List <string>(); using (FileStream fStream = new FileStream(clientPipeHandle, FileAccess.ReadWrite, BUFFER_SIZE, true)) using (StreamReader sRd = new StreamReader(fStream)) while (!sRd.EndOfStream) { InLine.Add(sRd.ReadLine()); } //Now, process accordingly. Command: [Zoom/Property/OneLine] [Element Type] [Name or TEID] ProcessCommand(InLine.ToArray()); } catch (Exception ex) { MM_System_Interfaces.MessageBox("Error receiving out-of-process command: " + ex.Message + "\n\n" + ex.StackTrace, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Warning); } } }
/// <summary> /// Handle the timer tick /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void UpdateTimer_Tick(object sender, EventArgs e) { pbToExcel.Value = CurrentRow; if (ExportThread.ThreadState == System.Threading.ThreadState.Stopped) { UpdateTimer.Stop(); try { Process.Start(FileName); } catch (Exception ex) { MM_System_Interfaces.MessageBox("The Excel file has been exported, but could not be opened: " + ex.Message, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Warning); } this.Close(); } }
/// <summary> /// Handle the submission of a new violation /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void SubmitButton_Click(object sender, EventArgs e) { if (SelectedElement == null) { MM_System_Interfaces.MessageBox("Please select an element to be violated.", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Information); } else { try { Data_Integration.CheckAddViolation(NewViolation); } catch (Exception ex) { MM_System_Interfaces.MessageBox("Error generating specific alarm: " + ex.Message + "\n" + ex.StackTrace, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error); } } //Now, clear our components and reset our violation NewViolation = new MM_AlarmViolation(); NewViolation.ViolatedElement = SelectedElement; foreach (Control ctl in tabViolations.Controls) { if (ctl is ComboBox) { (ctl as ComboBox).SelectedItem = null; } else if (ctl is TextBox) { (ctl as TextBox).Text = ""; } else if (ctl is CheckBox) { (ctl as CheckBox).Checked = false; } } }
/// <summary> /// Process the command /// </summary> /// <param name="InLine"></param> private static void ProcessCommand(String[] InLine) { MM_Element Element = null; if (InLine.Length == 3) { if (InLine[1].Equals("Substation", StringComparison.CurrentCultureIgnoreCase)) { MM_Substation FoundSub; if (MM_Repository.Substations.TryGetValue(InLine[2], out FoundSub)) { Element = FoundSub; } else { foreach (MM_Substation Sub in MM_Repository.Substations.Values) { if (Sub.LongName.Equals(InLine[2], StringComparison.CurrentCultureIgnoreCase)) { Element = Sub; break; } } } } else if (InLine[1].Equals("Line", StringComparison.CurrentCultureIgnoreCase)) { Element = MM_Repository.Lines[InLine[2]]; } else if (InLine[1].Equals("Contingency", StringComparison.CurrentCultureIgnoreCase)) { Element = MM_Repository.Contingencies[InLine[2]]; } else { Element = MM_Repository.LocateElement(InLine[2].Split('.')[0], InLine[2].Split('.')[1], InLine[1], ""); } } else if (InLine.Length == 2) { Int32 TryNum; if (!Int32.TryParse(InLine[1], out TryNum) || !MM_Repository.TEIDs.TryGetValue(TryNum, out Element)) { return; } } if (InLine[0].Equals("Search", StringComparison.CurrentCultureIgnoreCase)) { MM_Form_Builder.SearchDisplay(Map.ctlNetworkMap, InLine[1], false, false); } else if (InLine[0].Equals("Message", StringComparison.CurrentCultureIgnoreCase)) { MM_System_Interfaces.MessageBox("Message received: " + String.Join(" ", InLine, 1, InLine.Length - 1), Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Information); } else if (InLine[0].Equals("Zoom", StringComparison.CurrentCultureIgnoreCase)) { if (Element is MM_AlarmViolation) { Element = (Element as MM_AlarmViolation).ViolatedElement; } if (Element is MM_Substation) { Map.ctlNetworkMap.Coordinates.Center = ((Element as MM_Substation).LngLat); Map.ctlNetworkMap.Coordinates.UpdateZoom(MM_Repository.OverallDisplay.StationZoomLevel); } else if (Element is MM_Line) { Map.ctlNetworkMap.Coordinates.Center = (((Element as MM_Line).Midpoint)); Map.ctlNetworkMap.Coordinates.UpdateZoom(MM_Repository.OverallDisplay.StationZoomLevel); } else if (Element.Substation != null) { Map.ctlNetworkMap.Coordinates.Center = (Element.Substation.LngLat); Map.ctlNetworkMap.Coordinates.UpdateZoom(MM_Repository.OverallDisplay.StationZoomLevel); } } else if (InLine[0].Equals("Property", StringComparison.CurrentCultureIgnoreCase)) { MM_Form_Builder.PropertyPage(Element, Map.ctlNetworkMap); } else if (InLine[0].Equals("OneLine", StringComparison.CurrentCultureIgnoreCase)) { MM_Form_Builder.OneLine_Display(Element, Map.ctlNetworkMap); } }