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);
            }
        }
Esempio n. 3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="messages"></param>
        public void SendAck(IList <UploadedMessage> messages)
        {
            var client = new STM.SSC.Internal.SccPrivateService();

            foreach (var message in messages)
            {
                try
                {
                    if (message.DeliveryAckReqested && !message.AckDelivered)
                    {
                        var ackObject = new DeliveryAck
                        {
                            AckResult      = "OK",
                            FromId         = message.FromOrg.UID,
                            FromName       = message.FromOrg.Name,
                            Id             = Guid.NewGuid().ToString(),
                            ReferenceId    = message.MessageID,
                            TimeOfDelivery = DateTime.UtcNow,
                            ToId           = InstanceContext.ServiceId,
                            ToName         = InstanceContext.ServiceName
                        };

                        var response = client.CallService(new CallServiceRequestObj
                        {
                            Body           = JsonConvert.SerializeObject(ackObject),
                            EndpointMethod = WebRequestHelper.CombineUrl(message.DeliveryAckEndpoint, "acknowledgement"),
                            Headers        = new List <Header>
                            {
                                new Header("content-type", "application/json; charset=utf-8")
                            },
                            RequestType = "POST",
                        });

                        if (response.StatusCode != 200)
                        {
                            log.Debug("Error from call service " + response.Body);
                            throw new Exception("Call service returned " + response.StatusCode);
                        }

                        //Add logg event
                        switch (message.MessageType.Name)
                        {
                        case "RTZ":
                            _logEventService.LogSuccess(EventNumber.VIS_sendAcknowledgement, EventDataType.RTZ, null, JsonConvert.SerializeObject(ackObject, Formatting.Indented));
                            break;

                        case "TXT":
                            _logEventService.LogSuccess(EventNumber.VIS_sendAcknowledgement, EventDataType.TXT, null, JsonConvert.SerializeObject(ackObject, Formatting.Indented));
                            break;

                        case "S124":
                            _logEventService.LogSuccess(EventNumber.VIS_sendAcknowledgement, EventDataType.S124, null, JsonConvert.SerializeObject(ackObject, Formatting.Indented));
                            break;

                        case "PCM":
                            _logEventService.LogSuccess(EventNumber.VIS_sendAcknowledgement, EventDataType.PCM, null, JsonConvert.SerializeObject(ackObject, Formatting.Indented));
                            break;
                        }
                    }
                }
                catch (Exception ex)
                {
                    log.Error(ex.Message, ex);

                    // Send notification
                    var notification = new Internal.Interfaces.Notification();
                    notification.FromOrgName        = message.FromOrg.Name;
                    notification.FromOrgId          = message.FromOrg.UID;
                    notification.FromServiceId      = message.FromServiceId;
                    notification.NotificationType   = EnumNotificationType.ERROR_MESSAGE;
                    notification.Subject            = "Unable to send acknowledgement";
                    notification.Body               = string.Format("Acknowledgement for voyageplan with UVID {0} could not be sent to {1}, {2}", message.MessageID, message.FromOrg.Name, message.FromOrg.UID);
                    notification.NotificationSource = EnumNotificationSource.VIS;
                    _notificationService.Notify(notification);
                }
            }
        }