Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            Subscriber sub = new Subscriber();

            try
            {
                using (var proxy = new OMSTopologyServiceProxy("TopologyServiceEndpoint"))
                {
                    var ui = proxy.GetOMSModel();
                }

                using (var proxy = new OutageSimulatorServiceProxy(EndpointNames.OutageSimulatorServiceEndpoint))
                {
                    proxy.StopOutageSimulation(0x0000000c00000029);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }

            //ProxyFactory proxyFactory = new ProxyFactory();
            //proxy = proxyFactory.CreatePRoxy<SubscriberProxy, ISubscriber>(new SCADASubscriber(), EndpointNames.SubscriberEndpoint);

            SubscriberProxy subProxy = new SubscriberProxy(sub, EndpointNames.SubscriberEndpoint);

            subProxy.Subscribe(Topic.OMS_MODEL);

            Console.ReadLine();
        }
        public bool StartLocationAndIsolationAlgorithm(OutageEntity outageEntity)
        {
            IOutageTopologyElement topologyElement = null;

            long reportedGid     = outageEntity.DefaultIsolationPoints.First().EquipmentId;
            long outageElementId = -1;
            long UpBreaker;

            Task.Delay(5000).Wait();
            using (OutageSimulatorServiceProxy proxy = proxyFactory.CreateProxy <OutageSimulatorServiceProxy, IOutageSimulatorContract>(EndpointNames.OutageSimulatorServiceEndpoint))
            {
                if (proxy == null)
                {
                    string message = "OutageModel::SendLocationIsolationCrew => OutageSimulatorProxy is null";
                    Logger.LogError(message);
                    throw new NullReferenceException(message);
                }
                //Da li je prijaveljen element OutageElement
                if (proxy.IsOutageElement(reportedGid))
                {
                    outageElementId = reportedGid;
                }
                else
                {
                    //Da li je mozda na ACL-novima ispod prijavljenog elementa
                    if (outageModel.TopologyModel.GetElementByGid(reportedGid, out topologyElement))
                    {
                        try
                        {
                            for (int i = 0; i < topologyElement.SecondEnd.Count; i++)
                            {
                                if (proxy.IsOutageElement(topologyElement.SecondEnd[i]))
                                {
                                    if (outageElementId == -1)
                                    {
                                        outageElementId = topologyElement.SecondEnd[i];
                                        outageEntity.OutageElementGid = outageElementId;
                                    }
                                    else
                                    {
                                        OutageEntity entity = new OutageEntity()
                                        {
                                            OutageElementGid = topologyElement.SecondEnd[i], ReportTime = DateTime.UtcNow
                                        };
                                        dbContext.OutageRepository.Add(entity);
                                    }
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            Logger.LogError("OutageModel::SendLocationIsolationCrew => failed with error", ex);
                            throw;
                        }
                    }
                }
                //Tragamo za ACL-om gore ka source-u
                while (outageElementId == -1 && !topologyElement.IsRemote && topologyElement.DmsType != "ENERGYSOURCE")
                {
                    if (proxy.IsOutageElement(topologyElement.Id))
                    {
                        outageElementId = topologyElement.Id;
                        outageEntity.OutageElementGid = outageElementId;
                    }
                    outageModel.TopologyModel.GetElementByGid(topologyElement.FirstEnd, out topologyElement);
                }
                if (outageElementId == -1)
                {
                    outageEntity.OutageState = OutageState.REMOVED;
                    dbContext.OutageRepository.Remove(outageEntity);
                    Logger.LogError("End of feeder no outage detected.");
                    return(false);
                }
                outageModel.TopologyModel.GetElementByGidFirstEnd(outageEntity.OutageElementGid, out topologyElement);
                while (topologyElement.DmsType != "BREAKER")
                {
                    outageModel.TopologyModel.GetElementByGidFirstEnd(topologyElement.Id, out topologyElement);
                }
                UpBreaker = topologyElement.Id;
                long nextBreaker = outageModel.GetNextBreaker(outageEntity.OutageElementGid);

                if (!outageModel.TopologyModel.OutageTopology.ContainsKey(nextBreaker))
                {
                    string message = $"Breaker (next breaker) with id: 0x{nextBreaker:X16} is not in topology";
                    Logger.LogError(message);
                    throw new Exception(message);
                }

                long outageElement = outageModel.TopologyModel.OutageTopology[nextBreaker].FirstEnd;

                if (!outageModel.TopologyModel.OutageTopology[UpBreaker].SecondEnd.Contains(outageElement))
                {
                    string message = $"Outage element with gid: 0x{outageElement:X16} is not on a second end of current breaker id";
                    Logger.LogError(message);
                    throw new Exception(message);
                }
                outageEntity.OptimumIsolationPoints = outageModel.GetEquipmentEntity(new List <long>()
                {
                    UpBreaker, nextBreaker
                });
                outageEntity.IsolatedTime = DateTime.UtcNow;
                outageEntity.OutageState  = OutageState.ISOLATED;

                dbContext.OutageRepository.Update(outageEntity);
                SendSCADACommand(UpBreaker, DiscreteCommandingType.OPEN);
                SendSCADACommand(nextBreaker, DiscreteCommandingType.OPEN);
            }

            return(true);
        }
Ejemplo n.º 3
0
        public bool SendRepairCrew(long outageId)
        {
            OutageEntity outageDbEntity = null;

            try
            {
                outageDbEntity = dbContext.OutageRepository.Get(outageId);
            }
            catch (Exception e)
            {
                string message = "OutageModel::SendRepairCrew => exception in UnitOfWork.ActiveOutageRepository.Get()";
                Logger.LogError(message, e);
                throw e;
            }

            if (outageDbEntity == null)
            {
                Logger.LogError($"Outage with id 0x{outageId:X16} is not found in database.");
                return(false);
            }

            if (outageDbEntity.OutageState != OutageState.ISOLATED)
            {
                Logger.LogError($"Outage with id 0x{outageId:X16} is in state {outageDbEntity.OutageState}, and thus repair crew can not be sent. (Expected state: {OutageState.ISOLATED})");
                return(false);
            }

            Task task = Task.Run(() =>
            {
                Task.Delay(10000).Wait();

                using (OutageSimulatorServiceProxy proxy = proxyFactory.CreateProxy <OutageSimulatorServiceProxy, IOutageSimulatorContract>(EndpointNames.OutageSimulatorServiceEndpoint))
                {
                    if (proxy == null)
                    {
                        string message = "OutageModel::SendRepairCrew => OutageSimulatorServiceProxy is null";
                        Logger.LogError(message);
                        throw new NullReferenceException(message);
                    }

                    if (proxy.StopOutageSimulation(outageDbEntity.OutageElementGid))
                    {
                        outageDbEntity.OutageState  = OutageState.REPAIRED;
                        outageDbEntity.RepairedTime = DateTime.UtcNow;
                        dbContext.OutageRepository.Update(outageDbEntity);

                        try
                        {
                            dbContext.Complete();
                            outageModel.PublishOutage(Topic.ACTIVE_OUTAGE, outageMessageMapper.MapOutageEntity(outageDbEntity));
                        }
                        catch (Exception e)
                        {
                            string message = "OutageModel::SendRepairCrew => exception in Complete method.";
                            Logger.LogError(message, e);
                        }
                    }
                    else
                    {
                        string message = "OutageModel::SendRepairCrew => ResolvedOutage() not finished with SUCCESS";
                        Logger.LogError(message);
                    }
                }
            });

            return(true);
        }