Ejemplo n.º 1
0
        protected void PushToAllClients(MessageType messageType)
        {
            Dictionary<string, Client> clientsList;
            lock (clients)
            {
                clientsList = new Dictionary<string, Client>(clients);	// we will take a copy of the global collection locally to avoid locking of the resource.
            }

            //This is not the best way to check for measurementType and have individual local collection of clients and foreach loop but
            //since this method is being called by different threads and timers, I have implemented it this way. --Mehul Thakkar.
            if (messageType == MessageType.LivePhasorDataMessage)
            {
                lock (clientsList)
                {
                    foreach (string session in clientsList.Keys)
                    {
                        if (clientsList[session].CurrentDisplayType == DisplayType.Home)
                        {
                            if (dataPerNode.ContainsKey(clientsList[session].NodeID))
                                PushMessageToClient(session, dataPerNode[clientsList[session].NodeID]);
                            else
                                PushMessageToClient(session, new LivePhasorDataMessage());
                        }
                    }
                }
            }
            else if (messageType == MessageType.TimeSeriesDataMessage)
            {
                lock (clientsList)
                {
                    foreach (string session in clientsList.Keys)
                    {
                        if (clientsList[session].CurrentDisplayType == DisplayType.Home && !string.IsNullOrEmpty(clientsList[session].TimeSeriesDataRootUrl))
                        {
                            TimeSeriesDataMessage message = new TimeSeriesDataMessage()
                            {
                                TimeSeriesData = CommonFunctions.GetTimeSeriesData(clientsList[session].TimeSeriesDataRootUrl + "/timeseriesdata/read/current/" + clientsList[session].DataPointID.ToString() + "/XML")
                            };
                            PushMessageToClient(session, message);
                        }
                    }
                }
            }
            else if (messageType == MessageType.TimeTaggedDataMessage)
            {
                lock (clientsList)
                {
                    foreach (string session in clientsList.Keys)
                    {
                        if (clientsList[session].CurrentDisplayType == DisplayType.DeviceMeasurements)
                        {
                            if (timeTaggedMeasurementsPerNode.ContainsKey(clientsList[session].NodeID))
                                PushMessageToClient(session, timeTaggedMeasurementsPerNode[clientsList[session].NodeID]);
                            else
                                PushMessageToClient(session, new TimeTaggedDataMessage());
                        }
                        else if (clientsList[session].CurrentDisplayType == DisplayType.RealTimeStatistics)
                        {
                            if (realTimeStatisticsPerNode.ContainsKey(clientsList[session].NodeID))
                                PushMessageToClient(session, realTimeStatisticsPerNode[clientsList[session].NodeID]);
                            else
                                PushMessageToClient(session, new TimeTaggedDataMessage());
                        }
                    }
                }
            }
        }
Ejemplo n.º 2
0
        protected void PushToAllClients(MessageType messageType)
        {
            Dictionary <string, Client> clientsList;

            lock (clients)
            {
                clientsList = new Dictionary <string, Client>(clients);  // we will take a copy of the global collection locally to avoid locking of the resource.
            }

            //This is not the best way to check for measurementType and have individual local collection of clients and foreach loop but
            //since this method is being called by different threads and timers, I have implemented it this way. --Mehul Thakkar.
            if (messageType == MessageType.LivePhasorDataMessage)
            {
                lock (clientsList)
                {
                    foreach (string session in clientsList.Keys)
                    {
                        if (clientsList[session].CurrentDisplayType == DisplayType.Home)
                        {
                            if (dataPerNode.ContainsKey(clientsList[session].NodeID))
                            {
                                PushMessageToClient(session, dataPerNode[clientsList[session].NodeID]);
                            }
                            else
                            {
                                PushMessageToClient(session, new LivePhasorDataMessage());
                            }
                        }
                    }
                }
            }
            else if (messageType == MessageType.TimeSeriesDataMessage)
            {
                lock (clientsList)
                {
                    foreach (string session in clientsList.Keys)
                    {
                        if (clientsList[session].CurrentDisplayType == DisplayType.Home && !string.IsNullOrEmpty(clientsList[session].TimeSeriesDataRootUrl))
                        {
                            TimeSeriesDataMessage message = new TimeSeriesDataMessage()
                            {
                                TimeSeriesData = CommonFunctions.GetTimeSeriesData(clientsList[session].TimeSeriesDataRootUrl + "/timeseriesdata/read/current/" + clientsList[session].DataPointID.ToString() + "/XML")
                            };
                            PushMessageToClient(session, message);
                        }
                    }
                }
            }
            else if (messageType == MessageType.TimeTaggedDataMessage)
            {
                lock (clientsList)
                {
                    foreach (string session in clientsList.Keys)
                    {
                        if (clientsList[session].CurrentDisplayType == DisplayType.DeviceMeasurements)
                        {
                            if (timeTaggedMeasurementsPerNode.ContainsKey(clientsList[session].NodeID))
                            {
                                PushMessageToClient(session, timeTaggedMeasurementsPerNode[clientsList[session].NodeID]);
                            }
                            else
                            {
                                PushMessageToClient(session, new TimeTaggedDataMessage());
                            }
                        }
                        else if (clientsList[session].CurrentDisplayType == DisplayType.RealTimeStatistics)
                        {
                            if (realTimeStatisticsPerNode.ContainsKey(clientsList[session].NodeID))
                            {
                                PushMessageToClient(session, realTimeStatisticsPerNode[clientsList[session].NodeID]);
                            }
                            else
                            {
                                PushMessageToClient(session, new TimeTaggedDataMessage());
                            }
                        }
                    }
                }
            }
        }