/// <summary>
        /// Add an event to our user space
        /// </summary>
        /// <param name="EventTime"></param>
        /// <param name="Elem"></param>
        /// <param name="Action"></param>
        /// <param name="NewValue"></param>
        /// <param name="OldValue"></param>
        public void AddEvent(DateTime EventTime, MM_Element Elem, String Action, String OldValue, String NewValue)
        {
            if (lvHistory.InvokeRequired)
            {
                lvHistory.Invoke(new SafeAddEvent(AddEvent), EventTime, Elem, Action, OldValue, NewValue);
            }
            else
            {
                lvHistory.Items.Add(new MM_UserInteraction(AssociatedEvent.EventTime = EventTime, Elem, Action, OldValue, NewValue));
                lvHistory.AutoResizeColumns(ColumnHeaderAutoResizeStyle.ColumnContent);
                AssociatedEvent.Text = (Elem.Substation == null ? "" : Elem.Substation.Name + " ") + Elem.ElemType.Name + " " + Name;
                AssociatedEvent.ViolatedElement.Substation = MM_Repository.Substations[Elem.Substation.Name];
                if (PriorEvent)
                {
                    Data_Integration.UpdateViolation(AssociatedEvent, AssociatedEvent.Text, EventTime);
                }
                //else

                //   Data_Integration.RemoveViolation(AssociatedEvent);
                //AssociatedEvent.ViolatedElement.Substation = MM_Repository.Substations[Station];
                //AssociatedEvent.ViolatedElement.Operator = AssociatedEvent.ViolatedElement.Substation.Operator;
                //AssociatedEvent.ViolatedElement.Owner= AssociatedEvent.ViolatedElement.Substation.Owner;
                Data_Integration.CheckAddViolation(AssociatedEvent);
                PriorEvent = true;
            }
        }
示例#2
0
        /// <summary>
        /// Create a clone of our display, and show
        /// </summary>
        /// <param name="state"></param>
        private void CreateCloneOfDisplay(object state)
        {
            MemberInfo mI      = FieldToCheck == null ? (MemberInfo)PropertyToCheck : (MemberInfo)FieldToCheck;
            MM_Form    NewForm = GenerateTrackingForm(this.Title, this.ElemType, mI, Elements.ToArray());

            if (Elements.Count == 1)
            {
                NewForm.Text = this.Title + " " + Elements[0].ToString();
            }
            else
            {
                NewForm.Text = this.Title + " " + this.ElemType + " (" + Elements.Count.ToString("#,##0") + ")";
            }
            NewForm.StartPosition = FormStartPosition.Manual;
            NewForm.Location      = Cursor.Position;
            MM_LoadGen_Tracking_Operator Oper = (MM_LoadGen_Tracking_Operator)NewForm.Controls[0];

            Oper.BeginTracking();
            Oper.TrackingCurve.Clear();
            for (int a = 0; a < TrackingCurve.Points.Count; a++)
            {
                Oper.TrackingCurve.AddPoint(TrackingCurve.Points[a]);
            }
            Oper.BaseValue = BaseValue;



            Oper.zgGraph.GraphPane.XAxis.IsVisible = true;
            Oper.zgGraph.GraphPane.YAxis.IsVisible = true;
            zgGraph.AxisChange();
            zgGraph.Invalidate();
            Data_Integration.DisplayForm(NewForm, Thread.CurrentThread);
        }
示例#3
0
 /// <summary>
 /// Initialize a new island
 /// </summary>
 /// <param name="ID"></param>
 public MM_Island(int ID)
 {
     this.ID       = ID;
     this.Name     = "Island " + this.ID.ToString();
     this.ElemType = MM_Repository.FindElementType("Island");
     this.TEID     = Data_Integration.GetTEID();
     MM_Repository.TEIDs.Add(this.TEID, this);
 }
示例#4
0
 /// <summary>
 /// Remove a basecase violation
 /// </summary>
 /// <param name="BasecaseData"></param>
 public void RemoveBasecaseViolationData(MM_Basecase_Violation_Data[] BasecaseData)
 {
     foreach (MM_Basecase_Violation_Data Basecase in BasecaseData)
     {
         Data_Integration.RemoveViolation(MM_Server_Interface.CreateViolation(Basecase));
     }
     MM_Server_Interface.UpdateTimestamp(typeof(MM_Basecase_Violation_Data));
 }
示例#5
0
 /// <summary>
 /// Update our transformer outage data
 /// </summary>
 /// <param name="TransformerOutageData"></param>
 public void UpdateTransformerOutageData(MM_Outage_Transformer_Data[] TransformerOutageData)
 {
     foreach (MM_Outage_Transformer_Data TransformerData in TransformerOutageData)
     {
         Data_Integration.UpdateViolation(MM_Server_Interface.CreateViolation(TransformerData));
     }
     MM_Server_Interface.UpdateTimestamp(typeof(MM_Outage_Transformer_Data));
 }
示例#6
0
 /// <summary>
 /// Update our unit outage data
 /// </summary>
 /// <param name="UnitOutageData"></param>
 public void UpdateUnitOutageData(MM_Outage_Unit_Data[] UnitOutageData)
 {
     foreach (MM_Outage_Unit_Data UnitData in UnitOutageData)
     {
         Data_Integration.UpdateViolation(MM_Server_Interface.CreateViolation(UnitData));
     }
     MM_Server_Interface.UpdateTimestamp(typeof(MM_Outage_Unit_Data));
 }
示例#7
0
 /// <summary>
 /// Remove a line outage
 /// </summary>
 /// <param name="LineOutageData"></param>
 public void RemoveLineOutageData(MM_Outage_Line_Data[] LineOutageData)
 {
     foreach (MM_Outage_Line_Data LineOutage in LineOutageData)
     {
         Data_Integration.RemoveViolation(MM_Server_Interface.CreateViolation(LineOutage));
     }
     MM_Server_Interface.UpdateTimestamp(typeof(MM_Outage_Line_Data));
 }
示例#8
0
 /// <summary>
 /// Remove a contingency violation
 /// </summary>
 /// <param name="ContingencyData"></param>
 public void RemoveContingencyViolationData(MM_Contingency_Violation_Data[] ContingencyData)
 {
     foreach (MM_Contingency_Violation_Data Contingency in ContingencyData)
     {
         Data_Integration.RemoveViolation(MM_Server_Interface.CreateViolation(Contingency));
     }
     MM_Server_Interface.UpdateTimestamp(typeof(MM_Contingency_Violation_Data));
 }
 /// <summary>
 /// Instantiate a comm viewer
 /// </summary>
 /// <param name="state">The state of the form</param>
 private static void InstantiateForm(object state)
 {
     object[] State = (object[])state;
     using (MM_LoadGen_Tracking oDisp = new MM_LoadGen_Tracking(State[1] as MM_Network_Map_DX))
     {
         (State[0] as ToolStripMenuItem).Tag = oDisp;
         Data_Integration.DisplayForm(oDisp, Thread.CurrentThread);
     }
 }
示例#10
0
 /// <summary>
 /// Instantiate a comm viewer
 /// </summary>
 /// <param name="state">The state of the form</param>
 private static void InstantiateForm(object state)
 {
     object[] State = (object[])state;
     using (MM_Operatorship_Display oDisp = new MM_Operatorship_Display(State[1] as MM_Network_Map_GDI))
     {
         (State[0] as ToolStripMenuItem).Tag = oDisp;
         Data_Integration.DisplayForm(oDisp, Thread.CurrentThread);
     }
 }
示例#11
0
 /// <summary>
 /// Instantiate a comm viewer
 /// </summary>
 /// <param name="state">The state of the form</param>
 private static void InstantiateForm(object state)
 {
     object[] State = (object[])state;
     using (MM_EMS_Command_Display bDisp = new MM_EMS_Command_Display(State[1] as MM_Network_Map_DX))
     {
         (State[0] as ToolStripMenuItem).Tag = bDisp;
         Data_Integration.DisplayForm(bDisp, Thread.CurrentThread);
     }
 }
示例#12
0
        /// <summary>
        /// Update our line outage data
        /// </summary>
        /// <param name="LineOutageData"></param>
        public void UpdateLineOutageData(MM_Outage_Line_Data[] LineOutageData)
        {
            foreach (MM_Outage_Line_Data LineData in LineOutageData)
            {
                Data_Integration.UpdateViolation(MM_Server_Interface.CreateViolation(LineData));
            }

            MM_Server_Interface.CheckForOutagedLines();

            MM_Server_Interface.UpdateTimestamp(typeof(MM_Outage_Line_Data));
        }
示例#13
0
 /// <summary>
 /// Handle exporting to Excel
 /// </summary>
 private void ExportToExcel()
 {
     using (SaveFileDialog sFd = new SaveFileDialog())
     {
         sFd.Title  = "Export Excel spreadsheet";
         sFd.Filter = "Excel 2007 Workbook (*.xlsx)|*.xlsx";
         if (sFd.ShowDialog() == DialogResult.OK)
         {
             Data_Integration.DisplayForm(new MM_Excel_Exporter(BaseData.Data, sFd.FileName), Thread.CurrentThread);
         }
     }
 }
示例#14
0
 /// <summary>
 /// Create a new note, and if selected, upload it.
 /// </summary>
 /// <param name="NoteElement">The element about which the note is being written</param>
 public static void CreateNote(MM_Element NoteElement)
 {
     using (MM_Note_Writer NewNote = new MM_Note_Writer(NoteElement))
         if (NewNote.ShowDialog() == DialogResult.OK)
         {
             MM_Note OutNote = NewNote.CreatedNote;
             if (MM_Server_Interface.Client != null)
             {
                 OutNote.ID = MM_Server_Interface.Client.UploadNote(OutNote);
             }
             Data_Integration.HandleNoteEntry(OutNote);
         }
 }
 /// <summary>
 /// Initialize a new user event tracking window
 /// </summary>
 /// <param name="UserName"></param>
 /// <param name="EventTime"></param>
 public MM_UserInteraction_Viewer(String UserName, DateTime EventTime)
 {
     InitializeComponent();
     this.Text = "Event log: " + UserName;
     lvHistory.ListViewItemSorter = new MM_UserInteraction_Sorter(0, true);
     ShowInTaskbar                            = true;
     lvHistory.FullRowSelect                  = true;
     AssociatedEvent                          = new MM_AlarmViolation();
     AssociatedEvent.EventTime                = EventTime;
     AssociatedEvent.New                      = true;
     AssociatedEvent.Type                     = MM_Repository.ViolationTypes["UserAction"];
     AssociatedEvent.ViolatedElement          = new MM_Element();
     AssociatedEvent.ViolatedElement.ElemType = MM_Repository.FindElementType("User");
     AssociatedEvent.ViolatedElement.Name     = UserName;
     AssociatedEvent.ViolatedElement.TEID     = Data_Integration.GetTEID();
 }
示例#16
0
        /// <summary>
        /// Handle an island simulation removal
        /// </summary>
        /// <param name="IslandData"></param>
        public void HandleIslandSimulationRemoval(MM_Island_Simulation_Data[] IslandData)
        {
            MM_Island FoundIsland;

            foreach (MM_Island_Simulation_Data Island in IslandData)
            {
                if (MM_Repository.Islands.TryGetValue(Island.Isl_Num, out FoundIsland))
                {
                    FoundIsland.Frequency = FoundIsland.Generation = FoundIsland.Load = float.NaN;
                    MM_Repository.Islands.Remove(Island.Isl_Num);
                    Data_Integration.HandleIslandRemoval(FoundIsland);
                }
            }
            MM_Server_Interface.UpdateTimestamp(typeof(MM_Island_Simulation_Data));
            Data_Integration.OverallIndicators[(int)Data_Integration.OverallIndicatorEnum.IslandCount] = MM_Repository.Islands.Count;
        }
示例#17
0
        /// <summary>
        /// Initialize a new remedial action scheme against an XML element
        /// </summary>
        /// <param name="xElem"></param>
        /// <param name="AddIfNew">Whether to add any new elements that may be created</param>
        public MM_RemedialActionScheme(XmlElement xElem, bool AddIfNew)
            : base(xElem, AddIfNew)
        {
            this.ElemType = MM_Repository.FindElementType("RemedialActionScheme");
            List <MM_Element> Elements = new List <MM_Element>();

            foreach (XmlElement xChild in xElem.ChildNodes)
            {
                if (xChild.Name == "Breaker" || xChild.Name == "Switch")
                {
                    Elements.Add(Data_Integration.LocateElement(xChild, typeof(MM_Breaker_Switch), true));
                }
                else
                {
                    Elements.Add(Data_Integration.LocateElement(xChild, Type.GetType("Macomber_Map.Data_Elements.MM_" + xChild.Name), true));
                }
            }
            RASElements = Elements.ToArray();
        }
        /// <summary>
        /// When we try and log in to a new server, update accordingly.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void lvMacomberMapServers_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            ListViewHitTestInfo hti = lvMacomberMapServers.HitTest(e.Location);
            Exception           LoginError;

            if (hti.Item != null)
            {
                try
                {
                    MM_Server_Interface.Client.InnerChannel.Close();
                }
                catch
                { }
                if (MM_Server_Interface.TryLoginAgain(hti.Item.Text, ((MM_Server_Information)hti.Item.Tag).ServerURI, out LoginError))
                {
                    Data_Integration.RestartModel(MM_Server_Interface.Client);
                }
                else
                {
                    MessageBox.Show("Unable to log into Macomber Map Server: " + LoginError.Message, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
示例#19
0
        /// <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;
                }
            }
        }
示例#20
0
        static void Main(params string[] args)
        {
            // CreateModelXml user password filepath (Build thMM_System_Interfacesis as a console app for this job).
            if (args.Length > 0 && args[0].Equals("CreateModelXml", StringComparison.OrdinalIgnoreCase))
            {
                try
                {
                    System.Console.Error.WriteLine("Starting XML Model creator client");
                    MM_Server_Interface.LoadModelFromSql = true;
                    MM_System_Interfaces.Headless        = true;
                    MM_Repository.OverallDisplay         = new MM_Display();
                    MM_Coordinates coord = new MM_Coordinates(-109f, 29f, -86f, 51f, 1f);

                    System.Console.Error.WriteLine("Waiting for server...");
                    while (MM_Server_Interface.MMServers == null || MM_Server_Interface.MMServers.Count == 0)
                    {
                        Thread.Sleep(3000);
                    }

                    var list = MM_Server_Interface.MMServers.Values.ToList();

                    System.Console.Error.WriteLine("Connecting to server: " + list[0].ServerName);

                    string user     = "******";
                    string password = "";
                    string file     = "MacomberMap-Combined.MM_Model";

                    if (args.Length > 1)
                    {
                        if (args[1].EndsWith(".MM_Model"))
                        {
                            file = args[1];
                        }
                        else
                        {
                            user = args[1];
                        }
                    }
                    if (args.Length > 2)
                    {
                        if (args[2].EndsWith(".MM_Model"))
                        {
                            file = args[2];
                        }
                        else
                        {
                            password = args[2];
                        }
                    }
                    if (args.Length > 3)
                    {
                        file = args[3];
                    }
                    Exception exp = new Exception();
                    MM_Server_Interface.TryLogin(list[0].ServerName, list[0].ServerURI, user, password, out exp);
                    MM_Server_Interface.LoadMacomberMapConfiguration();

                    Data_Integration.InitializationComplete = false;
                    System.Console.Error.WriteLine("Starting SQL Model Loader...");
                    SqlModelLoader sqlModelLoader = new SqlModelLoader();
                    sqlModelLoader.ConnectionString = Settings.Default.ModelDatabase;
                    sqlModelLoader.LoadStaticRepository();
                    System.Console.Error.WriteLine("Rolling up Elements...");
                    Data_Integration.UseEstimates = false;
                    Data_Integration.RollUpElementsToSubstation();
                    Data_Integration.CommLoaded                 = true;
                    Data_Integration.ModelLoadCompletion        = DateTime.Now;
                    Data_Integration.NetworkSource              = new MM_Data_Source();
                    Data_Integration.NetworkSource.Estimates    = false;
                    Data_Integration.NetworkSource.Database     = "NETMOM";
                    Data_Integration.NetworkSource.Application  = "RTNET";
                    Data_Integration.NetworkSource.BackColor    = Color.Blue;
                    Data_Integration.NetworkSource.Telemetry    = true;
                    Data_Integration.NetworkSource.Default      = true;
                    Data_Integration.NetworkSource.Master       = true;
                    Data_Integration.NetworkSource.ViolationApp = "RTCA";
                    Data_Integration.InitializationComplete     = true;
                    // Data_Integration.RestartModel(MM_Server_Interface.Client);
                    Data_Integration.SaveXMLData(file, coord);
                    System.Console.WriteLine("Waiting for data...");
                    for (int i = 0; i < 60 * 8; i++)
                    {
                        System.Console.Write(".");
                        Thread.Sleep(1000); // wait for EMS data to flow in.
                    }
                    Data_Integration.SaveXMLData(file, coord);
                }
                catch (Exception ex)
                {
                    System.Console.Error.WriteLine(ex.Message);
                    System.Console.Error.WriteLine(ex.StackTrace);
                    System.Environment.Exit(1);
                }
                System.Environment.Exit(0);
            }

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.ThreadException += Application_ThreadException;
            //   Application.Run(new frmControlTester());
            // return;
            try
            {
                Microsoft.Win32.RegistryKey key;
                key = Microsoft.Win32.Registry.LocalMachine.OpenSubKey("SOFTWARE").OpenSubKey("Policies", true);

                if (!key.GetSubKeyNames().Contains("Chromium"))
                {
                    key.CreateSubKey("Chromium");
                }
                key = key.OpenSubKey("Chromium", true);
                if (!key.GetSubKeyNames().Contains("EnabledPlugins"))
                {
                    key.CreateSubKey("EnabledPlugins");
                }
                key = key.OpenSubKey("EnabledPlugins", true);

                if (!key.GetValueNames().Contains("1"))
                {
                    key.SetValue("1", "Silverlight*");
                    key.SetValue("2", "npapi");
                }
            }
            catch (Exception ex)
            {
                MM_System_Interfaces.LogError(ex);
            }
            if (Environment.CommandLine.IndexOf("/Test", StringComparison.CurrentCultureIgnoreCase) != -1)
            {
                Application.Run(new frmTest());
            }
            else
            {
                using (MM_Startup_Form Startup = new MM_Startup_Form())
                    if (Startup.ShowDialog(StartNetworkMap) == DialogResult.OK)
                    {
                        Application.Run();
                    }
                    else
                    {
                        Application.Exit();
                    }
            }
        }
示例#21
0
 /// <summary>
 /// Add an EMS command
 /// </summary>
 /// <param name="Command"></param>
 public void AddEMSCommands(MM_EMS_Command[] Command)
 {
     Data_Integration.HandleEMSCommands(Command);
 }
示例#22
0
        /// <summary>
        /// Determine our next question
        /// </summary>
        public void NextQuestion()
        {
            //First, determine what our current level should be, and by threshold move to the next level if needed
            MM_Training_Level FoundLevel;

            if (CurrentLevel == null)
            {
                PriorLevel = null;
                if (!Levels.TryGetValue(0, out FoundLevel))
                {
                    TrainingMode = enumTrainingMode.NotTraning;
                    return;
                }
                else
                {
                    CurrentLevel = FoundLevel;
                }
            }
            else if (LevelScore >= CurrentLevel.ExitThresholdScore && QuestionsRight >= CurrentLevel.NumberOfQuestions)
            {
                if (!Levels.TryGetValue(CurrentLevel.ID + 1, out FoundLevel))
                {
                    MessageTime  = DateTime.Now;
                    TrainingMode = enumTrainingMode.UserWon;
                    return;
                }
                else
                {
                    CurrentLevel = FoundLevel;
                }
            }

            else if (QuestionsWrong >= CurrentLevel.FailureThreshold)
            {
                MessageTime  = DateTime.Now;
                TrainingMode = enumTrainingMode.UserFailed;
                return;
            }



            //Based on our question, determine our next
            if (PriorLevel != CurrentLevel)
            {
                PrepareLevel();
            }

            //If we have no elements, assume we won
            if (AvailableElements.Length == 0)
            {
                TrainingMode = enumTrainingMode.UserWon;
                return;
            }

            //Pick random elements based on our needs
            TargetElement = AvailableElements[rnd.Next(0, AvailableElements.Length)];
            if (TargetElement is MM_Line || TargetElement is MM_Substation)
            {
            }
            else
            {
                TargetElement = TargetElement.Substation;
            }

            //Now, handle our target element
            if (TargetElement is MM_Substation)
            {
                MM_Substation TargetSub = (MM_Substation)TargetElement;
                QuestionText = "Where is substation " + TargetSub.LongName + (String.Equals(TargetSub.LongName, TargetSub.Name, StringComparison.CurrentCultureIgnoreCase) ? "?" : " (" + TargetSub.Name + ")?");
            }
            else if (TargetElement is MM_Line)
            {
                MM_Line TargetLine = (MM_Line)TargetElement;
                QuestionText = "Where is line " + TargetLine.Name + " (from " + TargetLine.Substation1.LongName + " to " + TargetLine.Substation2.LongName + ")?";
            }
            else
            {
                QuestionText = "Where is " + TargetElement.ElemType.Name + " " + TargetElement.Name + "?";
            }
            Data_Integration.ReportSystemLevelData(QuestionText);
            TrainingMode          = enumTrainingMode.QuestionAsked;
            TimeQuestionPresented = DateTime.Now;
        }
 /// <summary>
 /// Instantiate a comm viewer
 /// </summary>
 /// <param name="state">The state of the form</param>
 private static void InstantiateForm(object state)
 {
     CommViewer = new MM_Communication_Viewer(state as MM_Communication_Status);
     Data_Integration.DisplayForm(CommViewer, Thread.CurrentThread);
 }
示例#24
0
 /// <summary>
 /// Display an about form in its own thread
 /// </summary>
 /// <param name="state"></param>
 private static void DisplayAboutForm(object state)
 {
     using (MM_About_Form frmAbout = new MM_About_Form())
         Data_Integration.DisplayForm(frmAbout, Thread.CurrentThread);
 }
示例#25
0
 /// <summary>
 /// When the user proceeds to shut down the form, automatically kill the process
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void MacomberMap_FormClosing(object sender, FormClosingEventArgs e)
 {
     Data_Integration.ShutDown();
     System.Diagnostics.Process.GetCurrentProcess().Kill();
 }
示例#26
0
 private void ReloadModel()
 {
     MM_Server_Interface.LoadNetworkModel();
     Data_Integration.RestartModel(MM_Server_Interface.Client);
 }