Exemplo n.º 1
0
        private void InsertMesureDetailForSensor(object sender, ProcessQueueItemEventArgs <List <MeasureDetail> > data)
        {
            if (data == null || data.ProcessItem == null || data.ProcessItem.Count == 0)
            {
                return;
            }

            //Console.WriteLine("sensor: " + data.ProcessItem.First().DBName);
            AppManager.GetDBChildConnection(data.ProcessItem.First().DBName).InsertMeasureDetailBulk(data.ProcessItem);
        }
 /// <summary>
 /// This method is called to process a outgoing message.
 /// </summary>
 /// <param name="sender">Sender object</param>
 /// <param name="e">Event arguments</param>
 private void OutgoingMessageQueue_ProcessItem(object sender, ProcessQueueItemEventArgs <MDSDataTransferMessage> e)
 {
     try
     {
         SendMessageToWebService(e.ProcessItem);
     }
     catch (Exception ex)
     {
         Logger.Error(ex.Message, ex);
     }
 }
Exemplo n.º 3
0
        /// <summary>
        /// This event handles processing messages when a message is added to queue (_incomingMessageQueue).
        /// </summary>
        /// <param name="sender">Reference to message queue</param>
        /// <param name="e">Event arguments</param>
        private void IncomingMessageQueue_ProcessItem(object sender, ProcessQueueItemEventArgs <MDSMessage> e)
        {
            //Process only MDSDataTransferMessage objects.
            if (e.ProcessItem.MessageTypeId != MDSMessageFactory.MessageTypeIdMDSDataTransferMessage)
            {
                return;
            }

            //Create IncomingDataMessage from MDSDataTransferMessage
            var dataMessage = new IncomingDataMessage(this, e.ProcessItem as MDSDataTransferMessage);

            try
            {
                //Check if client application registered to MessageReceived event.
                if (MessageReceived == null)
                {
                    dataMessage.Reject("Client application did not registered to MessageReceived event to receive messages.");
                    return;
                }

                //Raise MessageReceived event
                MessageReceived(this, new MessageReceivedEventArgs {
                    Message = dataMessage
                });

                //Check if client application acknowledged or rejected message
                if (dataMessage.AckState != MessageAckStates.WaitingForAck)
                {
                    return;
                }

                //Check if auto acknowledge is active
                if (!AutoAcknowledgeMessages)
                {
                    dataMessage.Reject("Client application did not acknowledged or rejected message.");
                    return;
                }

                //Auto acknowledge message
                dataMessage.Acknowledge();
            }
            catch
            {
                try
                {
                    dataMessage.Reject("An unhandled exception occured during processing message by client application.");
                }
                catch (Exception ex)
                {
                    Logger.Warn(ex.Message, ex);
                }
            }
        }
Exemplo n.º 4
0
        private void ExceptionForSensor(object sender, ProcessQueueItemEventArgs <DSF602Exception> exception)
        {
            if (exception == null || exception.ProcessItem == null)
            {
                return;
            }

            var obj      = (QueueProcessorThread <DSF602Exception>)sender;
            var sensorId = ConvertHelper.CnvNullToInt(obj.Name);

            if (ErrorsReceiveDataFromBlock != null)
            {
                ErrorsReceiveDataFromBlock(sensorId, exception.ProcessItem);
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// This event handles processing messages when a message is added to queue (_incomingMessageQueue).
        /// </summary>
        /// <param name="sender">Reference to message queue</param>
        /// <param name="e">Event arguments</param>
        private void IncomingMessageQueue_ProcessItem(object sender, ProcessQueueItemEventArgs <NGRIDMessage> e)
        {
            try
            {
                if (e.ProcessItem.MessageTypeId == NGRIDMessageFactory.MessageTypeIdNGRIDControllerMessage && ControlMessageReceived != null)
                {
                    var controllerMessage = e.ProcessItem as NGRIDControllerMessage;
                    if (controllerMessage == null)
                    {
                        return;
                    }

                    ControlMessageReceived(this, new ControlMessageReceivedEventArgs(DeserializeControlMessage(controllerMessage)));
                }
            }
            catch (Exception ex)
            {
                Logger.Error(ex.Message, ex);
            }
        }
Exemplo n.º 6
0
        private void eventProcessCharge(object sender, ProcessQueueItemEventArgs <DataCharge> e)
        {
            var sensor   = e.ProcessItem.Sensor;
            var state    = e.ProcessItem.ChargeState;
            var item     = e.ProcessItem.BlockThread;
            var sensorId = sensor.SensorId;
            var isAlarm  = e.ProcessItem.IsAlarm;

            if (isAlarm)
            {
                sensor.Result_Measure = (int)clsConst.emMeasureResult.Fail;
                sensor.Alarm          = true;
            }

            sensor.MeasureState = state;

            if (state == MeasureState.Positive)
            {
                isDecayRuning = true;
                var objLayout = tabGraph.Controls[0] as GraphTypeBase;
                if (objLayout == null)
                {
                    return;
                }

                var graph = objLayout.GetPlotterDisplayExByIndex(sensor.Ordinal_Display - 1);

                if (graph.InvokeRequired)
                {
                    graph.Invoke(new MethodInvoker(() => clsSupportGraph.GraphInit(graph)));
                }
                else
                {
                    clsSupportGraph.GraphInit(graph);
                }

                sensor.ActualDecayPositiveTime = 0;
                sensor.ActualDecayNegativeTime = 0;
                sensor.ActualIBMax             = 0;

                item.SelectSensor(sensorId);
                item.Charge(sensorId, 1);
            }
            else if (state == MeasureState.StopPositive)
            {
                item.StopCharge(sensorId, 1);
                Thread.Sleep(800);
            }
            else if (state == MeasureState.Negative)
            {
                item.Charge(sensorId, -1);
            }
            else if (state == MeasureState.StopNegative)
            {
                item.StopCharge(sensorId, -1);
            }
            else if (state == MeasureState.Ion)
            {
                item.ConnectGround(sensorId);
            }
            else if (state == MeasureState.StopIon)
            {
                item.ConnectGround(sensorId, true);
                var objLayout = tabGraph.Controls[0] as GraphTypeBase;
                if (objLayout == null)
                {
                    return;
                }
                var lbl = objLayout.GetDisplaySensorByIndex(sensor.Ordinal_Display - 1);

                if (lbl != null)
                {
                    this.UpdateSafeControl(lbl, l =>
                    {
                        if (sensor.Active == (int)clsConst.emBlockStatus.Active)
                        {
                            sensor.ActualIBMax = maxIonVal;
                            ((DisplaySensor)l).DisplayDecayValue(maxIonVal, sensor.MeasureState);
                        }
                    });
                }

                isDecayRuning = false;
            }

            Console.WriteLine(DateTime.Now.ToString("HH:mm:ss:ffff") + ": " + state.ToString());
        }
Exemplo n.º 7
0
        /// <summary>
        /// This event handles processing messages when a message is added to queue (_incomingMessageQueue).
        /// </summary>
        /// <param name="sender">Reference to message queue</param>
        /// <param name="e">Event arguments</param>
        private void IncomingMessageQueue_ProcessItem(object sender, ProcessQueueItemEventArgs<MDSMessage> e)
        {
            try
            {
                if (e.ProcessItem.MessageTypeId == MDSMessageFactory.MessageTypeIdMDSControllerMessage && ControlMessageReceived != null)
                {
                    var controllerMessage = e.ProcessItem as MDSControllerMessage;
                    if (controllerMessage == null)
                    {
                        return;
                    }

                    ControlMessageReceived(this, new ControlMessageReceivedEventArgs(DeserializeControlMessage(controllerMessage)));
                }
            }
            catch(Exception ex)
            {
                Logger.Error(ex.Message, ex);
            }
        }
Exemplo n.º 8
0
 /// <summary>
 /// This method is called for each incoming message by _incomingMessageQueue to process incoming messages as ordered.
 /// </summary>
 /// <param name="sender">Sender object</param>
 /// <param name="e">Event arguments</param>
 private void IncomingMessageQueue_ProcessItem(object sender, ProcessQueueItemEventArgs<MessageReceivedFromCommunicatorEventArgs> e)
 {
     OnMessageReceived(this, e.ProcessItem);
 }
Exemplo n.º 9
0
 /// <summary>
 /// This method is called for each incoming message by _incomingMessageQueue to process incoming messages as ordered.
 /// </summary>
 /// <param name="sender">Sender object</param>
 /// <param name="e">Event arguments</param>
 private void IncomingMessageQueue_ProcessItem(object sender, ProcessQueueItemEventArgs <MessageReceivedFromCommunicatorEventArgs> e)
 {
     OnMessageReceived(this, e.ProcessItem);
 }
Exemplo n.º 10
0
 /// <summary>
 /// This method is called to process a outgoing message.
 /// </summary>
 /// <param name="sender">Sender object</param>
 /// <param name="e">Event arguments</param>
 private void OutgoingMessageQueue_ProcessItem(object sender, ProcessQueueItemEventArgs<NGRIDDataTransferMessage> e)
 {
     try
     {
         SendMessageToWebService(e.ProcessItem);
     }
     catch (Exception ex)
     {
         Logger.Error(ex.Message, ex);
     }
 }
Exemplo n.º 11
0
        /// <summary>
        /// This event handles processing messages when a message is added to queue (_incomingMessageQueue).
        /// </summary>
        /// <param name="sender">Reference to message queue</param>
        /// <param name="e">Event arguments</param>
        private void IncomingMessageQueue_ProcessItem(object sender, ProcessQueueItemEventArgs<NGRIDMessage> e)
        {
            //Process only NGRIDDataTransferMessage objects.
            if (e.ProcessItem.MessageTypeId != NGRIDMessageFactory.MessageTypeIdNGRIDDataTransferMessage)
            {
                return;
            }

            //Create IncomingDataMessage from NGRIDDataTransferMessage
            var dataMessage = new IncomingDataMessage(this, e.ProcessItem as NGRIDDataTransferMessage);

            try
            {
                //Check if client application registered to MessageReceived event.
                if (MessageReceived == null)
                {
                    dataMessage.Reject("Client application did not registered to MessageReceived event to receive messages.");
                    return;
                }

                //Raise MessageReceived event
                MessageReceived(this, new MessageReceivedEventArgs { Message = dataMessage });

                //Check if client application acknowledged or rejected message
                if (dataMessage.AckState != MessageAckStates.WaitingForAck)
                {
                    return;
                }

                //Check if auto acknowledge is active
                if (!AutoAcknowledgeMessages)
                {
                    dataMessage.Reject("Client application did not acknowledged or rejected message.");
                    return;
                }

                //Auto acknowledge message
                dataMessage.Acknowledge();
            }
            catch
            {
                try
                {
                    dataMessage.Reject("An unhandled exception occured during processing message by client application.");
                }
                catch (Exception ex)
                {
                    Logger.Warn(ex.Message, ex);
                }
            }
        }