Skip to content

Commit dc1c8aa

Browse files
committed
- initial release
1 parent be45843 commit dc1c8aa

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+2770
-0
lines changed

.gitignore

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
DynamicLinqPadPostgreSqlDriver/obj/
2+
packages/
3+
DynamicLinqPadPostgreSqlDriver/bin/
4+
DynamicLinqPadPostgreSqlDriver.UI/obj/
5+
DynamicLinqPadPostgreSqlDriver.UI/bin/
6+
DynamicLinqPadPostgreSqlDriver.Shared/obj/
7+
DynamicLinqPadPostgreSqlDriver.Shared/bin/
8+
DynamicLinqPadPostgreSqlDriver.Tests/obj/
9+
DynamicLinqPadPostgreSqlDriver.Tests/bin/
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
namespace DynamicLinqPadPostgreSqlDriver.Shared
2+
{
3+
public enum DriverOption
4+
{
5+
PluralizeSetAndTableProperties,
6+
SingularizeEntityNames,
7+
CapitalizePropertiesTablesAndColumns,
8+
UseExperimentalTypes
9+
}
10+
}
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
4+
<PropertyGroup>
5+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
6+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
7+
<ProjectGuid>{8D343A09-D0DF-4C9E-B8FD-BDEB70CF7097}</ProjectGuid>
8+
<OutputType>Library</OutputType>
9+
<AppDesignerFolder>Properties</AppDesignerFolder>
10+
<RootNamespace>DynamicLinqPadPostgreSqlDriver.Shared</RootNamespace>
11+
<AssemblyName>DynamicLinqPadPostgreSqlDriver.Shared</AssemblyName>
12+
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
13+
<FileAlignment>512</FileAlignment>
14+
</PropertyGroup>
15+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
16+
<DebugSymbols>true</DebugSymbols>
17+
<DebugType>full</DebugType>
18+
<Optimize>false</Optimize>
19+
<OutputPath>bin\Debug\</OutputPath>
20+
<DefineConstants>DEBUG;TRACE</DefineConstants>
21+
<ErrorReport>prompt</ErrorReport>
22+
<WarningLevel>4</WarningLevel>
23+
</PropertyGroup>
24+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
25+
<DebugType>pdbonly</DebugType>
26+
<Optimize>true</Optimize>
27+
<OutputPath>bin\Release\</OutputPath>
28+
<DefineConstants>TRACE</DefineConstants>
29+
<ErrorReport>prompt</ErrorReport>
30+
<WarningLevel>4</WarningLevel>
31+
</PropertyGroup>
32+
<PropertyGroup>
33+
<SignAssembly>true</SignAssembly>
34+
</PropertyGroup>
35+
<PropertyGroup>
36+
<AssemblyOriginatorKeyFile>StrongName.snk</AssemblyOriginatorKeyFile>
37+
</PropertyGroup>
38+
<ItemGroup>
39+
<Reference Include="linq2db, Version=1.0.7.3, Culture=neutral, PublicKeyToken=f19f8aed7feff67e, processorArchitecture=MSIL">
40+
<HintPath>..\packages\linq2db.1.0.7.3\lib\net45\linq2db.dll</HintPath>
41+
<Private>True</Private>
42+
</Reference>
43+
<Reference Include="LINQPad">
44+
<HintPath>..\..\..\Program Files (x86)\LINQPad5\LINQPad.exe</HintPath>
45+
</Reference>
46+
<Reference Include="Npgsql, Version=3.0.4.0, Culture=neutral, PublicKeyToken=5d8b90d52f46fda7, processorArchitecture=MSIL">
47+
<HintPath>..\packages\Npgsql.3.0.4\lib\net45\Npgsql.dll</HintPath>
48+
<Private>True</Private>
49+
</Reference>
50+
<Reference Include="System" />
51+
<Reference Include="System.Core" />
52+
<Reference Include="System.Xml.Linq" />
53+
<Reference Include="System.Data.DataSetExtensions" />
54+
<Reference Include="Microsoft.CSharp" />
55+
<Reference Include="System.Data" />
56+
<Reference Include="System.Net.Http" />
57+
<Reference Include="System.Xml" />
58+
</ItemGroup>
59+
<ItemGroup>
60+
<Compile Include="DriverOption.cs" />
61+
<Compile Include="Extensions\ConnectionInfoExtensions.cs" />
62+
<Compile Include="Extensions\XElementExtensions.cs" />
63+
<Compile Include="Helpers\ConnectionHelper.cs" />
64+
<Compile Include="Properties\AssemblyInfo.cs" />
65+
</ItemGroup>
66+
<ItemGroup>
67+
<None Include="packages.config" />
68+
<None Include="StrongName.snk" />
69+
</ItemGroup>
70+
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
71+
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
72+
Other similar extension points exist, see Microsoft.Common.targets.
73+
<Target Name="BeforeBuild">
74+
</Target>
75+
<Target Name="AfterBuild">
76+
</Target>
77+
-->
78+
</Project>
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
using LINQPad.Extensibility.DataContext;
2+
using System;
3+
using System.Text;
4+
5+
namespace DynamicLinqPadPostgreSqlDriver.Shared.Extensions
6+
{
7+
public static class ConnectionInfoExtensions
8+
{
9+
public static string GetPostgreSqlConnectionString(this IConnectionInfo cxInfo)
10+
{
11+
if (cxInfo == null)
12+
throw new ArgumentNullException(nameof(cxInfo));
13+
14+
if (!string.IsNullOrWhiteSpace(cxInfo.DatabaseInfo.CustomCxString))
15+
return cxInfo.DatabaseInfo.CustomCxString;
16+
17+
return BuildConnectionString(cxInfo.DatabaseInfo.Server, cxInfo.DatabaseInfo.Database, cxInfo.DatabaseInfo.UserName, cxInfo.DatabaseInfo.Password);
18+
}
19+
20+
internal static string BuildConnectionString(string serverWithPort, string database, string userName, string password)
21+
{
22+
if (string.IsNullOrWhiteSpace(serverWithPort))
23+
throw new ArgumentException("The argument may not be null or empty.", nameof(serverWithPort));
24+
25+
if (string.IsNullOrWhiteSpace(database))
26+
throw new ArgumentException("The argument may not be null or empty.", nameof(database));
27+
28+
var server = "";
29+
var port = "";
30+
31+
if (serverWithPort.Contains(":"))
32+
{
33+
var parts = serverWithPort.Split(':');
34+
server = parts[0];
35+
port = parts[1];
36+
}
37+
else
38+
{
39+
server = serverWithPort;
40+
}
41+
42+
var sb = new StringBuilder();
43+
44+
sb.AppendFormat("Server={0};", server);
45+
46+
if (!string.IsNullOrWhiteSpace(port))
47+
{
48+
sb.AppendFormat("Port={0};", port);
49+
}
50+
51+
sb.AppendFormat("Database={0};", database);
52+
53+
if (!string.IsNullOrWhiteSpace(userName) && !string.IsNullOrWhiteSpace(password))
54+
{
55+
sb.AppendFormat("User Id={0};", userName);
56+
sb.AppendFormat("Password={0};", password);
57+
}
58+
else
59+
{
60+
sb.Append("Integrated Security=true;");
61+
}
62+
63+
return sb.ToString();
64+
}
65+
}
66+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
using System;
2+
using System.Linq;
3+
using System.Xml.Linq;
4+
5+
namespace DynamicLinqPadPostgreSqlDriver.Shared.Extensions
6+
{
7+
public static class XElementExtensions
8+
{
9+
public static T GetDescendantValue<T>(this XElement parent, DriverOption driverOption, Func<string, T> converter)
10+
{
11+
return parent.GetDescendantValue(driverOption.ToString(), converter, default(T));
12+
}
13+
14+
public static T GetDescendantValue<T>(this XElement parent, string name, Func<string, T> converter)
15+
{
16+
return parent.GetDescendantValue(name, converter, default(T));
17+
}
18+
19+
public static T GetDescendantValue<T>(this XElement parent, DriverOption driverOption, Func<string, T> converter, T defaultValue)
20+
{
21+
return parent.GetDescendantValue(driverOption.ToString(), converter, defaultValue);
22+
}
23+
24+
public static T GetDescendantValue<T>(this XElement parent, string name, Func<string, T> converter, T defaultValue)
25+
{
26+
if (name == null)
27+
throw new ArgumentNullException(nameof(name));
28+
29+
if (converter == null)
30+
throw new ArgumentNullException(nameof(converter));
31+
32+
if (parent == null)
33+
return defaultValue;
34+
35+
var element = parent.Descendants(name).FirstOrDefault();
36+
if (element == null)
37+
return defaultValue;
38+
39+
try
40+
{
41+
return converter(element.Value);
42+
}
43+
catch { }
44+
45+
return defaultValue;
46+
}
47+
}
48+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
using DynamicLinqPadPostgreSqlDriver.Shared.Extensions;
2+
using Npgsql;
3+
using System;
4+
using System.Data;
5+
using System.Threading.Tasks;
6+
7+
namespace DynamicLinqPadPostgreSqlDriver.Shared.Helpers
8+
{
9+
public class ConnectionHelper
10+
{
11+
public static async Task<bool> CheckConnection(string connectionString)
12+
{
13+
if (string.IsNullOrWhiteSpace(connectionString))
14+
throw new ArgumentException("The argument may not be null or empty", nameof(connectionString));
15+
16+
using (var connection = new NpgsqlConnection(connectionString))
17+
{
18+
await connection.OpenAsync();
19+
return connection.State == ConnectionState.Open;
20+
}
21+
}
22+
23+
public static async Task<bool> CheckConnection(string server, string database, string userName, string password)
24+
{
25+
return await CheckConnection(ConnectionInfoExtensions.BuildConnectionString(server, database, userName, password));
26+
}
27+
}
28+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
using System.Reflection;
2+
using System.Runtime.InteropServices;
3+
4+
[assembly: AssemblyTitle("DynamicLinqPadPostgreSqlDriver.Shared")]
5+
[assembly: AssemblyDescription("Shared part of the LINQPad PostgreSQL Driver")]
6+
[assembly: AssemblyProduct("DynamicLinqPadPostgreSqlDriver.Shared")]
7+
[assembly: AssemblyCopyright("Copyright © 2015 Frederik Knust")]
8+
[assembly: AssemblyCulture("")]
9+
10+
[assembly: ComVisible(false)]
11+
[assembly: Guid("8d343a09-d0df-4c9e-b8fd-bdeb70cf7097")]
12+
13+
[assembly: AssemblyVersion("0.1.0.0")]
14+
[assembly: AssemblyFileVersion("0.1.0.0")]
Binary file not shown.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<packages>
3+
<package id="linq2db" version="1.0.7.3" targetFramework="net452" />
4+
<package id="linq2db.PostgreSQL" version="1.0.7.3" targetFramework="net452" />
5+
<package id="linq2db.t4models" version="1.0.7.3" targetFramework="net452" />
6+
<package id="Npgsql" version="3.0.4" targetFramework="net452" />
7+
</packages>
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<Import Project="..\packages\xunit.runner.visualstudio.2.1.0\build\net20\xunit.runner.visualstudio.props" Condition="Exists('..\packages\xunit.runner.visualstudio.2.1.0\build\net20\xunit.runner.visualstudio.props')" />
4+
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
5+
<PropertyGroup>
6+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
7+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
8+
<ProjectGuid>{E04B12BF-0D89-40DB-8A9C-B5FA095A3F39}</ProjectGuid>
9+
<OutputType>Library</OutputType>
10+
<AppDesignerFolder>Properties</AppDesignerFolder>
11+
<RootNamespace>DynamicLinqPadPostgreSqlDriver.Tests</RootNamespace>
12+
<AssemblyName>DynamicLinqPadPostgreSqlDriver.Tests</AssemblyName>
13+
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
14+
<FileAlignment>512</FileAlignment>
15+
<NuGetPackageImportStamp>
16+
</NuGetPackageImportStamp>
17+
</PropertyGroup>
18+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
19+
<DebugSymbols>true</DebugSymbols>
20+
<DebugType>full</DebugType>
21+
<Optimize>false</Optimize>
22+
<OutputPath>bin\Debug\</OutputPath>
23+
<DefineConstants>DEBUG;TRACE</DefineConstants>
24+
<ErrorReport>prompt</ErrorReport>
25+
<WarningLevel>4</WarningLevel>
26+
</PropertyGroup>
27+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
28+
<DebugType>pdbonly</DebugType>
29+
<Optimize>true</Optimize>
30+
<OutputPath>bin\Release\</OutputPath>
31+
<DefineConstants>TRACE</DefineConstants>
32+
<ErrorReport>prompt</ErrorReport>
33+
<WarningLevel>4</WarningLevel>
34+
</PropertyGroup>
35+
<ItemGroup>
36+
<Reference Include="Dapper, Version=1.40.0.0, Culture=neutral, PublicKeyToken=e3e8412083d25dd3, processorArchitecture=MSIL">
37+
<HintPath>..\packages\Dapper.StrongName.1.40\lib\net45\Dapper.dll</HintPath>
38+
<Private>True</Private>
39+
</Reference>
40+
<Reference Include="linq2db, Version=1.0.7.3, Culture=neutral, PublicKeyToken=f19f8aed7feff67e, processorArchitecture=MSIL">
41+
<HintPath>..\packages\linq2db.1.0.7.3\lib\net45\linq2db.dll</HintPath>
42+
<Private>True</Private>
43+
</Reference>
44+
<Reference Include="Npgsql, Version=3.0.4.0, Culture=neutral, PublicKeyToken=5d8b90d52f46fda7, processorArchitecture=MSIL">
45+
<HintPath>..\packages\Npgsql.3.0.4\lib\net45\Npgsql.dll</HintPath>
46+
<Private>True</Private>
47+
</Reference>
48+
<Reference Include="System" />
49+
<Reference Include="System.Core" />
50+
<Reference Include="System.Xml.Linq" />
51+
<Reference Include="System.Data.DataSetExtensions" />
52+
<Reference Include="Microsoft.CSharp" />
53+
<Reference Include="System.Data" />
54+
<Reference Include="System.Net.Http" />
55+
<Reference Include="System.Xml" />
56+
<Reference Include="xunit.abstractions, Version=2.0.0.0, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c, processorArchitecture=MSIL">
57+
<HintPath>..\packages\xunit.abstractions.2.0.0\lib\net35\xunit.abstractions.dll</HintPath>
58+
<Private>True</Private>
59+
</Reference>
60+
<Reference Include="xunit.assert, Version=2.1.0.3179, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c, processorArchitecture=MSIL">
61+
<HintPath>..\packages\xunit.assert.2.1.0\lib\dotnet\xunit.assert.dll</HintPath>
62+
<Private>True</Private>
63+
</Reference>
64+
<Reference Include="xunit.core, Version=2.1.0.3179, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c, processorArchitecture=MSIL">
65+
<HintPath>..\packages\xunit.extensibility.core.2.1.0\lib\dotnet\xunit.core.dll</HintPath>
66+
<Private>True</Private>
67+
</Reference>
68+
<Reference Include="xunit.execution.desktop, Version=2.1.0.3179, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c, processorArchitecture=MSIL">
69+
<HintPath>..\packages\xunit.extensibility.execution.2.1.0\lib\net45\xunit.execution.desktop.dll</HintPath>
70+
<Private>True</Private>
71+
</Reference>
72+
</ItemGroup>
73+
<ItemGroup>
74+
<Compile Include="TestAdvancedTypeMappings.cs" />
75+
<Compile Include="TestBase.cs" />
76+
<Compile Include="TestBasicTypeMappings.cs" />
77+
<Compile Include="Properties\AssemblyInfo.cs" />
78+
</ItemGroup>
79+
<ItemGroup>
80+
<None Include="packages.config" />
81+
</ItemGroup>
82+
<ItemGroup>
83+
<ProjectReference Include="..\DynamicLinqPadPostgreSqlDriver.Shared\DynamicLinqPadPostgreSqlDriver.Shared.csproj">
84+
<Project>{8d343a09-d0df-4c9e-b8fd-bdeb70cf7097}</Project>
85+
<Name>DynamicLinqPadPostgreSqlDriver.Shared</Name>
86+
</ProjectReference>
87+
<ProjectReference Include="..\DynamicLinqPadPostgreSqlDriver\DynamicLinqPadPostgreSqlDriver.csproj">
88+
<Project>{824f300b-f0f9-4994-9097-b1b2270be12f}</Project>
89+
<Name>DynamicLinqPadPostgreSqlDriver</Name>
90+
</ProjectReference>
91+
</ItemGroup>
92+
<ItemGroup>
93+
<Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
94+
</ItemGroup>
95+
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
96+
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
97+
<PropertyGroup>
98+
<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>
99+
</PropertyGroup>
100+
<Error Condition="!Exists('..\packages\xunit.runner.visualstudio.2.1.0\build\net20\xunit.runner.visualstudio.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\xunit.runner.visualstudio.2.1.0\build\net20\xunit.runner.visualstudio.props'))" />
101+
</Target>
102+
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
103+
Other similar extension points exist, see Microsoft.Common.targets.
104+
<Target Name="BeforeBuild">
105+
</Target>
106+
<Target Name="AfterBuild">
107+
</Target>
108+
-->
109+
</Project>

0 commit comments

Comments
 (0)