public void SendReport(string requestor, ShipPosition position, string referenceId, DataCenterTypesIDE.responseTypeType responseType, DataCenterLogic.DataCenterTypesIDE.messageTypeType messageType) { //Configuracion del datacenter var configMgr = new ConfigurationManager(); //DataCenterTypesIDE.responseTypeType responseType = getResponseTypeFromRequest(spr); //DataCenterLogic.DataCenterTypesIDE.messageTypeType messageType = getMessageTypeFromRequest(spr); //Obtengo el ship al que pertenece la posicion using (var shipdao = new ShipDataAccess()) { Ship ship = shipdao.getById(position.ShipId); var shipPosReport = new DataCenterTypesIDE.ShipPositionReportType(); var point = SqlGeography.STPointFromWKB(new System.Data.SqlTypes.SqlBytes(position.Position.ToArray()), 4326); shipPosReport.ASPId = configMgr.Configuration.ASPId; shipPosReport.DataUserProvider = "1005"; //if( responseType == DataCenterLogic.DataCenterTypesIDE.responseTypeType.Item4 ) // shipPosReport.DataUserProvider = "3005"; shipPosReport.DataUserRequestor = requestor; shipPosReport.DCId = configMgr.Configuration.DataCenterID; shipPosReport.DDPVersionNum = DDPVersionManager.currentDDP(); shipPosReport.IMONum = ship.IMONum; shipPosReport.Latitude = WGS84LatFormat(point.Lat.Value); shipPosReport.Longitude = WGS84LongFormat(point.Long.Value); shipPosReport.MessageId = MessageIdManager.Generate(); shipPosReport.MessageType = messageType; shipPosReport.MMSINum = ship.MMSINum; shipPosReport.ReferenceId = referenceId; shipPosReport.ResponseType = responseType; shipPosReport.schemaVersion = decimal.Parse(configMgr.Configuration.SchemaVersion); shipPosReport.ShipborneEquipmentId = ship.EquipID; shipPosReport.ShipName = ship.Name; shipPosReport.test = DataCenterLogic.DataCenterTypesIDE.testType.Item1; shipPosReport.TimeStamp1 = position.TimeStamp; shipPosReport.TimeStamp2 = position.TimeStampInASP; shipPosReport.TimeStamp3 = position.TimeStampOutASP; shipPosReport.TimeStamp4 = position.TimeStampInDC; shipPosReport.TimeStamp5 = DateTime.UtcNow; log.Debug("Enqueing Report for ship: " + shipPosReport.IMONum + " Pos. Long. Lat.:" + shipPosReport.Longitude + " " + shipPosReport.Latitude + " Requestor: " + shipPosReport.DataUserRequestor); QueueManager.Instance().EnqueueOut(shipPosReport, "shipPositionReport"); } }
public void ProcessPendingUpdates() { DDPImportHelper helper = new DDPImportHelper(); using (TransactionScope ts = new TransactionScope(TransactionScopeOption.RequiresNew, TimeSpan.FromMinutes(10))) { try { var ddpvermgr = new DDPVersionManager(); var pendings = PendingUpdateManager.GetPendingUpdates(); foreach (var pending in pendings) { DDPVersion ver = null; if (pending.type == 0) { ver = ddpvermgr.GetInmediateDDPVersion(pending.targetVersion); } else { ver = ddpvermgr.GetRegularDDPVersion(pending.targetVersion); } if (ver != null) { log.Info(string.Format("ProcessPendingUpdates: version {0} already exists skping ...", pending.targetVersion)); continue; } helper.UpdateIncrementalOrRegular(pending); } using (var d = new PendingUpdatesDataAccess()) { d.Remove(pendings); } } catch (Exception ex) { log.Error("ProcessPendingUpdates: error!", ex); } ts.Complete(); } }
public Message MakeDDPRequest(DDPServerTypes.DDPRequestType ddpRequest) { ConfigurationManager configMgr = new ConfigurationManager(); var ddpverda = new DDPVersionManager(); var ddpver = ddpverda.DDPFromDate(DateTime.UtcNow); //Fill necesary parameters ddpRequest.DDPVersionNum = ddpver.regularVer + ":" + ddpver.inmediateVer; ddpRequest.MessageId = MessageIdManager.Generate(); ddpRequest.MessageType = DataCenterLogic.DDPServerTypes.messageTypeType.Item9; ddpRequest.Originator = configMgr.Configuration.DataCenterID; //ddpRequest.ReferenceId ddpRequest.schemaVersion = decimal.Parse(configMgr.Configuration.SchemaVersion); ddpRequest.TimeStamp = DateTime.UtcNow; //Enqueue DDPrequest Message msgout = new Message(ddpRequest); msgout.Label = "ddpRequest"; return(msgout); }
/// <summary> /// Envia un Recibo a el Destino especificado. /// </summary> /// <param name="Destination">Destino del recibo</param> /// <param name="ReferenceId">ID LRIT del mensaje al que hace referencia este recibo</param> /// <param name="receiptCode">Codigo del recibo</param> /// <param name="msg">Mensaje de texto decribiendo el porque del recibo</param> static public void SendReceipt(string Destination, string ReferenceId, DataCenterLogic.DataCenterTypesIDE.receiptCodeType receiptCode, string msg) { //The ship does not exists in our system, send receipt var configMgr = new ConfigurationManager(); DataCenterTypesIDE.ReceiptType receipt = new DataCenterLogic.DataCenterTypesIDE.ReceiptType(); receipt.DDPVersionNum = DDPVersionManager.currentDDP(); receipt.Destination = Destination; receipt.Message = msg; receipt.MessageId = MessageIdManager.Generate(); receipt.MessageType = DataCenterLogic.DataCenterTypesIDE.messageTypeType3.Item7; receipt.ReceiptCode = receiptCode; receipt.Originator = "1005"; receipt.ReferenceId = ReferenceId; receipt.schemaVersion = decimal.Parse(configMgr.Configuration.SchemaVersion); receipt.test = DataCenterLogic.DataCenterTypesIDE.testType.Item1; receipt.TimeStamp = DateTime.UtcNow; Message msgout = new Message(receipt); msgout.Label = "receipt"; QueueManager.Instance().EnqueueOut(msgout); }
/// <summary> /// Verifica si la ultima posicion de cada uno de nuestros barcos esta en alguna standing order. /// Tinen en cuenta hay un STOP para ese requestor. /// Tiene en cuenta la titulacion /// </summary> public void Process() { ShipDataAccess sda = null; try { sda = new ShipDataAccess(); var cgm = new ContractingGovermentManager(); var ddpm = new DDPVersionManager(); var ddpVersion = ddpm.GetCurrentDDPVersion(); log.Info("Procesando standing orders."); foreach (Ship ship in sda.GetAll()) { ShipPosition pos = null; using (var spda = new ShipPositionDataAccess()) { pos = spda.GetLastShipPosition(ship.IMONum); } if (pos == null) { log.Info(string.Format("No hay ultima posicion para {0}", ship.IMONum)); continue; } List <StandingOrder> orders = new List <StandingOrder>(); using (var soda = new StandingOrderDataAccess()) { orders = soda.GetOrdersForPosition(pos, ddpVersion); } if (orders.Count == 0) { log.Info(string.Format("No hay ninguna SO para {0},posid:{1},ddpVer:{2}", ship.IMONum, pos.Id, ddpVersion.Id)); continue; } var sprm = new ShipPositionReportManager(); foreach (StandingOrder order in orders) { var cg = order.Place.ContractingGoverment; //Skipeo las SO de argentina (no chekeo si mis barcos estan en mis SO) if (cg.LRITId == 1005) { continue; } using (var asprda = new ActiveShipPositionRequestDataAccess()) { if (asprda.IsStopRequired(ship, cg.LRITId.ToString()) == true) { log.Info("Stop Activo Para el Barco: " + ship.IMONum + " Requestor: " + cg.LRITId.ToString()); continue; } } log.Info(string.Format("El barco {0} esta dentro de la standing order {1}", ship.IMONum, order.PlaceId)); if (cgm.IsEntitled(cg, pos, ddpVersion, false) == false) { log.Info("no esta titulado para recibir la informacion, se envia recibo"); ReceiptManager.SendReceipt(cg.LRITId.ToString(), "0", DataCenterLogic.DataCenterTypesIDE.receiptCodeType.Item0, string.Format("Not entitled to recieve")); } else { sprm.SendReport(cg.LRITId.ToString(), pos, "", DataCenterLogic.DataCenterTypesIDE.responseTypeType.Item1, DataCenterLogic.DataCenterTypesIDE.messageTypeType.Item1); } } } } catch (Exception ex) { log.Error("Error procesando StandingOrders", ex); } finally { sda.Dispose(); } }
public void UpdateIncrementalOrRegular(PendingDDPUpdate pending) { XmlDocument newdoc = new XmlDocument(); ICSharpCode.SharpZipLib.Zip.ZipFile zipFile = new ICSharpCode.SharpZipLib.Zip.ZipFile(new MemoryStream(pending.DDPUpdate.DDPFile.ToArray())); Stream stream = zipFile.GetInputStream(0); newdoc.Load(stream); //--------------------------------------------------- XmlNamespaceManager nsmanager = new XmlNamespaceManager(newdoc.NameTable); nsmanager.AddNamespace("lr", "http://gisis.imo.org/XML/LRIT/ddp/2008"); //--------------------------------------------------- XmlNode root = newdoc.SelectSingleNode("/lr:DataDistributionPlan-IncrementalUpdate", nsmanager); //Get ddp to modify var verman = new DDPVersionManager(); //Just get what is ready from the XML string qstr = string.Format("/lr:DataDistributionPlan-IncrementalUpdate/lr:{0}[@base{0}VersionNum='{1}' and @target{0}VersionNum='{2}']", pending.type == 0?"Immediate":"Regular", pending.baseVersion, pending.targetVersion); //Ontener el nodo "inmediate" o "regular" XmlNode inmediate = newdoc.SelectSingleNode(qstr, nsmanager); string baseVer = inmediate.Attributes[pending.type == 0 ? "baseImmediateVersionNum" : "baseRegularVersionNum"].Value; string targetVer = inmediate.Attributes[pending.type == 0 ? "targetImmediateVersionNum" : "targetRegularVersionNum"].Value; DateTime targetImplementationAt = DateTime.Parse(inmediate.Attributes["targetImplementationAt"].Value); var ddpver = pending.type == 0 ? verman.GetInmediateDDPVersion(baseVer) : verman.GetRegularDDPVersion(baseVer); if (ddpver == null) { log.Error(string.Format("UpdateIncrementalOrRegular: Unable to get old DDP file with version {1} type:{0}--> aborting", baseVer, pending.type)); return; } byte[] rawbuffer = ddpver.DDPFile.ToArray(); MemoryStream xms = new MemoryStream(rawbuffer); XmlDocument olddoc = new XmlDocument(); if (rawbuffer[0] == 0x50 && rawbuffer[1] == 0x4b) { ICSharpCode.SharpZipLib.Zip.ZipFile zipFile0 = new ICSharpCode.SharpZipLib.Zip.ZipFile(xms); Stream s = zipFile0.GetInputStream(0); olddoc.Load(s); } else { olddoc.Load(xms); } //Generar nueva version del xml mezclando los dos docuemtnos; var theNewXml = MixDocs(inmediate, olddoc, nsmanager); string newver = ddpver.regularVer + ":" + targetVer; if (pending.type != 0) { newver = targetVer + ":" + ddpver.inmediateVer; } var ms = new MemoryStream(300000); theNewXml.Save(ms); var raw = ms.ToArray(); File.WriteAllBytes(@"c:\" + newver.Split(':')[0] + "x" + newver.Split(':')[1] + ".textos", raw); Import(theNewXml, DDPManager.InsertCompleteDDP(newver, targetImplementationAt, raw)); log.Info("UpdateIncrementalOrRegular: New version ready => " + newver); stream.Close(); }
/// <summary> /// Valida la combinacion de accesType y requestType para un ShipPositionRequest. /// Si hay algun error esta funcion envia un Receipt al requisitor, informandole el problema. /// </summary> /// <param name="shipPositionRequest">El mensaje ShipPositionRequest a ser analizado.</param> /// <returns>Verdadero, si el mensaje es valido, False otra cosa</returns> private bool ValidateShipPositionRequest(DataCenterLogic.DataCenterTypes.ShipPositionRequestType shipPositionRequest) { var ddpm = new DDPVersionManager(); var ddpVersion = ddpm.GetCurrentDDPVersion(); log.Info("Validando SPR"); #region Port state with time trigger could not be used with RequestType 1,7 or 9: //log.Debug("Port state with time trigger could not be used with RequestType 1,7 or 9"); if (shipPositionRequest.AccessType == DataCenterLogic.DataCenterTypes.accessTypeType.Item3 && (shipPositionRequest.RequestType == DataCenterLogic.DataCenterTypes.requestTypeType.Item1 || shipPositionRequest.RequestType == DataCenterLogic.DataCenterTypes.requestTypeType.Item7 || shipPositionRequest.RequestType == DataCenterLogic.DataCenterTypes.requestTypeType.Item9)) { log.Error("Validacion erronea, se envia receipt"); ReceiptManager.SendReceipt(shipPositionRequest.DataUserRequestor, shipPositionRequest.MessageId, DataCenterLogic.DataCenterTypesIDE.receiptCodeType.Item7, string.Format("Invalid request parameters: Port could not be used with RequestType 1,7 or 9")); return(false); } #endregion #region Access type 0 only with message 4 and request 0 //log.Debug("AccessType 0 (reset) solo valido con RT 0 y MS 4"); if (shipPositionRequest.AccessType == DataCenterLogic.DataCenterTypes.accessTypeType.Item0 || shipPositionRequest.RequestType == requestTypeType.Item0) { //Invalid request parameters: AccessType 0 only valid with MessageType 4 if (shipPositionRequest.MessageType != DataCenterLogic.DataCenterTypes.messageTypeType1.Item4) { ReceiptManager.SendReceipt(shipPositionRequest.DataUserRequestor, shipPositionRequest.MessageId, DataCenterLogic.DataCenterTypesIDE.receiptCodeType.Item7, string.Format("Invalid request parameters: AccessType 0 only valid with MessageType 4")); log.Error("Validacion erronea, se envia receipt"); return(false); } // Invalid request parameters: AccessType 0 only valid with RequestType 0 if (shipPositionRequest.RequestType != DataCenterLogic.DataCenterTypes.requestTypeType.Item0 || shipPositionRequest.AccessType != DataCenterLogic.DataCenterTypes.accessTypeType.Item0) { ReceiptManager.SendReceipt(shipPositionRequest.DataUserRequestor, shipPositionRequest.MessageId, DataCenterLogic.DataCenterTypesIDE.receiptCodeType.Item7, string.Format("Invalid request parameters: AccessType 0 only valid with RequestType 0")); log.Info("Validacion erronea, se envia receipt"); return(false); } } #endregion #region REVISAR /* * log.Debug("Port State"); * //Invalid request parameters: Port state and RequestTypes 1,7 and 9 only valid with AccessType 5 * if( shipPositionRequest.ItemElementName == DataCenterLogic.DataCenterTypes.ItemChoiceType.Port || * shipPositionRequest.ItemElementName == DataCenterLogic.DataCenterTypes.ItemChoiceType.PortFacility * && ( shipPositionRequest.RequestType == DataCenterLogic.DataCenterTypes.requestTypeType.Item1 || * shipPositionRequest.RequestType == DataCenterLogic.DataCenterTypes.requestTypeType.Item7 || * shipPositionRequest.RequestType == DataCenterLogic.DataCenterTypes.requestTypeType.Item9 ) * && shipPositionRequest.AccessType != DataCenterLogic.DataCenterTypes.accessTypeType.Item5 ) * { * ReceiptManager.SendReceipt(shipPositionRequest.DataUserRequestor, shipPositionRequest.MessageId, DataCenterLogic.DataCenterTypesIDE.receiptCodeType.Item7, * string.Format("Invalid request parameters: Port state and RequestTypes 1,7 and 9 only valid with AccessType 5")); * * return false; * } */ #endregion #region Invalid request parameters: RequestTypes 1,7 and 9 are the only valid for MessageType 5 //log.Debug("Si es mensaje de tipo 5 (Sar) RT solo puede ser 1 o 9"); if (shipPositionRequest.MessageType == DataCenterLogic.DataCenterTypes.messageTypeType1.Item5 && shipPositionRequest.RequestType != DataCenterLogic.DataCenterTypes.requestTypeType.Item1 && shipPositionRequest.RequestType != DataCenterLogic.DataCenterTypes.requestTypeType.Item7 && shipPositionRequest.RequestType != DataCenterLogic.DataCenterTypes.requestTypeType.Item9) { log.Error("Validacion erronea, se envia receipt"); ReceiptManager.SendReceipt(shipPositionRequest.DataUserRequestor, shipPositionRequest.MessageId, DataCenterLogic.DataCenterTypesIDE.receiptCodeType.Item7, string.Format("Invalid request parameters: RequestTypes 1,7 and 9 are the only valid for MessageType 5")); return(false); } #endregion #region Distance is only valid with access type 3 log.Debug("Distance is only valid with access type 3"); if (shipPositionRequest.Distance != "0" && shipPositionRequest.AccessType != DataCenterLogic.DataCenterTypes.accessTypeType.Item3) { log.Info("Validacion erronea, se envia receipt"); ReceiptManager.SendReceipt(shipPositionRequest.DataUserRequestor, shipPositionRequest.MessageId, DataCenterLogic.DataCenterTypesIDE.receiptCodeType.Item7, string.Format("Invalid request parameters: Distance is only valid with access type 3")); return(false); } #endregion #region Request Duration not valid for one time poll log.Debug("Request Duration not valid for one time poll"); if (ShipPositionRequestHelper.IsOneTimePoll(shipPositionRequest.RequestType) && (shipPositionRequest.RequestDuration != null && (shipPositionRequest.RequestDuration.startTimeSpecified == true || shipPositionRequest.RequestDuration.stopTimeSpecified == true))) { log.Info("Validacion erronea, se envia receipt"); ReceiptManager.SendReceipt(shipPositionRequest.DataUserRequestor, shipPositionRequest.MessageId, DataCenterLogic.DataCenterTypesIDE.receiptCodeType.Item7, string.Format("Invalid request parameters: Request Duration not valid for one time poll")); return(false); } #endregion #region Port State log.Debug("Validacion Para PortStates"); if (shipPositionRequest.AccessType == DataCenterLogic.DataCenterTypes.accessTypeType.Item3 || shipPositionRequest.AccessType == DataCenterLogic.DataCenterTypes.accessTypeType.Item5) { if (shipPositionRequest.ItemElementName != ItemChoiceType.Port && shipPositionRequest.ItemElementName != ItemChoiceType.PortFacility) { log.Info("invalid fields for port state request, ItemElementName not port or portfacility"); ReceiptManager.SendReceipt(shipPositionRequest.DataUserRequestor, shipPositionRequest.MessageId, DataCenterLogic.DataCenterTypesIDE.receiptCodeType.Item7, string.Format("Invalid fields for port state request, ItemElementName not port or portfacility")); return(false); } string portName = shipPositionRequest.Item.ToString(); using (var pda = new PlaceDataAccess()) { if (pda.PortExists(portName, ddpVersion.Id) == false && pda.PortFacilityExists(portName, ddpVersion.Id) == false) { log.Info("invalid fields for port state request, Item" + shipPositionRequest.Item.ToString() + " doesn't exists"); ReceiptManager.SendReceipt(shipPositionRequest.DataUserRequestor, shipPositionRequest.MessageId, DataCenterLogic.DataCenterTypesIDE.receiptCodeType.Item7, string.Format("invalid fields for port state request, Item" + shipPositionRequest.Item.ToString() + " doesn't exists") ); return(false); } } } #endregion #region AccessType2 log.Debug("Validacion Para AccessType2"); if (shipPositionRequest.AccessType == DataCenterLogic.DataCenterTypes.accessTypeType.Item2 && shipPositionRequest.RequestType != requestTypeType.Item7) { ReceiptManager.SendReceipt(shipPositionRequest.DataUserRequestor, shipPositionRequest.MessageId, DataCenterLogic.DataCenterTypesIDE.receiptCodeType.Item7, string.Format("Access type 2 only valid for archived data")); return(false); } #endregion //Verifica si existe el Data User que requiere la información var cgm = new ContractingGovermentManager(); var contractingGoverment = cgm.GetContractingGovermentByLRITId(shipPositionRequest.DataUserRequestor, ddpVersion.Id); if (contractingGoverment == null) { string strError = string.Format("Specified LDU '{0}' does not exist", shipPositionRequest.DataUserRequestor); //Arma mensaje de Recibo DataCenterLogic.DataCenterTypes.ReceiptType receipt = new DataCenterLogic.DataCenterTypes.ReceiptType(); var cmgr = new ConfigurationManager(); receipt.DDPVersionNum = DDPVersionManager.currentDDP(); receipt.Destination = shipPositionRequest.DataUserRequestor; receipt.Message = strError; receipt.MessageId = MessageIdManager.Generate(); receipt.MessageType = DataCenterLogic.DataCenterTypes.messageTypeType3.Item7; receipt.Originator = cmgr.Configuration.DataCenterID; receipt.ReceiptCode = DataCenterLogic.DataCenterTypes.receiptCodeType.Item7; receipt.ReferenceId = shipPositionRequest.MessageId; receipt.schemaVersion = decimal.Parse(cmgr.Configuration.SchemaVersion); receipt.test = DataCenterLogic.DataCenterTypes.testType.Item1; receipt.TimeStamp = DateTime.UtcNow; Message msgout = new Message(receipt); msgout.Label = "receipt"; //Encola mensaje QueueManager.Instance().EnqueueOut(msgout); log.Error(strError); return(false); } log.Info("Validacion Ok"); return(true); }
/// <summary> /// Procesa un pedido de posicion historica. /// Los pedidos de posicion historicas son RequestType 7 y RequestType 9 /// </summary> /// <param name="shipPositionRequest">Mensaje de ShipPositionRequest</param> /// <param name="ship">Barco al que se hace referencia</param> private void ProcessHistoricShipPositionRequest(DataCenterLogic.DataCenterTypes.ShipPositionRequestType shipPositionRequest, Ship ship) { log.Info("Procesando ShipPositionRequest Historico"); log.Debug("Obteniendo CgId de LRITId"); //Obtener Contracting goverment ID ContractingGovermentManager cgmgr = new ContractingGovermentManager(); var ddpm = new DDPVersionManager(); var currentDDP = ddpm.GetCurrentDDPVersion(); var contractingGoverment = cgmgr.GetContractingGovermentByLRITId(shipPositionRequest.DataUserRequestor, currentDDP.Id); if (contractingGoverment == null) { log.Info("CGID no válido se envia recibo"); ReceiptManager.SendReceipt(shipPositionRequest.DataUserRequestor, shipPositionRequest.MessageId, DataCenterLogic.DataCenterTypesIDE.receiptCodeType.Item7, string.Format("Invalid Contracting Government ID")); return; } ShipPositionManager spm = new ShipPositionManager(); List <ShipPosition> positions = new List <ShipPosition>(); log.Debug("Verificando si se pide ultima posicion"); if (ShipPositionRequestHelper.IsMostRecentPosition(shipPositionRequest.RequestType)) { ShipPosition pos = spm.GetLastShipPosition(shipPositionRequest.IMONum); if (pos != null) { positions.Add(pos); } } else { log.Debug("No, se piden mas posiciones"); log.Debug("Verificando titulacion"); positions = spm.GetShipPositionHistory(shipPositionRequest.IMONum, shipPositionRequest.RequestDuration.startTime, shipPositionRequest.RequestDuration.stopTime); } if (positions.Count == 0) { log.Info("No hay posiciones"); //The ship didnt send message in that period ReceiptManager.SendReceipt(shipPositionRequest.DataUserRequestor, shipPositionRequest.MessageId, DataCenterLogic.DataCenterTypesIDE.receiptCodeType.Item6, string.Format("No archived data for the request")); return; } var configMgr = new ConfigurationManager(); log.Debug("Procesando Posiciones"); int not_entitled_count = 0; var ddpVersion = ddpm.DDPFromDate(DateTime.UtcNow); var cgOld = cgmgr.GetContractingGovermentByLRITId(shipPositionRequest.DataUserRequestor, ddpVersion.Id); foreach (ShipPosition position in positions) { bool verifyWatersOf = true; if (shipPositionRequest.AccessType == accessTypeType.Item3 || shipPositionRequest.AccessType == accessTypeType.Item5) { verifyWatersOf = false; } //Solo valido titulacion si el access type es distinto a 6 (SAR) if (shipPositionRequest.AccessType != accessTypeType.Item6 && (ddpVersion == null || cgmgr.IsEntitled(cgOld, position, ddpVersion, verifyWatersOf) == false)) { not_entitled_count++; continue; } var sprm = new ShipPositionReportManager(); if (ShipPositionRequestHelper.IsMostRecentPosition(shipPositionRequest.RequestType)) { sprm.SendReport(shipPositionRequest.DataUserRequestor, position, shipPositionRequest.MessageId, DataCenterLogic.DataCenterTypesIDE.responseTypeType.Item4, DataCenterLogic.DataCenterTypesIDE.messageTypeType.Item3); } else { if (shipPositionRequest.AccessType == accessTypeType.Item3 || shipPositionRequest.AccessType == accessTypeType.Item5) { sprm.SendReport(shipPositionRequest.DataUserRequestor, position, shipPositionRequest.MessageId, DataCenterLogic.DataCenterTypesIDE.responseTypeType.Item3, DataCenterLogic.DataCenterTypesIDE.messageTypeType.Item1); } else if (shipPositionRequest.AccessType == accessTypeType.Item1) { sprm.SendReport(shipPositionRequest.DataUserRequestor, position, shipPositionRequest.MessageId, DataCenterLogic.DataCenterTypesIDE.responseTypeType.Item1, DataCenterLogic.DataCenterTypesIDE.messageTypeType.Item1); } else if (shipPositionRequest.AccessType == accessTypeType.Item2) { sprm.SendReport(shipPositionRequest.DataUserRequestor, position, shipPositionRequest.MessageId, DataCenterLogic.DataCenterTypesIDE.responseTypeType.Item2, DataCenterLogic.DataCenterTypesIDE.messageTypeType.Item1); } else { sprm.SendReport(shipPositionRequest.DataUserRequestor, position, shipPositionRequest.MessageId, DataCenterLogic.DataCenterTypesIDE.responseTypeType.Item4, DataCenterLogic.DataCenterTypesIDE.messageTypeType.Item1); } } log.Debug("Report Enviado"); } //Hubo alguna posicion para la que no tuvo permiso if (not_entitled_count != 0) { ReceiptManager.SendReceipt(shipPositionRequest.DataUserRequestor, shipPositionRequest.MessageId, DataCenterLogic.DataCenterTypesIDE.receiptCodeType.Item7, string.Format("Not entitled to recieve {0} positions", not_entitled_count)); log.Debug("Receipt Enviado"); } return; }
/// <summary> /// Procesa un mensaje de tipo ShipPositionReport /// </summary> /// <param name="msg">El mensaje ShipPositionReport</param> public void ProcessShipPositionReport(DataCenterTypes.ShipPositionReportType shipPositionReport) { var configMgr = new ConfigurationManager(); //Verifica si existe el Data User que requiere la información var cgm = new ContractingGovermentManager(); var ddpm = new DDPVersionManager(); var ddpVersion = ddpm.GetCurrentDDPVersion(); var contractingGoverment = cgm.GetContractingGovermentByLRITId(shipPositionReport.DataUserRequestor, ddpVersion.Id); if (contractingGoverment == null) { string strError = string.Format("Specified LDU '{0}' does not exist", shipPositionReport.DataUserRequestor); //Arma mensaje de Recibo DataCenterLogic.DataCenterTypes.ReceiptType receipt = new DataCenterLogic.DataCenterTypes.ReceiptType(); receipt.DDPVersionNum = DDPVersionManager.currentDDP(); receipt.Destination = shipPositionReport.DCId; receipt.Message = strError; receipt.MessageId = MessageIdManager.Generate(); receipt.MessageType = DataCenterLogic.DataCenterTypes.messageTypeType3.Item7; receipt.Originator = configMgr.Configuration.DataCenterID; receipt.ReceiptCode = DataCenterLogic.DataCenterTypes.receiptCodeType.Item7; receipt.ReferenceId = shipPositionReport.MessageId; receipt.schemaVersion = decimal.Parse(configMgr.Configuration.SchemaVersion); receipt.test = DataCenterLogic.DataCenterTypes.testType.Item1; receipt.TimeStamp = DateTime.UtcNow; Message msgout = new Message(receipt); msgout.Label = "receipt"; //Encola mensaje QueueManager.Instance().EnqueueOut(msgout); log.Error(strError); return; } //Verifica si el existe el Id de referencia if (shipPositionReport.ReferenceId != "") { var sprda = new ShipPositionRequestDataAccess(); if (sprda.RequestExists(shipPositionReport.ReferenceId) == false) { string strError = string.Format("MessageID not found for ReferenceID '{0}'", shipPositionReport.ReferenceId); //Envía Recibo DataCenterLogic.DataCenterTypes.ReceiptType receipt = new DataCenterLogic.DataCenterTypes.ReceiptType(); receipt.DDPVersionNum = DDPVersionManager.currentDDP(); receipt.Destination = shipPositionReport.DCId; receipt.Message = strError; receipt.MessageId = MessageIdManager.Generate(); receipt.MessageType = DataCenterLogic.DataCenterTypes.messageTypeType3.Item7; receipt.Originator = configMgr.Configuration.DataCenterID; receipt.ReceiptCode = DataCenterLogic.DataCenterTypes.receiptCodeType.Item7; receipt.ReferenceId = shipPositionReport.MessageId; receipt.schemaVersion = decimal.Parse(configMgr.Configuration.SchemaVersion); receipt.test = DataCenterLogic.DataCenterTypes.testType.Item1; receipt.TimeStamp = DateTime.UtcNow; Message msgout = new Message(receipt); msgout.Label = "receipt"; //Envia mensaje QueueManager.Instance().EnqueueOut(msgout); log.Error(strError); return; } } //ReferenceID puede ser de un report o "" si es SO //DataUserProvider es el usuario que nos manda (deberiamos tener contrato con el) var pricing = new PricingManager(); decimal?price = pricing.GetPriceForRequest(shipPositionReport.ReferenceId, shipPositionReport.DataUserProvider); //No tengo precio? if (price == null) { log.Warn(string.Format("SendShipPositionReport: Se recibio un reporte {0} de posicion, no podemos poner precio", shipPositionReport.MessageId)); } //Save position report to DB using (var dao = new ShipPositionReportDataAccess()) { dao.Create(TypeHelper.Map2DB(shipPositionReport), 0, price); } log.Info(string.Format("ShipPositionReport successfully processed: price {0}", price)); }
/// <summary> /// Verifica si el DataUserRequestor esta titulado para recibir un mensaje de posicion /// </summary> /// <param name="spr">Mensaje ShipPositionRequest</param> /// <param name="spos">Posicion del barco</param> private void CheckEntitlementAndSendReportOrReceipt(ShipPositionRequest spr, ShipPosition spos) { var cgm = new ContractingGovermentManager(); var ddpm = new DDPVersionManager(); //Febrero 2011 var ddpVersion = ddpm.DDPFromDate(spos.TimeStamp); var contractingGoverment = cgm.GetContractingGovermentByLRITId(spr.DataUserRequestor, ddpVersion.Id); //Solo verifico aguas internas del que lo pide si el acceso es COASTAL o FLAG bool verifyWatersOf = true; if (spr.AccessType == 3 || spr.AccessType == 5) { verifyWatersOf = false; } //Solo verifico titulacion si es distinto a SAR if (spr.AccessType != 6 && cgm.IsEntitled(contractingGoverment, spos, ddpVersion, verifyWatersOf) == false) { log.Debug("No titulado"); ReceiptManager.SendReceipt(spr.DataUserRequestor, spr.MessageId, DataCenterLogic.DataCenterTypesIDE.receiptCodeType.Item0, string.Format("Not entitled to recieve")); return; } var sprm = new ShipPositionReportManager(); /*************************** MEDITAR *****************************/ //Default Coastal var responseType = DataCenterLogic.DataCenterTypesIDE.responseTypeType.Item1; //Periodic report var messageType = DataCenterLogic.DataCenterTypesIDE.messageTypeType.Item1; //Flag if (spr.AccessType == 2) { responseType = DataCenterLogic.DataCenterTypesIDE.responseTypeType.Item2; } //Port else if (spr.AccessType == 3 || spr.AccessType == 5) { responseType = DataCenterLogic.DataCenterTypesIDE.responseTypeType.Item3; } //Coastal else if (spr.AccessType == 1) { responseType = DataCenterLogic.DataCenterTypesIDE.responseTypeType.Item1; } //SAR else { responseType = DataCenterLogic.DataCenterTypesIDE.responseTypeType.Item4; messageType = DataCenterLogic.DataCenterTypesIDE.messageTypeType.Item3; } //si es onetimepoll => msgtype polled report if (spr.RequestType == 1) { messageType = DataCenterLogic.DataCenterTypesIDE.messageTypeType.Item3; } /*************************************************************/ sprm.SendReport(spr.DataUserRequestor, spos, spr.MessageId, responseType, messageType); }