public void S124Parser() { byte[] msg = GetMessageRaw(@"STMMessageSamples\S124_01.gml"); var msgString = Serialization.ByteArrayToString(msg); var validator = new StmSchemaValidator(); validator.ValidateAreaMessageXML(msgString); var parser = new S124Parser(msgString); var id = parser.AreaMessageId; }
public virtual ResponseObj UploadArea([FromBody] string area, [FromUri] string deliveryAckEndPoint = null) { log.Info("Incoming request to " + GetCurrentMethod()); _messageType = _messageTypeService.Get(x => x.Name.ToLower() == "s124").First(); var parser = new S124Parser(area); var dataId = parser.AreaMessageId; var paramList = new List <KeyValuePair <string, string> >(); var param = new KeyValuePair <string, string>("deliveryAckEndPoint", deliveryAckEndPoint); paramList.Add(param); var errorMsgResponse = string.Empty; var request = Request; var headers = request.Headers; if (string.IsNullOrEmpty(area)) { log.Debug("AreaMessage is empty"); errorMsgResponse += "Required parameter AreaMessage is missing." + Environment.NewLine; throw CreateHttpResponseException(HttpStatusCode.BadRequest, "Required parameter AreaMessage is missing."); } try { if (string.IsNullOrEmpty(InstanceContext.CallerOrgId)) { log.Debug("Calling organization identity missing in header."); errorMsgResponse += "Calling organization identity missing in header." + Environment.NewLine; throw CreateHttpResponseException(HttpStatusCode.BadRequest, "Required header incomingOrganizationId is missing."); } //Write to log table _logEventService.LogInfo(EventNumber.VIS_uploadAreaMessage_request, EventDataType.S124, paramList, area); // Get identity ether from internal id talbe or from id registry var identity = _identityService.GetCallerIdentity(); var result = new UploadedMessage(); result.AckDelivered = false; result.DeliveryAckEndpoint = deliveryAckEndPoint; result.DeliveryAckReqested = string.IsNullOrEmpty(deliveryAckEndPoint) ? false : true; result.FetchedByShip = false; result.FetchTime = null; result.FromOrg = identity; result.FromServiceId = InstanceContext.CallerServiceId; result.Message = Serialization.StrToByteArray(area); result.MessageType = _messageType; result.Notified = false; result.ReceiveTime = DateTime.UtcNow; result.MessageID = dataId; _uploadedMessageService.InsertArea(result); //Notify STM module var notification = new Common.Services.Internal.Interfaces.Notification(); notification.FromOrgName = identity.Name; notification.FromOrgId = identity.UID; notification.FromServiceId = InstanceContext.CallerServiceId; notification.NotificationType = EnumNotificationType.MESSAGE_WAITING; notification.Subject = "New Area message uploaded."; notification.NotificationSource = EnumNotificationSource.VIS; var notified = _notificationService.Notify(notification); if (notified) { result.Notified = true; _uploadedMessageService.Update(result); } var responsObj = new ResponseObj("Success store message"); //Save to DB _context.SaveChanges(); _logEventService.LogSuccess(EventNumber.VIS_uploadAreaMessage_response, EventDataType.Other, paramList, JsonConvert.SerializeObject(responsObj, Formatting.Indented)); return(responsObj); } catch (HttpResponseException ex) { log.Error(ex.Message, ex); _logEventService.LogError(EventNumber.VIS_uploadAreaMessage_request, EventType.Error_internal, paramList, JsonConvert.SerializeObject(ex.Response, Formatting.Indented)); throw; } catch (DbEntityValidationException dbEx) { var response = request.CreateResponse(HttpStatusCode.InternalServerError); StringBuilder sb = new StringBuilder(); foreach (var item in dbEx.EntityValidationErrors) { sb.Append(item + " errors: "); foreach (var i in item.ValidationErrors) { sb.Append(i.PropertyName + " : " + i.ErrorMessage); } sb.Append(Environment.NewLine); } string msg = "VIS internal server error. " + dbEx.Message; _logEventService.LogError(EventNumber.VIS_uploadAreaMessage_request, EventType.Error_internal, paramList, msg); log.ErrorFormat("Validation errors: {0}", sb.ToString()); throw CreateHttpResponseException(HttpStatusCode.InternalServerError, sb.ToString()); } catch (Exception ex) { log.Error(ex.Message, ex); _logEventService.LogError(EventNumber.VIS_uploadAreaMessage_request, EventType.Error_internal, paramList, ex.Message); string msg = "VIS internal server error. " + ex.Message; throw CreateHttpResponseException(HttpStatusCode.InternalServerError, msg); } }