Beispiel #1
0
        private void ProcessCrew(IncidentReport report, Crew crew)
        {
            do
            {
                try
                {
                    if (IMSClient.State == CommunicationState.Created)
                    {
                        IMSClient.Open();
                    }

                    if (IMSClient.Ping())
                    {
                        break;
                    }
                }
                catch (Exception e)
                {
                    //Console.WriteLine(e);
                    Console.WriteLine("ProcessCrew() -> IMS is not available yet.");
                    if (IMSClient.State == CommunicationState.Faulted)
                    {
                        NetTcpBinding binding = new NetTcpBinding();
                        binding.CloseTimeout           = TimeSpan.FromMinutes(10);
                        binding.OpenTimeout            = TimeSpan.FromMinutes(10);
                        binding.ReceiveTimeout         = TimeSpan.FromMinutes(10);
                        binding.SendTimeout            = TimeSpan.FromMinutes(10);
                        binding.MaxReceivedMessageSize = Int32.MaxValue;
                        IMSClient = new IMSClient(new EndpointAddress("net.tcp://localhost:6090/IncidentManagementSystemService"), binding);
                    }
                }

                Thread.Sleep(1000);
            } while (true);

            Publisher publisher = new Publisher();

            report.Id = IMSClient.GetReport(report.Time).Id;

            if (report != null)
            {
                if (report.Crewtype == CrewType.Investigation)
                {
                    crew.Working             = true;
                    report.InvestigationCrew = crew;
                    report.RepairCrew        = new Crew();
                    report.CurrentValue      = 0;
                    report.MaxValue          = 4;
                    report.IncidentState     = IncidentState.INVESTIGATING;

                    publisher.PublishIncident(report);

                    Thread.Sleep(TimeSpan.FromSeconds(4));

                    var rnd        = new Random(DateTime.Now.Second);
                    int repairtime = rnd.Next(30, 180);

                    Array             values = Enum.GetValues(typeof(ReasonForIncident));
                    Random            rand   = new Random();
                    ReasonForIncident res    = (ReasonForIncident)values.GetValue(rand.Next(1, values.Length));

                    report.Reason     = res;
                    report.RepairTime = TimeSpan.FromMinutes(repairtime);
                    report.CrewSent   = true;
                    crew.Working      = false;

                    report.IncidentState = IncidentState.READY_FOR_REPAIR;
                    report.Crewtype      = CrewType.Repair;
                }
                else if (report.Crewtype == CrewType.Repair)
                {
                    crew.Working         = true;
                    report.RepairCrew    = crew;
                    report.CurrentValue  = 0;
                    report.MaxValue      = report.RepairTime.TotalMinutes / 10;
                    report.IncidentState = IncidentState.REPAIRING;

                    publisher.PublishIncident(report);

                    Thread.Sleep(TimeSpan.FromSeconds(report.RepairTime.TotalMinutes / 10));

                    crew.Working         = false;
                    report.IncidentState = IncidentState.REPAIRED;

                    Switch sw = null;
                    foreach (var item in DMSService.Instance.Tree.Data.Values)
                    {
                        if (item.MRID == report.MrID)
                        {
                            sw          = (Switch)item;
                            sw.Incident = false;

                            if (item.UnderSCADA)
                            {
                                sw.CanCommand = true;
                                break;
                            }
                            else
                            {
                                sw.State = SwitchState.Closed;
                                ElementStateReport elementStateReport = new ElementStateReport()
                                {
                                    MrID = sw.MRID, Time = DateTime.UtcNow, State = 0
                                };
                                IMSClient.AddElementStateReport(elementStateReport);

                                List <UIUpdateModel> networkChange = new List <UIUpdateModel>();
                                if (EnergizationAlgorithm.TraceUp((Node)DMSService.Instance.Tree.Data[sw.End1], DMSService.Instance.Tree))
                                {
                                    networkChange.Add(new UIUpdateModel(sw.ElementGID, true, OMSSCADACommon.States.CLOSED));
                                    sw.Marker = true;
                                    Node n = (Node)DMSService.Instance.Tree.Data[sw.End2];
                                    n.Marker = true;
                                    networkChange.Add(new UIUpdateModel(n.ElementGID, true));
                                    networkChange = EnergizationAlgorithm.TraceDown(n, networkChange, true, false, DMSService.Instance.Tree);
                                }
                                else
                                {
                                    networkChange.Add(new UIUpdateModel(sw.ElementGID, false, OMSSCADACommon.States.CLOSED));
                                }

                                publisher.PublishUpdateDigital(networkChange);
                                break;
                            }
                        }
                    }
                }

                IMSClient.UpdateReport(report);

                publisher.PublishIncident(report);
            }
        }
Beispiel #2
0
        private void ProcessCrew(IncidentReport report)
        {
            bool isImsAvailable = false;

            do
            {
                try
                {
                    if (IMSClient.State == CommunicationState.Created)
                    {
                        IMSClient.Open();
                    }

                    isImsAvailable = IMSClient.Ping();
                }
                catch (Exception e)
                {
                    //Console.WriteLine(e);
                    Console.WriteLine("ProcessCrew() -> IMS is not available yet.");
                    if (IMSClient.State == CommunicationState.Faulted)
                    {
                        IMSClient = new IMSClient(new EndpointAddress("net.tcp://localhost:6090/IncidentManagementSystemService"));
                    }
                }
                Thread.Sleep(2000);
            } while (!isImsAvailable);

            report.Id = IMSClient.GetReport(report.Time).Id;

            if (report != null)
            {
                var rnd        = new Random(DateTime.Now.Second);
                int repairtime = rnd.Next(5, 180);

                Thread.Sleep(repairtime * 100);

                Switch sw = null;
                foreach (var item in DMSService.Instance.Tree.Data.Values)
                {
                    if (item.MRID == report.MrID)
                    {
                        sw            = (Switch)item;
                        sw.CanCommand = true;
                        break;
                    }
                }

                Array             values = Enum.GetValues(typeof(CrewResponse));
                Random            rand   = new Random();
                ReasonForIncident res    = (ReasonForIncident)values.GetValue(rand.Next(1, values.Length));

                report.Reason     = res;
                report.RepairTime = TimeSpan.FromMinutes(repairtime);
                report.CrewSent   = true;

                Array values1 = Enum.GetValues(typeof(IncidentState));
                report.IncidentState = (IncidentState)values1.GetValue(rand.Next(2, values.Length - 1));

                IMSClient.UpdateReport(report);

                Publisher publisher = new Publisher();
                publisher.PublishIncident(report);

                //publisher.PublishCrew(new SCADAUpdateModel(sw.ElementGID, true));
            }
        }
        private void ProcessCrew(IncidentReport report, Crew crew)
        {
            Publisher publisher = new Publisher();

            report.Id = IMSCommunicationClient.InvokeWithRetry(client => client.Channel.GetReport(report.Time)).Id;

            if (report != null)
            {
                if (report.Crewtype == CrewType.Investigation)
                {
                    crew.Working             = true;
                    report.InvestigationCrew = crew;
                    report.RepairCrew        = new Crew();
                    report.CurrentValue      = 0;
                    report.MaxValue          = 4;
                    report.IncidentState     = IncidentState.INVESTIGATING;

                    publisher.PublishIncident(report);

                    Thread.Sleep(TimeSpan.FromSeconds(4));

                    var rnd        = new Random(DateTime.Now.Second);
                    int repairtime = rnd.Next(30, 180);

                    Array             values = Enum.GetValues(typeof(ReasonForIncident));
                    Random            rand   = new Random();
                    ReasonForIncident res    = (ReasonForIncident)values.GetValue(rand.Next(1, values.Length));

                    report.Reason     = res;
                    report.RepairTime = TimeSpan.FromMinutes(repairtime);
                    report.CrewSent   = true;
                    crew.Working      = false;

                    report.IncidentState = IncidentState.READY_FOR_REPAIR;
                    report.Crewtype      = CrewType.Repair;
                }
                else if (report.Crewtype == CrewType.Repair)
                {
                    crew.Working         = true;
                    report.RepairCrew    = crew;
                    report.CurrentValue  = 0;
                    report.MaxValue      = report.RepairTime.TotalMinutes / 10;
                    report.IncidentState = IncidentState.REPAIRING;

                    publisher.PublishIncident(report);

                    Thread.Sleep(TimeSpan.FromSeconds(report.RepairTime.TotalMinutes / 10));

                    crew.Working         = false;
                    report.IncidentState = IncidentState.REPAIRED;

                    Switch sw = null;
                    foreach (var item in DMSService.Instance.Tree.Data.Values)
                    {
                        if (item.MRID == report.MrID)
                        {
                            sw          = (Switch)item;
                            sw.Incident = false;

                            if (item.UnderSCADA)
                            {
                                sw.CanCommand = true;
                                break;
                            }
                            else
                            {
                                sw.State = SwitchState.Closed;
                                ElementStateReport elementStateReport = new ElementStateReport()
                                {
                                    MrID = sw.MRID, Time = DateTime.UtcNow, State = 0
                                };
                                IMSCommunicationClient.InvokeWithRetry(client => client.Channel.AddElementStateReport(elementStateReport));

                                List <UIUpdateModel> networkChange = new List <UIUpdateModel>();
                                if (EnergizationAlgorithm.TraceUp((Node)DMSService.Instance.Tree.Data[sw.End1], DMSService.Instance.Tree))
                                {
                                    networkChange.Add(new UIUpdateModel(sw.ElementGID, true, OMSSCADACommon.States.CLOSED));
                                    sw.Marker = true;
                                    Node n = (Node)DMSService.Instance.Tree.Data[sw.End2];
                                    n.Marker = true;
                                    networkChange.Add(new UIUpdateModel(n.ElementGID, true));
                                    networkChange = EnergizationAlgorithm.TraceDown(n, networkChange, true, false, DMSService.Instance.Tree);
                                }
                                else
                                {
                                    networkChange.Add(new UIUpdateModel(sw.ElementGID, false, OMSSCADACommon.States.CLOSED));
                                }

                                Publisher publisher1 = new Publisher();
                                publisher1.PublishUpdate(networkChange);
                                break;
                            }
                        }
                    }
                }

                IMSCommunicationClient.InvokeWithRetry(client => client.Channel.UpdateReport(report));

                publisher.PublishIncident(report);
            }
        }