Exemplo n.º 1
0
        /// <summary>
        /// Заполнение роутов для драйверов
        /// </summary>
        /// <param name="routes"></param>
        void FillingRoutes(RouteXml.DirectionsResponse routes, DriverEntity driver)
        {
            int    i = 0;
            double d = 0;
            int    t = 0;

            // DriverEntity driverEntity = new DriverEntity(driver.DriverName);
            foreach (var route in routes.Route.Leg)
            {
                if (double.TryParse(route.Distance.Value, out d) && int.TryParse(route.Duration.Value, out t))
                {
                    driver.Routes.Add(new Route
                    {
                        OrderId    = i++, // temp
                        EndAddress = route.End_address,
                        Distance   = d / 1000,
                        Time       = new TimeSpan(0, 0, 0, t),
                        Status     = i.ToString() + "status"
                    });
                }
                else
                {
                    throw new ArgumentException("route.Distance.Value не обработано!");
                }
            }
        }
Exemplo n.º 2
0
        public Point(List <string> zips)
        {
            zip    = zips;
            points = new long[zip.Count, zip.Count];
            string d = null;

            dr1 = new DriverEntity("driver 1");
            dr2 = new DriverEntity("driver 2");
            //for (int i = 0; i < 250; i++)
            //{
            //    Console.WriteLine(i+". "+ GetDistance("K1V 2K3", "k4a 0e7"));
            //}
            GetValues(zip);
            separateOrderList(2);
            GetRoutDriver(driver1, dr1);
            GetRoutDriver(driver2, dr2);
        }
Exemplo n.º 3
0
        void GetRoutDriver(List <string> driverZipList, DriverEntity driver)
        {
            try
            {
                string     query   = GetQueryForDriver(driverZipList);
                WebRequest request = WebRequest.Create(query);

                WebResponse response = request.GetResponse();

                Stream data = response.GetResponseStream();

                StreamReader reader = new StreamReader(data);

                // json-formatted string from maps api
                string responseFromServer = reader.ReadToEnd();

                RouteXml.DirectionsResponse routes = null;
                //    string path = cars.xml;

                XmlSerializer serializer = new XmlSerializer(typeof(RouteXml.DirectionsResponse));

                StreamReader reader1 = new StreamReader(data);
                // distance = (Xml.DirectionsResponse)serializer.Deserialize(reader);
                reader1.Close();
                response.Close();

                using (XmlReader readerXml = XmlReader.Create(new StringReader(responseFromServer)))
                {
                    routes = (RouteXml.DirectionsResponse)serializer.Deserialize(readerXml);
                }

                FillingRoutes(routes, driver);
                //double.TryParse(distance.Route.Leg.Distance.Value, out result);
                // result = result / 1000;
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
        }