MongoDbRepository rewrite

This commit is contained in:
alexandre-spieser
2017-08-27 01:54:45 +00:00
parent 6deb1c5ea9
commit ca3c208cca
122 changed files with 124390 additions and 35176 deletions
Binary file not shown.
+1 -1
View File
@@ -163,7 +163,7 @@
</site>
<site name="MongoDbGenericRepository" id="2">
<application path="/" applicationPool="Clr4IntegratedAppPool">
<virtualDirectory path="/" physicalPath="c:\users\alex\documents\visual studio 2015\Projects\MongoDbGenericRepository\MongoDbGenericRepository" />
<virtualDirectory path="/" physicalPath="C:\dev\MongoDbRepoUpdate\MongoDbGenericRepository" />
</application>
<bindings>
<binding protocol="http" bindingInformation="*:52313:localhost" />
+18
View File
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
For more information on how to configure your ASP.NET application, please visit
http://go.microsoft.com/fwlink/?LinkId=169433
-->
<configuration>
<connectionStrings>
<add name="MongoDbTests" connectionString="mongodb://localhost:27017" />
</connectionStrings>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Runtime.InteropServices.RuntimeInformation" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.1.0" newVersion="4.0.1.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
+88
View File
@@ -0,0 +1,88 @@
using MongoDbGenericRepository;
using MongoDbGenericRepository.Models;
using NUnit.Framework;
using System.Collections.Generic;
using System.Configuration;
namespace IntegrationTests
{
public class InsertTestsRepository : BaseMongoRepository
{
/// <inheritdoc />
public InsertTestsRepository(string connectionString, string databaseName) : base(connectionString, databaseName)
{
}
public void DropTestCollection<TDocument>()
{
_mongoDbContext
}
}
public class InsertTests
{
private class InsertTestsDocument : Document
{
public InsertTestsDocument()
{
Version = 2;
}
public string SomeContent { get; set; }
}
private void Cleanup(InsertTestsDocument document)
{
SUT.DeleteOne(document);
Assert.AreEqual(0, SUT.Count<InsertTestsDocument>(e => e.Id == document.Id));
}
private void Cleanup(List<InsertTestsDocument> documents)
{
SUT.DeleteMany(documents);
SUT.Count<InsertTestsDocument>(e => e.Id == documents[0].Id || e.Id == documents[1].Id);
}
/// <summary>
/// SUT: System Under Test
/// </summary>
private static InsertTestsRepository SUT { get; set; }
[OneTimeSetUp]
public void Init()
{
var connectionString = ConfigurationManager.ConnectionStrings["MongoDbTests"].ConnectionString;
SUT = new InsertTestsRepository(connectionString, "MongoDbTests");
}
[Test]
public void InsertOne()
{
// Arrange
var document = new InsertTestsDocument();
// Act
SUT.AddOne(document);
// Assert
long count = SUT.Count<InsertTestsDocument>(e => e.Id == document.Id);
Assert.AreEqual(1, count);
// Cleanup
Cleanup(document);
}
[Test]
public void InsertMany()
{
// Arrange
var documents = new List<InsertTestsDocument> { new InsertTestsDocument(), new InsertTestsDocument() };
// Act
SUT.AddMany(documents);
// Assert
long count = SUT.Count<InsertTestsDocument>(e => e.Id == documents[0].Id || e.Id == documents[1].Id);
Assert.AreEqual(2, count);
// Cleanup
Cleanup(documents);
}
}
}
+78
View File
@@ -0,0 +1,78 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" 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>{A484A355-A015-40CC-9B35-A4E872421128}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>IntegrationTests</RootNamespace>
<AssemblyName>IntegrationTests</AssemblyName>
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<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' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="MongoDB.Bson, Version=2.4.4.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\MongoDB.Bson.2.4.4\lib\net45\MongoDB.Bson.dll</HintPath>
</Reference>
<Reference Include="MongoDB.Driver, Version=2.4.4.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\MongoDB.Driver.2.4.4\lib\net45\MongoDB.Driver.dll</HintPath>
</Reference>
<Reference Include="MongoDB.Driver.Core, Version=2.4.4.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\MongoDB.Driver.Core.2.4.4\lib\net45\MongoDB.Driver.Core.dll</HintPath>
</Reference>
<Reference Include="nunit.framework, Version=3.7.1.0, Culture=neutral, PublicKeyToken=2638cd05610744eb, processorArchitecture=MSIL">
<HintPath>..\packages\NUnit.3.7.1\lib\net45\nunit.framework.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Configuration" />
<Reference Include="System.Core" />
<Reference Include="System.Runtime.InteropServices.RuntimeInformation, Version=4.0.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\System.Runtime.InteropServices.RuntimeInformation.4.3.0\lib\net45\System.Runtime.InteropServices.RuntimeInformation.dll</HintPath>
</Reference>
<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="InsertTests.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config">
<SubType>Designer</SubType>
</None>
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\MongoDbGenericRepository\MongoDbGenericRepository.csproj">
<Project>{d154e7d0-9a3c-43ab-8e90-ed92bc4343f0}</Project>
<Name>MongoDbGenericRepository</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
@@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// Les informations générales relatives à un assembly dépendent de
// l'ensemble d'attributs suivant. Changez les valeurs de ces attributs pour modifier les informations
// associées à un assembly.
[assembly: AssemblyTitle("IntegrationTests")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("IntegrationTests")]
[assembly: AssemblyCopyright("Copyright © 2017")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// L'affectation de la valeur false à ComVisible rend les types invisibles dans cet assembly
// aux composants COM. Si vous devez accéder à un type dans cet assembly à partir de
// COM, affectez la valeur true à l'attribut ComVisible sur ce type.
[assembly: ComVisible(false)]
// Le GUID suivant est pour l'ID de la typelib si ce projet est exposé à COM
[assembly: Guid("a484a355-a015-40cc-9b35-a4e872421128")]
// Les informations de version pour un assembly se composent des quatre valeurs suivantes :
//
// Version principale
// Version secondaire
// Numéro de build
// Révision
//
// Vous pouvez spécifier toutes les valeurs ou indiquer les numéros de build et de révision par défaut
// en utilisant '*', comme indiqué ci-dessous :
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
@@ -0,0 +1,3 @@
<?xml version="1.0" encoding="utf-8"?>
<ApplicationInsights xmlns="http://schemas.microsoft.com/ApplicationInsights/2013/Settings">
</ApplicationInsights>
Binary file not shown.
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
For more information on how to configure your ASP.NET application, please visit
http://go.microsoft.com/fwlink/?LinkId=169433
-->
<configuration>
<connectionStrings>
<add name="MongoDbTests" connectionString="mongodb://localhost:27017" />
</connectionStrings>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Runtime.InteropServices.RuntimeInformation" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.1.0" newVersion="4.0.1.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
Binary file not shown.
Binary file not shown.
File diff suppressed because it is too large Load Diff
Binary file not shown.
File diff suppressed because it is too large Load Diff
Binary file not shown.
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,32 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
For more information on how to configure your ASP.NET application, please visit
http://go.microsoft.com/fwlink/?LinkId=169433
-->
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.5.2" />
<httpRuntime targetFramework="4.5.2" />
<httpModules>
</httpModules>
</system.web>
<system.webServer>
<validation validateIntegratedModeConfiguration="false" />
<modules>
</modules>
</system.webServer>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Runtime.InteropServices.RuntimeInformation" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.1.0" newVersion="4.0.1.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
<system.codedom>
<compilers>
<compiler language="c#;cs;csharp" extension=".cs" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.7.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:6 /nowarn:1659;1699;1701" />
<compiler language="vb;vbs;visualbasic;vbscript" extension=".vb" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.VBCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.7.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:14 /nowarn:41008 /define:_MYTYPE=\&quot;Web\&quot; /optionInfer+" />
</compilers>
</system.codedom>
</configuration>
Binary file not shown.
File diff suppressed because it is too large Load Diff
@@ -0,0 +1 @@
869251795
@@ -0,0 +1 @@
9328cb4857410d6812be797e81f196e19a673b92
@@ -0,0 +1,19 @@
C:\dev\MongoDbRepoUpdate\IntegrationTests\bin\Debug\ApplicationInsights.config
C:\dev\MongoDbRepoUpdate\IntegrationTests\bin\Debug\IntegrationTests.dll.config
C:\dev\MongoDbRepoUpdate\IntegrationTests\bin\Debug\IntegrationTests.dll
C:\dev\MongoDbRepoUpdate\IntegrationTests\bin\Debug\IntegrationTests.pdb
C:\dev\MongoDbRepoUpdate\IntegrationTests\bin\Debug\MongoDbGenericRepository.dll
C:\dev\MongoDbRepoUpdate\IntegrationTests\bin\Debug\nunit.framework.dll
C:\dev\MongoDbRepoUpdate\IntegrationTests\bin\Debug\MongoDB.Driver.dll
C:\dev\MongoDbRepoUpdate\IntegrationTests\bin\Debug\MongoDB.Bson.dll
C:\dev\MongoDbRepoUpdate\IntegrationTests\bin\Debug\MongoDB.Driver.Core.dll
C:\dev\MongoDbRepoUpdate\IntegrationTests\bin\Debug\MongoDbGenericRepository.pdb
C:\dev\MongoDbRepoUpdate\IntegrationTests\bin\Debug\MongoDbGenericRepository.dll.config
C:\dev\MongoDbRepoUpdate\IntegrationTests\bin\Debug\nunit.framework.xml
C:\dev\MongoDbRepoUpdate\IntegrationTests\bin\Debug\MongoDB.Driver.xml
C:\dev\MongoDbRepoUpdate\IntegrationTests\bin\Debug\MongoDB.Bson.xml
C:\dev\MongoDbRepoUpdate\IntegrationTests\obj\Debug\IntegrationTests.csprojResolveAssemblyReference.cache
C:\dev\MongoDbRepoUpdate\IntegrationTests\obj\Debug\IntegrationTests.dll
C:\dev\MongoDbRepoUpdate\IntegrationTests\obj\Debug\IntegrationTests.pdb
C:\dev\MongoDbRepoUpdate\IntegrationTests\bin\Debug\System.Runtime.InteropServices.RuntimeInformation.dll
C:\dev\MongoDbRepoUpdate\IntegrationTests\bin\Debug\MongoDB.Driver.Core.xml
Binary file not shown.
Binary file not shown.
+9
View File
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="MongoDB.Bson" version="2.4.4" targetFramework="net461" />
<package id="MongoDB.Driver" version="2.4.4" targetFramework="net461" />
<package id="MongoDB.Driver.Core" version="2.4.4" targetFramework="net461" />
<package id="NUnit" version="3.7.1" targetFramework="net461" />
<package id="NUnit.ConsoleRunner" version="3.7.0" targetFramework="net461" />
<package id="System.Runtime.InteropServices.RuntimeInformation" version="4.3.0" targetFramework="net461" />
</packages>
+8 -2
View File
@@ -1,10 +1,12 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 14
VisualStudioVersion = 14.0.24720.0
# Visual Studio 15
VisualStudioVersion = 15.0.26430.16
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MongoDbGenericRepository", "MongoDbGenericRepository\MongoDbGenericRepository.csproj", "{D154E7D0-9A3C-43AB-8E90-ED92BC4343F0}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "IntegrationTests", "IntegrationTests\IntegrationTests.csproj", "{A484A355-A015-40CC-9B35-A4E872421128}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@@ -15,6 +17,10 @@ Global
{D154E7D0-9A3C-43AB-8E90-ED92BC4343F0}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D154E7D0-9A3C-43AB-8E90-ED92BC4343F0}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D154E7D0-9A3C-43AB-8E90-ED92BC4343F0}.Release|Any CPU.Build.0 = Release|Any CPU
{A484A355-A015-40CC-9B35-A4E872421128}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A484A355-A015-40CC-9B35-A4E872421128}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A484A355-A015-40CC-9B35-A4E872421128}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A484A355-A015-40CC-9B35-A4E872421128}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@@ -0,0 +1,5 @@
<SolutionConfiguration>
<Settings>
<CurrentEngineMode>Run all tests automatically [Global]</CurrentEngineMode>
</Settings>
</SolutionConfiguration>
@@ -0,0 +1,28 @@
using MongoDB.Driver;
using MongoDbGenericRepository.Models;
namespace MongoDbGenericRepository
{
public interface IMongoDbContext
{
/// <summary>
/// The private GetCollection method
/// </summary>
/// <typeparam name="TDocument"></typeparam>
/// <returns></returns>
IMongoCollection<TDocument> GetCollection<TDocument>();
/// <summary>
/// The private GetCollection method
/// </summary>
/// <typeparam name="TDocument"></typeparam>
/// <returns></returns>
IMongoCollection<TDocument> GetCollection<TDocument>(TDocument document) where TDocument : IDocument;
/// <summary>
/// Drops a collection, use very carefully.
/// </summary>
/// <typeparam name="TDocument"></typeparam>
void DropCollection<TDocument>();
}
}
@@ -1,157 +0,0 @@
using MongoDB.Driver;
using MongoDbGenericRepository.ViewModels;
using System.Collections.Generic;
using System.Threading.Tasks;
namespace MongoDbGenericRepository
{
public interface IMongoDbRepository
{
/// <summary>
/// A generic GetOne method
/// </summary>
/// <typeparam name="TEntity"></typeparam>
/// <param name="id"></param>
/// <returns></returns>
Task<GetOneResult<TEntity>> GetOne<TEntity>(string id) where TEntity : class, new();
/// <summary>
/// A generic GetOne method
/// </summary>
/// <typeparam name="TEntity"></typeparam>
/// <param name="id"></param>
/// <returns></returns>
Task<GetOneResult<TEntity>> GetOne<TEntity>(FilterDefinition<TEntity> filter) where TEntity : class, new();
/// <summary>
/// A generic get many method
/// </summary>
/// <typeparam name="TEntity"></typeparam>
/// <param name="ids"></param>
/// <returns></returns>
Task<GetManyResult<TEntity>> GetMany<TEntity>(IEnumerable<string> ids) where TEntity : class, new();
/// <summary>
/// A generic get many method with filter
/// </summary>
/// <typeparam name="TEntity"></typeparam>
/// <param name="ids"></param>
/// <returns></returns>
Task<GetManyResult<TEntity>> GetMany<TEntity>(FilterDefinition<TEntity> filter) where TEntity : class, new();
/// <summary>
/// GetMany with filter and projection
/// </summary>
/// <typeparam name="TEntity"></typeparam>
/// <param name="filter"></param>
/// <returns>A cursor for the query</returns>
IFindFluent<TEntity, TEntity> FindCursor<TEntity>(FilterDefinition<TEntity> filter) where TEntity : class, new();
/// <summary>
/// A generic get all method
/// </summary>
/// <typeparam name="TEntity"></typeparam>
/// <returns></returns>
Task<GetManyResult<TEntity>> GetAll<TEntity>() where TEntity : class, new();
/// <summary>
/// A generic Exists method
/// </summary>
/// <typeparam name="TEntity"></typeparam>
/// <param name="key"></param>
/// <returns></returns>
Task<bool> Exists<TEntity>(string id) where TEntity : class, new();
/// <summary>
/// A generic count method
/// </summary>
/// <typeparam name="TEntity"></typeparam>
/// <param name="id"></param>
/// <returns></returns>
Task<long> Count<TEntity>(string id) where TEntity : class, new();
/// <summary>
/// A generic count method
/// </summary>
/// <typeparam name="TEntity"></typeparam>
/// <param name="id"></param>
/// <returns></returns>
Task<long> Count<TEntity>(FilterDefinition<TEntity> filter) where TEntity : class, new();
/// <summary>
/// A generic Add One method
/// </summary>
/// <typeparam name="TEntity"></typeparam>
/// <param name="item"></param>
/// <returns></returns>
Task<Result> AddOne<TEntity>(TEntity item) where TEntity : class, new();
/// <summary>
/// A generic delete one method
/// </summary>
/// <typeparam name="TEntity"></typeparam>
/// <param name="id"></param>
/// <returns></returns>
Task<Result> DeleteOne<TEntity>(string id) where TEntity : class, new();
/// <summary>
/// A generic delete many method
/// </summary>
/// <typeparam name="TEntity"></typeparam>
/// <param name="ids"></param>
/// <returns></returns>
Task<Result> DeleteMany<TEntity>(IEnumerable<string> ids) where TEntity : class, new();
#region Update
/// <summary>
/// UpdateOne by id
/// </summary>
/// <typeparam name="TEntity"></typeparam>
/// <param name="id"></param>
/// <param name="update"></param>
/// <returns></returns>
Task<Result> UpdateOne<TEntity>(string id, UpdateDefinition<TEntity> update) where TEntity : class, new();
/// <summary>
/// UpdateOne with filter
/// </summary>
/// <typeparam name="TEntity"></typeparam>
/// <param name="filter"></param>
/// <param name="update"></param>
/// <returns></returns>
Task<Result> UpdateOne<TEntity>(FilterDefinition<TEntity> filter, UpdateDefinition<TEntity> update) where TEntity : class, new();
/// <summary>
/// UpdateMany with Ids
/// </summary>
/// <typeparam name="TEntity"></typeparam>
/// <param name="id"></param>
/// <param name="update"></param>
/// <returns></returns>
Task<Result> UpdateMany<TEntity>(IEnumerable<string> ids, UpdateDefinition<TEntity> update) where TEntity : class, new();
/// <summary>
/// UpdateMany with filter
/// </summary>
/// <typeparam name="TEntity"></typeparam>
/// <param name="filter"></param>
/// <param name="update"></param>
/// <returns></returns>
Task<Result> UpdateMany<TEntity>(FilterDefinition<TEntity> filter, UpdateDefinition<TEntity> update) where TEntity : class, new();
#endregion Update
#region Find And Update
/// <summary>
/// GetAndUpdateOne with filter
/// </summary>
/// <typeparam name="TEntity"></typeparam>
/// <param name="filter"></param>
/// <param name="update"></param>
/// <param name="options"></param>
/// <returns></returns>
Task<GetOneResult<TEntity>> GetAndUpdateOne<TEntity>(FilterDefinition<TEntity> filter, UpdateDefinition<TEntity> update, FindOneAndUpdateOptions<TEntity, TEntity> options) where TEntity : class, new();
#endregion Find And Update
}
}
@@ -0,0 +1,43 @@
using MongoDB.Bson.Serialization.Attributes;
using System;
namespace MongoDbGenericRepository.Models
{
/// <summary>
/// This class represents a basic document that can be stored in MongoDb
/// </summary>
public class Document : IDocument
{
/// <summary>
/// The document constructor
/// </summary>
public Document()
{
Id = Guid.NewGuid();
AddedAtUtc = DateTime.UtcNow;
}
/// <summary>
/// The Id of the document
/// </summary>
[BsonId]
public Guid Id { get; set; }
/// <summary>
/// The name of the property used for partitioning the collection
/// This will not be inserted into the collection.
/// This partition key will be prepended to the collection name to create a new collection.
/// </summary>
public string PartitionKey { get; set; }
/// <summary>
/// The datetime in UTC at which the document was added.
/// </summary>
public DateTime AddedAtUtc { get; set; }
/// <summary>
/// The version of the schema of the document
/// </summary>
public int Version { get; set; }
}
}
@@ -0,0 +1,12 @@
using System;
namespace MongoDbGenericRepository.Models
{
public interface IDocument
{
DateTime AddedAtUtc { get; set; }
Guid Id { get; set; }
string PartitionKey { get; set; }
int Version { get; set; }
}
}
+49 -13
View File
@@ -1,30 +1,66 @@
using MongoDB.Driver;
using System.Configuration;
using MongoDbGenericRepository.Models;
namespace MongoDbGenericRepository
{
public class MongoDbContext
/// <summary>
/// The MongoDb context
/// </summary>
public class MongoDbContext : IMongoDbContext
{
public const string CONNECTION_STRING_NAME = "MongoDbTest";
public const string DATABASE_NAME = "MongoDbTest";
private static readonly IMongoClient _client;
private static readonly IMongoDatabase _database;
static MongoDbContext()
{
var connectionString = ConfigurationManager.ConnectionStrings[CONNECTION_STRING_NAME].ConnectionString;
// Avoid legacy UUID representation: use Binary 0x04 subtype.
MongoDefaults.GuidRepresentation = MongoDB.Bson.GuidRepresentation.Standard;
}
public MongoDbContext(string connectionString, string databaseName)
{
_client = new MongoClient(connectionString);
_database = _client.GetDatabase(DATABASE_NAME);
_database = _client.GetDatabase(databaseName);
}
private readonly IMongoClient _client;
private readonly IMongoDatabase _database;
/// <summary>
/// The private GetCollection method
/// </summary>
/// <typeparam name="TDocument"></typeparam>
/// <returns></returns>
public IMongoCollection<TDocument> GetCollection<TDocument>()
{
return _database.GetCollection<TDocument>(Pluralize<TDocument>());
}
/// <summary>
/// The private GetCollection method
/// </summary>
/// <typeparam name="TEntity"></typeparam>
/// <typeparam name="TDocument"></typeparam>
/// <returns></returns>
public IMongoCollection<TEntity> GetCollection<TEntity>()
public IMongoCollection<TDocument> GetCollection<TDocument>(TDocument document) where TDocument : IDocument
{
return _database.GetCollection<TEntity>(typeof(TEntity).Name.ToLower() + "s");
return _database.GetCollection<TDocument>(PluralizePartitioned(document));
}
/// <summary>
/// Drops a collection, use very carefully.
/// </summary>
/// <typeparam name="TDocument"></typeparam>
public void DropCollection<TDocument>()
{
_database.DropCollection(Pluralize<TDocument>());
}
private string Pluralize<TDocument>()
{
return typeof(TDocument).Name.ToLower() + "s";
}
private string PluralizePartitioned<TDocument>(TDocument document) where TDocument : IDocument
{
return document.PartitionKey + typeof(TDocument).Name.ToLower() + "s";
}
}
}
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.1.0.0\build\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.props" Condition="Exists('..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.1.0.0\build\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.props')" />
<Import Project="..\packages\Microsoft.Net.Compilers.1.0.0\build\Microsoft.Net.Compilers.props" Condition="Exists('..\packages\Microsoft.Net.Compilers.1.0.0\build\Microsoft.Net.Compilers.props')" />
<Import Project="..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.1.0.7\build\net45\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.props" Condition="Exists('..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.1.0.7\build\net45\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.props')" />
<Import Project="..\packages\Microsoft.Net.Compilers.2.3.1\build\Microsoft.Net.Compilers.props" Condition="Exists('..\packages\Microsoft.Net.Compilers.2.3.1\build\Microsoft.Net.Compilers.props')" />
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
@@ -43,22 +43,21 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.1.0.0\lib\net45\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.dll</HintPath>
<Private>True</Private>
<Reference Include="Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.7.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.1.0.7\lib\net45\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.dll</HintPath>
</Reference>
<Reference Include="Microsoft.CSharp" />
<Reference Include="MongoDB.Bson, Version=2.2.3.3, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\MongoDB.Bson.2.2.3\lib\net45\MongoDB.Bson.dll</HintPath>
<Private>True</Private>
<Reference Include="MongoDB.Bson, Version=2.4.4.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\MongoDB.Bson.2.4.4\lib\net45\MongoDB.Bson.dll</HintPath>
</Reference>
<Reference Include="MongoDB.Driver, Version=2.2.3.3, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\MongoDB.Driver.2.2.3\lib\net45\MongoDB.Driver.dll</HintPath>
<Private>True</Private>
<Reference Include="MongoDB.Driver, Version=2.4.4.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\MongoDB.Driver.2.4.4\lib\net45\MongoDB.Driver.dll</HintPath>
</Reference>
<Reference Include="MongoDB.Driver.Core, Version=2.2.3.3, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\MongoDB.Driver.Core.2.2.3\lib\net45\MongoDB.Driver.Core.dll</HintPath>
<Private>True</Private>
<Reference Include="MongoDB.Driver.Core, Version=2.4.4.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\MongoDB.Driver.Core.2.4.4\lib\net45\MongoDB.Driver.Core.dll</HintPath>
</Reference>
<Reference Include="System.Runtime.InteropServices.RuntimeInformation, Version=4.0.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\System.Runtime.InteropServices.RuntimeInformation.4.3.0\lib\net45\System.Runtime.InteropServices.RuntimeInformation.dll</HintPath>
</Reference>
<Reference Include="System.Web.DynamicData" />
<Reference Include="System.Web.Entity" />
@@ -93,12 +92,12 @@
<Content Include="Web.config" />
</ItemGroup>
<ItemGroup>
<Compile Include="IMongoDbRepository.cs" />
<Compile Include="IMongoDbContext.cs" />
<Compile Include="Models\Document.cs" />
<Compile Include="Models\IDocument.cs" />
<Compile Include="MongoDbContext.cs" />
<Compile Include="MongoDbRepository.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Services\HelperService.cs" />
<Compile Include="ViewModels\Results.cs" />
</ItemGroup>
<PropertyGroup>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
@@ -129,8 +128,8 @@
<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.Net.Compilers.1.0.0\build\Microsoft.Net.Compilers.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.Net.Compilers.1.0.0\build\Microsoft.Net.Compilers.props'))" />
<Error Condition="!Exists('..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.1.0.0\build\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.1.0.0\build\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.props'))" />
<Error Condition="!Exists('..\packages\Microsoft.Net.Compilers.2.3.1\build\Microsoft.Net.Compilers.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.Net.Compilers.2.3.1\build\Microsoft.Net.Compilers.props'))" />
<Error Condition="!Exists('..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.1.0.7\build\net45\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.1.0.7\build\net45\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.props'))" />
</Target>
<!-- 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.
@@ -1,5 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<UseIISExpress>true</UseIISExpress>
</PropertyGroup>
<ProjectExtensions>
<VisualStudio>
<FlavorProperties GUID="{349c5851-65df-11da-9384-00065b846f21}">
+189 -253
View File
@@ -1,122 +1,73 @@
using MongoDB.Driver;
using System;
using System.Collections.Generic;
using MongoDbGenericRepository.ViewModels;
using System.Threading.Tasks;
using MongoDbGenericRepository.Services;
using MongoDB.Bson;
using System.Linq.Expressions;
using MongoDbGenericRepository.Models;
namespace MongoDbGenericRepository
{
public class MongoRepository : IMongoDbRepository
public abstract class BaseMongoRepository
{
public string ConnectionString { get; set; }
public string DatabaseName { get; set; }
private MongoDbContext _mongoDbContext = null;
public MongoRepository(MongoDbContext mongoDbContext = null)
/// <summary>
/// The base constructor
/// </summary>
/// <param name="connectionString">The connection string of the MongoDb server.</param>
/// <param name="databaseName">The name of the database against which you want to perform operations.</param>
protected BaseMongoRepository(string connectionString, string databaseName)
{
_mongoDbContext = mongoDbContext != null ? mongoDbContext : new MongoDbContext();
_mongoDbContext = new MongoDbContext(connectionString, databaseName);
}
protected IMongoDbContext _mongoDbContext = null;
#region Get
/// <summary>
/// A generic GetOne method
/// </summary>
/// <typeparam name="TEntity"></typeparam>
/// <typeparam name="TDocument"></typeparam>
/// <param name="id"></param>
/// <returns></returns>
public async Task<GetOneResult<TEntity>> GetOne<TEntity>(string id) where TEntity : class, new()
public async Task<TDocument> GetOne<TDocument>(string id) where TDocument : IDocument
{
var filter = Builders<TEntity>.Filter.Eq("Id", id);
return await GetOne<TEntity>(filter);
var filter = Builders<TDocument>.Filter.Eq("Id", id);
return await GetOne<TDocument>(filter);
}
/// <summary>
/// A generic GetOne method
/// </summary>
/// <typeparam name="TEntity"></typeparam>
/// <typeparam name="TDocument"></typeparam>
/// <param name="id"></param>
/// <returns></returns>
public async Task<GetOneResult<TEntity>> GetOne<TEntity>(FilterDefinition<TEntity> filter) where TEntity : class, new()
public async Task<TDocument> GetOne<TDocument>(FilterDefinition<TDocument> filter) where TDocument : IDocument
{
var res = new GetOneResult<TEntity>();
try
{
var collection = GetCollection<TEntity>();
var entity = await collection.Find(filter).SingleOrDefaultAsync();
if (entity != null)
{
res.Entity = entity;
}
res.Success = true;
return res;
}
catch (Exception ex)
{
res.Message = HelperService.NotifyException("GetOne", "Exception getting one " + typeof(TEntity).Name, ex);
return res;
}
}
/// <summary>
/// A generic get many method
/// </summary>
/// <typeparam name="TEntity"></typeparam>
/// <param name="ids"></param>
/// <returns></returns>
public async Task<GetManyResult<TEntity>> GetMany<TEntity>(IEnumerable<string> ids) where TEntity : class, new()
{
try
{
var collection = GetCollection<TEntity>();
var filter = Builders<TEntity>.Filter.Eq("Id", ids);
return await GetMany<TEntity>(filter);
}
catch (Exception ex)
{
var res = new GetManyResult<TEntity>();
res.Message = HelperService.NotifyException("GetMany", "Exception getting many " + typeof(TEntity).Name + "s", ex);
return res;
}
return await GetCollection<TDocument>().Find(filter).FirstOrDefaultAsync();
}
/// <summary>
/// A generic get many method with filter
/// </summary>
/// <typeparam name="TEntity"></typeparam>
/// <param name="ids"></param>
/// <typeparam name="TDocument"></typeparam>
/// <returns></returns>
public async Task<GetManyResult<TEntity>> GetMany<TEntity>(FilterDefinition<TEntity> filter) where TEntity : class, new()
public async Task<List<TDocument>> GetAll<TDocument>(FilterDefinition<TDocument> filter) where TDocument : IDocument
{
var res = new GetManyResult<TEntity>();
try
{
var collection = GetCollection<TEntity>();
var entities = await collection.Find(filter).ToListAsync();
if (entities != null)
{
res.Entities = entities;
}
res.Success = true;
return res;
}
catch (Exception ex)
{
res.Message = HelperService.NotifyException("GetMany", "Exception getting many " + typeof(TEntity).Name + "s", ex);
return res;
}
return await GetCollection<TDocument>().Find(filter).ToListAsync();
}
/// <summary>
/// FindCursor
/// </summary>
/// <typeparam name="TEntity"></typeparam>
/// <typeparam name="TDocument"></typeparam>
/// <param name="filter"></param>
/// <returns>A cursor for the query</returns>
public IFindFluent<TEntity, TEntity> FindCursor<TEntity>(FilterDefinition<TEntity> filter) where TEntity : class, new()
public IFindFluent<TDocument, TDocument> FindCursor<TDocument>(FilterDefinition<TDocument> filter) where TDocument : IDocument
{
var res = new GetManyResult<TEntity>();
var collection = GetCollection<TEntity>();
var collection = GetCollection<TDocument>();
var cursor = collection.Find(filter);
return cursor;
}
@@ -124,38 +75,23 @@ namespace MongoDbGenericRepository
/// <summary>
/// A generic get all method
/// </summary>
/// <typeparam name="TEntity"></typeparam>
/// <typeparam name="TDocument"></typeparam>
/// <returns></returns>
public async Task<GetManyResult<TEntity>> GetAll<TEntity>() where TEntity : class, new()
public async Task<List<TDocument>> GetAll<TDocument>() where TDocument : IDocument
{
var res = new GetManyResult<TEntity>();
try
{
var collection = GetCollection<TEntity>();
var entities = await collection.Find(new BsonDocument()).ToListAsync();
if (entities != null)
{
res.Entities = entities;
}
res.Success = true;
return res;
}
catch (Exception ex)
{
res.Message = HelperService.NotifyException("GetAll", "Exception getting all " + typeof(TEntity).Name + "s", ex);
return res;
}
var collection = GetCollection<TDocument>();
return await collection.Find(new BsonDocument()).ToListAsync();
}
/// <summary>
/// A generic Exists method
/// </summary>
/// <typeparam name="TEntity"></typeparam>
/// <typeparam name="TDocument"></typeparam>
/// <param name="key"></param>
/// <returns></returns>
public async Task<bool> Exists<TEntity>(string id) where TEntity : class, new()
public async Task<bool> Exists<TDocument>(string id) where TDocument : IDocument
{
var collection = GetCollection<TEntity>();
var collection = GetCollection<TDocument>();
var query = new BsonDocument("Id", id);
var cursor = collection.Find(query);
var count = await cursor.CountAsync();
@@ -165,223 +101,226 @@ namespace MongoDbGenericRepository
/// <summary>
/// A generic count method
/// </summary>
/// <typeparam name="TEntity"></typeparam>
/// <typeparam name="TDocument"></typeparam>
/// <param name="id"></param>
/// <returns></returns>
public async Task<long> Count<TEntity>(string id) where TEntity : class, new()
public async Task<long> Count<TDocument>(string id) where TDocument : IDocument
{
var filter = new FilterDefinitionBuilder<TEntity>().Eq("Id", id);
return await Count<TEntity>(filter);
var filter = new FilterDefinitionBuilder<TDocument>().Eq("Id", id);
return await Count<TDocument>(filter);
}
/// <summary>
/// A generic count method
/// </summary>
/// <typeparam name="TEntity"></typeparam>
/// <typeparam name="TDocument"></typeparam>
/// <param name="id"></param>
/// <returns></returns>
public async Task<long> Count<TEntity>(FilterDefinition<TEntity> filter) where TEntity : class, new()
public async Task<long> Count<TDocument>(FilterDefinition<TDocument> filter) where TDocument : IDocument
{
var collection = GetCollection<TEntity>();
var collection = GetCollection<TDocument>();
var cursor = collection.Find(filter);
var count = await cursor.CountAsync();
return count;
}
/// <summary>
/// A generic count method
/// </summary>
/// <typeparam name="TDocument"></typeparam>
/// <param name="id"></param>
/// <returns></returns>
public async Task<long> CountAsync<TDocument>(Expression<Func<TDocument, bool>> filter) where TDocument : IDocument
{
var collection = GetCollection<TDocument>();
var cursor = collection.Find(filter);
var count = await cursor.CountAsync();
return count;
}
/// <summary>
/// A generic count method
/// </summary>
/// <typeparam name="TDocument"></typeparam>
/// <param name="id"></param>
/// <returns></returns>
public long Count<TDocument>(Expression<Func<TDocument, bool>> filter) where TDocument : IDocument
{
return GetCollection<TDocument>().Find(filter).Count();
}
/// <summary>
/// Returns a list of projected objects
/// </summary>
/// <typeparam name="TDocument">T is a DbEntity</typeparam>
/// <typeparam name="TProjection"></typeparam>
/// <returns></returns>
public async Task<TProjection> ProjectBy<TDocument, TProjection>(Expression<Func<TDocument, bool>> filter, Expression<Func<TDocument, TProjection>> projection)
where TDocument : IDocument
where TProjection : class, new()
{
return await GetCollection<TDocument>().Find(Builders<TDocument>.Filter.Where(filter))
.Project(projection)
.FirstOrDefaultAsync();
}
#endregion Get
#region Create
/// <summary>
/// A generic Add One method
/// A generic Add One method async
/// </summary>
/// <typeparam name="TEntity"></typeparam>
/// <typeparam name="TDocument"></typeparam>
/// <param name="item"></param>
/// <returns></returns>
public async Task<Result> AddOne<TEntity>(TEntity item) where TEntity : class, new()
public async Task AddOneAsync<TDocument>(TDocument item) where TDocument : IDocument
{
var res = new Result();
try
await GetCollection<TDocument>().InsertOneAsync(item);
}
/// <summary>
/// A generic method to add a document
/// </summary>
/// <typeparam name="TDocument"></typeparam>
/// <param name="item"></param>
/// <returns></returns>
public void AddOne<TDocument>(TDocument item) where TDocument : IDocument
{
var collection = GetCollection<TEntity>();
await collection.InsertOneAsync(item);
res.Success = true;
res.Message = "OK";
return res;
}
catch (Exception ex)
if (item.Id == default(Guid))
{
res.Message = HelperService.NotifyException("AddOne", "Exception adding one " + typeof(TEntity).Name, ex);
return res;
item.Id = Guid.NewGuid();
}
if (item.AddedAtUtc == default(DateTime))
{
item.AddedAtUtc = DateTime.UtcNow;
}
GetCollection<TDocument>().InsertOne(item);
}
/// <summary>
/// A generic Add Many method, performs a bulk insert in mongo
/// </summary>
/// <typeparam name="TDocument"></typeparam>
/// <param name="items"></param>
/// <returns></returns>
public async Task AddManyAsync<TDocument>(IEnumerable<TDocument> items) where TDocument : IDocument
{
await GetCollection<TDocument>().InsertManyAsync(items);
}
/// <summary>
/// A generic Add Many method, performs a bulk insert in mongo
/// </summary>
/// <typeparam name="TDocument"></typeparam>
/// <param name="items"></param>
/// <returns></returns>
public void AddMany<TDocument>(IEnumerable<TDocument> items) where TDocument : IDocument
{
GetCollection<TDocument>().InsertMany(items);
}
#endregion Create
#region Delete
/// <summary>
/// A generic delete one method
/// </summary>
/// <typeparam name="TEntity"></typeparam>
/// <typeparam name="TDocument"></typeparam>
/// <param name="id"></param>
/// <returns></returns>
public async Task<Result> DeleteOne<TEntity>(string id) where TEntity : class, new()
public async Task<long> DeleteOneAsync<TDocument>(TDocument document) where TDocument : IDocument
{
var filter = new FilterDefinitionBuilder<TEntity>().Eq("Id", id);
return await DeleteOne<TEntity>(filter);
return await DeleteOneAsync<TDocument>(x => x.Id == document.Id);
}
/// <summary>
/// A generic delete one method
/// </summary>
/// <typeparam name="TEntity"></typeparam>
/// <typeparam name="TDocument"></typeparam>
/// <param name="id"></param>
/// <returns></returns>
public async Task<Result> DeleteOne<TEntity>(FilterDefinition<TEntity> filter) where TEntity : class, new()
public long DeleteOne<TDocument>(TDocument document) where TDocument : IDocument
{
var result = new Result();
try
{
var collection = GetCollection<TEntity>();
var deleteRes = await collection.DeleteOneAsync(filter);
result.Success = true;
result.Message = "OK";
return result;
return DeleteOne<TDocument>(x => x.Id == document.Id);
}
catch (Exception ex)
/// <summary>
/// A generic delete one method
/// </summary>
/// <typeparam name="TDocument"></typeparam>
/// <param name="filter"></param>
/// <returns></returns>
public long DeleteOne<TDocument>(Expression<Func<TDocument, bool>> filter) where TDocument : IDocument
{
result.Message = HelperService.NotifyException("DeleteOne", "Exception deleting one " + typeof(TEntity).Name, ex);
return result;
return GetCollection<TDocument>().DeleteOne(filter).DeletedCount;
}
/// <summary>
/// A generic delete one method
/// </summary>
/// <typeparam name="TDocument"></typeparam>
/// <param name="filter"></param>
/// <returns></returns>
public async Task<long> DeleteOneAsync<TDocument>(Expression<Func<TDocument, bool>> filter) where TDocument : IDocument
{
return (await GetCollection<TDocument>().DeleteOneAsync(filter)).DeletedCount;
}
/// <summary>
/// A generic delete many method
/// </summary>
/// <typeparam name="TEntity"></typeparam>
/// <param name="ids"></param>
/// <typeparam name="TDocument"></typeparam>
/// <param name="filter"></param>
/// <returns></returns>
public async Task<Result> DeleteMany<TEntity>(IEnumerable<string> ids) where TEntity : class, new()
public async Task<long> DeleteMany<TDocument>(Expression<Func<TDocument, bool>> filter) where TDocument : IDocument
{
var filter = new FilterDefinitionBuilder<TEntity>().In("Id", ids);
return await DeleteMany<TEntity>(filter);
}
/// <summary>
/// A generic delete many method
/// </summary>
/// <typeparam name="TEntity"></typeparam>
/// <param name="ids"></param>
/// <returns></returns>
public async Task<Result> DeleteMany<TEntity>(FilterDefinition<TEntity> filter) where TEntity : class, new()
{
var result = new Result();
try
{
var collection = GetCollection<TEntity>();
var deleteRes = await collection.DeleteManyAsync(filter);
if (deleteRes.DeletedCount < 1)
{
var ex = new Exception();
result.Message = HelperService.NotifyException("DeleteMany", "Some " + typeof(TEntity).Name + "s could not be deleted.", ex);
return result;
}
result.Success = true;
result.Message = "OK";
return result;
}
catch (Exception ex)
{
result.Message = HelperService.NotifyException("DeleteMany", "Some " + typeof(TEntity).Name + "s could not be deleted.", ex);
return result;
}
var deleteRes = await GetCollection<TDocument>().DeleteManyAsync(filter);
return deleteRes.DeletedCount;
}
#endregion Delete
#region Update
/// <summary>
/// UpdateOne by id
/// Updates a document
/// </summary>
/// <typeparam name="TEntity"></typeparam>
/// <param name="id"></param>
/// <param name="update"></param>
/// <typeparam name="TDocument"></typeparam>
/// <param name="entity"></param>
/// <returns></returns>
public async Task<Result> UpdateOne<TEntity>(string id, UpdateDefinition<TEntity> update) where TEntity : class, new()
public async Task<bool> UpdateOneAsync<TDocument>(TDocument entity) where TDocument : IDocument
{
var filter = new FilterDefinitionBuilder<TEntity>().Eq("Id", id);
return await UpdateOne<TEntity>(filter, update);
var updateRes = await GetCollection<TDocument>().ReplaceOneAsync(x => x.Id == entity.Id, entity);
return updateRes.ModifiedCount < 1;
}
/// <summary>
/// UpdateOne with filter
/// </summary>
/// <typeparam name="TEntity"></typeparam>
/// <typeparam name="TDocument"></typeparam>
/// <param name="filter"></param>
/// <param name="update"></param>
/// <returns></returns>
public async Task<Result> UpdateOne<TEntity>(FilterDefinition<TEntity> filter, UpdateDefinition<TEntity> update) where TEntity : class, new()
private async Task<long> UpdateOne<TDocument>(FilterDefinition<TDocument> filter, UpdateDefinition<TDocument> update) where TDocument : IDocument
{
var result = new Result();
try
{
var collection = GetCollection<TEntity>();
var updateRes = await collection.UpdateOneAsync(filter, update);
if (updateRes.ModifiedCount < 1)
{
var ex = new Exception();
result.Message = HelperService.NotifyException("UpdateOne", "ERROR: updateRes.ModifiedCount < 1 for entity: " + typeof(TEntity).Name, ex);
return result;
}
result.Success = true;
result.Message = "OK";
return result;
}
catch (Exception ex)
{
result.Message = HelperService.NotifyException("UpdateOne", "Exception updating entity: " + typeof(TEntity).Name, ex);
return result;
}
}
/// <summary>
/// UpdateMany with Ids
/// </summary>
/// <typeparam name="TEntity"></typeparam>
/// <param name="id"></param>
/// <param name="update"></param>
/// <returns></returns>
public async Task<Result> UpdateMany<TEntity>(IEnumerable<string> ids, UpdateDefinition<TEntity> update) where TEntity : class, new()
{
var filter = new FilterDefinitionBuilder<TEntity>().In("Id", ids);
return await UpdateOne<TEntity>(filter, update);
var updateRes = await GetCollection<TDocument>().UpdateOneAsync(filter, update);
return updateRes.ModifiedCount;
}
/// <summary>
/// UpdateMany with filter
/// </summary>
/// <typeparam name="TEntity"></typeparam>
/// <typeparam name="TDocument"></typeparam>
/// <param name="filter"></param>
/// <param name="update"></param>
/// <returns></returns>
public async Task<Result> UpdateMany<TEntity>(FilterDefinition<TEntity> filter, UpdateDefinition<TEntity> update) where TEntity : class, new()
public async Task<long> UpdateMany<TDocument>(FilterDefinition<TDocument> filter, UpdateDefinition<TDocument> update) where TDocument : IDocument
{
var result = new Result();
try
{
var collection = GetCollection<TEntity>();
var collection = GetCollection<TDocument>();
var updateRes = await collection.UpdateManyAsync(filter, update);
if (updateRes.ModifiedCount < 1)
{
var ex = new Exception();
result.Message = HelperService.NotifyException("UpdateMany", "ERROR: updateRes.ModifiedCount < 1 for entities: " + typeof(TEntity).Name + "s", ex);
return result;
}
result.Success = true;
result.Message = "OK";
return result;
}
catch (Exception ex)
{
result.Message = HelperService.NotifyException("UpdateMany", "Exception updating entities: " + typeof(TEntity).Name + "s", ex);
return result;
}
return updateRes.ModifiedCount;
}
#endregion Update
@@ -390,27 +329,14 @@ namespace MongoDbGenericRepository
/// <summary>
/// GetAndUpdateOne with filter
/// </summary>
/// <typeparam name="TEntity"></typeparam>
/// <typeparam name="TDocument"></typeparam>
/// <param name="filter"></param>
/// <param name="update"></param>
/// <param name="options"></param>
/// <returns></returns>
public async Task<GetOneResult<TEntity>> GetAndUpdateOne<TEntity>(FilterDefinition<TEntity> filter, UpdateDefinition<TEntity> update, FindOneAndUpdateOptions<TEntity, TEntity> options) where TEntity : class, new()
public async Task<TDocument> GetAndUpdateOne<TDocument>(FilterDefinition<TDocument> filter, UpdateDefinition<TDocument> update, FindOneAndUpdateOptions<TDocument, TDocument> options) where TDocument : IDocument
{
var result = new GetOneResult<TEntity>();
try
{
var collection = GetCollection<TEntity>();
result.Entity = await collection.FindOneAndUpdateAsync(filter, update, options);
result.Success = true;
result.Message = "OK";
return result;
}
catch (Exception ex)
{
result.Message = HelperService.NotifyException("GetAndUpdateOne", "Exception getting and updating entity: " + typeof(TEntity).Name, ex);
return result;
}
return await GetCollection<TDocument>().FindOneAndUpdateAsync(filter, update, options);
}
#endregion Find And Update
@@ -419,11 +345,21 @@ namespace MongoDbGenericRepository
/// <summary>
/// The private GetCollection method
/// </summary>
/// <typeparam name="TEntity"></typeparam>
/// <typeparam name="TDocument"></typeparam>
/// <returns></returns>
private IMongoCollection<TEntity> GetCollection<TEntity>()
private IMongoCollection<TDocument> GetCollection<TDocument>(TDocument document) where TDocument : IDocument
{
return _mongoDbContext.GetCollection<TEntity>();
return _mongoDbContext.GetCollection<TDocument>(document);
}
/// <summary>
/// The private GetCollection method
/// </summary>
/// <typeparam name="TDocument"></typeparam>
/// <returns></returns>
private IMongoCollection<TDocument> GetCollection<TDocument>() where TDocument : IDocument
{
return _mongoDbContext.GetCollection<TDocument>();
}
}
}
@@ -1,61 +0,0 @@
using System;
using System.Diagnostics;
using System.Text;
namespace MongoDbGenericRepository.Services
{
public static class HelperService
{
public static string NotifyException(string FunctionName, string Context, Exception ex)
{
string source = FunctionName + ": " + Context;
source = GetAllInformation(ex, source);
Debug.WriteLine(source);
return source;
}
/// <summary>
/// Get all exception information
/// </summary>
/// <param name="exception"></param>
/// <param name="information"></param>
/// <returns></returns>
public static string GetAllInformation(Exception exception, string source)
{
var sb = new StringBuilder();
sb.AppendLine("********** " + DateTime.Now.ToLongDateString() + "**********");
while (exception != null)
{
sb.AppendLine("Inner Exception Type: ");
sb.AppendLine(exception.InnerException.GetType().ToString());
sb.AppendLine("Inner Exception: ");
sb.AppendLine(exception.InnerException.Message);
sb.AppendLine("Inner Source: ");
sb.AppendLine(exception.InnerException.Source);
if (exception.InnerException.StackTrace != null)
{
sb.AppendLine("Inner Stack Trace: ");
sb.AppendLine(exception.InnerException.StackTrace);
}
sb.AppendLine("Exception Type: ");
sb.AppendLine(sb.GetType().ToString());
sb.AppendLine("Exception: " + exception.Message);
sb.AppendLine("Source: " + source);
sb.AppendLine("Stack Trace: ");
if (exception.StackTrace != null)
{
sb.AppendLine(exception.StackTrace);
sb.AppendLine();
}
exception = exception.InnerException;
}
return sb.ToString();
}
}
}
@@ -1,36 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace MongoDbGenericRepository.ViewModels
{
public class Result
{
public bool Success { get; set; }
public string Message { get; set; }
public int ErrorCode { get; set; }
public Result()
{
Success = false;
Message = "";
ErrorCode = 500;
}
}
public class GetOneResult<TEntity> : Result where TEntity : class, new()
{
public TEntity Entity { get; set; }
}
public class GetManyResult<TEntity> : Result where TEntity : class, new()
{
public IEnumerable<TEntity> Entities { get; set; }
}
public class GetListResult<T> : Result
{
public List<T> Entities { get; set; }
}
}
+17 -13
View File
@@ -5,24 +5,28 @@
-->
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.5.2"/>
<httpRuntime targetFramework="4.5.2"/>
<compilation debug="true" targetFramework="4.5.2" />
<httpRuntime targetFramework="4.5.2" />
<httpModules>
</httpModules>
</system.web>
<system.codedom>
<compilers>
<compiler language="c#;cs;csharp" extension=".cs"
type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
warningLevel="4" compilerOptions="/langversion:6 /nowarn:1659;1699;1701"/>
<compiler language="vb;vbs;visualbasic;vbscript" extension=".vb"
type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.VBCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
warningLevel="4" compilerOptions="/langversion:14 /nowarn:41008 /define:_MYTYPE=\&quot;Web\&quot; /optionInfer+"/>
</compilers>
</system.codedom>
<system.webServer>
<validation validateIntegratedModeConfiguration="false"/>
<validation validateIntegratedModeConfiguration="false" />
<modules>
</modules>
</system.webServer>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Runtime.InteropServices.RuntimeInformation" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.1.0" newVersion="4.0.1.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
<system.codedom>
<compilers>
<compiler language="c#;cs;csharp" extension=".cs" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.7.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:6 /nowarn:1659;1699;1701" />
<compiler language="vb;vbs;visualbasic;vbscript" extension=".vb" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.VBCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.7.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:14 /nowarn:41008 /define:_MYTYPE=\&quot;Web\&quot; /optionInfer+" />
</compilers>
</system.codedom>
</configuration>
Binary file not shown.
File diff suppressed because it is too large Load Diff
Binary file not shown.
File diff suppressed because it is too large Load Diff
Binary file not shown.
File diff suppressed because it is too large Load Diff
@@ -5,24 +5,28 @@
-->
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.5.2"/>
<httpRuntime targetFramework="4.5.2"/>
<compilation debug="true" targetFramework="4.5.2" />
<httpRuntime targetFramework="4.5.2" />
<httpModules>
</httpModules>
</system.web>
<system.codedom>
<compilers>
<compiler language="c#;cs;csharp" extension=".cs"
type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
warningLevel="4" compilerOptions="/langversion:6 /nowarn:1659;1699;1701"/>
<compiler language="vb;vbs;visualbasic;vbscript" extension=".vb"
type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.VBCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
warningLevel="4" compilerOptions="/langversion:14 /nowarn:41008 /define:_MYTYPE=\&quot;Web\&quot; /optionInfer+"/>
</compilers>
</system.codedom>
<system.webServer>
<validation validateIntegratedModeConfiguration="false"/>
<validation validateIntegratedModeConfiguration="false" />
<modules>
</modules>
</system.webServer>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Runtime.InteropServices.RuntimeInformation" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.1.0" newVersion="4.0.1.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
<system.codedom>
<compilers>
<compiler language="c#;cs;csharp" extension=".cs" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.7.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:6 /nowarn:1659;1699;1701" />
<compiler language="vb;vbs;visualbasic;vbscript" extension=".vb" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.VBCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.7.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:14 /nowarn:41008 /define:_MYTYPE=\&quot;Web\&quot; /optionInfer+" />
</compilers>
</system.codedom>
</configuration>
@@ -1,27 +1,42 @@
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Target
Name="CoreCompile"
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -->
<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Target Name="ShimReferencePathsWhenCommonTargetsDoesNotUnderstandReferenceAssemblies"
BeforeTargets="CoreCompile"
Condition="'@(ReferencePathWithRefAssemblies)' == ''">
<!-- Common targets should populate this item from dev15.3, but this file
may be used (via NuGet package) on earlier MSBuilds. If the
adjusted-for-reference-assemblies item is not populated, just use
the older item's contents. -->
<ItemGroup>
<ReferencePathWithRefAssemblies Include="@(ReferencePath)" />
</ItemGroup>
</Target>
<Target Name="CoreCompile"
Inputs="$(MSBuildAllProjects);
@(Compile);
@(_CoreCompileResourceInputs);
$(ApplicationIcon);
$(AssemblyOriginatorKeyFile);
@(ReferencePath);
@(ReferencePathWithRefAssemblies);
@(CompiledLicenseFile);
@(LinkResource);
@(EmbeddedDocumentation);
$(Win32Resource);
$(Win32Manifest);
@(CustomAdditionalCompileInputs);
$(ResolvedCodeAnalysisRuleSet)"
$(ResolvedCodeAnalysisRuleSet);
@(AdditionalFiles);
@(EmbeddedFiles)"
Outputs="@(DocFileItem);
@(IntermediateAssembly);
@(IntermediateRefAssembly);
@(_DebugSymbolsIntermediatePath);
$(NonExistentFile);
@(CustomAdditionalCompileOutputs)"
Returns=""
DependsOnTargets="$(CoreCompileDependsOn)"
>
Returns="@(CscCommandLineArgs)"
DependsOnTargets="$(CoreCompileDependsOn)">
<!-- These two compiler warnings are raised when a reference is bound to a different version
than specified in the assembly reference version number. MSBuild raises the same warning in this case,
so the compiler warning would be redundant. -->
@@ -31,22 +46,22 @@
<PropertyGroup>
<!-- To match historical behavior, when inside VS11+ disable the warning from csc.exe indicating that no sources were passed in-->
<NoWarn Condition=" '$(BuildingInsideVisualStudio)' == 'true' and '$(VisualStudioVersion)' != '' and '$(VisualStudioVersion)' > '10.0' ">$(NoWarn);2008</NoWarn>
<NoWarn Condition="'$(BuildingInsideVisualStudio)' == 'true' AND '$(VisualStudioVersion)' != '' AND '$(VisualStudioVersion)' &gt; '10.0'">$(NoWarn);2008</NoWarn>
</PropertyGroup>
<ItemGroup Condition="'$(TargetingClr2Framework)'=='true'">
<ReferencePath>
<EmbedInteropTypes/>
</ReferencePath>
<ItemGroup Condition="'$(TargetingClr2Framework)' == 'true'">
<ReferencePathWithRefAssemblies>
<EmbedInteropTypes />
</ReferencePathWithRefAssemblies>
</ItemGroup>
<PropertyGroup>
<!-- If the user has specified AppConfigForCompiler, we'll use it. If they have not, but they set UseAppConfigForCompiler,
then we'll use AppConfig -->
<AppConfigForCompiler Condition="'$(AppConfigForCompiler)' == '' and '$(UseAppConfigForCompiler)' == 'true'">$(AppConfig)</AppConfigForCompiler>
<AppConfigForCompiler Condition="'$(AppConfigForCompiler)' == '' AND '$(UseAppConfigForCompiler)' == 'true'">$(AppConfig)</AppConfigForCompiler>
<!-- If we are targeting winmdobj we want to specifically the pdbFile property since we do not want it to collide with the output of winmdexp-->
<PdbFile Condition="'$(PdbFile)' == '' and '$(OutputType)' == 'winmdobj' and '$(_DebugSymbolsProduced)' == 'true'">$(IntermediateOutputPath)$(TargetName).compile.pdb</PdbFile>
<PdbFile Condition="'$(PdbFile)' == '' AND '$(OutputType)' == 'winmdobj' AND '$(_DebugSymbolsProduced)' == 'true'">$(IntermediateOutputPath)$(TargetName).compile.pdb</PdbFile>
</PropertyGroup>
<!-- Prefer32Bit was introduced in .NET 4.5. Set it to false if we are targeting 4.0 -->
@@ -54,6 +69,8 @@
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<!-- TODO: Remove this ItemGroup once it has been moved to "_GenerateCompileInputs" target in Microsoft.Common.CurrentVersion.targets.
https://github.com/dotnet/roslyn/issues/12223 -->
<ItemGroup Condition="('$(AdditionalFileItemNames)' != '')">
<AdditionalFileItems Include="$(AdditionalFileItemNames)" />
<AdditionalFiles Include="@(%(AdditionalFileItems.Identity))" />
@@ -64,7 +81,7 @@
</PropertyGroup>
<!-- Condition is to filter out the _CoreCompileResourceInputs so that it doesn't pass in culture resources to the compiler -->
<Csc Condition=" '%(_CoreCompileResourceInputs.WithCulture)' != 'true' "
<Csc Condition="'%(_CoreCompileResourceInputs.WithCulture)' != 'true'"
AdditionalLibPaths="$(AdditionalLibPaths)"
AddModules="@(AddModules)"
AdditionalFiles="@(AdditionalFiles)"
@@ -73,6 +90,7 @@
ApplicationConfiguration="$(AppConfigForCompiler)"
BaseAddress="$(BaseAddress)"
CheckForOverflowUnderflow="$(CheckForOverflowUnderflow)"
ChecksumAlgorithm="$(ChecksumAlgorithm)"
CodeAnalysisRuleSet="$(ResolvedCodeAnalysisRuleSet)"
CodePage="$(CodePage)"
DebugType="$(DebugType)"
@@ -80,14 +98,17 @@
DelaySign="$(DelaySign)"
DisabledWarnings="$(NoWarn)"
DocumentationFile="@(DocFileItem)"
EmbeddedFiles="@(EmbeddedFiles)"
EmitDebugInformation="$(DebugSymbols)"
EnvironmentVariables="$(CscEnvironment)"
ErrorEndLocation="$(ErrorEndLocation)"
ErrorLog="$(ErrorLog)"
ErrorReport="$(ErrorReport)"
Features="$(Features)"
FileAlignment="$(FileAlignment)"
GenerateFullPaths="$(GenerateFullPaths)"
HighEntropyVA="$(HighEntropyVA)"
Instrument="$(Instrument)"
KeyContainer="$(KeyContainerName)"
KeyFile="$(KeyOriginatorFile)"
LangVersion="$(LangVersion)"
@@ -99,15 +120,21 @@
NoStandardLib="$(NoCompilerStandardLib)"
NoWin32Manifest="$(NoWin32Manifest)"
Optimize="$(Optimize)"
Deterministic="$(Deterministic)"
PublicSign="$(PublicSign)"
OutputAssembly="@(IntermediateAssembly)"
OutputRefAssembly="@(IntermediateRefAssembly)"
PdbFile="$(PdbFile)"
Platform="$(PlatformTarget)"
Prefer32Bit="$(Prefer32Bit)"
PreferredUILang="$(PreferredUILang)"
References="@(ReferencePath)"
ProvideCommandLineArgs="$(ProvideCommandLineArgs)"
References="@(ReferencePathWithRefAssemblies)"
ReportAnalyzer="$(ReportAnalyzer)"
Resources="@(_CoreCompileResourceInputs);@(CompiledLicenseFile)"
ResponseFiles="$(CompilerResponseFile)"
RuntimeMetadataVersion="$(RuntimeMetadataVersion)"
SkipCompilerExecution="$(SkipCompilerExecution)"
Sources="@(Compile)"
SubsystemVersion="$(SubsystemVersion)"
TargetType="$(OutputType)"
@@ -124,12 +151,15 @@
Win32Icon="$(ApplicationIcon)"
Win32Manifest="$(Win32Manifest)"
Win32Resource="$(Win32Resource)"
/>
PathMap="$(PathMap)"
SourceLink="$(SourceLink)">
<Output TaskParameter="CommandLineArgs" ItemName="CscCommandLineArgs" />
</Csc>
<ItemGroup>
<_CoreCompileResourceInputs Remove="@(_CoreCompileResourceInputs)" />
</ItemGroup>
<CallTarget Targets="$(TargetsTriggeredByCompilation)" Condition="'$(TargetsTriggeredByCompilation)' != ''"/>
<CallTarget Targets="$(TargetsTriggeredByCompilation)" Condition="'$(TargetsTriggeredByCompilation)' != ''" />
</Target>
</Project>
@@ -1,41 +1,56 @@
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Target
Name="CoreCompile"
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -->
<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Target Name="ShimReferencePathsWhenCommonTargetsDoesNotUnderstandReferenceAssemblies"
BeforeTargets="CoreCompile"
Condition="'@(ReferencePathWithRefAssemblies)' == ''">
<!-- Common targets should populate this item from dev15.3, but this file
may be used (via NuGet package) on earlier MSBuilds. If the
adjusted-for-reference-assemblies item is not populated, just use
the older item's contents. -->
<ItemGroup>
<ReferencePathWithRefAssemblies Include="@(ReferencePath)" />
</ItemGroup>
</Target>
<Target Name="CoreCompile"
Inputs="$(MSBuildAllProjects);
@(Compile);
@(_CoreCompileResourceInputs);
$(ApplicationIcon);
$(AssemblyOriginatorKeyFile);
@(ReferencePath);
@(ReferencePathWithRefAssemblies);
@(CompiledLicenseFile);
@(LinkResource);
@(EmbeddedDocumentation);
$(Win32Resource);
$(Win32Manifest);
@(CustomAdditionalCompileInputs);
$(ResolvedCodeAnalysisRuleSet)"
$(ResolvedCodeAnalysisRuleSet);
@(AdditionalFiles);
@(EmbeddedFiles)"
Outputs="@(DocFileItem);
@(IntermediateAssembly);
@(IntermediateRefAssembly);
@(_DebugSymbolsIntermediatePath);
$(NonExistentFile);
@(CustomAdditionalCompileOutputs)"
Returns=""
DependsOnTargets="$(CoreCompileDependsOn)"
>
Returns="@(VbcCommandLineArgs)"
DependsOnTargets="$(CoreCompileDependsOn)">
<PropertyGroup>
<_NoWarnings Condition=" '$(WarningLevel)' == '0' ">true</_NoWarnings>
<_NoWarnings Condition=" '$(WarningLevel)' == '1' ">false</_NoWarnings>
<_NoWarnings Condition="'$(WarningLevel)' == '0'">true</_NoWarnings>
<_NoWarnings Condition="'$(WarningLevel)' == '1'">false</_NoWarnings>
</PropertyGroup>
<PropertyGroup>
<!-- If we are targeting winmdobj we want to specifically the pdbFile property since we do not want it to collide with the output of winmdexp-->
<PdbFile Condition="'$(PdbFile)' == '' and '$(OutputType)' == 'winmdobj' and '$(DebugSymbols)' == 'true'">$(IntermediateOutputPath)$(TargetName).compile.pdb</PdbFile>
<PdbFile Condition="'$(PdbFile)' == '' AND '$(OutputType)' == 'winmdobj' AND '$(DebugSymbols)' == 'true'">$(IntermediateOutputPath)$(TargetName).compile.pdb</PdbFile>
</PropertyGroup>
<ItemGroup Condition="'$(TargetingClr2Framework)'=='true'">
<ReferencePath>
<EmbedInteropTypes/>
</ReferencePath>
<ItemGroup Condition="'$(TargetingClr2Framework)' == 'true'">
<ReferencePathWithRefAssemblies>
<EmbedInteropTypes />
</ReferencePathWithRefAssemblies>
</ItemGroup>
<!-- Prefer32Bit was introduced in .NET 4.5. Set it to false if we are targeting 4.0 -->
@@ -43,6 +58,8 @@
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<!-- TODO: Remove this ItemGroup once it has been moved to "_GenerateCompileInputs" target in Microsoft.Common.CurrentVersion.targets.
https://github.com/dotnet/roslyn/issues/12223 -->
<ItemGroup Condition="('$(AdditionalFileItemNames)' != '')">
<AdditionalFileItems Include="$(AdditionalFileItemNames)" />
<AdditionalFiles Include="@(%(AdditionalFileItems.Identity))" />
@@ -53,12 +70,13 @@
</PropertyGroup>
<!-- Condition is to filter out the _CoreCompileResourceInputs so that it doesn't pass in culture resources to the compiler -->
<Vbc Condition=" '%(_CoreCompileResourceInputs.WithCulture)' != 'true' "
<Vbc Condition="'%(_CoreCompileResourceInputs.WithCulture)' != 'true'"
AdditionalLibPaths="$(AdditionalLibPaths)"
AddModules="@(AddModules)"
AdditionalFiles="@(AdditionalFiles)"
Analyzers="@(Analyzer)"
BaseAddress="$(BaseAddress)"
ChecksumAlgorithm="$(ChecksumAlgorithm)"
CodeAnalysisRuleSet="$(ResolvedCodeAnalysisRuleSet)"
CodePage="$(CodePage)"
DebugType="$(DebugType)"
@@ -66,14 +84,17 @@
DelaySign="$(DelaySign)"
DisabledWarnings="$(NoWarn)"
DocumentationFile="@(DocFileItem)"
EmbeddedFiles="@(EmbeddedFiles)"
EmitDebugInformation="$(DebugSymbols)"
EnvironmentVariables="$(VbcEnvironment)"
ErrorLog="$(ErrorLog)"
ErrorReport="$(ErrorReport)"
Features="$(Features)"
FileAlignment="$(FileAlignment)"
GenerateDocumentation="$(GenerateDocumentation)"
HighEntropyVA="$(HighEntropyVA)"
Imports="@(Import)"
Instrument="$(Instrument)"
KeyContainer="$(KeyContainerName)"
KeyFile="$(KeyOriginatorFile)"
LangVersion="$(LangVersion)"
@@ -86,23 +107,29 @@
NoWarnings="$(_NoWarnings)"
NoWin32Manifest="$(NoWin32Manifest)"
Optimize="$(Optimize)"
Deterministic="$(Deterministic)"
PublicSign="$(PublicSign)"
OptionCompare="$(OptionCompare)"
OptionExplicit="$(OptionExplicit)"
OptionInfer="$(OptionInfer)"
OptionStrict="$(OptionStrict)"
OptionStrictType="$(OptionStrictType)"
OutputAssembly="@(IntermediateAssembly)"
OutputRefAssembly="@(IntermediateRefAssembly)"
PdbFile="$(PdbFile)"
Platform="$(PlatformTarget)"
Prefer32Bit="$(Prefer32Bit)"
PreferredUILang="$(PreferredUILang)"
References="@(ReferencePath)"
ProvideCommandLineArgs="$(ProvideCommandLineArgs)"
References="@(ReferencePathWithRefAssemblies)"
RemoveIntegerChecks="$(RemoveIntegerChecks)"
ReportAnalyzer="$(ReportAnalyzer)"
Resources="@(_CoreCompileResourceInputs);@(CompiledLicenseFile)"
ResponseFiles="$(CompilerResponseFile)"
RootNamespace="$(RootNamespace)"
RuntimeMetadataVersion="$(RuntimeMetadataVersion)"
SdkPath="$(FrameworkPathOverride)"
SkipCompilerExecution="$(SkipCompilerExecution)"
Sources="@(Compile)"
SubsystemVersion="$(SubsystemVersion)"
TargetCompactFramework="$(TargetCompactFramework)"
@@ -122,12 +149,14 @@
Win32Manifest="$(Win32Manifest)"
Win32Resource="$(Win32Resource)"
VBRuntime="$(VBRuntime)"
/>
PathMap="$(PathMap)"
SourceLink="$(SourceLink)">
<Output TaskParameter="CommandLineArgs" ItemName="VbcCommandLineArgs" />
</Vbc>
<ItemGroup>
<_CoreCompileResourceInputs Remove="@(_CoreCompileResourceInputs)" />
</ItemGroup>
<CallTarget Targets="$(TargetsTriggeredByCompilation)" Condition="'$(TargetsTriggeredByCompilation)' != ''"/>
<CallTarget Targets="$(TargetsTriggeredByCompilation)" Condition="'$(TargetsTriggeredByCompilation)' != ''" />
</Target>
</Project>
Binary file not shown.
@@ -1,14 +1,142 @@
<?xml version="1.0" encoding="utf-8" ?>
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -->
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6" />
</startup>
<runtime>
<gcServer enabled="true"/>
<gcConcurrent enabled="false"/>
<gcServer enabled="true" />
<gcConcurrent enabled="false" />
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Microsoft.CodeAnalysis" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-2.3.0.0" newVersion="2.3.0.0" />
</dependentAssembly>
</assemblyBinding>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Microsoft.CodeAnalysis.CSharp" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-2.3.0.0" newVersion="2.3.0.0" />
</dependentAssembly>
</assemblyBinding>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Microsoft.CodeAnalysis.VisualBasic" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-2.3.0.0" newVersion="2.3.0.0" />
</dependentAssembly>
</assemblyBinding>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Collections.Immutable" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-1.2.1.0" newVersion="1.2.1.0" />
</dependentAssembly>
</assemblyBinding>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Console" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.1.0" newVersion="4.0.1.0" />
</dependentAssembly>
</assemblyBinding>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Diagnostics.FileVersionInfo" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.1.0" newVersion="4.0.1.0" />
</dependentAssembly>
</assemblyBinding>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Diagnostics.StackTrace" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.3.0" newVersion="4.0.3.0" />
</dependentAssembly>
</assemblyBinding>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.IO.Compression" publicKeyToken="b77a5c561934e089" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.1.2.0" newVersion="4.1.2.0" />
</dependentAssembly>
</assemblyBinding>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.IO.FileSystem" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.2.0" newVersion="4.0.2.0" />
</dependentAssembly>
</assemblyBinding>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.IO.FileSystem.Primitives" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.2.0" newVersion="4.0.2.0" />
</dependentAssembly>
</assemblyBinding>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.IO.Pipes" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.1.0" newVersion="4.0.1.0" />
</dependentAssembly>
</assemblyBinding>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Reflection.Metadata" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-1.4.1.0" newVersion="1.4.1.0" />
</dependentAssembly>
</assemblyBinding>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Threading.Thread" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.1.0" newVersion="4.0.1.0" />
</dependentAssembly>
</assemblyBinding>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Security.Cryptography.Primitives" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.1.0" newVersion="4.0.1.0" />
</dependentAssembly>
</assemblyBinding>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Security.Principal.Windows" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.1.0" newVersion="4.0.1.0" />
</dependentAssembly>
</assemblyBinding>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.IO.Compression" publicKeyToken="b77a5c561934e089" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.1.2.0" newVersion="4.1.2.0" />
</dependentAssembly>
</assemblyBinding>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.IO.FileSystem.Primitives" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.2.0" newVersion="4.0.2.0" />
</dependentAssembly>
</assemblyBinding>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Xml.XPath.XDocument" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.2.0" newVersion="4.0.2.0" />
</dependentAssembly>
</assemblyBinding>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Security.Cryptography.Primitives" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.1.0" newVersion="4.0.1.0" />
</dependentAssembly>
</assemblyBinding>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Collections.Immutable" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-1.2.1.0" newVersion="1.2.1.0" />
</dependentAssembly>
</assemblyBinding>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.IO.FileSystem" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.2.0" newVersion="4.0.2.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
<appSettings>
<!-- Number of seconds with no activity before the server times out and closes.
Set to -1 to never shut down the server. -->
<add key="keepalive" value="600"/>
<add key="keepalive" value="600" />
</appSettings>
</configuration>
Binary file not shown.

Some files were not shown because too many files have changed in this diff Show More