Добавил утилиту установки координат объектов учёта.

This commit is contained in:
Антон Чичков 2017-02-21 15:36:11 +10:00
parent da73f18b9c
commit e04d3ff4be
8 changed files with 318 additions and 0 deletions

View File

@ -9,3 +9,4 @@
|ImportTemperature | Импорт температуры наружного воздуха в ЛЭРС УЧЁТ. | |ImportTemperature | Импорт температуры наружного воздуха в ЛЭРС УЧЁТ. |
|KhvAdmDataAdapter | Экспорт данных из ЛЭРС УЧЁТ. Обработчик HttpHandler для веб-сайта | |KhvAdmDataAdapter | Экспорт данных из ЛЭРС УЧЁТ. Обработчик HttpHandler для веб-сайта |
|WebApiSamples | Примеры использования веб-службы ЛЭРС УЧЁТ | |WebApiSamples | Примеры использования веб-службы ЛЭРС УЧЁТ |
|SetNodeCoordinates| Утилита установки координат объектов учёта. Координаты запрашиваются у сервиса nominatim|

View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />
</startup>
</configuration>

View File

@ -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<dynamic[]>(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";
}
}
}

View File

@ -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")]

View File

@ -0,0 +1,71 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{F1AF72C6-EBF2-41DB-AB22-BD05B50BCFD5}</ProjectGuid>
<OutputType>Exe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>SetNodeCoordinates</RootNamespace>
<AssemblyName>SetNodeCoordinates</AssemblyName>
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Newtonsoft.Json, Version=9.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="P:\trunk\Framework\Lers.System\Lers.System.csproj">
<Project>{78302bfb-2ca1-4ef4-998e-cf137cf21922}</Project>
<Name>Lers.System</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>

View File

@ -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

View File

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Newtonsoft.Json" version="9.0.1" targetFramework="net461" />
</packages>

View File

@ -0,0 +1,4 @@
SetNodeCoordinates.
Утилита подключаетя к серверу ЛЭРС УЧЁТ, получает список объектов учёта и для каждого из них пытается определить и сохранить географические коордитаны по адресу.
Для запуска требуются права на редактирование объектов учёта.