Ejemplo n.º 1
0
        public void DisplayDateTime(BetaBrite bb)
        {
            try
            {
                LogBook.Write("Enter method display datetime");
                //"MM/DD/YY","DD/MM/YY","MM-DD-YY","DD-MM-YY","MM.DD.YY","DD.MM.YY","MM DD YY","DD MM YY","MMM.DD, YYYY","MMM.DD,YYYY"
                //"DDD"
                byte[] byteArray;
                //wait for 5secs for message board to reset
                //Thread.Sleep(5000);
                LogBook.Write("Setting date time for the message board");
                //set message board date time to current date and time
                WriteBytes(bb.SetDateAndTime(DateTime.Now));
                //specify the type of file to be used
                bb.UseMemoryText('A', 256);
                LogBook.Write("Creating file: A to display date and time");
                //allocate memory
                byteArray = bb.AllocateMemory();
                WriteBytes(byteArray);
                LogBook.Write("Allocated memory at file : A");
                //write the message to the file
                byteArray = bb.SetText('A', "<color=green><calldate=DDD> <calltime>", AlphaSignProtocol.Transition.Hold, AlphaSignProtocol.Special.None);
                WriteBytes(byteArray);
                LogBook.Write("Set time and date  formats and calling the time and date functions");
                //run the file on the message board
                byteArray = bb.SetRunSequence("A");
                WriteBytes(byteArray);
                LogBook.Write("Sent run sequence command to message board");

                LogBook.Write("Exiting method display datetime");
            }
            catch (Exception ex)
            {
                LogBook.Write(ex, "NotifyEngine-MessageBoard");
                throw ex;
            }
        }
Ejemplo n.º 2
0
        public void DisplayMessage(string msg, int priority = 5)
        {
            LogBook.Write(this.SensorFactoryID + " " + this.SensorAlarmID + " " + "Executing DisplayMessage Method");
            try
            {
                //create instance for beta bite message board
                BetaBrite bb = new BetaBrite();

                //to process an array of files ex:"ABCD"  A, B, C, D are the file labels
                string fileLabelsToProcess = string.Empty;
                //we are initializing file label to 66, as we are using 65 to display time and date
                int fileLabel = 66;
                //byte array instance to send data to network
                byte[] byteArray;


                if (SetServerTime)
                {
                    //clear all the messages in the message board
                    WriteBytes(bb.ClearMemory());
                    //wait for a second for the message board to reset
                    Thread.Sleep(100);

                    LogBook.Write(this.SensorFactoryID + " " + this.SensorAlarmID + " " + "Call Display date time method");
                    //else display date and time
                    DisplayDateTime(bb);
                    return;
                }

                //IsDynamicNotificationCleared will be null, if the request comes form utility tool
                if (IsDynamicNotificationCleared == null)
                {
                    LogBook.Write("Message from utility");
                    _hasUtilityMessage = true;
                    sensorMessages.Clear();
                }//notification from the service, IsDynamicNotificationCleared will be false
                else if (IsDynamicNotificationCleared != null)
                {
                    //if the message board has already a message from the utility tool,
                    //clear that message and set hasUtilityMessage to false
                    if (_hasUtilityMessage)
                    {
                        LogBook.Write("Clearing any messages from utility");
                        sensorMessages.Clear();
                    }
                    _hasUtilityMessage = false;
                }

                //check if the sensor id value already exists in the list
                //for testing message board we are sending IsDynamicNotificationCleared as null
                if (sensorMessages.ContainsKey(SensorAlarmID + "M" + _id + "M".ToString()) && IsDynamicNotificationCleared != null)
                {
                    string message = string.Empty;
                    message = "Check whether the dynamic notification cleared: " + SensorAlarmID + "message:" + msg;

                    //if dynamic notification is not cleared
                    if (!Convert.ToBoolean(IsDynamicNotificationCleared))
                    {
                        //if the current message is same as the previous message, ignore the message
                        if (msg == sensorMessages[SensorAlarmID + "M" + _id + "M".ToString()])
                        {
                            message += "/r/nDynamic notification was not cleared, ignore sensor information : " + SensorAlarmID + "message:" + msg;
                            return;
                        }
                        else
                        {   //if the current message is not same as the previous message, update the message in the dictionary
                            sensorMessages[SensorAlarmID + "M" + _id + "M".ToString()] = msg;
                        }
                    }
                    else
                    {
                        //remove the sensor information from dictionary
                        message += "/r/nDynamic notification was cleared, Clearing sensor Information for sensorID: " + SensorAlarmID + "message:" + msg;
                        if (sensorMessages.ContainsKey(SensorAlarmID + "M" + _id + "M".ToString()))
                        {
                            sensorMessages.Remove(SensorAlarmID + "M" + _id + "M".ToString());
                        }
                    }
                    LogBook.Write(this.SensorFactoryID + " " + this.SensorAlarmID + " " + message);
                }
                //new message received from the service
                else if (IsDynamicNotificationCleared == false || IsDynamicNotificationCleared == null)
                {
                    LogBook.Write(this.SensorFactoryID + " " + "Add sensor information to dictionary sensorID: " + SensorAlarmID + "message:" + msg);
                    if (msg == string.Empty)
                    {
                        return;
                    }

                    //add new message to dictionary
                    sensorMessages.Add(SensorAlarmID + "M" + _id + "M".ToString(), msg);
                    LogBook.Write(this.SensorFactoryID + " " + "Sensor information added to dictionary sensorID: " + SensorAlarmID + "message:" + msg);
                }
                else if (!sensorMessages.ContainsKey(SensorAlarmID + "M" + _id + "M".ToString()) && IsDynamicNotificationCleared == true)
                {
                    /*it will happen only when the key was removed intentionally and when it was unable to connect the message board.*/
                    throw new Exception("Unable to connect");
                }
                else
                {
                    return;
                }

                foreach (KeyValuePair <string, string> pair in sensorMessages)
                {
                    LogBook.Write("Sensor's to be processed : " + pair.Key);
                }


                //clear all the messages in the message board
                WriteBytes(bb.ClearMemory());
                //wait for a second for the message board to reset
                Thread.Sleep(100);

                //loop through messages in the sensorMessages dictionary
                foreach (KeyValuePair <string, string> pair in sensorMessages)
                {
                    if (pair.Key.Contains("M" + _id + "M"))
                    {
                        //convert int value to corresponding char
                        char charfileLabel = (char)fileLabel;
                        //increment the file label for the next message
                        fileLabel += 1;
                        //validate file label
                        charfileLabel = ValidateFileLabel(charfileLabel, fileLabelsToProcess);
                        //add the new file label to fileLabelsToProcess string
                        fileLabelsToProcess += charfileLabel.ToString();
                        //specify the type of file to be used
                        bb.UseMemoryText(charfileLabel, 256);
                        LogBook.Write(this.SensorFactoryID + " " + "Creating file: " + charfileLabel.ToString() + " Sensor ID : " + pair.Key);
                        //allocate memory
                        byteArray = bb.AllocateMemory();

                        WriteBytes(byteArray);

                        Thread.Sleep(100);

                        LogBook.Write(this.SensorFactoryID + " " + "Allocated memory at file : " + charfileLabel.ToString() + "for Sensor ID : " + pair.Key);
                        //set the message for the text file
                        byteArray = bb.SetText(charfileLabel, "<color=red><font=sevenbold>" + pair.Value, AlphaSignProtocol.Transition.Rotate, AlphaSignProtocol.Special.None);

                        WriteBytes(byteArray);

                        Thread.Sleep(100);

                        LogBook.Write(this.SensorFactoryID + " " + "Set text at file : " + charfileLabel.ToString() + "for Sensor ID : " + pair.Key);
                    }
                }
                //if there are file labels to process
                if (fileLabelsToProcess != string.Empty)
                {
                    LogBook.Write(this.SensorFactoryID + " " + this.SensorAlarmID + " " + "Send run sequence command to message board");
                    //run the messages on the board
                    byteArray = bb.SetRunSequence(fileLabelsToProcess);
                    WriteBytes(byteArray);

                    Thread.Sleep(100);

                    LogBook.Write(this.SensorFactoryID + " " + this.SensorAlarmID + " " + "Sent run sequence command to message board for files : " + fileLabelsToProcess);
                }
                else
                {
                    LogBook.Write(this.SensorFactoryID + " " + this.SensorAlarmID + " " + "Call Display date time method");
                    //else display date and time
                    DisplayDateTime(bb);
                }
            }
            catch (Exception ex)
            {
                LogBook.Write(ex, this.SensorFactoryID + " " + this.SensorAlarmID + " " + "NotifyEngine-MsgBrdBetaBrite");

                if ((bool)IsDynamicNotificationCleared == false)
                {
                    /*remove the message from dictionary to push the data next time when the same message and same board came in*/
                    if (sensorMessages.ContainsKey(SensorAlarmID + "M" + _id + "M".ToString()))
                    {
                        sensorMessages.Remove(SensorAlarmID + "M" + _id + "M".ToString());
                    }
                }

                throw ex;
            }
        }