private string SendShipPositionRequest(Message msg) { DataCenterLogic.DataCenterTypesIDE.ShipPositionRequestType shipPositionRequest = (DataCenterLogic.DataCenterTypesIDE.ShipPositionRequestType)(msg.Body); //Send to IDE if (System.Configuration.ConfigurationManager.AppSettings["send2servers"] != "False") { shipPositionRequest.test = DataCenterLogic.DataCenterTypesIDE.testType.Item0; ideClient.ShipPositionRequest(shipPositionRequest); log.Info("SendShipPositionRequest: shipPositionRequest sent to IDE"); } if (ShipPositionRequestHelper.IsPeriodicRequest(shipPositionRequest.RequestType)) { //Es periodico, y pedimos sacarlo de la frecuencia estandard 6hs (RequestType==6), y no es SAR (msgtype==5)? //Debemos imputarnos la presunta reprogramacion PRICING if (shipPositionRequest.RequestType != DataCenterLogic.DataCenterTypesIDE.requestTypeType.Item6 && shipPositionRequest.MessageType == DataCenterLogic.DataCenterTypesIDE.messageTypeType1.Item5) { /************************************************/ var pmgr = new PricingManager(); decimal?price = pmgr.AddASPReprogrMessage(0, shipPositionRequest.DataUserRequestor, shipPositionRequest.DataUserProvider); log.Info(string.Format("SendShipPositionRequest: Reprogramacion presunta par {0} => precio={1}", shipPositionRequest.MessageId, price)); /************************************************/ } } //Guarda el mensaje en la base de datos using (var dao = new ShipPositionRequestDataAccess()) { dao.Create(TypeHelper.Map2DB(shipPositionRequest), 1); } log.Info("ShipPositionRequest stored"); return(shipPositionRequest.MessageId); }
/// <summary> /// Procesa un mensaje de tipo ShipPositionRequest /// </summary> /// <param name="msg">Mensaje de la cola con ShipPositionRequest en el body</param> public void ProcessShipPositionRequest(ShipPositionRequestType shipPositionRequest) { log.Info("Procesando ShipPositionRequest"); try { if (ValidateShipPositionRequest(shipPositionRequest) != true) { return; } } catch (Exception ex) { log.Debug(ex); } Ship ship = null; using (var sdao = new ShipDataAccess()) { log.Debug("Verifica si existe el barco en la base de datos"); ship = sdao.getByIMONum(shipPositionRequest.IMONum); if (ship == null) { //The ship is not in our system, send receipt CODE 7 log.Debug("el barco no esta en nuestro sistema, se envia recibo codigo 7"); ReceiptManager.SendReceipt(shipPositionRequest.DataUserRequestor, shipPositionRequest.MessageId, DataCenterLogic.DataCenterTypesIDE.receiptCodeType.Item7, string.Format("The ship {0} is not registered", shipPositionRequest.IMONum)); return; } } //Save ship position request to obtain id log.Debug("Guardando SPR en base de datos para obtener id"); var shipPositionRequestDB = TypeHelper.Map2DB(shipPositionRequest); try { using (var spreq = new ShipPositionRequestDataAccess()) { spreq.Create(shipPositionRequestDB, 0); } } catch (Exception ex) { log.Error("Hubo un problema al guardar el mensaje"); log.Debug(ex); return; } //log.Debug("Verificando si ya hay un request activo para el barco"); //using (var asprDa = new ActiveShipPositionRequestDataAccess()) //{ // List<ActiveShipPositionRequest> asprlist = asprDa.GetAll(); // foreach (ActiveShipPositionRequest aspr in asprlist) // { // if (shipPositionRequest.IMONum == aspr.ShipPositionRequest.IMONum && // Convert.ToInt32(shipPositionRequest.AccessType) == aspr.ShipPositionRequest.AccessType && // shipPositionRequest.DataUserRequestor == aspr.ShipPositionRequest.DataUserRequestor // ) // { // log.Debug("Se reemplaza request del barco:" + shipPositionRequest.IMONum); // asprDa.Remove(aspr); // } // } //} #region Historics position report log.Debug("Verificando si es un request para datos archivados"); if (ShipPositionRequestHelper.IsHistoricRequest(shipPositionRequest.RequestType)) { ProcessHistoricShipPositionRequest(shipPositionRequest, ship); return; } #endregion #region Periodic position report log.Debug("Verificando si es un request periodico"); if (ShipPositionRequestHelper.IsPeriodicRequest(shipPositionRequest.RequestType)) { ActiveShipPositionRequestManager asprManager = new ActiveShipPositionRequestManager(); asprManager.AddOrReplace(shipPositionRequestDB); log.Debug("ASPR REPLACED: Barco:" + shipPositionRequest.IMONum); log.Debug("Requestor: " + shipPositionRequest.DataUserRequestor); log.Debug("Access-Request Type: " + shipPositionRequest.AccessType + "-" + shipPositionRequest.RequestType); //Es periodico, y nos saca de la frecuencia estandard 6hs (RequestType==6), y no es SAR (msgtype==5)? //Debemos cobrarle la presunta reprogramacion PRICING if (shipPositionRequest.RequestType != requestTypeType.Item6 && shipPositionRequest.MessageType == messageTypeType1.Item5) { /************************************************/ var pmgr = new PricingManager(); decimal?price = pmgr.AddASPReprogrMessage(0, shipPositionRequest.DataUserRequestor, shipPositionRequest.DataUserProvider); log.Info(string.Format("ProcessShipPositionRequest: Reprogramacion presunta par {0} => precio={1}", shipPositionRequest.MessageId, price)); /************************************************/ } return; } #endregion #region One Time poll log.Debug("Verificando si es un request para unica vez"); if (ShipPositionRequestHelper.IsOneTimePoll(shipPositionRequest.RequestType)) { ActiveShipPositionRequestManager asprManager = new ActiveShipPositionRequestManager(); //Crea Active asprManager.AddNew(shipPositionRequestDB.Id); log.Debug("ASPR ADDED: Barco:" + shipPositionRequest.IMONum); log.Debug("Requestor: " + shipPositionRequest.DataUserRequestor); log.Debug("Access-Request Type: " + shipPositionRequest.AccessType + "-" + shipPositionRequest.RequestType); } #endregion #region Reset Request log.Debug("Verificando si es un request reset"); if (ShipPositionRequestHelper.IsResetRequest(shipPositionRequest.RequestType)) { var asprManager = new ActiveShipPositionRequestManager(); asprManager.RemoveAllForRequestor(shipPositionRequestDB); } #endregion #region Stop Request log.Debug("Verificando si es un request Stop"); if (ShipPositionRequestHelper.IsStopRequest(shipPositionRequest.RequestType)) { ActiveShipPositionRequestManager asprManager = new ActiveShipPositionRequestManager(); asprManager.AddOrReplace(shipPositionRequestDB); log.Debug("ASPR REPLACED: Barco:" + shipPositionRequest.IMONum); log.Debug("Requestor: " + shipPositionRequest.DataUserRequestor); log.Debug("Access-Request Type: " + shipPositionRequest.AccessType + "-" + shipPositionRequest.RequestType); } #endregion return; }