-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0e2fe7c
commit 4f73557
Showing
26 changed files
with
1,290 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
**/.classpath | ||
**/.dockerignore | ||
**/.env | ||
**/.git | ||
**/.gitignore | ||
**/.project | ||
**/.settings | ||
**/.toolstarget | ||
**/.vs | ||
**/.vscode | ||
**/*.*proj.user | ||
**/*.dbmdl | ||
**/*.jfm | ||
**/azds.yaml | ||
**/bin | ||
**/charts | ||
**/docker-compose* | ||
**/Dockerfile* | ||
**/node_modules | ||
**/npm-debug.log | ||
**/obj | ||
**/secrets.dev.yaml | ||
**/values.dev.yaml | ||
LICENSE | ||
README.md |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# Use the base image for installing libpostal dependencies | ||
FROM mcr.microsoft.com/dotnet/aspnet:7.0 AS libpostal_base | ||
RUN apt-get update \ | ||
&& apt-get install -y curl autoconf automake libtool pkg-config git build-essential \ | ||
&& git clone https://github.com/openvenues/libpostal \ | ||
&& cd libpostal \ | ||
&& ./bootstrap.sh \ | ||
&& ./configure --datadir=/var/lib/ \ | ||
&& make -j4 \ | ||
&& make install \ | ||
&& ldconfig | ||
|
||
FROM mcr.microsoft.com/dotnet/aspnet:7.0 AS base | ||
WORKDIR /app | ||
EXPOSE 80 | ||
EXPOSE 443 | ||
|
||
FROM mcr.microsoft.com/dotnet/sdk:7.0 AS build | ||
WORKDIR /src | ||
COPY ["LinuxDockerApi/LinuxDockerApi.csproj", "LinuxDockerApi/"] | ||
COPY ["LibPostalNet/LibPostalNet.csproj", "LibPostalNet/"] | ||
RUN dotnet restore "LinuxDockerApi/LinuxDockerApi.csproj" | ||
COPY . . | ||
WORKDIR "/src/LinuxDockerApi" | ||
RUN dotnet build "LinuxDockerApi.csproj" -c Release -o /app/build | ||
|
||
FROM build AS publish | ||
RUN dotnet publish "LinuxDockerApi.csproj" -c Release -o /app/publish /p:UseAppHost=false | ||
|
||
# Use libpostal_base as the starting point for the final image | ||
FROM libpostal_base AS final | ||
WORKDIR /app | ||
COPY --from=publish /app/publish . | ||
ENTRYPOINT ["dotnet", "LinuxDockerApi.dll"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio Version 17 | ||
VisualStudioVersion = 17.7.33711.374 | ||
MinimumVisualStudioVersion = 10.0.40219.1 | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LibPostalApi", "LinuxDockerApi\LibPostalApi.csproj", "{C78E185A-20AB-4826-A7B2-3A06B4298E65}" | ||
EndProject | ||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{DE620D2C-39FE-4C68-869B-633C09412AB6}" | ||
ProjectSection(SolutionItems) = preProject | ||
Dockerfile = Dockerfile | ||
EndProjectSection | ||
EndProject | ||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LibPostalNet", "LibPostalNet\LibPostalNet.csproj", "{DAFCE0DC-A469-46EC-985F-3059C711E45B}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{C78E185A-20AB-4826-A7B2-3A06B4298E65}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{C78E185A-20AB-4826-A7B2-3A06B4298E65}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{C78E185A-20AB-4826-A7B2-3A06B4298E65}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{C78E185A-20AB-4826-A7B2-3A06B4298E65}.Release|Any CPU.Build.0 = Release|Any CPU | ||
{DAFCE0DC-A469-46EC-985F-3059C711E45B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{DAFCE0DC-A469-46EC-985F-3059C711E45B}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{DAFCE0DC-A469-46EC-985F-3059C711E45B}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{DAFCE0DC-A469-46EC-985F-3059C711E45B}.Release|Any CPU.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
GlobalSection(ExtensibilityGlobals) = postSolution | ||
SolutionGuid = {A301567F-18D1-4C8B-9ED5-8CB44EAC7D12} | ||
EndGlobalSection | ||
EndGlobal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
using System; | ||
|
||
namespace LibPostalNet | ||
{ | ||
[Flags] | ||
public enum AddressComponents : int | ||
{ | ||
NONE = 0, | ||
ANY = (1 << 0), | ||
NAME = (1 << 1), | ||
HOUSE_NUMBER = (1 << 2), | ||
STREET = (1 << 3), | ||
UNIT = (1 << 4), | ||
LEVEL = (1 << 5), | ||
STAIRCASE = (1 << 6), | ||
ENTRANCE = (1 << 7), | ||
CATEGORY = (1 << 8), | ||
NEAR = (1 << 9), | ||
|
||
TOPONYM = (1 << 13), | ||
POSTAL_CODE = (1 << 14), | ||
PO_BOX = (1 << 15), | ||
ALL = ((1 << 16) - 1) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
using Newtonsoft.Json.Linq; | ||
using System; | ||
using System.Runtime.InteropServices; | ||
using System.Xml; | ||
|
||
namespace LibPostalNet | ||
{ | ||
public unsafe class AddressExpansionResponse : IDisposable | ||
{ | ||
private IntPtr _Instance; | ||
private IntPtr _InputString; | ||
private ulong _NumExpansions; | ||
|
||
public string[] Expansions { get; private set; } | ||
|
||
internal AddressExpansionResponse(string input, AddressExpansionOptions options) | ||
{ | ||
if (ReferenceEquals(options, null)) throw new NullReferenceException(); | ||
_InputString = MarshalUTF8.StringToPtr(input); | ||
var native = LibPostal.UnsafeNativeMethods.ExpandAddress(_InputString, options._Native, ref _NumExpansions); | ||
if (native == IntPtr.Zero || native.ToPointer() == null) | ||
return; | ||
_Instance = native; | ||
|
||
Expansions = new string[_NumExpansions]; | ||
for (int x = 0; x < (int)_NumExpansions; x++) | ||
{ | ||
int offset = x * Marshal.SizeOf(typeof(IntPtr)); | ||
Expansions[x] = MarshalUTF8.PtrToString(Marshal.ReadIntPtr(native, offset)); | ||
} | ||
} | ||
|
||
~AddressExpansionResponse() { Dispose(false); } | ||
public void Dispose() | ||
{ | ||
Dispose(true); | ||
GC.SuppressFinalize(this); | ||
} | ||
protected virtual void Dispose(bool disposing) | ||
{ | ||
if (_Instance != IntPtr.Zero) | ||
{ | ||
LibPostal.UnsafeNativeMethods.ExpansionArrayDestroy(_Instance, _NumExpansions); | ||
_Instance = IntPtr.Zero; | ||
} | ||
if (_InputString != IntPtr.Zero) | ||
{ | ||
Marshal.FreeHGlobal(_InputString); | ||
_InputString = IntPtr.Zero; | ||
} | ||
} | ||
|
||
public string ToJSON() | ||
{ | ||
var json = new JArray(); | ||
foreach (var expansion in Expansions) | ||
{ | ||
json.Add(new JValue(expansion)); | ||
} | ||
return json.ToString(Newtonsoft.Json.Formatting.None); | ||
} | ||
|
||
public string ToXML() | ||
{ | ||
XmlDocument doc = new XmlDocument(); | ||
doc.AppendChild(doc.CreateXmlDeclaration("1.0", string.Empty, string.Empty)); | ||
var address = doc.CreateElement("address"); | ||
foreach (var expansion in Expansions) | ||
{ | ||
var elem = doc.CreateElement("expansion"); | ||
elem.AppendChild(doc.CreateTextNode(expansion)); | ||
address.AppendChild(elem); | ||
} | ||
doc.AppendChild(address); | ||
return doc.OuterXml; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
using System; | ||
using System.Runtime.InteropServices; | ||
|
||
namespace LibPostalNet | ||
{ | ||
public partial class AddressParserOptions | ||
{ | ||
[StructLayout(LayoutKind.Explicit, Pack = 1, Size = 16)] | ||
protected internal struct UnsafeNativeMethods | ||
{ | ||
[FieldOffset(0)] | ||
internal IntPtr language; | ||
|
||
[FieldOffset(8)] | ||
internal IntPtr country; | ||
|
||
//[SuppressUnmanagedCodeSecurity] | ||
//[DllImport("libpostal", CallingConvention = CallingConvention.Cdecl, | ||
// EntryPoint = "??0libpostal_address_parser_options@@QEAA@AEBU0@@Z")] | ||
//internal static extern IntPtr cctor(IntPtr instance, IntPtr _0); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
| ||
namespace LibPostalNet | ||
{ | ||
public unsafe partial class AddressParserOptions | ||
{ | ||
internal UnsafeNativeMethods _Native; | ||
|
||
internal AddressParserOptions() | ||
{ | ||
_Native = LibPostal.UnsafeNativeMethods.GetAddressParserDefaultOptions(); | ||
} | ||
|
||
public string Language | ||
{ | ||
get { return MarshalUTF8.PtrToString(_Native.language); } | ||
set { _Native.language = MarshalUTF8.StringToPtr(value); } | ||
} | ||
|
||
public string Country | ||
{ | ||
get { return MarshalUTF8.PtrToString(_Native.country); } | ||
set { _Native.country = MarshalUTF8.StringToPtr(value); } | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
using System; | ||
using System.Runtime.InteropServices; | ||
|
||
namespace LibPostalNet | ||
{ | ||
public partial class AddressParserResponse | ||
{ | ||
[StructLayout(LayoutKind.Explicit, Size = 24)] | ||
protected internal struct UnsafeNativeMethods | ||
{ | ||
[FieldOffset(0)] | ||
internal ulong num_components; | ||
|
||
[FieldOffset(8)] | ||
internal IntPtr components; | ||
|
||
[FieldOffset(16)] | ||
internal IntPtr labels; | ||
|
||
//[SuppressUnmanagedCodeSecurity] | ||
//[DllImport("libpostal", CallingConvention = CallingConvention.Cdecl, | ||
// EntryPoint = "??0libpostal_address_parser_response@@QEAA@AEBU0@@Z")] | ||
//internal static extern IntPtr cctor(IntPtr instance, IntPtr _0); | ||
} | ||
} | ||
} |
Oops, something went wrong.