Skip to content

Commit

Permalink
Code cleanup.
Browse files Browse the repository at this point in the history
  • Loading branch information
SebastianStehle committed Jan 9, 2019
1 parent 68e7cc7 commit 7e2fc6f
Show file tree
Hide file tree
Showing 68 changed files with 73 additions and 127 deletions.
4 changes: 2 additions & 2 deletions src/Squidex.Domain.Apps.Core.Model/Schemas/FieldCollection.cs
Expand Up @@ -90,7 +90,7 @@ protected override void OnCloned()
[Pure]
public FieldCollection<T> Remove(long fieldId)
{
if (!ById.TryGetValue(fieldId, out var field))
if (!ById.TryGetValue(fieldId, out _))
{
return this;
}
Expand Down Expand Up @@ -150,7 +150,7 @@ public FieldCollection<T> Update(long fieldId, Func<T, T> updater)
return this;
}

if (!(newField is T typedField))
if (!(newField is T))
{
throw new InvalidOperationException($"Field must be of type {typeof(T)}");
}
Expand Down
2 changes: 1 addition & 1 deletion src/Squidex.Domain.Apps.Core.Model/Schemas/Fields.cs
Expand Up @@ -13,7 +13,7 @@ public static class Fields
{
public static RootField<ArrayFieldProperties> Array(long id, string name, Partitioning partitioning, params NestedField[] fields)
{
return new ArrayField(id, name, partitioning, fields: fields);
return new ArrayField(id, name, partitioning, fields);
}

public static ArrayField Array(long id, string name, Partitioning partitioning, ArrayFieldProperties properties = null, IFieldSettings settings = null)
Expand Down
Expand Up @@ -8,7 +8,6 @@
using Newtonsoft.Json;
using Squidex.Infrastructure;
using System;
using System.Linq;
using P = Squidex.Domain.Apps.Core.Partitioning;

namespace Squidex.Domain.Apps.Core.Schemas.Json
Expand Down
Expand Up @@ -6,7 +6,6 @@
// ==========================================================================

using System;
using System.Linq;
using Newtonsoft.Json;
using Squidex.Infrastructure;

Expand Down
Expand Up @@ -73,7 +73,7 @@ public static FieldConverter ResolveAssetUrls(IReadOnlyCollection<string> fields

return (data, field) =>
{
if (field is IField<AssetsFieldProperties> assetField && (isAll || fields.Contains(field.Name)))
if (field is IField<AssetsFieldProperties> && (isAll || fields.Contains(field.Name)))
{
foreach (var partition in data)
{
Expand Down
Expand Up @@ -67,9 +67,9 @@ protected override bool Triggers(EnrichedContentEvent @event, ContentChangedTrig
return false;
}

private bool MatchsSchema(ContentChangedTriggerSchemaV2 schema, NamedId<Guid> @eventId)
private static bool MatchsSchema(ContentChangedTriggerSchemaV2 schema, NamedId<Guid> eventId)
{
return @eventId.Id == schema.SchemaId;
return eventId.Id == schema.SchemaId;
}

private bool MatchsCondition(ContentChangedTriggerSchemaV2 schema, EnrichedSchemaEvent @event)
Expand Down
Expand Up @@ -11,7 +11,7 @@ namespace Squidex.Domain.Apps.Core.Scripting.ContentWrapper
{
public abstract class CustomProperty : PropertyDescriptor
{
public CustomProperty()
protected CustomProperty()
: base(PropertyFlag.CustomJsValue)
{
Enumerable = true;
Expand Down
Expand Up @@ -229,7 +229,7 @@ private Engine CreateScriptEngine(IReferenceResolver resolver = null, Dictionary

private static Func<string> Safe(Func<string> func)
{
return new Func<string>(() =>
return () =>
{
try
{
Expand All @@ -239,7 +239,7 @@ private static Func<string> Safe(Func<string> func)
{
return "null";
}
});
};
}

private static JsValue Slugify(JsValue thisObject, JsValue[] arguments)
Expand Down
Expand Up @@ -49,7 +49,7 @@ protected override async Task SetupCollectionAsync(IMongoCollection<MongoContent
.Text(x => x.DataText)
.Ascending(x => x.IndexedSchemaId)
.Ascending(x => x.IsDeleted)
.Ascending(x => x.Status)),
.Ascending(x => x.Status))
}, ct);

await base.SetupCollectionAsync(collection, ct);
Expand Down
Expand Up @@ -50,7 +50,7 @@ public static FilterNode AdjustToModel(this FilterNode filterNode, Schema schema

private static Func<IReadOnlyList<string>, IReadOnlyList<string>> PathConverter(Schema schema, bool useDraft)
{
return new Func<IReadOnlyList<string>, IReadOnlyList<string>>(propertyNames =>
return propertyNames =>
{
var result = new List<string>(propertyNames);
Expand Down Expand Up @@ -91,7 +91,7 @@ public static FilterNode AdjustToModel(this FilterNode filterNode, Schema schema
}
return result;
});
};
}

public static IFindFluent<MongoContentEntity, MongoContentEntity> ContentSort(this IFindFluent<MongoContentEntity, MongoContentEntity> cursor, Query query)
Expand Down
Expand Up @@ -7,7 +7,6 @@

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using MongoDB.Driver;
Expand Down
10 changes: 3 additions & 7 deletions src/Squidex.Domain.Apps.Entities/Apps/BackupApps.cs
Expand Up @@ -15,7 +15,6 @@
using Squidex.Domain.Apps.Events.Apps;
using Squidex.Infrastructure;
using Squidex.Infrastructure.EventSourcing;
using Squidex.Infrastructure.Json;
using Squidex.Infrastructure.Json.Objects;
using Squidex.Infrastructure.Orleans;
using Squidex.Shared.Users;
Expand All @@ -28,7 +27,6 @@ public sealed class BackupApps : BackupHandler
private const string SettingsFile = "Settings.json";
private readonly IGrainFactory grainFactory;
private readonly IUserResolver userResolver;
private readonly IJsonSerializer serializer;
private readonly IAppsByNameIndex appsByNameIndex;
private readonly HashSet<string> contributors = new HashSet<string>();
private Dictionary<string, string> usersWithEmail = new Dictionary<string, string>();
Expand All @@ -38,14 +36,12 @@ public sealed class BackupApps : BackupHandler

public override string Name { get; } = "Apps";

public BackupApps(IGrainFactory grainFactory, IUserResolver userResolver, IJsonSerializer serializer)
public BackupApps(IGrainFactory grainFactory, IUserResolver userResolver)
{
Guard.NotNull(grainFactory, nameof(grainFactory));
Guard.NotNull(serializer, nameof(serializer));
Guard.NotNull(userResolver, nameof(userResolver));

this.grainFactory = grainFactory;
this.serializer = serializer;
this.userResolver = userResolver;

appsByNameIndex = grainFactory.GetGrain<IAppsByNameIndex>(SingleGrain.Id);
Expand Down Expand Up @@ -83,7 +79,7 @@ public override async Task<bool> RestoreEventAsync(Envelope<IEvent> @event, Guid
{
appName = appCreated.Name;

await ResolveUsersAsync(reader, actor);
await ResolveUsersAsync(reader);
await ReserveAppAsync(appId);

break;
Expand Down Expand Up @@ -148,7 +144,7 @@ private RefToken MapUser(string userId, RefToken fallback)
return userMapping.GetOrAdd(userId, fallback);
}

private async Task ResolveUsersAsync(BackupReader reader, RefToken actor)
private async Task ResolveUsersAsync(BackupReader reader)
{
await ReadUsersAsync(reader);

Expand Down
10 changes: 2 additions & 8 deletions src/Squidex.Domain.Apps.Entities/Assets/BackupAssets.cs
Expand Up @@ -9,7 +9,6 @@
using System.Collections.Generic;
using System.Threading.Tasks;
using Squidex.Domain.Apps.Core.Tags;
using Squidex.Domain.Apps.Entities.Assets.Repositories;
using Squidex.Domain.Apps.Entities.Assets.State;
using Squidex.Domain.Apps.Entities.Backup;
using Squidex.Domain.Apps.Events.Assets;
Expand All @@ -26,23 +25,18 @@ public sealed class BackupAssets : BackupHandlerWithStore
private const string TagsFile = "AssetTags.json";
private readonly HashSet<Guid> assetIds = new HashSet<Guid>();
private readonly IAssetStore assetStore;
private readonly IAssetRepository assetRepository;
private readonly ITagService tagService;

public override string Name { get; } = "Assets";

public BackupAssets(IStore<Guid> store,
IAssetStore assetStore,
IAssetRepository assetRepository,
ITagService tagService)
public BackupAssets(IStore<Guid> store, IAssetStore assetStore, ITagService tagService)
: base(store)
{
Guard.NotNull(assetStore, nameof(assetStore));
Guard.NotNull(assetRepository, nameof(assetRepository));
Guard.NotNull(tagService, nameof(tagService));

this.assetStore = assetStore;
this.assetRepository = assetRepository;

this.tagService = tagService;
}

Expand Down
Expand Up @@ -5,6 +5,7 @@
// All rights reserved. Licensed under the MIT license.
// ==========================================================================

using System.Globalization;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Squidex.Infrastructure.EventSourcing;
Expand Down Expand Up @@ -79,7 +80,7 @@ public static CompatibleEventData V1(EventData data)

public EventData ToData()
{
return new EventData(Type, Metadata, Payload.ToString());
return new EventData(Type, Metadata, Payload.ToString(CultureInfo.InvariantCulture));
}
}

Expand Down
Expand Up @@ -111,7 +111,7 @@ private static ScriptContext CreateScriptContext(object operation, ContentComman

private ValidationContext CreateValidationContext()
{
return new ValidationContext(contentId, schemaId, (sid, filterNode) => QueryContentsAsync(sid, filterNode), QueryAssetsAsync);
return new ValidationContext(contentId, schemaId, QueryContentsAsync, QueryAssetsAsync);
}

private async Task<IReadOnlyList<IAssetInfo>> QueryAssetsAsync(IEnumerable<Guid> assetIds)
Expand Down
Expand Up @@ -25,7 +25,6 @@
using Squidex.Infrastructure.Reflection;
using Squidex.Shared;
using Squidex.Shared.Identity;
using Squidex.Shared.Users;

#pragma warning disable RECS0147

Expand Down Expand Up @@ -275,7 +274,7 @@ public async Task<ISchemaEntity> GetSchemaAsync(QueryContext context, string sch
return schema;
}

private void CheckPermission(ISchemaEntity schema, ClaimsPrincipal user)
private static void CheckPermission(ISchemaEntity schema, ClaimsPrincipal user)
{
var permissions = user.Permissions();
var permission = Permissions.ForApp(Permissions.AppContentsRead, schema.AppId.Name, schema.Name);
Expand Down
2 changes: 1 addition & 1 deletion src/Squidex.Domain.Apps.Entities/Rules/EventEnricher.cs
Expand Up @@ -170,7 +170,7 @@ private Task<IUser> FindUserAsync(RefToken actor)
{
x.AbsoluteExpirationRelativeToNow = UserCacheDuration;
IUser user = null;
IUser user;
try
{
user = await userResolver.FindByIdOrEmailAsync(actor.Identifier);
Expand Down
7 changes: 1 addition & 6 deletions src/Squidex.Domain.Apps.Entities/Schemas/BackupSchemas.cs
Expand Up @@ -9,7 +9,6 @@
using System.Collections.Generic;
using System.Threading.Tasks;
using Orleans;
using Squidex.Domain.Apps.Core.Schemas;
using Squidex.Domain.Apps.Entities.Backup;
using Squidex.Domain.Apps.Entities.Schemas.Indexes;
using Squidex.Domain.Apps.Events.Schemas;
Expand All @@ -22,18 +21,14 @@ namespace Squidex.Domain.Apps.Entities.Schemas
public sealed class BackupSchemas : BackupHandler
{
private readonly Dictionary<string, Guid> schemasByName = new Dictionary<string, Guid>();
private readonly FieldRegistry fieldRegistry;
private readonly IGrainFactory grainFactory;

public override string Name { get; } = "Schemas";

public BackupSchemas(FieldRegistry fieldRegistry, IGrainFactory grainFactory)
public BackupSchemas(IGrainFactory grainFactory)
{
Guard.NotNull(fieldRegistry, nameof(fieldRegistry));
Guard.NotNull(grainFactory, nameof(grainFactory));

this.fieldRegistry = fieldRegistry;

this.grainFactory = grainFactory;
}

Expand Down
6 changes: 3 additions & 3 deletions src/Squidex.Domain.Users.MongoDb/MongoUserStore.cs
Expand Up @@ -141,7 +141,7 @@ public IQueryable<IdentityUser> Users

public bool IsId(string id)
{
return ObjectId.TryParse(id, out var _);
return ObjectId.TryParse(id, out _);
}

public IdentityUser Create(string email)
Expand Down Expand Up @@ -279,7 +279,7 @@ public Task<bool> GetTwoFactorEnabledAsync(IdentityUser user, CancellationToken

public Task<DateTimeOffset?> GetLockoutEndDateAsync(IdentityUser user, CancellationToken cancellationToken)
{
return Task.FromResult<DateTimeOffset?>(((MongoUser)user).LockoutEnd);
return Task.FromResult(((MongoUser)user).LockoutEnd);
}

public Task<int> GetAccessFailedCountAsync(IdentityUser user, CancellationToken cancellationToken)
Expand Down Expand Up @@ -309,7 +309,7 @@ public Task<bool> HasPasswordAsync(IdentityUser user, CancellationToken cancella

public Task<int> CountCodesAsync(IdentityUser user, CancellationToken cancellationToken)
{
return Task.FromResult(((MongoUser)user).GetToken(InternalLoginProvider, RecoveryCodeTokenName)?.Split(';')?.Length ?? 0);
return Task.FromResult(((MongoUser)user).GetToken(InternalLoginProvider, RecoveryCodeTokenName)?.Split(';').Length ?? 0);
}

public Task SetUserNameAsync(IdentityUser user, string userName, CancellationToken cancellationToken)
Expand Down
Expand Up @@ -49,7 +49,7 @@ public async Task InitializeAsync(CancellationToken ct = default(CancellationTok
throw new ConfigurationException("Cannot connect to event store.", ex);
}

await projectionClient.ConnectAsync();
await projectionClient.ConnectAsync(ct);
}

public IEventSubscription CreateSubscription(IEventSubscriber subscriber, string streamFilter, string position = null)
Expand Down
Expand Up @@ -5,7 +5,6 @@
// All rights reserved. Licensed under the MIT license.
// ==========================================================================

using MongoDB.Bson;
using MongoDB.Bson.Serialization.Attributes;
using Squidex.Infrastructure.MongoDb;

Expand Down
Expand Up @@ -89,7 +89,7 @@ public async Task<bool> DropCollectionIfExistsAsync(CancellationToken ct = defau
{
try
{
await mongoDatabase.DropCollectionAsync(CollectionName());
await mongoDatabase.DropCollectionAsync(CollectionName(), ct);

mongoCollection = CreateCollection();

Expand Down
2 changes: 1 addition & 1 deletion src/Squidex.Infrastructure/Diagnostics/GCHealthCheck.cs
Expand Up @@ -34,7 +34,7 @@ public Task<HealthCheckResult> CheckHealthAsync(HealthCheckContext context, Canc
{ "Allocated", allocated.ToReadableSize() },
{ "Gen0Collections", GC.CollectionCount(0) },
{ "Gen1Collections", GC.CollectionCount(1) },
{ "Gen2Collections", GC.CollectionCount(2) },
{ "Gen2Collections", GC.CollectionCount(2) }
};

var status = allocated < threshold ? HealthStatus.Healthy : HealthStatus.Unhealthy;
Expand Down
2 changes: 1 addition & 1 deletion src/Squidex.Infrastructure/IMigrated.cs
Expand Up @@ -7,7 +7,7 @@

namespace Squidex.Infrastructure
{
public interface IMigrated<T>
public interface IMigrated<out T>
{
T Migrate();
}
Expand Down
Expand Up @@ -38,7 +38,7 @@ public override object ReadJson(JsonReader reader, Type objectType, object exist
return ReadJson(reader);
}

private IJsonValue ReadJson(JsonReader reader)
private static IJsonValue ReadJson(JsonReader reader)
{
switch (reader.TokenType)
{
Expand Down Expand Up @@ -125,11 +125,11 @@ public override void WriteJson(JsonWriter writer, object value, JsonSerializer s
WriteJson(writer, (IJsonValue)value);
}

private void WriteJson(JsonWriter writer, IJsonValue value)
private static void WriteJson(JsonWriter writer, IJsonValue value)
{
switch (value)
{
case JsonNull n:
case JsonNull _:
writer.WriteNull();
break;
case JsonBoolean s:
Expand Down
6 changes: 4 additions & 2 deletions src/Squidex.Infrastructure/Log/Internal/FileLogProcessor.cs
Expand Up @@ -65,8 +65,10 @@ public void Initialize()

var fs = new FileStream(fileInfo.FullName, FileMode.Append, FileAccess.Write, FileShare.ReadWrite);

writer = new StreamWriter(fs, Encoding.UTF8);
writer.AutoFlush = true;
writer = new StreamWriter(fs, Encoding.UTF8)
{
AutoFlush = true
};

writer.WriteLine($"--- Started Logging {DateTime.UtcNow} ---", 1);
}
Expand Down

0 comments on commit 7e2fc6f

Please sign in to comment.