Пример #1
0
        public DataSet GetPositionsOnStandingOrder()
        {
            using (var sqlconn = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["mio"].ConnectionString))
            {
                sqlconn.Open();
                var dsout = new DataSet();
                var dt    = new DataTable();
                var pos   = new SqlGeography();

                ShipDataAccess          sda  = null;
                StandingOrderDataAccess soda = null;

                using (var da = new SqlDataAdapter("SELECT * FROM AIS", sqlconn))
                {
                    da.Fill(dt);
                }
                dt.Columns.Add("LATITUD", typeof(Decimal));
                dt.Columns.Add("LONGITUD", typeof(Decimal));

                foreach (DataRow row in dt.Rows)
                {
                    try
                    {
                        sda  = new ShipDataAccess();
                        soda = new StandingOrderDataAccess();

                        var spman               = new ShipPositionManager();
                        var ddpman              = new DDPVersionManager();
                        var ddpver              = ddpman.GetCurrentDDPVersion();
                        var lastpos             = spman.GetLastShipPosition(sda.getById((int)row["ID_BARCO"]).IMONum);
                        List <StandingOrder> so = new List <StandingOrder>();
                        if (lastpos != null)
                        {
                            so = soda.GetOrdersForPosition(lastpos, ddpver);
                        }
                        if (so.Count == 0)
                        {
                            dt.Rows.Remove(row);
                            continue;
                        }
                    }
                    catch (Exception ex)
                    {
                        System.Diagnostics.Debug.WriteLine(ex);
                    }
                    finally
                    {
                        sda.Dispose();
                        soda.Dispose();
                    }

                    pos             = SqlGeography.STGeomFromWKB(new SqlBytes((byte[])row["Position"]), 4326);
                    row["LATITUD"]  = decimal.Parse(pos.Lat.ToString());
                    row["LONGITUD"] = decimal.Parse(pos.Long.ToString());
                }
                dt.Columns.Remove("Position");
                dsout.Tables.Add(dt);
                return(dsout);
            }
        }
Пример #2
0
        public string GetShipState(Ship ship)
        {
            ShipDataAccess          sda  = null;
            StandingOrderDataAccess soda = null;

            try
            {
                sda  = new ShipDataAccess();
                soda = new StandingOrderDataAccess();

                var spman               = new ShipPositionManager();
                var ddpman              = new DDPVersionManager();
                var ddpver              = ddpman.GetCurrentDDPVersion();
                var lastpos             = spman.GetLastShipPosition(ship.IMONum);
                List <StandingOrder> so = new List <StandingOrder>();


                if (lastpos != null)
                {
                    so = soda.GetOrdersForPosition(lastpos, ddpver);
                }

                if (so.Count != 0)
                {
                    return("blue");
                }

                if (sda.HasActiveRequest(ship) != 0)
                {
                    return("green");
                }

                if (lastpos != null)
                {
                    if (DateTime.UtcNow - lastpos.TimeStamp > TimeSpan.FromDays(1))
                    {
                        return("red");
                    }
                }

                return("normal");
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex);
                return("normal");
            }
            finally
            {
                if (sda != null)
                {
                    sda.Dispose();
                }
                if (soda != null)
                {
                    soda.Dispose();
                }
            }
        }
Пример #3
0
        /// <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();
            }
        }