Ejemplo n.º 1
0
        public void SetServerTime()
        {
            NotificationEndPointElement element            = null;
            NotificationClient          notificationClient = NotificationClient.GetInstance();

            //notificationClient.WhoAmI("MessageBoard", out element);

            AlarmObject alarmObject = new AlarmObject();

            alarmObject.SetServerTime = true;

            notificationClient.Send(alarmObject, new string[] { "MessageBoard" });
        }
        internal string WhoAmI(string name, out NotificationEndPointElement endPoint)
        {
            string comFullName = "";

            endPoint = null;
            foreach (ComposerElement element in AlarmModuleConfiguration.Instance.Configuration.Composers)
            {
                if (element.Name.ToLower() == name.ToLower())
                {
                    comFullName = element.ModuleType;
                    if (element.EndPoint != null && element.EndPoint.WType != "" && element.EndPoint.EndpointAddress != "")
                    {
                        endPoint = element.EndPoint;
                    }
                    break;
                }
            }
            return(comFullName);
        }
        internal NotifyComResponse InvokeNotifyEngine(INotifyObject notifyObject, NotificationEndPointElement endpoint)
        {
            //Implement client INotifyReceiver for client and notification server communication.
            int    notifyClienttimeOutValue = 0;
            string senderType = "", endpointAddress;

            if (endpoint != null && !string.IsNullOrEmpty(endpoint.WType) && !string.IsNullOrEmpty(endpoint.EndpointAddress))
            {
                senderType               = endpoint.WType;
                endpointAddress          = endpoint.EndpointAddress;
                notifyClienttimeOutValue = endpoint.Timeout;
                LogBook.Write(notifyObject.NotificationType + " end point type is " + endpointAddress);
            }
            else
            {
                senderType               = Interface.Alarm.AlarmModuleConfiguration.Instance.Configuration.EndPoint.WType;
                endpointAddress          = Interface.Alarm.AlarmModuleConfiguration.Instance.Configuration.EndPoint.EndpointAddress;
                notifyClienttimeOutValue = Interface.Alarm.AlarmModuleConfiguration.Instance.Configuration.EndPoint.Timeout;
                LogBook.Write(notifyObject.NotificationType + " end point type is {embed}");
            }

            NotifyComResponse response = null;

            if (senderType == "{embed}")
            {
                _notifyReceiver = CommunicationAdapter.GetInstance();
                response        = _notifyReceiver.Execute(notifyObject);
            }
            else
            {
                //Invoke remote object
                INotificationChannelClient client = _notifyClientEnd.GetClient(senderType, endpointAddress);
                //client.EndPointAddress = endpoint.EndpointAddress;
                client.OnReceive((data, remEndpoint) =>
                {
                    try
                    {
                        response = NotifyComResponse.Create(data);
                    }
                    catch (Exception ex)
                    {
                        response                 = new NotifyComResponse();
                        response.IsSucceeded     = true;
                        response.IsError         = true;
                        response.ResponseContent = "Notification Failed, while receiving data from notification engine.";
                        LogBook.Write("Error has occurred while receiving data from notification engine (Exception Message:" + ex.Message + ") \n Received Data: " + data);
                    }
                });

                bool timeout   = false;
                long startTick = DateTime.Now.Ticks;
Label4Retry:

                try
                {
                    client.Send(notifyObject.GetXML());
                }
                catch (Exception ex)
                {
                    if (notifyClienttimeOutValue == 0 || notifyClienttimeOutValue >= ((DateTime.Now.Ticks - startTick) / TimeSpan.TicksPerMillisecond))
                    {
                        timeout = true;
                    }

                    if (!timeout)
                    {
                        goto Label4Retry;
                    }
                    else
                    {
                        StringBuilder sb = new StringBuilder();
                        sb.AppendLine("Notification Service - Error has occurred while connecting to the remote notification engine.");
                        sb.AppendLine("Remote endpoint:" + endpointAddress);
                        sb.AppendLine("NotificationType:" + notifyObject.NotificationType);
                        sb.AppendLine("Data:" + notifyObject.NotificationData);
                        sb.AppendLine("Technical Information:" + ex.Message + ". " + ex.StackTrace);
                        LogBook.Write(sb.ToString(), "Notification Client", ErrorSeverity.Critical);

                        response                 = new NotifyComResponse();
                        response.IsSucceeded     = false;
                        response.IsError         = true;
                        response.ResponseContent = "Failed, while connecting to notification engine.";
                        LogBook.Write("Error has occurred while connecting to the remote notification engine (Exception Message:" + ex.Message + ")");


                        //record notification

                        NotifyTypes notifyType;
                        Enum.TryParse <NotifyTypes>(notifyObject.NotificationType.Trim(), true, out notifyType);

                        NotificationStyle notificationStyle = new NotificationStyle();
                        notificationStyle.RecordNotification(sb.ToString(), 0, 0, response.IsSucceeded ? NotifyStatus.PASS : NotifyStatus.FAIL, notifyType);
                    }
                }
            }
            return(response);
        }
        private void SendToNotifyEngine(CooperAtkins.Interface.Alarm.AlarmObject alarmObject, INotificationComposer composer, string composeType, NotificationEndPointElement endpoint)
        {
            INotifyObject[] notifyObjects = null;
            if (composer != null)
            {
                notifyObjects = composer.Compose(alarmObject);
            }

            if (notifyObjects != null)
            {
                foreach (INotifyObject notifyObject in notifyObjects)
                {
                    notifyObject.NotificationType = composeType;
                    Interface.NotifyCom.NotifyComResponse response = null;

                    //Invoke Engine and send
                    //Engine returns NotifyComResponse
                    response = InvokeNotifyEngine(notifyObject, endpoint);
                    composer.Receive(response, notifyObject);
                }
            }
        }