Esempio n. 1
0
        public ActionResult <Graph> Calculate([FromBody] int[] input)
        {
            if (input == null || input.Length == 0)
            {
                throw new ArgumentException("input must be provided and not empty");
            }

            var result = _calculationService.Traverse(input);

            return(Ok(_graphMapper.Map(result)));
        }
        /// <summary>
        /// Maps the input topology object to a graph object and dispatches it
        /// to a Graph Hub endpoint
        /// </summary>
        /// <param name="message"></param>
        public void Notify(IPublishableMessage message)
        {
            if (message is TopologyForUIMessage topologyMessage)
            {
                OmsGraphViewModel graph = _mapper.Map(topologyMessage.UIModel);

                _dispatcher.Connect();
                try
                {
                    _dispatcher.NotifyGraphUpdate(graph.Nodes, graph.Relations);
                }
                catch (Exception)
                {
                    // retry ?
                }
            }
        }
Esempio n. 3
0
        public async Task <OmsGraphViewModel> Handle(GetTopologyQuery request, CancellationToken cancellationToken)
        {
            ITopologyProviderContract topologyServiceClient = TopologyProviderClient.CreateClient();

            try
            {
                Logger.LogInformation("[TopologyQueryHandler::GetTopologyQuery] Sending GET query to topology client.");
                UIModel topologyModel = await topologyServiceClient.GetUIModel();

                OmsGraphViewModel graph = _mapper.Map(topologyModel);
                return(graph);
            }
            catch (Exception ex)
            {
                Logger.LogError("[TopologyQueryHandler::GetTopologyQuery] Sending GET query to topology client failed.", ex);
                return(null);
            }
        }
 public Task <OmsGraphViewModel> Handle(GetTopologyQuery request, CancellationToken cancellationToken)
 {
     return(Task.Run(() =>
     {
         using (UITopologyServiceProxy topologyProxy = _proxyFactory.CreateProxy <UITopologyServiceProxy, ITopologyServiceContract>(EndpointNames.TopologyServiceEndpoint))
         {
             try
             {
                 _logger.LogInfo("[TopologyQueryHandler::GetTopologyQuery] Sending GET query to topology client.");
                 UIModel topologyModel = topologyProxy.GetTopology();
                 OmsGraphViewModel graph = _mapper.Map(topologyModel);
                 return graph;
             }
             catch (Exception ex)
             {
                 _logger.LogError("[TopologyQueryHandler::GetTopologyQuery] Sending GET query to topology client failed.", ex);
                 return null;
             }
         }
     }));
 }
Esempio n. 5
0
        public async Task Notify(IPublishableMessage message, string publisherName)
        {
            if (message is ActiveOutageMessage activeOutage)
            {
                Logger.LogInformation($"{baseLogString} Notify => ActiveOutageMessageReceived. OutageId: 0x{activeOutage.OutageId:x16} ElementId: 0x{activeOutage.OutageElementGid}");
                var outageDispatcher = new OutageHubDispatcher(_outageMapper);
                outageDispatcher.Connect();

                try
                {
                    await outageDispatcher.NotifyActiveOutageUpdate(activeOutage);
                }
                catch (Exception e)
                {
                    string errorMessage = $"{baseLogString} Notify => exception {e.Message}";
                    Logger.LogError(errorMessage, e);
                }
            }
            else if (message is ArchivedOutageMessage archivedOutage)
            {
                var outageDispatcher = new OutageHubDispatcher(_outageMapper);
                outageDispatcher.Connect();

                try
                {
                    await outageDispatcher.NotifyArchiveOutageUpdate(archivedOutage);
                }
                catch (Exception e)
                {
                    string errorMessage = $"{baseLogString} Notify => exception {e.Message}";
                    Logger.LogError(errorMessage, e);
                }
            }
            else if (message is TopologyForUIMessage topologyMessage)
            {
                OmsGraphViewModel graph = _graphMapper.Map(topologyMessage.UIModel);

                var graphDispatcher = new GraphHubDispatcher();
                graphDispatcher.Connect();

                try
                {
                    await graphDispatcher.NotifyGraphUpdate(graph.Nodes, graph.Relations);
                }
                catch (Exception e)
                {
                    string errorMessage = $"{baseLogString} Notify => exception {e.Message}";
                    Logger.LogError(errorMessage, e);
                }
            }
            else if (message is MultipleAnalogValueSCADAMessage analogValuesMessage)
            {
                Dictionary <long, AnalogModbusData> analogModbusData = new Dictionary <long, AnalogModbusData>(analogValuesMessage.Data);

                var scadaDispatcher = new ScadaHubDispatcher();
                scadaDispatcher.Connect();

                try
                {
                    await scadaDispatcher.NotifyScadaDataUpdate(analogModbusData);
                }
                catch (Exception e)
                {
                    string errorMessage = $"{baseLogString} Notify => exception {e.Message}";
                    Logger.LogError(errorMessage, e);
                }
            }
        }