Skip to content

Commit 4aa841a

Browse files
committed
Initial Version of the new Package
1 parent 44538d8 commit 4aa841a

18 files changed

+561
-290
lines changed

.github/workflows/dotnet.yml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: Build and Publish Nuget Package
2+
3+
on:
4+
push:
5+
tags:
6+
- 'v*.*.*'
7+
8+
permissions:
9+
contents: write
10+
11+
jobs:
12+
build:
13+
runs-on: ubuntu-latest
14+
15+
steps:
16+
- uses: actions/checkout@v4
17+
- name: Setup .NET
18+
uses: actions/setup-dotnet@v4
19+
with:
20+
dotnet-version: 6.0.x
21+
22+
- name: Restore dependencies
23+
run: dotnet restore
24+
25+
- name: Build
26+
run: dotnet build --no-restore --configuration Release --output ./nupkg
27+
28+
- name: Publish to NuGet.org
29+
run: dotnet nuget push --skip-duplicate ./nupkg/*.nupkg --api-key ${{ secrets.NUGET_API_KEY }} --source https://api.nuget.org/v3/index.json
30+
31+
- name: Create GitHub Release
32+
uses: softprops/action-gh-release@v2
33+
with:
34+
files: ./nupkg/*.nupkg
35+
env:
36+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

Linq2MongoDB.LINQPadDriver.sln

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.13.35919.96
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Linq2MongoDB.LINQPadDriver", "Linq2MongoDB.LINQPadDriver\Linq2MongoDB.LINQPadDriver.csproj", "{EF593AFE-60F5-4D5D-B817-5A286CF56B43}"
7+
EndProject
8+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{266EC4D5-711E-4E94-81D3-E2C0E07E147F}"
9+
ProjectSection(SolutionItems) = preProject
10+
.editorconfig = .editorconfig
11+
.gitattributes = .gitattributes
12+
.gitignore = .gitignore
13+
README.md = README.md
14+
EndProjectSection
15+
EndProject
16+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".github", ".github", "{02EA681E-C7D8-13C7-8484-4AC65E1B71E8}"
17+
EndProject
18+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "workflows", "workflows", "{55AAB2D2-D4AA-4B9F-B9B1-619C376DE0BD}"
19+
ProjectSection(SolutionItems) = preProject
20+
.github\workflows\dotnet.yml = .github\workflows\dotnet.yml
21+
EndProjectSection
22+
EndProject
23+
Global
24+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
25+
Debug|Any CPU = Debug|Any CPU
26+
Release|Any CPU = Release|Any CPU
27+
EndGlobalSection
28+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
29+
{EF593AFE-60F5-4D5D-B817-5A286CF56B43}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
30+
{EF593AFE-60F5-4D5D-B817-5A286CF56B43}.Debug|Any CPU.Build.0 = Debug|Any CPU
31+
{EF593AFE-60F5-4D5D-B817-5A286CF56B43}.Release|Any CPU.ActiveCfg = Release|Any CPU
32+
{EF593AFE-60F5-4D5D-B817-5A286CF56B43}.Release|Any CPU.Build.0 = Release|Any CPU
33+
EndGlobalSection
34+
GlobalSection(SolutionProperties) = preSolution
35+
HideSolutionNode = FALSE
36+
EndGlobalSection
37+
GlobalSection(NestedProjects) = preSolution
38+
{02EA681E-C7D8-13C7-8484-4AC65E1B71E8} = {266EC4D5-711E-4E94-81D3-E2C0E07E147F}
39+
{55AAB2D2-D4AA-4B9F-B9B1-619C376DE0BD} = {02EA681E-C7D8-13C7-8484-4AC65E1B71E8}
40+
EndGlobalSection
41+
GlobalSection(ExtensibilityGlobals) = postSolution
42+
SolutionGuid = {1EA80BCD-58BA-4B6A-A1C4-ACFACA59608D}
43+
EndGlobalSection
44+
EndGlobal
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
namespace Linq2MongoDB.LINQPadDriver
2+
{
3+
public class CollectionItem
4+
{
5+
public CollectionItem(string mongoCollectionName, string collectionPropertyName)
6+
{
7+
MongoCollectionName = mongoCollectionName;
8+
CollectionPropertyName = collectionPropertyName;
9+
}
10+
11+
public string MongoCollectionName { get; }
12+
public string CollectionPropertyName { get; }
13+
14+
public string DisplayName()
15+
{
16+
if (CollectionPropertyName == MongoCollectionName)
17+
{
18+
return CollectionPropertyName;
19+
}
20+
21+
return $"{CollectionPropertyName} ({MongoCollectionName})";
22+
}
23+
}
24+
}
5.62 KB
Loading

Mongodb.LINQPadDriver/ConnectionDialog.xaml renamed to Linq2MongoDB.LINQPadDriver/ConnectionDialog.xaml

Lines changed: 2 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,12 @@
1-
<Window x:Class="MongoDB.LINQPadDriver.ConnectionDialog"
1+
<Window x:Class="Linq2MongoDB.LINQPadDriver.ConnectionDialog"
22
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
33
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4-
Title="Universal Demo Connection"
4+
Title="MongoDB Connection"
55
Background="{x:Static SystemColors.ControlBrush}"
66
SizeToContent="Height"
77
Width="500"
88
WindowStartupLocation="CenterOwner" ShowInTaskbar="False" Topmost="True" ResizeMode="NoResize" WindowStyle="ToolWindow">
99
<StackPanel Margin="12">
10-
11-
<DockPanel>
12-
<Label DockPanel.Dock="Right" Padding="1">
13-
<Hyperlink Click="BrowseAssembly">Browse...</Hyperlink>
14-
</Label>
15-
<Label Padding="0,0,0,1">Path to typed documents assembly:</Label>
16-
</DockPanel>
17-
18-
<TextBox Name="txtAssemblyPath" Padding="2" Margin="0,1,0,9" Text="{Binding CustomTypeInfo.CustomAssemblyPath}"/>
19-
20-
<DockPanel>
21-
<!--<Label DockPanel.Dock="Right" Padding="1">
22-
<Hyperlink Click="ChooseNamespace">Choose...</Hyperlink>
23-
</Label>-->
24-
<Label Padding="0,0,0,1">Document Type Namespace:</Label>
25-
</DockPanel>
26-
27-
<TextBox Name="txtTypeName" Padding="2" Margin="0,1,0,9" ToolTip="';' separator for multiple" Text="{Binding DatabaseInfo.Server}"/>
28-
2910
<DockPanel>
3011
<Label Padding="0,0,0,1">Connection URL:</Label>
3112
</DockPanel>
@@ -38,15 +19,6 @@
3819

3920
<TextBox Name="txtDatabaseName" Padding="2" Margin="0,1,0,9" Text="{Binding DatabaseInfo.Database}"/>
4021

41-
<DockPanel>
42-
<Label DockPanel.Dock="Right" Padding="1">
43-
<Hyperlink Click="BrowseAppConfig">Browse...</Hyperlink>
44-
</Label>
45-
<Label Padding="0,0,0,1">Path to appsettings.json file (if required):</Label>
46-
</DockPanel>
47-
48-
<TextBox Name="txtAppConfigPath" Padding="2" Margin="0,1,0,9" Text="{Binding AppConfigPath}"/>
49-
5022
<Label Padding="0,0,0,2">Friendly name for this connection (optional):</Label>
5123
<TextBox Name="txtFriendlyName" Padding="2" Text="{Binding DisplayName}" />
5224

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
using System.Windows;
2+
using LINQPad.Extensibility.DataContext;
3+
4+
namespace Linq2MongoDB.LINQPadDriver
5+
{
6+
/// <summary>
7+
/// Interaction logic for ConnectionDialog.xaml
8+
/// </summary>
9+
public partial class ConnectionDialog : Window
10+
{
11+
private readonly IConnectionInfo _cxInfo;
12+
13+
public ConnectionDialog(IConnectionInfo cxInfo)
14+
{
15+
if (string.IsNullOrWhiteSpace(cxInfo.DatabaseInfo.CustomCxString))
16+
{
17+
cxInfo.DatabaseInfo.CustomCxString = "mongodb://mongo:27017";
18+
}
19+
_cxInfo = cxInfo;
20+
DataContext = cxInfo;
21+
InitializeComponent();
22+
}
23+
24+
private void btnOK_Click(object sender, RoutedEventArgs e)
25+
{
26+
if (string.IsNullOrWhiteSpace(_cxInfo.DatabaseInfo.Database))
27+
{
28+
MessageBox.Show("Database must be specified");
29+
DialogResult = null;
30+
return;
31+
}
32+
DialogResult = true;
33+
}
34+
}
35+
}
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
5+
namespace Linq2MongoDB.LINQPadDriver
6+
{
7+
public static class DataContextSourceGenerator
8+
{
9+
/// <summary>
10+
/// {0} - namespace
11+
/// {1} - class name
12+
/// {2} - collection initialization code
13+
/// {3} - collection properties
14+
/// </summary>
15+
private const string SourceCodeTemplate = @"
16+
using System;
17+
using System.Collections.Generic;
18+
using System.Linq;
19+
using MongoDB.Bson;
20+
using MongoDB.Driver;
21+
using Linq2MongoDB.LINQPadDriver;
22+
23+
namespace {0} {{
24+
public class {1} : IDisposable
25+
{{
26+
public IMongoDatabase Database => _db;
27+
private IMongoDatabase _db;
28+
29+
private Lazy<QueryableMongoCollection> InitCollection(string collectionName)
30+
=> new Lazy<QueryableMongoCollection>(()=> new QueryableMongoCollection(_db.GetCollection<BsonDocument>(collectionName)));
31+
32+
public {1}()
33+
{{
34+
{2}
35+
}}
36+
37+
internal void Initial(IMongoDatabase db)
38+
{{
39+
_db = db;
40+
}}
41+
42+
{3}
43+
44+
public void Dispose()
45+
{{
46+
if (_db != null)
47+
{{
48+
_db.Client.Cluster.Dispose();
49+
_db.Client.Dispose();
50+
_db = null;
51+
}}
52+
}}
53+
}}
54+
}}";
55+
56+
/// <summary>
57+
/// {0} - property name
58+
/// {1} - collection name
59+
/// </summary>
60+
private const string SourceCodeInitCollectionTemplate = "_{0} = InitCollection(\"{1}\");";
61+
62+
/// <summary>
63+
/// {0} - property name
64+
/// </summary>
65+
private const string SourceCodeCollectionPropertyTemplate = @"
66+
private readonly Lazy<QueryableMongoCollection> _{0};
67+
public QueryableMongoCollection {0} => _{0}.Value;";
68+
69+
private static string SanitizeName(string name)
70+
=> new string(Array.FindAll(name.ToCharArray(), c => char.IsLetterOrDigit(c) || c == '_'));
71+
72+
public static string GenerateSource(string nameSpace, string typeName, ICollection<CollectionItem> collectionNames)
73+
{
74+
var collectionInitSource = string.Join("\n", collectionNames.Select(c => string.Format(SourceCodeInitCollectionTemplate, c.CollectionPropertyName, c.MongoCollectionName)));
75+
var collectionPropertiesSource = string.Join("\n", collectionNames.Select(c => string.Format(SourceCodeCollectionPropertyTemplate, c.CollectionPropertyName)));
76+
var source = string.Format(SourceCodeTemplate, nameSpace, typeName, collectionInitSource, collectionPropertiesSource);
77+
78+
return source;
79+
}
80+
}
81+
}
5.24 KB
Loading
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
<PropertyGroup>
3+
<TargetFramework>net6.0-windows</TargetFramework>
4+
<UseWpf>true</UseWpf>
5+
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
6+
<PackageTags>linqpaddriver;linqpad;linqpad-samples;mongo;mongodb;</PackageTags>
7+
<LangVersion>8.0</LangVersion>
8+
<RootNamespace>Linq2MongoDB.LINQPadDriver</RootNamespace>
9+
<EnableWindowsTargeting>true</EnableWindowsTargeting>
10+
</PropertyGroup>
11+
<PropertyGroup>
12+
<DefineConstants>NETCORE</DefineConstants>
13+
<Authors>Sirozha1337</Authors>
14+
<PackageLicenseExpression>MIT</PackageLicenseExpression>
15+
<PackageProjectUrl>https://github.com/Sirozha1337/Linq2MongoDB.LINQPadDriver</PackageProjectUrl>
16+
<RepositoryUrl>https://github.com/Sirozha1337/Linq2MongoDB.LINQPadDriver</RepositoryUrl>
17+
<Title>MongoDB LINQPad driver</Title>
18+
<Description>MongoDB LINQPad driver that allows you to access MongoDB using Linq queries without having to provide custom assembly types</Description>
19+
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
20+
<Version>1.0.0</Version>
21+
</PropertyGroup>
22+
<ItemGroup>
23+
<PackageReference Include="LINQPad.Reference" Version="1.3.1" />
24+
<PackageReference Include="MongoDB.Driver" Version="3.2.1" />
25+
</ItemGroup>
26+
<ItemGroup>
27+
<None Update="ConnectionDialog.xaml">
28+
<Generator>MSBuild:Compile</Generator>
29+
</None>
30+
</ItemGroup>
31+
<ItemGroup>
32+
<Content Include="Connection.png">
33+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
34+
</Content>
35+
<Content Include="FailedConnection.png">
36+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
37+
</Content>
38+
<Content Include="linqpad-samples/CRUD.linq">
39+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
40+
</Content>
41+
</ItemGroup>
42+
<!-- This PostBuild action installs the Driver -->
43+
<Target Condition="'$(Configuration)' == 'Debug'" Name="PostBuild1" AfterTargets="PostBuildEvent">
44+
<Exec Command="xcopy /i/y/s &quot;$(TargetDir)*.*&quot; &quot;%25LocalAppData%25\\LINQPad\\Drivers\\DataContext\\NetCore\\$(TargetName)&quot;" />
45+
</Target>
46+
</Project>

0 commit comments

Comments
 (0)