Exemple #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 не обработано!");
                }
            }
        }
Exemple #2
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);
            }
        }