private void SendToAmssService(string message, string dataId, string amssEndpoint, Identity identity) { var paramList = new List <KeyValuePair <string, string> >(); var p1 = new KeyValuePair <string, string>("dataId", dataId); paramList.Add(p1); p1 = new KeyValuePair <string, string>("amssEndpoint", amssEndpoint); paramList.Add(p1); var requestObj = new CallServiceRequestObj { Body = message, EndpointMethod = WebRequestHelper.CombineUrl(amssEndpoint, "/amss/state_update"), Headers = null, RequestType = "POST", }; try { var headers = new List <Header> { new Header("content-type", "application/xml") }; requestObj.Headers = headers; _logEventService.LogInfo(EventNumber.SPIS_amss_request, EventDataType.PCM, paramList, JsonConvert.SerializeObject(requestObj, Newtonsoft.Json.Formatting.Indented)); var client = new SSC.Internal.SccPrivateService(); var queueResult = client.CallService(requestObj); if (queueResult.StatusCode < 200 || queueResult.StatusCode >= 300) { throw new Exception("Unable to send state update. " + queueResult.StatusCode + " " + queueResult.Body); } _logEventService.LogSuccess(EventNumber.SPIS_amss_response, EventDataType.Other, paramList, JsonConvert.SerializeObject(queueResult, Newtonsoft.Json.Formatting.Indented)); } catch (Exception ex) { log.Error(ex.Message, ex); _logEventService.LogError(EventNumber.SPIS_amss_request, EventType.Error_internal, paramList, JsonConvert.SerializeObject(requestObj, Newtonsoft.Json.Formatting.Indented)); // Send notification var notification = new Interfaces.Notification(); notification.FromOrgName = identity.Name; notification.FromOrgId = identity.UID; notification.FromServiceId = InstanceContext.CallerServiceId; notification.NotificationType = EnumNotificationType.ERROR_MESSAGE; notification.Subject = "Unable to send message"; notification.Body = string.Format("Unable to send message with id {0} to identity {1}, {2}. {3}", dataId, identity.Name, identity.UID, ex.Message); notification.NotificationSource = EnumNotificationSource.SPIS; _notificationService.Notify(notification); } }
/// <summary> /// /// </summary> /// <param name="message"></param> /// <param name="dataId"></param> /// <param name="endpoint"></param> /// <param name="identity"></param> public void SendMessage(string message, string dataId, string endpoint, Identity identity) { var client = new SSC.Internal.SccPrivateService(); string msg = string.Format("Voyageplan with uvid {0} sent to subscriber {1}", dataId, identity.Name); //Add event logging var paramList = new List <KeyValuePair <string, string> >(); var param = new KeyValuePair <string, string>("Message", msg); paramList.Add(param); try { var result = client.CallService(new CallServiceRequestObj { Body = message, EndpointMethod = WebRequestHelper.CombineUrl(endpoint, "voyagePlans?uvid=" + dataId), Headers = new List <Header> { new Header("content-type", "text/xml; charset=utf-8") }, RequestType = "POST", }); if (result.StatusCode != 200) { throw new Exception(result.Body); } log.Info(msg); _logEventService.LogSuccess(EventNumber.VIS_publishMessage, EventDataType.RTZ, paramList, message); } catch (Exception ex) { log.Error(ex.Message, ex); //logg event _logEventService.LogError(EventNumber.VIS_publishMessage, EventType.Error_internal, paramList, ex.Message); // Send notification var notification = new Interfaces.Notification(); notification.FromOrgName = identity.Name; notification.FromOrgId = identity.UID; notification.FromServiceId = InstanceContext.CallerServiceId; notification.NotificationType = EnumNotificationType.ERROR_MESSAGE; notification.Subject = "Unable to send message to subscriber"; notification.Body = string.Format("Voyageplan with UVID {0} could not be sent to subscriber {1}, {2}", dataId, identity.Name, identity.UID); notification.NotificationSource = EnumNotificationSource.VIS; _notificationService.Notify(notification); } }
/// <summary> /// /// </summary> /// <param name="notification"></param> /// <returns></returns> public bool Notify(Interfaces.Notification notification) { try { var sentToClient = _stmModuleService.Notify(notification); if (sentToClient) { log.Info("Success send notification to STM Module"); } else { log.Info("Notification saved to VIS database. Unable to send it to STM Module. STM Module needs to pull the notification from VIS."); } return(true); } catch (Exception ex) { log.Error(ex.Message, ex); throw; } }
private string SetupQueue(string message, string dataId, string mbEndpoint, Identity identity) { string result = null; string vesselId = ConfigurationManager.AppSettings["vesselId"]; if (!string.IsNullOrEmpty(InstanceContext.IMO)) { vesselId += "IMO:" + InstanceContext.IMO; } else if (!string.IsNullOrEmpty(InstanceContext.MMSI)) { vesselId += "MMSI:" + InstanceContext.MMSI; } else { throw new Exception("Failed to find vessel identifier."); } try { // Setup filter var queueFilter = new List <QueueFilter> { new QueueFilter { type = "VESSEL", element = vesselId } }; var headers = new List <Header> { new Header("content-type", "application/json; charset=utf-8") }; var client = new SSC.Internal.SccPrivateService(); var queueResult = client.CallService(new CallServiceRequestObj { Body = JsonConvert.SerializeObject(queueFilter), EndpointMethod = WebRequestHelper.CombineUrl(mbEndpoint, "/mb/mqs"), Headers = headers, RequestType = "POST", }); if (queueResult.StatusCode == 200 || queueResult.StatusCode == 201) { result = queueResult.Body; } else { throw new Exception("Unable to create queue. " + queueResult.StatusCode + " " + queueResult.Body); } } catch (Exception ex) { log.Error(ex.Message, ex); // Send notification var notification = new Interfaces.Notification(); notification.FromOrgName = identity.Name; notification.FromOrgId = identity.UID; notification.FromServiceId = InstanceContext.CallerServiceId; notification.NotificationType = EnumNotificationType.ERROR_MESSAGE; notification.NotificationSource = EnumNotificationSource.SPIS; notification.Subject = "Unable to send set up message broker queue"; notification.Body = string.Format("Unable to create queue for message with id {0}, identity {1}, {2}", dataId, identity.Name, identity.UID); _notificationService.Notify(notification); } return(result); }