Skip to content

Commit

Permalink
Merging 0.22.1 hotfix
Browse files Browse the repository at this point in the history
  • Loading branch information
tmm360 committed May 21, 2021
2 parents 38ea2c8 + b14e308 commit 8626369
Show file tree
Hide file tree
Showing 37 changed files with 156 additions and 56 deletions.
8 changes: 8 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,11 @@ indent_size = 2
# C# files
[*.cs]

# CA1031: Do not catch general exception types
dotnet_diagnostic.CA1031.severity = none

# CA1040: Avoid empty interfaces
dotnet_diagnostic.CA1040.severity = none # Sometime they are needed

# CA1812: Avoid uninstantiated internal classes
dotnet_diagnostic.CA1812.severity = none # Doing extensive use of dependency injection
2 changes: 1 addition & 1 deletion src/ExecutionContext/AsyncLocal/AsyncLocalContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ namespace Etherna.ExecContext.AsyncLocal
public class AsyncLocalContext : IAsyncLocalContext, IHandledAsyncLocalContext
{
// Fields.
private static readonly AsyncLocal<IDictionary<object, object?>?> asyncLocalContext = new AsyncLocal<IDictionary<object, object?>?>();
private static readonly AsyncLocal<IDictionary<object, object?>?> asyncLocalContext = new();

// Properties.
public IDictionary<object, object?>? Items => asyncLocalContext.Value;
Expand Down
2 changes: 1 addition & 1 deletion src/ExecutionContext/ExecutionContext.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="GitVersionTask" Version="5.5.1">
<PackageReference Include="GitVersion.MsBuild" Version="5.6.9">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
2 changes: 2 additions & 0 deletions src/ExecutionContext/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
// See the License for the specific language governing permissions and
// limitations under the License.

using System;
using System.Runtime.CompilerServices;

[assembly: CLSCompliant(false)]
[assembly: InternalsVisibleTo("DynamicProxyGenAssembly2")]
[assembly: InternalsVisibleTo("ExecutionContext.Tests")]
2 changes: 1 addition & 1 deletion src/MongODM.AspNetCore.UI/MongODM.AspNetCore.UI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="GitVersionTask" Version="5.5.1">
<PackageReference Include="GitVersion.MsBuild" Version="5.6.9">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
3 changes: 3 additions & 0 deletions src/MongODM.AspNetCore.UI/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
using System;

[assembly: CLSCompliant(false)]
2 changes: 1 addition & 1 deletion src/MongODM.AspNetCore/MongODM.AspNetCore.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="GitVersionTask" Version="5.5.1">
<PackageReference Include="GitVersion.MsBuild" Version="5.6.9">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
2 changes: 1 addition & 1 deletion src/MongODM.Core/Domain/Models/DbMigrationOperation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public enum Status
}

// Fields.
private List<MigrationLogBase> _logs = new List<MigrationLogBase>();
private List<MigrationLogBase> _logs = new();

// Constructors.
public DbMigrationOperation(IDbContext dbContext)
Expand Down
2 changes: 2 additions & 0 deletions src/MongODM.Core/Domain/Models/ModelBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@
// limitations under the License.

using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;

namespace Etherna.MongODM.Core.Domain.Models
{
public abstract class ModelBase : IModel
{
[SuppressMessage("Usage", "CA2227:Collection properties should be read only", Justification = "This is needed by MongoDB drivers")]
public virtual IDictionary<string, object>? ExtraElements { get; protected set; }
}
}
4 changes: 2 additions & 2 deletions src/MongODM.Core/Migration/MigrationResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ private MigrationResult() { }

// Methods.
public static MigrationResult Failed() =>
new MigrationResult
new()
{
Succeded = false
};

public static MigrationResult Succeeded(long migratedDocuments) =>
new MigrationResult
new()
{
Succeded = true,
MigratedDocuments = migratedDocuments
Expand Down
2 changes: 1 addition & 1 deletion src/MongODM.Core/MongODM.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

<ItemGroup>
<PackageReference Include="Castle.Core" Version="4.4.1" />
<PackageReference Include="GitVersionTask" Version="5.5.1">
<PackageReference Include="GitVersion.MsBuild" Version="5.6.9">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
20 changes: 16 additions & 4 deletions src/MongODM.Core/MongODMConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,28 @@ namespace Etherna.MongODM.Core
public abstract class MongODMConfiguration : IMongODMConfiguration, IDisposable
{
// Fields.
private readonly ReaderWriterLockSlim configLock = new ReaderWriterLockSlim(LockRecursionPolicy.SupportsRecursion);
private readonly List<Type> _dbContextTypes = new List<Type>();
private readonly ReaderWriterLockSlim configLock = new(LockRecursionPolicy.SupportsRecursion);
private bool disposed;
private readonly List<Type> _dbContextTypes = new();

// Constructor and dispose.
// Dispose.
public void Dispose()
{
configLock.Dispose();
Dispose(true);
GC.SuppressFinalize(this);
}

protected virtual void Dispose(bool disposing)
{
if (disposed) return;

// Dispose managed resources.
if (disposing)
configLock.Dispose();

disposed = true;
}

// Properties.
public IEnumerable<Type> DbContextTypes
{
Expand Down
3 changes: 3 additions & 0 deletions src/MongODM.Core/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
using System;

[assembly: CLSCompliant(false)]
2 changes: 1 addition & 1 deletion src/MongODM.Core/ProxyModels/AuditableInterceptor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public class AuditableInterceptor<TModel> : ModelInterceptorBase<TModel>
{
// Fields.
private bool isAuditingEnabled;
private readonly HashSet<MemberInfo> changedMembers = new HashSet<MemberInfo>();
private readonly HashSet<MemberInfo> changedMembers = new();

// Constructors.
public AuditableInterceptor(IEnumerable<Type> additionalInterfaces)
Expand Down
38 changes: 26 additions & 12 deletions src/MongODM.Core/ProxyModels/ProxyGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@ namespace Etherna.MongODM.Core.ProxyModels
public class ProxyGenerator : IProxyGenerator, IDisposable
{
// Fields.
private bool disposed;
private readonly Castle.DynamicProxy.IProxyGenerator proxyGeneratorCore;

private readonly Dictionary<Type,
(Type[] AdditionalInterfaces, Func<IDbContext, IInterceptor[]> InterceptorInstancerSelector)> modelConfigurationDictionary =
new Dictionary<Type, (Type[] AdditionalInterfaces, Func<IDbContext, IInterceptor[]> InterceptorInstancerSelector)>();
private readonly ReaderWriterLockSlim modelConfigurationDictionaryLock = new ReaderWriterLockSlim(LockRecursionPolicy.SupportsRecursion);
(Type[] AdditionalInterfaces, Func<IDbContext, IInterceptor[]> InterceptorInstancerSelector)> modelConfigurationDictionary = new();
private readonly ReaderWriterLockSlim modelConfigurationDictionaryLock = new(LockRecursionPolicy.SupportsRecursion);

private readonly Dictionary<Type, Type> proxyTypeDictionary = new Dictionary<Type, Type>();
private readonly ReaderWriterLockSlim proxyTypeDictionaryLock = new ReaderWriterLockSlim(LockRecursionPolicy.SupportsRecursion);
private readonly Dictionary<Type, Type> proxyTypeDictionary = new();
private readonly ReaderWriterLockSlim proxyTypeDictionaryLock = new(LockRecursionPolicy.SupportsRecursion);

// Constructors.
public ProxyGenerator(
Expand All @@ -41,6 +41,27 @@ public ProxyGenerator(
this.proxyGeneratorCore = proxyGeneratorCore;
}

// Dispose.
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}

protected virtual void Dispose(bool disposing)
{
if (disposed) return;

// Dispose managed resources.
if (disposing)
{
modelConfigurationDictionaryLock.Dispose();
proxyTypeDictionaryLock.Dispose();
}

disposed = true;
}

// Methods.
public object CreateInstance(
Type type,
Expand Down Expand Up @@ -133,13 +154,6 @@ public object CreateInstance(
public TModel CreateInstance<TModel>(IDbContext dbContext, params object[] constructorArguments) =>
(TModel)CreateInstance(typeof(TModel), dbContext, constructorArguments);

public void Dispose()
{
modelConfigurationDictionaryLock.Dispose();
proxyTypeDictionaryLock.Dispose();
GC.SuppressFinalize(this);
}

public bool IsProxyType(Type type)
{
proxyTypeDictionaryLock.EnterReadLock();
Expand Down
2 changes: 1 addition & 1 deletion src/MongODM.Core/ProxyModels/ReferenceableInterceptor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public class ReferenceableInterceptor<TModel, TKey> : ModelInterceptorBase<TMode
{
// Fields.
private bool isSummary;
private readonly Dictionary<string, bool> settedMemberNames = new Dictionary<string, bool>(); //<memberName, isFromSummary>
private readonly Dictionary<string, bool> settedMemberNames = new(); //<memberName, isFromSummary>
private readonly IRepository repository;

// Constructors.
Expand Down
4 changes: 2 additions & 2 deletions src/MongODM.Core/ReflectionHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ namespace Etherna.MongODM.Core
{
public static class ReflectionHelper
{
private static readonly Dictionary<Type, IEnumerable<PropertyInfo>> propertyRegister = new Dictionary<Type, IEnumerable<PropertyInfo>>();
private static readonly ReaderWriterLockSlim propertyRegisterLock = new ReaderWriterLockSlim();
private static readonly Dictionary<Type, IEnumerable<PropertyInfo>> propertyRegister = new();
private static readonly ReaderWriterLockSlim propertyRegisterLock = new();

public static MemberInfo FindProperty(LambdaExpression lambdaExpression)
{
Expand Down
2 changes: 1 addition & 1 deletion src/MongODM.Core/Serialization/Mapping/MemberDependency.cs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ public string MemberPathToString() =>

public override string ToString()
{
StringBuilder strBuilder = new StringBuilder();
StringBuilder strBuilder = new();

strBuilder.AppendLine(FullPathToString());
strBuilder.AppendLine($" modelMapId: {RootModelMap.Id}");
Expand Down
14 changes: 7 additions & 7 deletions src/MongODM.Core/Serialization/Mapping/SchemaRegister.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
using MongoDB.Bson.Serialization;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Reflection;
using System.Text;
Expand Down Expand Up @@ -66,21 +67,18 @@ public ICustomSerializerSchemaBuilder<TModel> AddCustomSerializerSchema<TModel>(
return modelSchemaConfiguration;
});

[SuppressMessage("Reliability", "CA2000:Dispose objects before losing scope", Justification = "The new model map instance can't be disposed")]
public IModelMapsSchemaBuilder<TModel> AddModelMapsSchema<TModel>(
string activeModelMapId,
Action<BsonClassMap<TModel>>? activeModelMapInitializer = null,
IBsonSerializer<TModel>? customSerializer = null) where TModel : class
{
// Verify if needs a default serializer.
if (!typeof(TModel).IsAbstract)
customSerializer ??= ModelMap.GetDefaultSerializer<TModel>(dbContext);

// Create model map.
var modelMap = new ModelMap<TModel>(
activeModelMapId,
new BsonClassMap<TModel>(activeModelMapInitializer ?? (cm => cm.AutoMap())),
null,
customSerializer);
customSerializer ?? ModelMap.GetDefaultSerializer<TModel>(dbContext));

return AddModelMapsSchema(modelMap);
}
Expand Down Expand Up @@ -158,7 +156,7 @@ public IModelMapsSchema GetModelMapsSchema(Type modelType)

public override string ToString()
{
StringBuilder strBuilder = new StringBuilder();
StringBuilder strBuilder = new();

// Member dependencies.
//memberInfoToMemberMapsDictionary
Expand Down Expand Up @@ -308,7 +306,9 @@ private void CompileDependencyRegisters(
//model maps schema serializers
if (memberSerializer is IModelMapsContainerSerializer schemaSerializer)
{
var useCascadeDelete = (memberSerializer as IReferenceContainerSerializer)?.UseCascadeDelete;
#pragma warning disable CA1508 // Avoid dead conditional code. Here code analyzer is wrong
bool? useCascadeDelete = (memberSerializer as IReferenceContainerSerializer)?.UseCascadeDelete;
#pragma warning restore CA1508 // Avoid dead conditional code
foreach (var childClassMap in schemaSerializer.AllChildClassMaps)
CompileDependencyRegisters(modelMap, childClassMap, lastEntityClassMap, currentMemberPath, useCascadeDelete);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

using MongoDB.Bson.Serialization;
using System;
using System.Diagnostics.CodeAnalysis;

namespace Etherna.MongODM.Core.Serialization.Mapping.Schemas
{
Expand All @@ -34,6 +35,7 @@ public IModelMapsSchemaBuilder<TModel> AddFallbackCustomSerializer(IBsonSerializ
return this;
}

[SuppressMessage("Reliability", "CA2000:Dispose objects before losing scope", Justification = "The new model map instance can't be disposed")]
public IModelMapsSchemaBuilder<TModel> AddSecondaryMap(
string id,
Action<BsonClassMap<TModel>>? modelMapInitializer = null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ abstract class ModelMapsSchemaBase : SchemaBase, IModelMapsSchema
{
// Fields.
private Dictionary<string, IModelMap> _allMapsDictionary = default!;
protected readonly List<IModelMap> _secondaryMaps = new List<IModelMap>();
protected readonly List<IModelMap> _secondaryMaps = new();

// Constructor.
protected ModelMapsSchemaBase(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

using MongoDB.Bson.Serialization;
using System;
using System.Diagnostics.CodeAnalysis;

namespace Etherna.MongODM.Core.Serialization.Mapping.Schemas
{
Expand All @@ -33,6 +34,7 @@ public IReferenceModelMapsSchemaBuilder<TModel> AddFallbackCustomSerializer(IBso
return this;
}

[SuppressMessage("Reliability", "CA2000:Dispose objects before losing scope", Justification = "The new model map instance can't be disposed")]
public IReferenceModelMapsSchemaBuilder<TModel> AddSecondaryMap(
string id,
string? baseModelMapId = null,
Expand Down
4 changes: 3 additions & 1 deletion src/MongODM.Core/Serialization/SemanticVersion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,8 @@ public override string ToString()

public static bool operator >=(SemanticVersion x, SemanticVersion y) => y <= x;

public static implicit operator SemanticVersion(string version) => new SemanticVersion(version);
public static implicit operator SemanticVersion(string version) => new(version);

public static SemanticVersion FromString(string version) => new(version);
}
}
Loading

0 comments on commit 8626369

Please sign in to comment.