Merge branch 'Branch_faff3b1'

Routendistanze Berechnung per Google Maps API und openrouteService API
This commit is contained in:
2023-03-24 15:53:34 +01:00
25 changed files with 1100 additions and 47 deletions

View File

@@ -40,6 +40,7 @@ Global
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{3FEBB560-9275-413A-9767-BB68C44EEBC3}.Debug|.NET.ActiveCfg = Debug|Any CPU
{3FEBB560-9275-413A-9767-BB68C44EEBC3}.Debug|.NET.Build.0 = Debug|Any CPU
{3FEBB560-9275-413A-9767-BB68C44EEBC3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{3FEBB560-9275-413A-9767-BB68C44EEBC3}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3FEBB560-9275-413A-9767-BB68C44EEBC3}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
@@ -50,6 +51,7 @@ Global
{3FEBB560-9275-413A-9767-BB68C44EEBC3}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{3FEBB560-9275-413A-9767-BB68C44EEBC3}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{094331C3-ECEE-4C89-BBFD-4C9DED89F0EF}.Debug|.NET.ActiveCfg = Debug|Any CPU
{094331C3-ECEE-4C89-BBFD-4C9DED89F0EF}.Debug|.NET.Build.0 = Debug|Any CPU
{094331C3-ECEE-4C89-BBFD-4C9DED89F0EF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{094331C3-ECEE-4C89-BBFD-4C9DED89F0EF}.Debug|Any CPU.Build.0 = Debug|Any CPU
{094331C3-ECEE-4C89-BBFD-4C9DED89F0EF}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
@@ -60,6 +62,7 @@ Global
{094331C3-ECEE-4C89-BBFD-4C9DED89F0EF}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{094331C3-ECEE-4C89-BBFD-4C9DED89F0EF}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{B0D73E3D-4AE7-4024-93A6-DB1F46D7CCEE}.Debug|.NET.ActiveCfg = Debug|Any CPU
{B0D73E3D-4AE7-4024-93A6-DB1F46D7CCEE}.Debug|.NET.Build.0 = Debug|Any CPU
{B0D73E3D-4AE7-4024-93A6-DB1F46D7CCEE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B0D73E3D-4AE7-4024-93A6-DB1F46D7CCEE}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B0D73E3D-4AE7-4024-93A6-DB1F46D7CCEE}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
@@ -70,6 +73,7 @@ Global
{B0D73E3D-4AE7-4024-93A6-DB1F46D7CCEE}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{B0D73E3D-4AE7-4024-93A6-DB1F46D7CCEE}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{2F50B83D-A3F0-4EC4-979A-3F9B7E3D8ED4}.Debug|.NET.ActiveCfg = Debug|Any CPU
{2F50B83D-A3F0-4EC4-979A-3F9B7E3D8ED4}.Debug|.NET.Build.0 = Debug|Any CPU
{2F50B83D-A3F0-4EC4-979A-3F9B7E3D8ED4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2F50B83D-A3F0-4EC4-979A-3F9B7E3D8ED4}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2F50B83D-A3F0-4EC4-979A-3F9B7E3D8ED4}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
@@ -80,6 +84,7 @@ Global
{2F50B83D-A3F0-4EC4-979A-3F9B7E3D8ED4}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{2F50B83D-A3F0-4EC4-979A-3F9B7E3D8ED4}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{D5E53B0F-BF5A-41E8-93E2-0F32845FC729}.Debug|.NET.ActiveCfg = Debug|Any CPU
{D5E53B0F-BF5A-41E8-93E2-0F32845FC729}.Debug|.NET.Build.0 = Debug|Any CPU
{D5E53B0F-BF5A-41E8-93E2-0F32845FC729}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D5E53B0F-BF5A-41E8-93E2-0F32845FC729}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D5E53B0F-BF5A-41E8-93E2-0F32845FC729}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
@@ -90,6 +95,7 @@ Global
{D5E53B0F-BF5A-41E8-93E2-0F32845FC729}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{D5E53B0F-BF5A-41E8-93E2-0F32845FC729}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{40D8B312-EA64-49E3-A31A-5E57ED4D5654}.Debug|.NET.ActiveCfg = Debug|Any CPU
{40D8B312-EA64-49E3-A31A-5E57ED4D5654}.Debug|.NET.Build.0 = Debug|Any CPU
{40D8B312-EA64-49E3-A31A-5E57ED4D5654}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{40D8B312-EA64-49E3-A31A-5E57ED4D5654}.Debug|Any CPU.Build.0 = Debug|Any CPU
{40D8B312-EA64-49E3-A31A-5E57ED4D5654}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
@@ -100,6 +106,7 @@ Global
{40D8B312-EA64-49E3-A31A-5E57ED4D5654}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{40D8B312-EA64-49E3-A31A-5E57ED4D5654}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{E1154C7B-BB77-4155-9854-DAD8FC5A8BC3}.Debug|.NET.ActiveCfg = Debug|Any CPU
{E1154C7B-BB77-4155-9854-DAD8FC5A8BC3}.Debug|.NET.Build.0 = Debug|Any CPU
{E1154C7B-BB77-4155-9854-DAD8FC5A8BC3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E1154C7B-BB77-4155-9854-DAD8FC5A8BC3}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E1154C7B-BB77-4155-9854-DAD8FC5A8BC3}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
@@ -110,6 +117,7 @@ Global
{E1154C7B-BB77-4155-9854-DAD8FC5A8BC3}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{E1154C7B-BB77-4155-9854-DAD8FC5A8BC3}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{663EFCB5-9E3E-4C76-97EE-3188E072634C}.Debug|.NET.ActiveCfg = Debug|Any CPU
{663EFCB5-9E3E-4C76-97EE-3188E072634C}.Debug|.NET.Build.0 = Debug|Any CPU
{663EFCB5-9E3E-4C76-97EE-3188E072634C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{663EFCB5-9E3E-4C76-97EE-3188E072634C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{663EFCB5-9E3E-4C76-97EE-3188E072634C}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU

View File

@@ -200,6 +200,7 @@
<Compile Include="Entities\AbwesenheitsInformationPrint.cs" />
<Compile Include="Entities\AddressHistory.cs" />
<Compile Include="Entities\ErrorMessage.cs" />
<Compile Include="Entities\AddressRoute.cs" />
<Compile Include="Entities\ConfirmationReceiptSignature.cs" />
<Compile Include="Entities\ContractHistory.cs" />
<Compile Include="Entities\CostBearer2SupportConceptHistory.cs" />
@@ -732,6 +733,9 @@
<EmbeddedResource Include="Mappings\ErrorMessage.hbm.xml">
<SubType>Designer</SubType>
</EmbeddedResource>
<EmbeddedResource Include="Mappings\AddressRoute.hbm.xml">
<SubType>Designer</SubType>
</EmbeddedResource>
<Content Include="Mappings\Timesheet2Mail.hbm.xml" />
<EmbeddedResource Include="Mappings\ContactHistory.hbm.xml">
<SubType>Designer</SubType>

View File

@@ -1,7 +1,9 @@
using BS.Shared;
using System.Diagnostics;
namespace BeWo.Data.Entities
{
[DebuggerDisplay("{Oid}: {Street}, {Town}")]
public class Address : BeWoEntityBase
{
public static string PropertyName_AddressLine1 = "AddressLine1";
@@ -30,6 +32,12 @@ namespace BeWo.Data.Entities
private string _Town;
private decimal? _Latitude;
private decimal? _Longitude;
private long? _L_Version;
public Address()
{
this._Tid = TableID.Address;
@@ -114,7 +122,7 @@ namespace BeWo.Data.Entities
}
}
}
public virtual string Street
{
get
@@ -147,6 +155,54 @@ namespace BeWo.Data.Entities
}
}
public virtual decimal? Latitude
{
get
{
return this._Latitude;
}
set
{
if (this.AreDifferent(this._Latitude, value))
{
this._Latitude = value;
}
}
}
public virtual decimal? Longitude
{
get
{
return this._Longitude;
}
set
{
if (this.AreDifferent(this._Longitude, value))
{
this._Longitude = value;
}
}
}
public virtual long? L_Version
{
get
{
return this._L_Version;
}
set
{
if (this.AreDifferent(this._L_Version, value))
{
this._L_Version = value;
}
}
}
public virtual Address CopyToNew()
{
return new Address
@@ -161,5 +217,13 @@ namespace BeWo.Data.Entities
Town = this.Town
};
}
public override int GetHashCode()
{
if (this is null)
return 0;
return Oid.Value.GetHashCode();
}
}
}

View File

@@ -0,0 +1,149 @@
using BS.Shared;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BeWo.Data.Entities
{
[DebuggerDisplay("{Oid}({Origin.Oid},{Destination.Oid}): {Distance_in_meter}m, {Time_in_seconds}s")]
public class AddressRoute : BeWoEntityBase
{
private Address _Origin;
private long _Origin_Version;
private Address _Destination;
private long _Destination_Version;
private int distance_in_meter;
private string distance_in_meter_txt;
private int time_in_seconds;
private string time_in_seconds_txt;
public AddressRoute()
{
_Tid = TableID.AddressRoute;
}
public virtual Address Origin
{
get
{
return _Origin;
}
set
{
if (AreDifferent(_Origin, value))
{
_Origin = value;
}
}
}
public virtual long Origin_Version
{
get
{
return _Origin_Version;
}
set
{
if (AreDifferent(_Origin_Version, value))
{
_Origin_Version = value;
}
}
}
public virtual Address Destination
{
get
{
return _Destination;
}
set
{
if (AreDifferent(_Destination, value))
{
_Destination = value;
}
}
}
public virtual long Destination_Version
{
get
{
return _Destination_Version;
}
set
{
if (AreDifferent(_Destination_Version, value))
{
_Destination_Version = value;
}
}
}
public virtual int Distance_in_meter
{
get
{
return distance_in_meter;
}
set
{
if (AreDifferent(distance_in_meter, value))
{
distance_in_meter = value;
}
}
}
public virtual string Distance_in_meter_txt
{
get
{
return distance_in_meter_txt;
}
set
{
if (AreDifferent(distance_in_meter_txt, value))
{
distance_in_meter_txt = value;
}
}
}
public virtual int Time_in_seconds
{
get
{
return time_in_seconds;
}
set
{
if (AreDifferent(time_in_seconds, value))
{
time_in_seconds = value;
}
}
}
public virtual string Time_in_seconds_txt
{
get
{
return time_in_seconds_txt;
}
set
{
if (AreDifferent(time_in_seconds_txt, value))
{
time_in_seconds_txt = value;
}
}
}
}
}

View File

@@ -6,19 +6,22 @@
<generator class="identity" />
</id>
<version type="Int64" column="Version" name="Version" />
<property column="Tid" type="BS.Shared.TableID, BS.Shared" name="_Tid" access="field" />
<property column="Tid" type="BS.Shared.TableID, BS.Shared" name="_Tid" access="field" />
<property column="AddressLine1" type="String" name="AddressLine1" length="64" />
<property column="AddressLine2" type="String" name="AddressLine2" length="64" />
<property column="Street" type="String" name="Street" length="256" />
<property column="PostalCode" type="String" name="PostalCode" length="128" />
<property column="Town" type="String" name="Town" length="256" />
<property column="State" type="String" name="State" length="256" />
<property column="Country" type="String" name="Country" length="256" />
<property column="Notice" type="String" name="Notice" length="1024" />
<property column="InsTs" type="DateTime" name="InsTs" />
<property column="InsUser" type="String" name="InsUser" length="256" />
<property column="UdpUser" type="String" name="UdpUser" length="256" />
<property column="IsActive" type="BS.Shared.ActivationTypeId, BS.Shared" name="IsActive" />
<property column="SystemEntryID" type="BS.Shared.SystemEntryID, BS.Shared" name="SystemEntryID" />
<property column="Street" type="String" name="Street" length="256" />
<property column="PostalCode" type="String" name="PostalCode" length="128" />
<property column="Town" type="String" name="Town" length="256" />
<property column="State" type="String" name="State" length="256" />
<property column="Country" type="String" name="Country" length="256" />
<property column="Notice" type="String" name="Notice" length="1024" />
<property column="InsTs" type="DateTime" name="InsTs" />
<property column="InsUser" type="String" name="InsUser" length="256" />
<property column="UdpUser" type="String" name="UdpUser" length="256" />
<property column="IsActive" type="BS.Shared.ActivationTypeId, BS.Shared" name="IsActive" />
<property column="SystemEntryID" type="BS.Shared.SystemEntryID, BS.Shared" name="SystemEntryID" />
<property column="Latitude" type="Decimal" name="Latitude" />
<property column="Longitude" type="Decimal" name="Longitude" />
<property column="L_Version" type="Int64" name="L_Version" />
</class>
</hibernate-mapping>

View File

@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
<class name="BeWo.Data.Entities.AddressRoute,BeWo.Data" table="AddressRoute">
<id name="Oid" column="Oid" type="Int64" unsaved-value="null">
<generator class="identity" />
</id>
<version column="Version" type="Int64" name="Version" />
<property column="Tid" type="BS.Shared.TableID, BS.Shared" name="_Tid" access="field" />
<property column="IsActive" type="BS.Shared.ActivationTypeId, BS.Shared" name="IsActive" />
<property column="Notice" type="String" name="Notice" length="1024" />
<property column="InsTs" type="DateTime" name="InsTs" />
<property column="InsUser" type="String" name="InsUser" length="256" />
<property column="UdpUser" type="String" name="UdpUser" length="256" />
<property column="SystemEntryID" type="BS.Shared.SystemEntryID, BS.Shared" name="SystemEntryID" />
<property column="Address1Version" type="Int64" name="Origin_Version" />
<property column="Address2Version" type="Int64" name="Destination_Version" />
<property column="DistanceMeter" type="Int32" name="Distance_in_meter" />
<property column="TimeSec" type="Int32" name="Time_in_seconds" />
<many-to-one name="Origin" column="Address1Oid" class="BeWo.Data.Entities.Address, BeWo.Data" cascade="all" fetch="join"/>
<many-to-one name="Destination" column="Address2Oid" class="BeWo.Data.Entities.Address, BeWo.Data" cascade="all" fetch="join"/>
</class>
</hibernate-mapping>

View File

@@ -3,7 +3,7 @@
<PropertyGroup>
<NameOfLastUsedPublishProfile>BeWo2.0</NameOfLastUsedPublishProfile>
<UseIISExpress>true</UseIISExpress>
<LastActiveSolutionConfig>Release|Any CPU</LastActiveSolutionConfig>
<LastActiveSolutionConfig>Debug|Any CPU</LastActiveSolutionConfig>
<Use64BitIISExpress>false</Use64BitIISExpress>
<IISExpressSSLPort />
<IISExpressAnonymousAuthentication />

View File

@@ -156,6 +156,12 @@
<service behaviorConfiguration="returnFaults" name="ReportingService.ServiceImplementations.ReportServiceImp">
<endpoint behaviorConfiguration="SecurityAndSessionBehavior" binding="basicHttpBinding" bindingConfiguration="TransportSecurity" name="ReportServiceEndpoint" contract="ReportingService.ServiceContracts.IReportService" />
</service>
<service behaviorConfiguration="returnFaults" name="BeWo.Service.ServiceImplementations.LauncherServiceImp">
<endpoint behaviorConfiguration="SecurityAndSessionBehavior" binding="basicHttpBinding" bindingConfiguration="TransportSecurity" name="LauncherServiceEndpoint" contract="BeWo.Service.ServiceContracts.ILauncherService" />
</service>
<service behaviorConfiguration="returnFaults" name="BeWo.Service.ServiceImplementations.EnumTranslationServiceImp">
<endpoint behaviorConfiguration="SecurityAndSessionBehavior" binding="basicHttpBinding" bindingConfiguration="TransportSecurity" name="EnumTranslationServiceEndpoint" contract="BeWo.Service.ServiceContracts.IEnumTranslationService" />
</service>
</services>
<behaviors>
<endpointBehaviors>
@@ -217,6 +223,11 @@
<add key="MaxDocumentSize" value="20971520" />
<add key="ICD10File" value="ICD10\icd10.xml" />
<add key="FileRootDirectory" value="\BWP-Files" />
<add key="GoogleDistanceMatrixApiUrl" value="https://maps.googleapis.com/maps/api/distancematrix/json" />
<add key="GoogleDistanceMatrixApiKey" value="AIzaSyDZ_tfNwm_YWC9JiCLQtHsd9X2OUUKuL0c" />
<add key="OpenrouteServiceApiUrl" value="https://api.openrouteservice.org/v2/matrix/driving-car" />
<add key="OpenrouteServiceApiUrlGeocode" value="https://api.openrouteservice.org/geocode/search" />
<add key="OpenrouteServiceApiKey" value="5b3ce3597851110001cf62484b0917529e9a4008acda819dc06e47e8" />
</appSettings>
<devExpress>
<themes enableThemesAssembly="true" styleSheetTheme="" theme="" />

View File

@@ -0,0 +1,18 @@
CREATE TABLE `AddressRoute` (
`Oid` bigint NOT NULL AUTO_INCREMENT,
`Tid` int DEFAULT NULL,
`IsActive` tinyint DEFAULT NULL,
`Notice` varchar(1024) DEFAULT NULL,
`InsTs` datetime DEFAULT NULL,
`InsUser` varchar(256) DEFAULT NULL,
`Version` bigint DEFAULT NULL,
`UdpUser` varchar(256) DEFAULT NULL,
`SystemEntryID` int DEFAULT NULL,
`Address1Oid` bigint DEFAULT NULL,
`Address1Version` bigint DEFAULT NULL,
`Address2Oid` bigint DEFAULT NULL,
`Address2Version` bigint DEFAULT NULL,
`DistanceMeter` int DEFAULT NULL,
`TimeSec` int DEFAULT NULL,
PRIMARY KEY (`Oid`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

View File

@@ -0,0 +1,4 @@
ALTER TABLE `bewodemo`.`address`
ADD COLUMN `Latitude` DECIMAL(8,6) NULL DEFAULT NULL AFTER `AddressLine2`,
ADD COLUMN `Longitude` DECIMAL(9,6) NULL DEFAULT NULL AFTER `Latitude`,
ADD COLUMN `L_Version` BIGINT(19) NULL DEFAULT NULL AFTER `Longitude`;

View File

@@ -0,0 +1,70 @@
using BeWo.Data.Entities;
using BS.Shared.DataContracts;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BeWo.Service.DCEntityMapper
{
public class AddressRouteDC_AddressRoute : AbstractIDCEntityMapper<AddressRoute, AddressRouteDC>
{
public override AddressRouteDC MergeWithDC(AddressRoute pEntity, AddressRouteDC pDataContract)
{
pDataContract.Oid = pEntity.Oid;
pDataContract.IsActive = pEntity.IsActive;
pDataContract.Notice = pEntity.Notice;
pDataContract.InsTs = pEntity.InsTs;
pDataContract.InsUser = pEntity.InsUser;
pDataContract.Version = pEntity.Version;
pDataContract.UdpUser = pEntity.UdpUser;
pDataContract.SystemEntryID = pEntity.SystemEntryID;
pDataContract.Origin_Address_Oid = pEntity.Origin.Oid.Value;
pDataContract.Origin_Address_Version = pEntity.Origin_Version;
pDataContract.Destination_Address_Oid = pEntity.Destination.Oid.Value;
pDataContract.Destination_Address_Version = pEntity.Destination_Version;
pDataContract.Distance_in_meter = pEntity.Distance_in_meter;
pDataContract.Distance_in_meter_txt = pEntity.Distance_in_meter_txt;
pDataContract.Time_in_sec = pEntity.Time_in_seconds;
pDataContract.Time_in_sec_txt = pEntity.Time_in_seconds_txt;
return pDataContract;
}
public override AddressRoute MergeWithEntity(AddressRouteDC pDataContract, AddressRoute pEntity)
{
throw new NotImplementedException("#84971983047130984");
//this.ConcurrencyCheck(pDataContract.Version, pEntity);
//pEntity.Oid = pDataContract.Oid;
//pEntity.Notice = pDataContract.Notice;
//pEntity.SystemEntryID = pDataContract.SystemEntryID;
//pEntity.Origin = pDataContract.Origin_Address_Oid;
//pEntity.Address1_Version = pDataContract.Origin_Address_Version;
//pEntity.Address2_Oid = pDataContract.Destination_Address_Oid;
//pEntity.Address2_Version = pDataContract.Destination_Address_Version;
//pEntity.Distance_in_meter = pDataContract.Distance_in_meter;
//pEntity.Distance_in_meter_txt = pDataContract.Distance_in_meter_txt;
//pEntity.Time_in_seconds = pDataContract.Time_in_sec;
//pEntity.Time_in_seconds_txt = pDataContract.Time_in_sec_txt;
return pEntity;
}
protected override bool AreDCAndEntityEqual(AddressRouteDC pDC, AddressRoute pEntity)
{
if (pDC.Oid == null)
{
return false;
}
return pDC.Oid == pEntity.Oid;
}
}
}

View File

@@ -288,6 +288,8 @@ namespace BeWo.Service.DCEntityMapper
private static AbwesenheitsInformationPrintDC_AbwesenheitsInformationPrint _AbwesenheitsInformationPrintDC_AbwesenheitsInformationPrint;
private static AddressRouteDC_AddressRoute _AddressRouteDC_AddressRoute;
public static MedRecordDC_MedRecord MedRecordDC_MedRecord =>
_MedRecordDC_MedRecord ?? (_MedRecordDC_MedRecord = new MedRecordDC_MedRecord());
@@ -723,5 +725,8 @@ namespace BeWo.Service.DCEntityMapper
public static AbwesenheitsInformationPrintDC_AbwesenheitsInformationPrint AbwesenheitsInformationPrintDC_AbwesenheitsInformationPrint =>
_AbwesenheitsInformationPrintDC_AbwesenheitsInformationPrint ?? (_AbwesenheitsInformationPrintDC_AbwesenheitsInformationPrint = new AbwesenheitsInformationPrintDC_AbwesenheitsInformationPrint());
public static AddressRouteDC_AddressRoute AddressRouteDC_AddressRoute =>
_AddressRouteDC_AddressRoute ?? (_AddressRouteDC_AddressRoute = new AddressRouteDC_AddressRoute());
}
}

View File

@@ -37,10 +37,19 @@ namespace BeWo.Service.Security
string lServiceInterface = lTemp[lTemp.Count - 2];
// TODO Hier kann man jetzt etwas bauen wer sich für welchen service autorisieren muss...
if (lMethodName == "IsUserValid" || lMethodName == "IsUserValidTwoFactor" || lMethodName == "ResetTenant" || lMethodName == "ResetAllTenants" || lMethodName == "GetEmailForUserName")
var skip = new string[] { "Download", "Download2", "DownloadInfo", "GetUpdatePlan", "GetUpdateFile" };
if (lMethodName == "IsUserValid" || lMethodName == "IsUserValidTwoFactor" || lMethodName == "ResetTenant" || lMethodName == "ResetAllTenant" || lMethodName == "GetEmailForUserName")
{
return null;
}
else if (skip.Contains(lMethodName))
{
return null;
}
else
{
// Vergessen neue Methode einzutragen?
}
string lUserName = null, lPassword = null;

View File

@@ -106,24 +106,6 @@
<Reference Include="Microsoft.Bcl.AsyncInterfaces, Version=5.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Bcl.AsyncInterfaces.5.0.0\lib\net461\Microsoft.Bcl.AsyncInterfaces.dll</HintPath>
</Reference>
<Reference Include="Microsoft.CodeAnalysis, Version=3.11.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.CodeAnalysis.Common.3.11.0\lib\netstandard2.0\Microsoft.CodeAnalysis.dll</HintPath>
</Reference>
<Reference Include="Microsoft.CodeAnalysis.CSharp, Version=3.11.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.CodeAnalysis.CSharp.3.11.0\lib\netstandard2.0\Microsoft.CodeAnalysis.CSharp.dll</HintPath>
</Reference>
<Reference Include="Microsoft.CodeAnalysis.CSharp.Workspaces, Version=3.11.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.CodeAnalysis.CSharp.Workspaces.3.11.0\lib\netstandard2.0\Microsoft.CodeAnalysis.CSharp.Workspaces.dll</HintPath>
</Reference>
<Reference Include="Microsoft.CodeAnalysis.VisualBasic, Version=3.11.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.CodeAnalysis.VisualBasic.3.11.0\lib\netstandard2.0\Microsoft.CodeAnalysis.VisualBasic.dll</HintPath>
</Reference>
<Reference Include="Microsoft.CodeAnalysis.VisualBasic.Workspaces, Version=3.11.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.CodeAnalysis.VisualBasic.Workspaces.3.11.0\lib\netstandard2.0\Microsoft.CodeAnalysis.VisualBasic.Workspaces.dll</HintPath>
</Reference>
<Reference Include="Microsoft.CodeAnalysis.Workspaces, Version=3.11.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.CodeAnalysis.Workspaces.Common.3.11.0\lib\netstandard2.0\Microsoft.CodeAnalysis.Workspaces.dll</HintPath>
</Reference>
<Reference Include="MySql.Data, Version=8.0.21.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\Lib\MySql.Data.dll</HintPath>
@@ -187,6 +169,7 @@
<Reference Include="System.Memory, Version=4.0.1.1, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\packages\System.Memory.4.5.4\lib\net461\System.Memory.dll</HintPath>
</Reference>
<Reference Include="System.Net.Http" />
<Reference Include="System.Numerics" />
<Reference Include="System.Numerics.Vectors, Version=4.1.4.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\System.Numerics.Vectors.4.5.0\lib\net46\System.Numerics.Vectors.dll</HintPath>
@@ -236,6 +219,7 @@
<Compile Include="Core\SettingsLogic.cs" />
<Compile Include="Core\Utils.cs" />
<Compile Include="DCEntityMapper\AbwesenheitsInformationPrintDC_AbwesenheitsInformationPrint.cs" />
<Compile Include="DCEntityMapper\AddressRouteDC_AddressRoute.cs" />
<Compile Include="DCEntityMapper\ConfirmationReceiptSignatureDC_ConfirmationReceiptSignature.cs" />
<Compile Include="DCEntityMapper\DienstvertretungDC_Dienstvertretung.cs" />
<Compile Include="DCEntityMapper\DokumentvorlageDC_Dokumentvorlage.cs" />
@@ -489,6 +473,11 @@
<Compile Include="ServiceImplementations\UserServiceImp.cs" />
<Compile Include="ServiceImplementations\ValueListServiceImp.cs" />
<Compile Include="Configuration\AppSettings.cs" />
<Compile Include="ServiceUtils\DistanceCalculator\AddressRouteManager.cs" />
<Compile Include="ServiceUtils\DistanceCalculator\AddressRouteMatrix.cs" />
<Compile Include="ServiceUtils\DistanceCalculator\GoogleDistanceMatrixAPI.cs" />
<Compile Include="ServiceUtils\DistanceCalculator\IDistanceAPI.cs" />
<Compile Include="ServiceUtils\DistanceCalculator\OpenrouteServiceAPI.cs" />
<Compile Include="UnitOfWork\HibernateSessionEndpointBehavior.cs" />
<Compile Include="UnitOfWork\HibernateSessionBehaviorExtension.cs" />
<Compile Include="UnitOfWork\HibernateSessionContextInitializer.cs" />
@@ -524,6 +513,8 @@
</BootstrapperPackage>
</ItemGroup>
<ItemGroup>
<Folder Include="ServiceUtils\API\" />
<Folder Include="ServiceUtils\Generell\" />
<Folder Include="Utils\" />
</ItemGroup>
<ItemGroup>
@@ -532,19 +523,7 @@
</None>
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<Analyzer Include="..\packages\Microsoft.CodeAnalysis.Analyzers.3.3.2\analyzers\dotnet\cs\Microsoft.CodeAnalysis.Analyzers.dll" />
<Analyzer Include="..\packages\Microsoft.CodeAnalysis.Analyzers.3.3.2\analyzers\dotnet\cs\Microsoft.CodeAnalysis.CSharp.Analyzers.dll" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\packages\Microsoft.CodeAnalysis.Analyzers.3.3.2\build\Microsoft.CodeAnalysis.Analyzers.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.CodeAnalysis.Analyzers.3.3.2\build\Microsoft.CodeAnalysis.Analyzers.props'))" />
<Error Condition="!Exists('..\packages\Microsoft.CodeAnalysis.Analyzers.3.3.2\build\Microsoft.CodeAnalysis.Analyzers.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.CodeAnalysis.Analyzers.3.3.2\build\Microsoft.CodeAnalysis.Analyzers.targets'))" />
</Target>
<Import Project="..\packages\Microsoft.CodeAnalysis.Analyzers.3.3.2\build\Microsoft.CodeAnalysis.Analyzers.targets" Condition="Exists('..\packages\Microsoft.CodeAnalysis.Analyzers.3.3.2\build\Microsoft.CodeAnalysis.Analyzers.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">

View File

@@ -13,6 +13,7 @@ using BeWo.Service.SBD;
using BeWo.Service.Security;
using BeWo.Service.ServiceContracts;
using BeWo.Service.Urlaubsplanung;
using BeWo.Service.ServiceUtils.DistanceCalculator;
using BeWo.View.Navigation.Filter;
using BS.Shared;
using BS.Shared.DataContracts;
@@ -1478,7 +1479,9 @@ namespace BeWo.Service.ServiceImplementations
vertretungsItem.Employee != null).Select(item => item.Employee.EmployeeOid);
employeeOids = employeeOids.Where(e => !abwesenendeEmployeeOids.Contains(e));
var list = MapperFactory.CompactVertreterEmployeeDC_VertreterEmployee.MapToNewDCs(DAOFactory.GenericDAO.GetActiveByIDs<Employee>(employeeOids));
var allEmps = DAOFactory.GenericDAO.GetActiveByIDs<Employee>(employeeOids).ToList();
var list = MapperFactory.CompactVertreterEmployeeDC_VertreterEmployee.MapToNewDCs(allEmps);
//Setze Betreuungszeiten
foreach (var vertreter in list)
@@ -1509,6 +1512,10 @@ namespace BeWo.Service.ServiceImplementations
}
}
}
if (customerOid.HasValue)
GetDistanceForVertreterEmployees(customerOid.Value, ref list, allEmps);
return list;
}
catch (Exception e)
@@ -1517,6 +1524,25 @@ namespace BeWo.Service.ServiceImplementations
}
}
private void GetDistanceForVertreterEmployees(long customerOid, ref List<CompactVertreterEmployeeDC> list, List<Employee> employees)
{
var customer = DAOFactory.GenericDAO.LoadByID<Customer>(customerOid);
var school = customer.Customer2OrganisationList.FirstOrDefault(f => f.ValueList.Any(b => b.Entry.Type == ValueListEntryType.EnvironmentOrganisationType && b.Entry.Value.Equals("Schule")));
var origin = new Address[] { school.Person.Address };
var destinations = employees.Select(x => x.Person.Address).ToArray();
var matrix = AddressRouteManager.GetMatrix(origin, destinations);
Employee empl; AddressRoute route;
foreach (var employee in list)
{
empl = employees.FirstOrDefault(e => e.Person.Oid.Value == employee.PersonOid);
route = matrix.GetRoute(school.Person.Address, empl.Person.Address);
employee.AddressRoute = MapperFactory.AddressRouteDC_AddressRoute.MapToNewDC(route);
}
}
public List<EmployeeTokenRelationDC> LoadEmployeeTokenRelationsByOid(IEnumerable<long> pOids)
{
try

View File

@@ -0,0 +1,94 @@
using BeWo.Data.Access;
using BeWo.Data.Entities;
using System;
using System.Collections.Generic;
using System.Linq;
namespace BeWo.Service.ServiceUtils.DistanceCalculator
{
public static class AddressRouteManager
{
public static IDistanceAPI DistanceAPI { get; set; }
static AddressRouteManager()
{
DistanceAPI =
//new GoogleDistanceMatrixApi();
new OpenrouteServiceAPI();
}
public static AddressRouteMatrix GetMatrix(Address[] origins, Address[] destinations)
{
var routes = DAOFactory.GenericDAO.GetAll<AddressRoute>();
var matrix = new AddressRouteMatrix(origins, destinations);
LoadExistingData(ref matrix, routes, out var needUpdate);
var requests = needUpdate.Union(matrix.GetUnkownRoutes()).ToList();
// Alles aktuell
if (!requests.Any())
return matrix;
var ori2req = requests.Select(x => x.Origin).ToHashSet();
var des2req = requests.Select(x => x.Destination).ToHashSet();
DistanceAPI.RequestMissingData(ref matrix, ori2req, des2req);
foreach (var req in requests)
{
var route = matrix.GetRoute(req.Origin, req.Destination);
if (route is null)
throw new NotImplementedException("Unerwartetes Verhalten #4314513094871");
route.Origin_Version = route.Origin.Version.Value;
route.Destination_Version = route.Destination.Version.Value;
if (!route.Version.HasValue)
{
// Neu
DAOFactory.GenericDAO.Insert(req);
}
else
{
// Update
DAOFactory.GenericDAO.Update(req);
}
}
return matrix;
}
public static void LoadExistingData(ref AddressRouteMatrix matrix, IList<AddressRoute> routes, out List<AddressRoute> needUpdate)
{
needUpdate = new List<AddressRoute>();
foreach (var route in routes)
{
var origin = route.Origin;
var destination = route.Destination;
if (!matrix.CanUseRoute(origin, destination))
continue;
if (origin.Version == route.Origin_Version && destination.Version == route.Destination_Version)
{
// Ist aktuell
matrix.SetRoute(origin, destination, route);
}
else
{
// Braucht Update
matrix.SetRoute(origin, destination, route);
needUpdate.Add(route);
}
}
}
public static string AddressToString(Address address)
{
return $"{address.Street}, {address.PostalCode}, {address.Town}, {address.State}, {address.Country}";
}
}
}

View File

@@ -0,0 +1,84 @@
using BeWo.Data.Entities;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BeWo.Service.ServiceUtils.DistanceCalculator
{
public class AddressRouteMatrix
{
public int OriginsLength { get; set; }
public int DestinationsLength { get; set; }
public Address[] OriginAddresses { get; set; }
public Address[] DestinationAddresses { get; set; }
public Dictionary<Address, int> Origins { get; set; }
public Dictionary<Address, int> Destinations { get; set; }
public AddressRoute[,] Routes { get; set; }
public AddressRouteMatrix(Address[] originAddresses, Address[] destinationAddresses)
{
OriginAddresses = originAddresses;
Origins = new Dictionary<Address, int>();
OriginsLength = originAddresses.Length;
DestinationAddresses = destinationAddresses;
Destinations = new Dictionary<Address, int>();
DestinationsLength = destinationAddresses.Length;
int i;
for (i = 0; i < OriginsLength; i++)
{
Origins.Add(originAddresses[i], i);
}
for (i = 0; i < DestinationsLength; i++)
{
Destinations.Add(destinationAddresses[i], i);
}
Routes = new AddressRoute[OriginsLength, DestinationsLength];
}
public void SetRoute(Address origin, Address destination, AddressRoute value) => Routes[Origins[origin], Destinations[destination]] = value;
public AddressRoute GetRoute(Address origin, Address destination)
{
return Routes[Origins[origin], Destinations[destination]];
}
public IEnumerable<AddressRoute> GetUnkownRoutes()
{
for (int i = 0; i < OriginsLength; i++)
{
for (int j = 0; j < DestinationsLength; j++)
{
var route = Routes[i, j];
if (route is null)
{
route = new AddressRoute
{
Origin = OriginAddresses[i],
Destination = DestinationAddresses[j]
};
Routes[i, j] = route;
yield return route;
}
}
}
}
public bool CanUseRoute(Address origin, Address destination)
{
if (!Origins.ContainsKey(origin))
return false;
if (!Destinations.ContainsKey(destination))
return false;
return true;
}
}
}

View File

@@ -0,0 +1,154 @@
using BeWo.Data.Entities;
using BS.Shared.DataContracts;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
using System.Web;
namespace BeWo.Service.ServiceUtils.DistanceCalculator
{
public class GoogleDistanceMatrixApi : IDistanceAPI
{
public class Response
{
public string Status { get; set; }
[JsonProperty(PropertyName = "origin_addresses")]
public string[] OriginAddresses { get; set; }
[JsonProperty(PropertyName = "destination_addresses")]
public string[] DestinationAddresses { get; set; }
public Row[] Rows { get; set; }
public class Data
{
public int Value { get; set; }
public string Text { get; set; }
}
public class Element
{
public string Status { get; set; }
public Data Duration { get; set; }
public Data Distance { get; set; }
}
public class Row
{
public Element[] Elements { get; set; }
}
}
private string Key { get; set; }
private string Url { get; set; }
private AddressRouteMatrix Matrix { get; set; }
private Address[] OriginAddresses { get; set; }
private Address[] DestinationAddresses { get; set; }
public GoogleDistanceMatrixApi()
{
var appSettings = ConfigurationManager.AppSettings;
if (string.IsNullOrEmpty(appSettings["GoogleDistanceMatrixApiUrl"]))
{
throw new Exception("GoogleDistanceMatrixApiUrl is not set in AppSettings.");
}
Url = appSettings["GoogleDistanceMatrixApiUrl"];
if (string.IsNullOrEmpty(appSettings["GoogleDistanceMatrixApiKey"]))
{
throw new Exception("GoogleDistanceMatrixApiKey is not set in AppSettings.");
}
Key = appSettings["GoogleDistanceMatrixApiKey"];
}
public void RequestMissingData(ref AddressRouteMatrix matrix, IEnumerable<Address> origins, IEnumerable<Address> destinations)
{
Matrix = matrix;
OriginAddresses = origins.ToArray();
DestinationAddresses = destinations.ToArray();
var task = GetMatrix();
task.Wait();
if (task.Exception is object)
{
throw task.Exception;
}
}
public async Task<AddressRouteMatrix> GetMatrix()
{
using (var client = new HttpClient())
{
var uri = new Uri(GetRequestUrl());
HttpResponseMessage response = await client.GetAsync(uri);
if (!response.IsSuccessStatusCode)
{
throw new Exception("GoogleDistanceMatrixApi failed with status code: " + response.StatusCode);
}
else
{
var content = await response.Content.ReadAsStringAsync();
return FillMatrix(JsonConvert.DeserializeObject<Response>(content));
}
}
}
public AddressRouteMatrix FillMatrix(Response response)
{
for (int i = 0; i < response.Rows.Length; i++)
{
var row = response.Rows[i];
var origin = OriginAddresses[i];
for (int j = 0; j < row.Elements.Length; j++)
{
var element = row.Elements[j];
var destination = DestinationAddresses[j];
var route = Matrix.GetRoute(origin, destination);
route.Distance_in_meter = element.Distance.Value;
route.Distance_in_meter_txt = element.Distance.Text;
route.Time_in_seconds = element.Duration.Value;
route.Time_in_seconds_txt = element.Duration.Text;
}
}
return Matrix;
}
public AddressRoute ToAddressRoute(Response.Element element)
{
var res = new AddressRoute();
res.Distance_in_meter = element.Distance.Value;
res.Distance_in_meter_txt = element.Distance.Text;
res.Time_in_seconds = element.Duration.Value;
res.Time_in_seconds_txt = element.Duration.Text;
return res;
}
private string GetRequestUrl()
{
var originAddresses = OriginAddresses.Select(str => AddressRouteManager.AddressToString(str)).Select(HttpUtility.UrlEncode).ToArray();
var origins = string.Join("|", originAddresses);
var destinationAddresses = DestinationAddresses.Select(str => AddressRouteManager.AddressToString(str)).Select(HttpUtility.UrlEncode).ToArray();
var destinations = string.Join("|", destinationAddresses);
return $"{Url}?origins={origins}&destinations={destinations}&key={Key}";
}
}
}

View File

@@ -0,0 +1,19 @@
using BeWo.Data.Entities;
using BS.Shared.DataContracts;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BeWo.Service.ServiceUtils.DistanceCalculator
{
public interface IDistanceAPI
{
//AddressRoute[,] GetAddressRoutes(Address[] originAddresses, Address[] destinationAddresses);
//AddressRouteMatrix GetAddressRouteMatrix(Address[] originAddresses, Address[] destinationAddresses);
void RequestMissingData(ref AddressRouteMatrix matrix, IEnumerable<Address> origins, IEnumerable<Address> destinations);
}
}

View File

@@ -0,0 +1,259 @@
using BeWo.Data.Access;
using BeWo.Data.Entities;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Globalization;
using System.Linq;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text;
using System.Threading.Tasks;
using System.Web;
using Task = System.Threading.Tasks.Task;
namespace BeWo.Service.ServiceUtils.DistanceCalculator
{
public class OpenrouteServiceAPI : IDistanceAPI
{
public class ResponseGeo
{
public Feature[] Features { get; set; }
public class Feature
{
public string Type { get; set; }
public Geometry Geometry { get; set; }
}
public class Geometry
{
public string Type { get; set; }
public decimal[] Coordinates { get; set; }
}
}
public class ResponseMatrix
{
public decimal[,] Durations { get; set; }
public decimal[,] Distances { get; set; }
}
private string Key { get; set; }
private string GeoKey { get; set; }
private string Url { get; set; }
private AddressRouteMatrix Matrix { get; set; }
private Address[] OriginAddresses { get; set; }
private Address[] DestinationAddresses { get; set; }
public OpenrouteServiceAPI()
{
var appSettings = ConfigurationManager.AppSettings;
if (string.IsNullOrEmpty(appSettings["OpenrouteServiceApiUrl"]))
{
throw new Exception("OpenrouteServiceApiUrl is not set in AppSettings.");
}
Url = appSettings["OpenrouteServiceApiUrl"];
if (string.IsNullOrEmpty(appSettings["OpenrouteServiceApiKey"]))
{
throw new Exception("OpenrouteServiceApiKey is not set in AppSettings.");
}
Key = appSettings["OpenrouteServiceApiKey"];
if (string.IsNullOrEmpty(appSettings["OpenrouteServiceApiUrlGeocode"]))
{
throw new Exception("OpenrouteServiceApiUrlGeocode is not set in AppSettings.");
}
GeoKey = appSettings["OpenrouteServiceApiUrlGeocode"];
}
public void RequestMissingData(ref AddressRouteMatrix matrix, IEnumerable<Address> origins, IEnumerable<Address> destinations)
{
Matrix = matrix;
OriginAddresses = origins.ToArray();
DestinationAddresses = destinations.ToArray();
if (!(origins.Any() && destinations.Any()))
throw new NotImplementedException("Keine Addresse angefragt");
LoadCoordinates().Wait();
var task = GetMatrix();
task.Wait();
if (task.Exception is object)
{
throw task.Exception;
}
}
public async Task LoadCoordinates()
{
// Update Koordinaten
var items = OriginAddresses.Union(DestinationAddresses).ToHashSet();
foreach (var item in items)
{
if (item.L_Version is object && item.L_Version == item.Version)
continue;
await LoadCoordinate(item);
DAOFactory.GenericDAO.Update(item);
}
}
public async Task LoadCoordinate(Address address)
{
using (var client = new HttpClient())
{
var uri = new Uri(GetGeocodeUrl(address));
client.DefaultRequestHeaders.Clear();
client.DefaultRequestHeaders.TryAddWithoutValidation("accept", "application/json; charset=utf-8");
client.DefaultRequestHeaders.TryAddWithoutValidation("Content-Type", "application/json; charset=utf-8");
using (var response = await client.GetAsync(uri))
{
string responseData = await response.Content.ReadAsStringAsync();
if (response.IsSuccessStatusCode)
{
try
{
var data = JsonConvert.DeserializeObject<ResponseGeo>(responseData);
address.Longitude = data.Features[0].Geometry.Coordinates[0];
address.Latitude = data.Features[0].Geometry.Coordinates[1];
address.L_Version = address.Version.Value + 1;
return;
}
catch (Exception e)
{
throw e;
}
}
else
{
throw new Exception("OpenrouteServiceAPI failed with status code: " + response.StatusCode + " |||Data: " + responseData);
}
}
}
}
public async Task<AddressRouteMatrix> GetMatrix()
{
using (var client = new HttpClient())
{
var uri = new Uri(Url);
client.DefaultRequestHeaders.Clear();
client.DefaultRequestHeaders.TryAddWithoutValidation("accept", "application/json; charset=utf-8");
client.DefaultRequestHeaders.TryAddWithoutValidation("Content-Type", "application/json; charset=utf-8");
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", Key);
using (var content = new StringContent(GetMatrixBodyContentString()))
//using (var content = new StringContent("{\"locations\":[[48.477473,9.70093],[49.153868,9.207916]]}"))
{
content.Headers.ContentType = new MediaTypeHeaderValue("application/json");
using (var response = await client.PostAsync(uri, content))
{
string responseData = await response.Content.ReadAsStringAsync();
if (response.IsSuccessStatusCode)
{
var data = JsonConvert.DeserializeObject<ResponseMatrix>(responseData);
return FillMatrix(data);
}
else
{
throw new Exception("OpenrouteServiceAPI failed with status code: " + response.StatusCode + " |||Data: " + responseData);
}
}
}
}
}
public AddressRouteMatrix FillMatrix(ResponseMatrix response)
{
for (int i = 0; i < response.Durations.GetLength(0); i++)
{
for (int j = 0; j < response.Durations.GetLength(1); j++)
{
var distance = response.Distances[i, j];
var duration = response.Durations[i, j];
var origin = OriginAddresses[i];
var destination = DestinationAddresses[j];
var route = Matrix.GetRoute(origin, destination);
route.Distance_in_meter = (int) (distance * 1000);
route.Time_in_seconds = (int) duration;
}
}
return Matrix;
}
private string GetGeocodeUrl(Address address)
{
var html = HttpUtility.UrlEncode(AddressRouteManager.AddressToString(address));
return $"{GeoKey}?api_key={Key}&text={html}&sources=openstreetmap&size=1";
}
private string GetMatrixBodyContentString()
{
var sb = new StringBuilder();
var origins = OriginAddresses.Select(GetCoordinates);
var olen = OriginAddresses.Count();
var destination = DestinationAddresses.Select(GetCoordinates);
var dlen = DestinationAddresses.Count();
sb.Append("{\"locations\":");
sb.Append("[");
sb.Append(string.Join(",", origins.Union(destination)));
sb.Append("]");
sb.Append(",\"metrics\":[\"distance\",\"duration\"]");
sb.Append(",\"units\":\"km\"");
sb.Append(",\"sources\":");
sb.Append(GetList(0, olen - 1));
sb.Append(",\"destinations\":");
sb.Append(GetList(olen, olen + dlen - 1));
sb.Append("}");
return sb.ToString();
}
private string GetCoordinates(Address add) => $"[{add.Longitude.Value.ToString(new CultureInfo("en-US"))},{add.Latitude.Value.ToString(new CultureInfo("en-US"))}]";
private string GetList(int x, int y)
{
if (y < x)
throw new ArgumentException($"y({y}) darf nicht kleiner als x({x}) sein");
var diff = y - x;
var list = new int[diff + 1];
for (int i = 0; i <= diff; i++)
{
list[i] = x + i;
}
return "[" + string.Join(",", list) + "]";
}
}
}

BIN
Service/SvcUtil.exe Normal file

Binary file not shown.

View File

@@ -166,6 +166,7 @@ namespace BS.Shared
SupportConceptApprovalPeriodHistory = 159,
ContractHistory = 160,
ErrorMessage = 161,
AddressRoute = 162
}
public enum SystemEntryID

View File

@@ -0,0 +1,61 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;
using System.Threading.Tasks;
namespace BS.Shared.DataContracts
{
public class AddressRouteDC : IDataContract
{
[DataMember]
public long? Oid { get; set; }
[DataMember]
public ActivationTypeId IsActive { get; set; }
[DataMember]
public string Notice { get; set; }
[DataMember]
public DateTime? InsTs { get; set; }
[DataMember]
public string InsUser { get; set; }
[DataMember]
public long? Version { get; set; }
[DataMember]
public string UdpUser { get; set; }
[DataMember]
public SystemEntryID? SystemEntryID { get; set; }
[DataMember]
public long Origin_Address_Oid { get; set; }
[DataMember]
public long Origin_Address_Version { get; set; }
[DataMember]
public long Destination_Address_Oid { get; set; }
[DataMember]
public long Destination_Address_Version { get; set; }
[DataMember]
public int Distance_in_meter { get; set; }
[DataMember]
public string Distance_in_meter_txt { get; set; }
[DataMember]
public int Time_in_sec { get; set; }
[DataMember]
public string Time_in_sec_txt { get; set; }
}
}

View File

@@ -81,6 +81,10 @@ namespace BS.Shared.DataContracts.Compact
public List<ArbeitszeitDC>Arbeitszeit { get; set; }
[DataMember]
public CompactEmployeeDC CompactEmployee { get; set; }
public CompactEmployeeDC CompactEmployee { get; set; }
[DataMember]
public AddressRouteDC AddressRoute { get; set; }
}
}

View File

@@ -157,6 +157,7 @@
<Compile Include="DataContracts\AdditionalServiceGroupOfPeopleDC.cs" />
<Compile Include="DataContracts\AdditionalServiceGroupOfPeopleRelationDC.cs" />
<Compile Include="DataContracts\AdditionalServiceRegionDC.cs" />
<Compile Include="DataContracts\AddressRouteDC.cs" />
<Compile Include="DataContracts\ClientPartials\ContactDC.cs" />
<Compile Include="DataContracts\BesetzungsstatusDC.cs" />
<Compile Include="DataContracts\ConfirmationReceiptSignatureDC.cs" />