コード例 #1
0
ファイル: Processing.cs プロジェクト: vulsim/prism-client
        private void UpdateChannel(ProducerChannelValue value)
        {
            string key = String.Format("{0},{1}", value.Group, value.Channel);

            if (value.Group.Equals("alarm"))
            {
                if (!value.Channel.Contains("-manual"))
                {          
                    bool update = false;
                    Alarm alarm = GetAlarm(value);

                    if (Alarms.ContainsKey(key))
                    {
                        if (alarm.State != Alarms[key].State)
                        {
                            update = true;
                        }                        
                    }
                    else
                    {
                        update = true;
                    }

                    if (update)
                    {
                        Alarms[key] = alarm;
                        Unit.Journal.Log(Unit, alarm);

                        ThreadPool.QueueUserWorkItem(delegate(object target)
                        {
                            if (ProcessingAlarmUpdateEvent != null)
                            {
                                ProcessingAlarmUpdateEvent(this,(Alarm)target);
                            }
                        }, alarm);
                    }
                }
            }
            else
            {                
                bool update = false;

                if (Values.ContainsKey(key))
                {
                    if (!Values[key].Equals(value.Value))
                    {
                        update = true;
                    }
                }
                else
                {
                    update = true;
                }

                if (update)
                {
                    Values[key] = value.Value;

                    if (ParamRelations.ContainsKey(key))
                    {
                        foreach (var param in ParamRelations[key])
                        {
                            ThreadPool.QueueUserWorkItem(delegate(object target)
                            {
                                if (ProcessingParamUpdateEvent != null)
                                {
                                    ProcessingParamUpdateEvent(this, (Param)target);
                                }
                            }, param);
                        }
                    }
                }
            }
        }
コード例 #2
0
ファイル: Processing.cs プロジェクト: vulsim/prism-client
        /*private void Poll(PollManagerCompleteHandler complete)
        {
            RequestProducer = new PrismRequestProducer(Unit.Settings.PollEndpoints);
            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;
                int ProcessedChannelCount = 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>(Alarms.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();
                foreach (var channel in pollingAlarmList)
                {
                    RequestProducer.ReadChannelValue(channel, delegate(string error1, ProducerChannelValue value)
                    {
                        ProcessedChannelCount++;
                        //System.Diagnostics.Debug.WriteLine(ProcessedChannelCount.ToString());

                        if (error1 == null)
                        {
                            SuccessChannelCount++;
                            UpdateChannel(value);
                        }
                        else
                        {
                            System.Diagnostics.Debug.WriteLine(error1.ToString());
                        }

                        if (ProcessedChannelCount == TotalChannelCount)
                        {
                            PollDoneEvent.Set();
                        }
                    });
                }

                foreach (var channel in pollingChannelList)
                {
                    RequestProducer.ReadChannelValue(channel, delegate(string error2, ProducerChannelValue value)
                    {
                        string key = value.Group + "," + value.Channel;

                        ProcessedChannelCount++;
                        //System.Diagnostics.Debug.WriteLine(ProcessedChannelCount.ToString());

                        if (error2 == null)
                        {
                            SuccessChannelCount++;
                            UpdateChannel(value);
                        }
                        else
                        {
                            ResetChannel(new ProducerChannel(value.Group, value.Channel));
                            System.Diagnostics.Debug.WriteLine(error2.ToString());
                        }

                        if (ProcessedChannelCount == TotalChannelCount)
                        {
                            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 = 60000;
                }

                UpdateTimer.Start();
                complete();

                RequestProducer.Terminate();
                RequestProducer = null;
                PollDoneEvent = null;
                PollThread = null;
            });
            PollThread.Start();
        }*/
        
        private Alarm GetAlarm(ProducerChannelValue value)
        {
            if (value.Group.Equals("alarm"))
            {
                string[] splitValue = value.Value.Split(" ".ToCharArray(), 2);

                if (splitValue != null && splitValue.Length == 2)
                {
                    ParamState paramState = ParamState.Unknown;

                    if (splitValue[0].Equals("[I]"))
                    {
                        paramState = ParamState.Idle;
                    }
                    else if (splitValue[0].Equals("[A]"))
                    {
                        paramState = ParamState.A;
                    }
                    else if (splitValue[0].Equals("[B]"))
                    {
                        paramState = ParamState.B;
                    }
                    if (splitValue[0].Equals("[C]"))
                    {
                        paramState = ParamState.C;
                    }

                    return new Alarm(value.Channel, splitValue[1], paramState);
                }
            }

            return null;
        }
コード例 #3
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();
            });            
        }
コード例 #4
0
ファイル: Processing.cs プロジェクト: vulsim/prism-client
 private void ProducerChannelValueEvent(object sender, ProducerChannelValue value)
 {
     UpdateChannel(value);
 }
コード例 #5
0
ファイル: Producer.cs プロジェクト: vulsim/prism-client
 private void ChannelValueEventHandler(object sender, ProducerChannelValue value)
 {
     if (ChannelValueEvent != null)
     {
         ChannelValueEvent(this, value);
     }
 }
コード例 #6
0
ファイル: Producer.cs プロジェクト: vulsim/prism-client
 public PrismZmqWriteChannelReqPacket(ProducerChannelValue value)
     : base("cwrite")
 {
     this.Group = value.Group;
     this.Channel = value.Channel;
     this.Value = value.Value;
 }
コード例 #7
0
ファイル: Producer.cs プロジェクト: vulsim/prism-client
 public void WriteChannelValue(ProducerChannelValue value, PrismRequest.WriteChannelValueCallback cb)
 {
     try
     {
         RequestQueue.Enqueue(new PrismRequest.PrismRequestItem(PrismRequest.PrismRequestItem.PrismRequestMethod.WriteChannel, JsonConvert.SerializeObject(new PrismZmqWriteChannelReqPacket(value)), value, cb));
         RouteProcessQueue();
     }
     catch (SystemException e)
     {
         System.Diagnostics.Debug.WriteLine(e.ToString());
         cb(e.ToString(), null);
     }
 }