コード例 #1
0
ファイル: Processing.cs プロジェクト: vulsim/prism-client
        private void Poll(PollManagerCompleteHandler complete)
        {
            RequestProducer = new PrismRequestProducer(new List<string> { Unit.Settings.CommonEndpoint });
            PollProducer = new PrismPollProducer(Unit.Settings.PollEndpoint);
            PollDoneEvent = new ManualResetEvent(false);
            PollThread = new Thread(delegate()
            {
                List<ProducerChannel> pollingChannelList = new List<ProducerChannel>();
                List<ProducerChannel> pollingAlarmList = new List<ProducerChannel>();

                int TotalChannelCount = 0;
                int SuccessChannelCount = 0;

                PollDoneEvent.Reset();
                RequestProducer.GetChannelList("alarm", delegate(string error0, List<ProducerChannel> channels)
                {
                    if (PollThreadAborted)
                    {
                        PollDoneEvent.Set();
                        return;
                    }

                    if (error0 == null)
                    {
                        List<string> expiredAlarms = new List<string>(Alarms.Keys);

                        foreach (var channel in channels)
                        {
                            if (!channel.Channel.Contains("-manual"))
                            {
                                expiredAlarms.Remove(String.Format("{0},{1}", channel.Group, channel.Channel));
                                pollingAlarmList.Add(channel);
                            }
                        }

                        foreach (var alarmKey in expiredAlarms)
                        {
                            ResetChannel(alarmKey);
                        }

                        PollDoneEvent.Set();
                    }
                    else
                    {
                        System.Diagnostics.Debug.WriteLine(error0.ToString());
                    }
                });

                PollDoneEvent.WaitOne();

                if (PollThreadAborted)
                {
                    return;
                }

                PollDoneEvent.Reset();
                RequestProducer.GetChannelList("io", delegate(string error0, List<ProducerChannel> channels)
                {
                    if (PollThreadAborted)
                    {
                        PollDoneEvent.Set();
                        return;
                    }

                    if (error0 == null)
                    {
                        List<string> expiredChannels = new List<string>(Values.Keys);

                        foreach (var channel in channels)
                        {
                            expiredChannels.Remove(String.Format("{0},{1}", channel.Group, channel.Channel));
                            pollingChannelList.Add(channel);
                        }

                        foreach (var channelKey in expiredChannels)
                        {
                            ResetChannel(channelKey);
                        }

                        PollDoneEvent.Set();
                    }
                    else
                    {
                        System.Diagnostics.Debug.WriteLine(error0.ToString());
                    }
                });

                PollDoneEvent.WaitOne();

                if (PollThreadAborted)
                {
                    return;
                }

                TotalChannelCount += pollingAlarmList.Count;
                TotalChannelCount += pollingChannelList.Count;

                PollDoneEvent.Reset();
                PollProducer.Enqueue(pollingAlarmList, delegate(string error1, List<ProducerChannelValue> alarmValueList)
                {
                    foreach (var value in alarmValueList)
                    {
                        UpdateChannel(value);
                    }

                    SuccessChannelCount += alarmValueList.Count;
                    PollProducer.Enqueue(pollingChannelList, delegate(string error2, List<ProducerChannelValue> channelValueList)
                    {
                        foreach (var value in channelValueList)
                        {
                            UpdateChannel(value);
                        }

                        SuccessChannelCount += channelValueList.Count;
                        PollDoneEvent.Set();
                    });
                });

                PollDoneEvent.WaitOne();

                if (PollThreadAborted)
                {
                    return;
                }

                bool newOnlineState = ((double)SuccessChannelCount / (double)TotalChannelCount > 0.85f);

                if (lastOnlineState != newOnlineState)
                {
                    lastOnlineState = newOnlineState;

                    if (ProcessingOnlineStateChangedEvent != null)
                    {
                        ProcessingOnlineStateChangedEvent(this, lastOnlineState);
                    }
                }

                if (SuccessChannelCount == TotalChannelCount)
                {
                    UpdateTimer.Interval = 300000;
                }
                else
                {
                    UpdateTimer.Interval = 30000;
                }

                UpdateTimer.Start();
                complete();

                RequestProducer.Terminate();
                PollProducer.Terminate();
                RequestProducer = null;                
                PollProducer = null;
                PollDoneEvent = null;
                PollThread = null;
            });
            PollThread.Start();
        }
コード例 #2
0
ファイル: Processing.cs プロジェクト: vulsim/prism-client
        public void Operate(ProducerChannelValue value, TimeSpan time, ProcessingOperateCallback cb)
        {
            PrismRequestProducer operateProducer = new PrismRequestProducer(new List<string> { Unit.Settings.OperateEndpoint });
            bool canCallCb = true;

            /*Unit.Manager.Silent(time, delegate()
            {
                if (canCallCb)
                {
                    cb("Waiting for a response over quota", new ProducerChannelValue(value.Group, value.Channel, null));
                    canCallCb = false;
                }
            });*/

            operateProducer.WriteChannelValue(value, delegate(string error, ProducerChannelValue value1)
            {
                if (canCallCb)
                {
                    cb(error, value1);
                    canCallCb = false;
                }

                operateProducer.Terminate();
            });            
        }