public INotificationChannelClient GetClient(string type, string endpointAddress) { if (type == null) { throw new ArgumentNullException(); } INotificationChannelClient client = _notificationChannelsWithName[type]; client.EndPointAddress = endpointAddress; return(client); }
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); }