From e04d3ff4be91a424ed6b913446ff6a070c679ea7 Mon Sep 17 00:00:00 2001 From: achi Date: Tue, 21 Feb 2017 15:36:11 +1000 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8=D0=BB=20?= =?UTF-8?q?=D1=83=D1=82=D0=B8=D0=BB=D0=B8=D1=82=D1=83=20=D1=83=D1=81=D1=82?= =?UTF-8?q?=D0=B0=D0=BD=D0=BE=D0=B2=D0=BA=D0=B8=20=D0=BA=D0=BE=D0=BE=D1=80?= =?UTF-8?q?=D0=B4=D0=B8=D0=BD=D0=B0=D1=82=20=D0=BE=D0=B1=D1=8A=D0=B5=D0=BA?= =?UTF-8?q?=D1=82=D0=BE=D0=B2=20=D1=83=D1=87=D1=91=D1=82=D0=B0.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 1 + SetNodeCoordinates/App.config | 6 + SetNodeCoordinates/Program.cs | 113 ++++++++++++++++++ SetNodeCoordinates/Properties/AssemblyInfo.cs | 36 ++++++ SetNodeCoordinates/SetNodeCoordinates.csproj | 71 +++++++++++ SetNodeCoordinates/SetNodeCoordinates.sln | 83 +++++++++++++ SetNodeCoordinates/packages.config | 4 + SetNodeCoordinates/readme.txt | 4 + 8 files changed, 318 insertions(+) create mode 100644 SetNodeCoordinates/App.config create mode 100644 SetNodeCoordinates/Program.cs create mode 100644 SetNodeCoordinates/Properties/AssemblyInfo.cs create mode 100644 SetNodeCoordinates/SetNodeCoordinates.csproj create mode 100644 SetNodeCoordinates/SetNodeCoordinates.sln create mode 100644 SetNodeCoordinates/packages.config create mode 100644 SetNodeCoordinates/readme.txt diff --git a/README.md b/README.md index 0d11e0a..d85c7ae 100644 --- a/README.md +++ b/README.md @@ -9,3 +9,4 @@ |ImportTemperature | Импорт температуры наружного воздуха в ЛЭРС УЧЁТ. | |KhvAdmDataAdapter | Экспорт данных из ЛЭРС УЧЁТ. Обработчик HttpHandler для веб-сайта | |WebApiSamples | Примеры использования веб-службы ЛЭРС УЧЁТ | +|SetNodeCoordinates| Утилита установки координат объектов учёта. Координаты запрашиваются у сервиса nominatim| diff --git a/SetNodeCoordinates/App.config b/SetNodeCoordinates/App.config new file mode 100644 index 0000000..731f6de --- /dev/null +++ b/SetNodeCoordinates/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/SetNodeCoordinates/Program.cs b/SetNodeCoordinates/Program.cs new file mode 100644 index 0000000..0b5929e --- /dev/null +++ b/SetNodeCoordinates/Program.cs @@ -0,0 +1,113 @@ +using System; +using System.IO; +using System.Net; +using Lers; +using Lers.Core; +using Newtonsoft.Json; + +namespace SetNodeCoorinates +{ + class Program + { + static void Main(string[] args) + { + if (args.Length != 5) + { + ShowUsage(); + return; + } + + try + { + string serverAddress = args[0]; + var serverPort = ushort.Parse(args[1]); + string login = args[2]; + string password = args[3]; + string city = args[4]; + + var server = new LersServer(); + server.VersionMismatch += (s, e) => e.Ignore = true; + + var auth = new Lers.Networking.BasicAuthenticationInfo(login, Lers.Networking.SecureStringHelper.ConvertToSecureString(password)); + server.Connect(serverAddress, serverPort, auth); + + var nodes = server.Nodes.GetList(); + + for (int i = 1050; i < nodes.Length; ++i) + { + var node = nodes[i]; + + string searchString = $"{city} {node.Address}"; + + var loc = GetCoordinates(searchString); + + if (loc != null) + { + node.GeoLocation = loc; + node.Save(); + } + + Console.WriteLine($"Обработано {++i} из {nodes.Length}"); + } + } + catch (Exception exc) + { + Console.WriteLine($"Ошибка установки координат объектов учёта. {exc.Message}"); + } + } + + private static void ShowUsage() + { + Console.WriteLine("Использование:"); + Console.WriteLine("SetNodeCoordinates lersServerAddress lersServerPort login password cityName"); + Console.WriteLine("lersServerAddress: адрес сервера ЛЭРС УЧЁТ"); + Console.WriteLine("lersServerPort: порт сервера ЛЭРС УЧЁТ"); + Console.WriteLine("login, password: логин и пароль на сервере ЛЭРС УЧЁТ. Учётная запись должна иметь право редактирования объектов учёта"); + Console.WriteLine("cityName: город, в котором расположены объекты учёта"); + } + + private static GeoLocation GetCoordinates(string address) + { + var request = WebRequest.Create(CreateSearchUrl(address)); + + var webRequest = (HttpWebRequest)request; + + webRequest.UserAgent = "Lers Client"; + + using (var response = request.GetResponse()) + { + using (var stream = response.GetResponseStream()) + { + var sr = new StreamReader(stream); + + string jsonResponse = sr.ReadToEnd(); + + dynamic[] responseObject = JsonConvert.DeserializeObject(jsonResponse); + + if (responseObject.Length == 0) + { + return null; + } + else + { + dynamic firstObject = responseObject[0]; + + var loc = new GeoLocation(); + + loc.Latitude = firstObject.lat; + loc.Longitude = firstObject.lon; + + return loc; + } + } + } + } + + private static string CreateSearchUrl(string whatToSearch) + { + string search = whatToSearch.Replace(' ', '+'); + + return $"http://nominatim.openstreetmap.org/search?q={search}&format=json"; + } + } +} diff --git a/SetNodeCoordinates/Properties/AssemblyInfo.cs b/SetNodeCoordinates/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..04feb5d --- /dev/null +++ b/SetNodeCoordinates/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("SetNodeCoorinates")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("SetNodeCoorinates")] +[assembly: AssemblyCopyright("Copyright © 2016")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("f1af72c6-ebf2-41db-ab22-bd05b50bcfd5")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/SetNodeCoordinates/SetNodeCoordinates.csproj b/SetNodeCoordinates/SetNodeCoordinates.csproj new file mode 100644 index 0000000..ed999ab --- /dev/null +++ b/SetNodeCoordinates/SetNodeCoordinates.csproj @@ -0,0 +1,71 @@ + + + + + Debug + AnyCPU + {F1AF72C6-EBF2-41DB-AB22-BD05B50BCFD5} + Exe + Properties + SetNodeCoordinates + SetNodeCoordinates + v4.6.1 + 512 + true + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll + True + + + + + + + + + + + + + + + + + + + + + {78302bfb-2ca1-4ef4-998e-cf137cf21922} + Lers.System + + + + + \ No newline at end of file diff --git a/SetNodeCoordinates/SetNodeCoordinates.sln b/SetNodeCoordinates/SetNodeCoordinates.sln new file mode 100644 index 0000000..cc1fe6a --- /dev/null +++ b/SetNodeCoordinates/SetNodeCoordinates.sln @@ -0,0 +1,83 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 14 +VisualStudioVersion = 14.0.25420.1 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lers.System", "P:\trunk\Framework\Lers.System\Lers.System.csproj", "{78302BFB-2CA1-4EF4-998E-CF137CF21922}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lers.Utils", "..\..\..\trunk\LersCore\Lers.Utils\Lers.Utils.csproj", "{49B55481-57AB-42BF-9DF8-77A44669C3ED}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SetNodeCoordinates", "SetNodeCoordinates.csproj", "{F1AF72C6-EBF2-41DB-AB22-BD05B50BCFD5}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Debug|x64 = Debug|x64 + Debug|x86 = Debug|x86 + Deploy|Any CPU = Deploy|Any CPU + Deploy|x64 = Deploy|x64 + Deploy|x86 = Deploy|x86 + Release|Any CPU = Release|Any CPU + Release|x64 = Release|x64 + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {78302BFB-2CA1-4EF4-998E-CF137CF21922}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {78302BFB-2CA1-4EF4-998E-CF137CF21922}.Debug|Any CPU.Build.0 = Debug|Any CPU + {78302BFB-2CA1-4EF4-998E-CF137CF21922}.Debug|x64.ActiveCfg = Debug|x64 + {78302BFB-2CA1-4EF4-998E-CF137CF21922}.Debug|x64.Build.0 = Debug|x64 + {78302BFB-2CA1-4EF4-998E-CF137CF21922}.Debug|x86.ActiveCfg = Debug|x86 + {78302BFB-2CA1-4EF4-998E-CF137CF21922}.Debug|x86.Build.0 = Debug|x86 + {78302BFB-2CA1-4EF4-998E-CF137CF21922}.Deploy|Any CPU.ActiveCfg = Deploy|Any CPU + {78302BFB-2CA1-4EF4-998E-CF137CF21922}.Deploy|Any CPU.Build.0 = Deploy|Any CPU + {78302BFB-2CA1-4EF4-998E-CF137CF21922}.Deploy|x64.ActiveCfg = Deploy|x64 + {78302BFB-2CA1-4EF4-998E-CF137CF21922}.Deploy|x64.Build.0 = Deploy|x64 + {78302BFB-2CA1-4EF4-998E-CF137CF21922}.Deploy|x86.ActiveCfg = Deploy|x86 + {78302BFB-2CA1-4EF4-998E-CF137CF21922}.Deploy|x86.Build.0 = Deploy|x86 + {78302BFB-2CA1-4EF4-998E-CF137CF21922}.Release|Any CPU.ActiveCfg = Release|Any CPU + {78302BFB-2CA1-4EF4-998E-CF137CF21922}.Release|Any CPU.Build.0 = Release|Any CPU + {78302BFB-2CA1-4EF4-998E-CF137CF21922}.Release|x64.ActiveCfg = Release|x64 + {78302BFB-2CA1-4EF4-998E-CF137CF21922}.Release|x64.Build.0 = Release|x64 + {78302BFB-2CA1-4EF4-998E-CF137CF21922}.Release|x86.ActiveCfg = Release|x86 + {78302BFB-2CA1-4EF4-998E-CF137CF21922}.Release|x86.Build.0 = Release|x86 + {49B55481-57AB-42BF-9DF8-77A44669C3ED}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {49B55481-57AB-42BF-9DF8-77A44669C3ED}.Debug|Any CPU.Build.0 = Debug|Any CPU + {49B55481-57AB-42BF-9DF8-77A44669C3ED}.Debug|x64.ActiveCfg = Debug|Any CPU + {49B55481-57AB-42BF-9DF8-77A44669C3ED}.Debug|x64.Build.0 = Debug|Any CPU + {49B55481-57AB-42BF-9DF8-77A44669C3ED}.Debug|x86.ActiveCfg = Debug|x86 + {49B55481-57AB-42BF-9DF8-77A44669C3ED}.Debug|x86.Build.0 = Debug|x86 + {49B55481-57AB-42BF-9DF8-77A44669C3ED}.Deploy|Any CPU.ActiveCfg = Deploy|Any CPU + {49B55481-57AB-42BF-9DF8-77A44669C3ED}.Deploy|Any CPU.Build.0 = Deploy|Any CPU + {49B55481-57AB-42BF-9DF8-77A44669C3ED}.Deploy|x64.ActiveCfg = Deploy|Any CPU + {49B55481-57AB-42BF-9DF8-77A44669C3ED}.Deploy|x64.Build.0 = Deploy|Any CPU + {49B55481-57AB-42BF-9DF8-77A44669C3ED}.Deploy|x86.ActiveCfg = Deploy|x86 + {49B55481-57AB-42BF-9DF8-77A44669C3ED}.Deploy|x86.Build.0 = Deploy|x86 + {49B55481-57AB-42BF-9DF8-77A44669C3ED}.Release|Any CPU.ActiveCfg = Release|Any CPU + {49B55481-57AB-42BF-9DF8-77A44669C3ED}.Release|Any CPU.Build.0 = Release|Any CPU + {49B55481-57AB-42BF-9DF8-77A44669C3ED}.Release|x64.ActiveCfg = Release|Any CPU + {49B55481-57AB-42BF-9DF8-77A44669C3ED}.Release|x64.Build.0 = Release|Any CPU + {49B55481-57AB-42BF-9DF8-77A44669C3ED}.Release|x86.ActiveCfg = Release|x86 + {49B55481-57AB-42BF-9DF8-77A44669C3ED}.Release|x86.Build.0 = Release|x86 + {F1AF72C6-EBF2-41DB-AB22-BD05B50BCFD5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {F1AF72C6-EBF2-41DB-AB22-BD05B50BCFD5}.Debug|Any CPU.Build.0 = Debug|Any CPU + {F1AF72C6-EBF2-41DB-AB22-BD05B50BCFD5}.Debug|x64.ActiveCfg = Debug|Any CPU + {F1AF72C6-EBF2-41DB-AB22-BD05B50BCFD5}.Debug|x64.Build.0 = Debug|Any CPU + {F1AF72C6-EBF2-41DB-AB22-BD05B50BCFD5}.Debug|x86.ActiveCfg = Debug|Any CPU + {F1AF72C6-EBF2-41DB-AB22-BD05B50BCFD5}.Debug|x86.Build.0 = Debug|Any CPU + {F1AF72C6-EBF2-41DB-AB22-BD05B50BCFD5}.Deploy|Any CPU.ActiveCfg = Debug|Any CPU + {F1AF72C6-EBF2-41DB-AB22-BD05B50BCFD5}.Deploy|Any CPU.Build.0 = Debug|Any CPU + {F1AF72C6-EBF2-41DB-AB22-BD05B50BCFD5}.Deploy|x64.ActiveCfg = Debug|Any CPU + {F1AF72C6-EBF2-41DB-AB22-BD05B50BCFD5}.Deploy|x64.Build.0 = Debug|Any CPU + {F1AF72C6-EBF2-41DB-AB22-BD05B50BCFD5}.Deploy|x86.ActiveCfg = Debug|Any CPU + {F1AF72C6-EBF2-41DB-AB22-BD05B50BCFD5}.Deploy|x86.Build.0 = Debug|Any CPU + {F1AF72C6-EBF2-41DB-AB22-BD05B50BCFD5}.Release|Any CPU.ActiveCfg = Release|Any CPU + {F1AF72C6-EBF2-41DB-AB22-BD05B50BCFD5}.Release|Any CPU.Build.0 = Release|Any CPU + {F1AF72C6-EBF2-41DB-AB22-BD05B50BCFD5}.Release|x64.ActiveCfg = Release|Any CPU + {F1AF72C6-EBF2-41DB-AB22-BD05B50BCFD5}.Release|x64.Build.0 = Release|Any CPU + {F1AF72C6-EBF2-41DB-AB22-BD05B50BCFD5}.Release|x86.ActiveCfg = Release|Any CPU + {F1AF72C6-EBF2-41DB-AB22-BD05B50BCFD5}.Release|x86.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/SetNodeCoordinates/packages.config b/SetNodeCoordinates/packages.config new file mode 100644 index 0000000..7ee8c10 --- /dev/null +++ b/SetNodeCoordinates/packages.config @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/SetNodeCoordinates/readme.txt b/SetNodeCoordinates/readme.txt new file mode 100644 index 0000000..a6f4304 --- /dev/null +++ b/SetNodeCoordinates/readme.txt @@ -0,0 +1,4 @@ +SetNodeCoordinates. + + ר, . + . \ No newline at end of file