示例#1
0
        /*
         * DEPRECATED:  this function was used when the sites_boundary backend sercice just replied with the carpooling data vesion.
         *              Then the backend added into the same service the version of all dynamic services.
         *              After implementing the "getDynamicDataVersionFromBackend" function, this should no longer be used.
         */
        //public static CarpoolerVersion getCarpoolingDataVersionFromBackend(Point MinPoint, Point MaxPoint)
        //{
        //    CarpoolerVersion version = null;
        //    CarpoolerVersionJson CarpoolerVersionJson = new CarpoolerVersionJson { };

        //    string url = sites_boundary + "?" +
        //        "min_lat=" + MinPoint.Latitude + "&" +
        //        "min_lon=" + MinPoint.Longitude + "&" +
        //        "max_lat=" + MaxPoint.Latitude + "&" +
        //        "max_lon=" + MaxPoint.Longitude;

        //    try
        //    {
        //        HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(url);
        //        httpWebRequest.Method = WebRequestMethods.Http.Get;
        //        httpWebRequest.Accept = "application/json";
        //        httpWebRequest.Credentials = new NetworkCredential(user, pw);
        //        httpWebRequest.UserAgent = "RP client";

        //        HttpWebResponse response = (HttpWebResponse)httpWebRequest.GetResponse();
        //        log.Info(url);
        //        if (response != null && response.StatusCode == HttpStatusCode.OK)
        //        {
        //            Stream stream = response.GetResponseStream();
        //            StreamReader reader = new StreamReader(stream, Encoding.UTF8);
        //            String responseString = reader.ReadToEnd();

        //            CarpoolerVersionJson = JsonConvert.DeserializeObject<CarpoolerVersionJson>(responseString);

        //            version = new CarpoolerVersion(CarpoolerVersionJson.sites.First().carpooling_info.version,
        //                CarpoolerVersionJson.sites.First().carpooling_info.updated,
        //                CarpoolerVersionJson.sites.First().name);
        //            log.Info("Version: " + version.version + " Timestamp: " + version.timestampVersion);
        //        }
        //        else
        //        {
        //            log.Error("An error occured while calling the carpooling data service: StatusCode=" + response.StatusCode);
        //            return null;
        //        }
        //    }
        //    catch (Exception ex)
        //    {
        //        log.Error("An error occured during the carpooling data get: " + ex.ToString());
        //        return null;
        //    }

        //    return version;
        //}


        public static DynamicDataVersion getDynamicDataVersionFromBackend(Point MinPoint, Point MaxPoint)
        {
            ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls
                                                   | SecurityProtocolType.Tls11
                                                   | SecurityProtocolType.Tls12
                                                   | SecurityProtocolType.Ssl3;
            DynamicDataVersion DynamicData = new DynamicDataVersion {
            };

            string url = sites_boundary + "?" +
                         "min_lat=" + MinPoint.Latitude + "&" +
                         "min_lon=" + MinPoint.Longitude + "&" +
                         "max_lat=" + MaxPoint.Latitude + "&" +
                         "max_lon=" + MaxPoint.Longitude;

            try
            {
                HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(url);
                httpWebRequest.Method      = WebRequestMethods.Http.Get;
                httpWebRequest.Accept      = "application/json";
                httpWebRequest.Credentials = new NetworkCredential(user, pw);
                httpWebRequest.UserAgent   = "RP client";

                //log.Info(url);
                HttpWebResponse response = (HttpWebResponse)httpWebRequest.GetResponse();

                if (response != null && response.StatusCode == HttpStatusCode.OK)
                {
                    Stream       stream         = response.GetResponseStream();
                    StreamReader reader         = new StreamReader(stream, Encoding.UTF8);
                    String       responseString = reader.ReadToEnd();

                    DynamicData = JsonConvert.DeserializeObject <DynamicDataVersion>(responseString);
                }
                else
                {
                    log.Error("An error occured while calling the dynamic data version service: StatusCode=" + response.StatusCode);
                    return(null);
                }
            }
            catch (Exception ex)
            {
                log.Warn("An issue occured during the dynamic data version get: " + ex.ToString());
                return(null);
            }

            return(DynamicData);
        }
示例#2
0
        void Timer_Tick_DynamicDataUpdate(object state)
        {
            try
            {
                bool CarpoolingEnabled               = bool.Parse(ConfigurationManager.AppSettings["CarpoolingEnabled"]);
                bool TrafficEnabled                  = bool.Parse(ConfigurationManager.AppSettings["TrafficEnabled"]);
                DynamicDataVersion DynamicData       = new DynamicDataVersion {
                };
                CarPoolerDataVersioned CarPoolingTmp = new CarPoolerDataVersioned {
                };
                TrafficDataVersioned TrafficTmp      = new TrafficDataVersioned {
                };

                /* Get the dynamic data version from the backend web service */
                DynamicData = HTTPRequests.getDynamicDataVersionFromBackend(productionRoutingNetwork.MinPoint, productionRoutingNetwork.MaxPoint);

                if (DynamicData != null)
                {
                    if (CarpoolingEnabled)
                    {
                        /* Carpooling data version */
                        CarPoolingTmp.Version = new CarpoolerVersion(DynamicData.sites.First().carpooling_info.version,
                                                                     DynamicData.sites.First().carpooling_info.updated,
                                                                     DynamicData.sites.First().name,
                                                                     DynamicData.sites.First().carpooling_info.nightly_version,
                                                                     DynamicData.sites.First().carpooling_info.nightly_updated);
                        /* Update the carpooling network */
                        updateCarpoolingNetwork(CarPoolingTmp);
                    }

                    if (TrafficEnabled)
                    {
                        /* Traffic data version */
                        TrafficTmp.Version = new TrafficVersion(DynamicData.sites.First().reports_info.version,
                                                                DynamicData.sites.First().reports_info.updated,
                                                                DynamicData.sites.First().name);
                        /* Update the traffic network */
                        updateTrafficNetwork(TrafficTmp);
                    }
                }
            }
            finally
            {
                m_Timer.Change(DynamicDataIntervalTimeRequest, 0);
            }
        }
示例#3
0
        static void Main(string[] args)
        {
            log.Info("Application starts");

            string host                             = ConfigurationManager.AppSettings["host"];
            string port                             = ConfigurationManager.AppSettings["port"];
            string service                          = ConfigurationManager.AppSettings["service"];
            string protocol                         = ConfigurationManager.AppSettings["protocol"];
            bool   CarpoolingEnabled                = bool.Parse(ConfigurationManager.AppSettings["CarpoolingEnabled"]);
            bool   TrafficEnabled                   = bool.Parse(ConfigurationManager.AppSettings["TrafficEnabled"]);
            double TrafficPropagationMaxDistance    = float.Parse(ConfigurationManager.AppSettings["TrafficPropagationMaxDistance"]);
            int    CarpoolingMaxConnectionsPerTNode = int.Parse(ConfigurationManager.AppSettings["CarpoolingMaxConnectionsPerTNode"]);
            /* This variable is used to decide if update at startup the external carpooling rides to the network or wait the midnight */
            bool updateExtRidesAtStartup = bool.Parse(ConfigurationManager.AppSettings["ExtCarpoolingRideUpdateAtStartup"]);

            //var host = Dns.GetHostAddresses(Dns.GetHostName())[0];
            string url = protocol + "://" + host + ":" + port + service;

            log.Info(url);

            Notification.SendMessageByEmail(Notification.AlarmType.INFO, DateTime.Now.ToString() + "\r\nWebAPI starts at " + url + "\r\nBuilding network...");

            /* Get the site timeZone from the GTFS data (needed for the carpooling date caonversion) */
            string timeZone = null;

            timeZone = DBParser.GetTimeZoneFromAgencyTable();

            /* Get the boundaries from the OSM Map (needed for the backend carpooling http requests) */
            Point  MapMinPoint = null, MapMaxPoint = null;
            string OSMXMLMapFilePath = System.IO.Path.GetFullPath(AppDomain.CurrentDomain.BaseDirectory + ConfigurationManager.AppSettings["dataPath"] + ConfigurationManager.AppSettings["OSMXMLMapFile"]);

            log.Info("Parsing " + OSMXMLMapFilePath + " OSM.");
            routingNetwork1 = new Routing.RoutingNetwork();
            OSM.XMLParser Parser = new OSM.XMLParser();
            Parser.GetBoundaries(OSMXMLMapFilePath, ref MapMinPoint, ref MapMaxPoint);
            if ((MapMinPoint != null) && (MapMaxPoint != null))
            {
                log.Info("Map Boundaries: minlat:" + MapMinPoint.Latitude + ", minlon:" + MapMinPoint.Longitude + ", maxlat:" + MapMaxPoint.Latitude + ", maxlon:" + MapMaxPoint.Longitude);
            }
            else
            {
                string message = "Application ends\r\nMap boundaries not found into the OSM map: minlat:" + MapMinPoint.Latitude + ", minlon:" + MapMinPoint.Longitude + ", maxlat:" + MapMaxPoint.Latitude + ", maxlon:" + MapMaxPoint.Longitude;
                log.Error(message);
                Notification.SendMessageByEmail(Notification.AlarmType.ERROR, DateTime.Now.ToString() + "\r\n" + message);
                Environment.Exit(0);
            }


            /* Get the dynamic data version from the backend web service */
            DynamicData = HTTPRequests.getDynamicDataVersionFromBackend(MapMinPoint, MapMaxPoint);

            if (DynamicData != null)
            {
                if (CarpoolingEnabled)
                {
                    /* Set the Carpooling data version */
                    CarPooling.Version = new CarpoolerVersion(DynamicData.sites.First().carpooling_info.version,
                                                              DynamicData.sites.First().carpooling_info.updated,
                                                              DynamicData.sites.First().name,
                                                              DynamicData.sites.First().carpooling_info.nightly_version,
                                                              DynamicData.sites.First().carpooling_info.nightly_updated);
                    log.Info("CARPOOLING Version:" + CarPooling.Version.version + " Timestamp:" + CarPooling.Version.timestampVersion +
                             " NightlyVersion:" + CarPooling.Version.nightly_version + " NightlyTimestamp: " + CarPooling.Version.nightly_timestampVersion);

                    bool updateExternalRides = false;
                    if ((updateExtRidesAtStartup) || ((DateTime.Now.Hour < ExtCarpoolingAvailableUpdateTimeFrom) && (DateTime.Now.Hour >= ExtCarpoolingAvailableUpdateTimeTo)))
                    {
                        updateExternalRides = true;
                    }

                    /* Get the carpooling rides list from the backend web service */
                    CarPooling.Carpoolers = HTTPRequests.getCarpoolingDataFromBackend(MapMinPoint, MapMaxPoint, updateExternalRides);
                }

                if (TrafficEnabled)
                {
                    /* Set the Traffic/incidents data version */
                    Traffic.Version = new TrafficVersion(DynamicData.sites.First().reports_info.version,
                                                         DynamicData.sites.First().reports_info.updated,
                                                         DynamicData.sites.First().name);
                    log.Info("TRAFFIC Version:" + Traffic.Version.version + " Timestamp:" + Traffic.Version.timestampVersion);

                    /* Get the Traffic/incidents data from the backend web service */
                    Traffic.TrafficReport = HTTPRequests.getTrafficDataFromBackend(MapMinPoint, MapMaxPoint, TrafficPropagationMaxDistance);
                }
            }

            /* Build the network */
            routingNetwork1 = RoutePlanner.Globals.BuildNetwork(ref CParser, ref TParser, CarPooling.Carpoolers, Traffic.TrafficReport, TrafficPropagationMaxDistance, CarpoolingMaxConnectionsPerTNode);

            /* Copy the network */
            //routingNetwork2 = new RoutingNetwork { };
            //routingNetwork1.duplicateNetwork(ref routingNetwork2);

            log.Info("Starting server at " + url);
            Notification.SendMessageByEmail(Notification.AlarmType.INFO, DateTime.Now.ToString() + "\r\nService is running at " + url);
            HTTPAsyncServer Server = new HTTPAsyncServer(url);

            log.Error("Application ends");
            Notification.SendMessageByEmail(Notification.AlarmType.ERROR, "Application ends");
        }