/// <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> /// 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(); } }
/// <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); }