Пример #1
0
        /// <summary>
        /// Update the browser OEE/KPI data using SignalR
        /// </summary>
        private static async Task UpdateSessionsOeeKpiData(CancellationToken ct)
        {
            while (true)
            {
                _updateClientOeeKpiData.WaitOne(Timeout.Infinite);

                if (ct.IsCancellationRequested)
                {
                    break;
                }

                OeeKpiDataUpdate[] sessionOeeKpiDataUpdate = new OeeKpiDataUpdate[Startup.SessionList.Count];
                int sessionUpdateIndex = 0;

                try
                {
                    foreach (KeyValuePair <string, DashboardModel> session in Startup.SessionList)
                    {
                        OeeKpiDataUpdate sessionOeeKpiData = new OeeKpiDataUpdate();
                        string           topNodeKey        = session.Value.TopNode.Key;

                        // Update the OEE/KPI relevant data.
                        sessionOeeKpiData.SessionId = session.Key;
                        sessionOeeKpiData.TopNode   = topNodeKey;

                        // Add the performance data relevant for the session.
                        ContosoTopologyNode             topNode    = (ContosoTopologyNode)Startup.Topology[topNodeKey];
                        ContosoAggregatedOeeKpiTimeSpan oeeKpiLast = topNode.Last;
                        sessionOeeKpiData.Kpi1Last = oeeKpiLast.Kpi1;
                        sessionOeeKpiData.Kpi1PerformanceSetting = topNode.Kpi1PerformanceSetting;
                        sessionOeeKpiData.Kpi2Last = oeeKpiLast.Kpi2;
                        sessionOeeKpiData.Kpi2PerformanceSetting            = topNode.Kpi2PerformanceSetting;
                        sessionOeeKpiData.OeeAvailabilityLast               = oeeKpiLast.OeeAvailability;
                        sessionOeeKpiData.OeeAvailabilityPerformanceSetting = topNode.OeeAvailabilityPerformanceSetting;
                        sessionOeeKpiData.OeePerformanceLast = oeeKpiLast.OeePerformance;
                        sessionOeeKpiData.OeePerformancePerformanceSetting = topNode.OeePerformancePerformanceSetting;
                        sessionOeeKpiData.OeeQualityLast = oeeKpiLast.OeeQuality;
                        sessionOeeKpiData.OeeQualityPerformanceSetting = topNode.OeeQualityPerformanceSetting;
                        sessionOeeKpiData.OeeOverallLast = oeeKpiLast.OeeOverall;
                        sessionOeeKpiData.OeeOverallPerformanceSetting = topNode.OeeOverallPerformanceSetting;
                        sessionOeeKpiDataUpdate[sessionUpdateIndex]    = sessionOeeKpiData;
                        sessionUpdateIndex++;
                    }

                    if (Startup.SessionList.Count > 0 && sessionUpdateIndex > 0)
                    {
                        string      _sessionOeeKpiDataUpdateJson = JsonConvert.SerializeObject(sessionOeeKpiDataUpdate);
                        IHubContext hubContext = GlobalHost.ConnectionManager.GetHubContext <TelemetryHub>();
                        hubContext.Clients.All.updateSessionOeeKpiData(_sessionOeeKpiDataUpdateJson);
                    }
                }
                catch (Exception e)
                {
                    Trace.TraceInformation($"Exception in UpdateSessionsOeeKpiData ({e.Message})");
                }
            }
        }
Пример #2
0
        /// <summary>
        /// Update the browser content using SignalR
        /// </summary>
        private void BrowserUpdate()
        {
            ChildrenDataUpdate[] sessionChildrenDataUpdate = new ChildrenDataUpdate[Startup.SessionList.Count];
            OeeKpiDataUpdate[]   sessionOeeKpiDataUpdate   = new OeeKpiDataUpdate[Startup.SessionList.Count];
            AlertDataUpdate[]    sessionAlertDataUpdate    = new AlertDataUpdate[Startup.SessionList.Count];
            int sessionUpdateIndex = 0;

            foreach (KeyValuePair <string, DashboardModel> session in Startup.SessionList)
            {
                ChildrenDataUpdate sessionChildrenData = new ChildrenDataUpdate();
                OeeKpiDataUpdate   sessionOeeKpiData   = new OeeKpiDataUpdate();
                AlertDataUpdate    sessionAlertData    = new AlertDataUpdate();
                string             topNodeKey          = session.Value.TopNode.Key;

                // Update the OEE/KPI relevant data.
                sessionOeeKpiData.SessionId = session.Key;
                sessionOeeKpiData.TopNode   = topNodeKey;

                // Add the performance data relevant for the session.
                ContosoTopologyNode             topNode    = (ContosoTopologyNode)Startup.Topology[topNodeKey];
                ContosoAggregatedOeeKpiTimeSpan oeeKpiLast = topNode.Last;
                sessionOeeKpiData.Kpi1Last = oeeKpiLast.Kpi1;
                sessionOeeKpiData.Kpi1PerformanceSetting = topNode.Kpi1PerformanceSetting;
                sessionOeeKpiData.Kpi2Last = oeeKpiLast.Kpi2;
                sessionOeeKpiData.Kpi2PerformanceSetting            = topNode.Kpi2PerformanceSetting;
                sessionOeeKpiData.OeeAvailabilityLast               = oeeKpiLast.OeeAvailability;
                sessionOeeKpiData.OeeAvailabilityPerformanceSetting = topNode.OeeAvailabilityPerformanceSetting;
                sessionOeeKpiData.OeePerformanceLast = oeeKpiLast.OeePerformance;
                sessionOeeKpiData.OeePerformancePerformanceSetting = topNode.OeePerformancePerformanceSetting;
                sessionOeeKpiData.OeeQualityLast = oeeKpiLast.OeeQuality;
                sessionOeeKpiData.OeeQualityPerformanceSetting = topNode.OeeQualityPerformanceSetting;
                sessionOeeKpiData.OeeOverallLast = oeeKpiLast.OeeOverall;
                sessionOeeKpiData.OeeOverallPerformanceSetting = topNode.OeeOverallPerformanceSetting;

                // Update the alert data.
                sessionAlertData.SessionId = session.Key;
                sessionAlertData.TopNode   = topNodeKey;
                sessionAlertData.Alerts    = Startup.Topology.GetAlerts(topNodeKey);

                // Update the children data.
                sessionChildrenData.SessionId = session.Key;
                sessionChildrenData.TopNode   = topNodeKey;
                sessionChildrenData.Children  = Startup.Topology.GetChildrenInfo(topNodeKey);

                // Update the data sent to the clients.
                sessionChildrenDataUpdate[sessionUpdateIndex] = sessionChildrenData;
                sessionOeeKpiDataUpdate[sessionUpdateIndex]   = sessionOeeKpiData;
                sessionAlertDataUpdate[sessionUpdateIndex]    = sessionAlertData;
                sessionUpdateIndex++;
            }

            if (Startup.SessionList.Count > 0 && sessionUpdateIndex > 0)
            {
                string      _sessionChildrenDataUpdateJson = JsonConvert.SerializeObject(sessionChildrenDataUpdate);
                string      _sessionOeeKpiDataUpdateJson   = JsonConvert.SerializeObject(sessionOeeKpiDataUpdate);
                string      _sessionAlertDataUpdateJson    = JsonConvert.SerializeObject(sessionAlertDataUpdate);
                IHubContext hubContext = GlobalHost.ConnectionManager.GetHubContext <TelemetryHub>();
                hubContext.Clients.All.updateSessionChildrenData(_sessionChildrenDataUpdateJson);
                hubContext.Clients.All.updateSessionOeeKpiData(_sessionOeeKpiDataUpdateJson);
                hubContext.Clients.All.updateSessionAlertData(_sessionAlertDataUpdateJson);
            }
        }