示例#1
0
        static void Main(string[] args)
        {
            var lines = File.ReadAllLines("streets.txt");
            var list  = lines.Select(line => new Street(line)).ToList();

            list = new List <Street>(list.OrderBy(street => street.Name));
            var dic = FindSameStreet(list).Where(pair => pair.Value.Count > 1);

            Console.WriteLine("Start read coordinate");
            Console.ReadKey(true);
            using (var progresBar = new ConsoleProgress("Update Yandex coordinate"))
            {
                progresBar.SetRange(0, list.Count);
                for (int index = 0; index < list.Count; index++)
                {
                    var street              = list[index];
                    var location            = $"{KievPrefix}{street}";
                    var geoObjectCollection = YandexGeocoder.Geocode(location, 1, LangType.ru_RU);
                    street.UpdateLocation(geoObjectCollection);
                    progresBar.SetProgress(index);
                }
            }

            var validStreets   = list.Where(street => street.CoordinatesCalculated).ToArray();
            var invalidStreets = list.Where(street => !street.CoordinatesCalculated).ToArray();

            Console.WriteLine($"Found {invalidStreets.Length} not valid streets. You can find it in Invalid.json");
            SerializeStreets(invalidStreets, "Invalid");
            Console.WriteLine("Write file name for output");
            var fileName = Console.ReadLine();

            SerializeStreets(validStreets, fileName);
        }
示例#2
0
        private static void SerializeStreets(Street[] streets, string fileName)
        {
            var contractJsonSerializer = new DataContractJsonSerializer(typeof(Street));

            using (var progresBar = new ConsoleProgress($"Serialize into {fileName}."))
            {
                progresBar.SetRange(0, streets.Length);
                using (var sw = new FileStream(Path.ChangeExtension(fileName, ".json"), FileMode.Create))
                {
                    for (int index = 0; index < streets.Length; index++)
                    {
                        var validStreet = streets[index];
                        contractJsonSerializer.WriteObject(sw, validStreet);
                        progresBar.SetProgress(index);
                    }
                }
            }
        }