Browse Source

Nullable fixes.

pull/502/head
Sebastian 6 years ago
parent
commit
59f87bb49b
  1. 4
      backend/src/Squidex.Domain.Apps.Entities/Apps/Indexes/AppsIndex.cs
  2. 2
      backend/src/Squidex.Domain.Apps.Entities/Contents/GraphQL/Types/Extensions.cs
  3. 4
      backend/src/Squidex.Domain.Apps.Entities/Contents/Queries/QueryExecutionContext.cs
  4. 2
      backend/src/Squidex.Domain.Apps.Entities/Rules/Guards/RuleTriggerValidator.cs
  5. 2
      backend/src/Squidex.Domain.Apps.Entities/Rules/Indexes/RulesIndex.cs
  6. 2
      backend/src/Squidex.Domain.Apps.Entities/Schemas/Indexes/SchemasIndex.cs
  7. 28
      backend/src/Squidex.Infrastructure.Azure/EventSourcing/CosmosDbSubscription.cs
  8. 21
      backend/src/Squidex.Infrastructure/CollectionExtensions.cs
  9. 2
      backend/src/Squidex.Infrastructure/Queries/Optimizer.cs
  10. 2
      backend/src/Squidex.Infrastructure/Queries/TransformVisitor.cs
  11. 3
      backend/tools/Migrate_01/MigrationPath.cs

4
backend/src/Squidex.Domain.Apps.Entities/Apps/Indexes/AppsIndex.cs

@ -80,7 +80,7 @@ namespace Squidex.Domain.Apps.Entities.Apps.Indexes
await Task.WhenAll(ids
.Select(GetAppAsync));
return apps.Where(x => x != null).ToList();
return apps.NotNull().ToList();
}
}
@ -98,7 +98,7 @@ namespace Squidex.Domain.Apps.Entities.Apps.Indexes
.SelectMany(x => x).Distinct()
.Select(GetAppAsync));
return apps.Where(x => x != null).ToList();
return apps.NotNull().ToList();
}
}

2
backend/src/Squidex.Domain.Apps.Entities/Contents/GraphQL/Types/Extensions.cs

@ -44,7 +44,7 @@ namespace Squidex.Domain.Apps.Entities.Contents.GraphQL.Types
{
var contents = await Task.WhenAll(keys.Select(dataLoader.LoadAsync));
return contents.Where(x => x != null).ToList();
return contents.NotNull().ToList();
}
}
}

4
backend/src/Squidex.Domain.Apps.Entities/Contents/Queries/QueryExecutionContext.cs

@ -113,7 +113,7 @@ namespace Squidex.Domain.Apps.Entities.Contents.Queries
}
}
return ids.Select(cachedAssets.GetOrDefault).Where(x => x != null).ToList();
return ids.Select(cachedAssets.GetOrDefault).NotNull().ToList();
}
public virtual async Task<IReadOnlyList<IContentEntity>> GetReferencedContentsAsync(ICollection<Guid> ids)
@ -132,7 +132,7 @@ namespace Squidex.Domain.Apps.Entities.Contents.Queries
}
}
return ids.Select(cachedContents.GetOrDefault).Where(x => x != null).ToList();
return ids.Select(cachedContents.GetOrDefault).NotNull().ToList();
}
}
}

2
backend/src/Squidex.Domain.Apps.Entities/Rules/Guards/RuleTriggerValidator.cs

@ -90,7 +90,7 @@ namespace Squidex.Domain.Apps.Entities.Rules.Guards
var checkErrors = await Task.WhenAll(tasks);
errors.AddRange(checkErrors.Where(x => x != null));
errors.AddRange(checkErrors.NotNull());
}
return errors;

2
backend/src/Squidex.Domain.Apps.Entities/Rules/Indexes/RulesIndex.cs

@ -43,7 +43,7 @@ namespace Squidex.Domain.Apps.Entities.Rules.Indexes
await Task.WhenAll(
ids.Select(GetRuleAsync));
return rules.Where(x => x != null).ToList();
return rules.NotNull().ToList();
}
}

2
backend/src/Squidex.Domain.Apps.Entities/Schemas/Indexes/SchemasIndex.cs

@ -44,7 +44,7 @@ namespace Squidex.Domain.Apps.Entities.Schemas.Indexes
await Task.WhenAll(
ids.Select(id => GetSchemaAsync(appId, id, allowDeleted)));
return schemas.Where(x => x != null).ToList();
return schemas.NotNull().ToList();
}
}

28
backend/src/Squidex.Infrastructure.Azure/EventSourcing/CosmosDbSubscription.cs

@ -56,22 +56,10 @@ namespace Squidex.Infrastructure.EventSourcing
{
try
{
Collection CreateCollection(string name)
{
var collection = new Collection();
collection.CollectionName = name;
collection.DatabaseName = store.DatabaseId;
collection.MasterKey = store.MasterKey;
collection.Uri = store.ServiceUri;
return collection;
}
var processor =
await new Builder()
.WithFeedCollection(CreateCollection(Constants.Collection))
.WithLeaseCollection(CreateCollection(Constants.LeaseCollection))
.WithFeedCollection(CreateCollection(store, Constants.Collection))
.WithLeaseCollection(CreateCollection(store, Constants.LeaseCollection))
.WithHostName(hostName)
.WithProcessorOptions(new Options { StartFromBeginning = fromBeginning, LeasePrefix = hostName })
.WithObserverFactory(this)
@ -88,6 +76,18 @@ namespace Squidex.Infrastructure.EventSourcing
});
}
private static Collection CreateCollection(CosmosDbEventStore store, string name)
{
var collection = new Collection();
collection.CollectionName = name;
collection.DatabaseName = store.DatabaseId;
collection.MasterKey = store.MasterKey;
collection.Uri = store.ServiceUri;
return collection;
}
public IChangeFeedObserver CreateObserver()
{
return this;

21
backend/src/Squidex.Infrastructure/CollectionExtensions.cs

@ -30,7 +30,7 @@ namespace Squidex.Infrastructure
public static IEnumerable<T> SortList<T, TKey>(this IEnumerable<T> input, Func<T, TKey> idProvider, IReadOnlyList<TKey> ids) where T : class
{
return ids.Select(id => input.FirstOrDefault(x => Equals(idProvider(x), id))).Where(x => x != null);
return ids.Select(id => input.FirstOrDefault(x => Equals(idProvider(x), id))).NotNull();
}
public static IEnumerable<T> Duplicates<T>(this IEnumerable<T> input)
@ -80,6 +80,11 @@ namespace Squidex.Infrastructure
return source ?? Enumerable.Empty<T>();
}
public static IEnumerable<T> NotNull<T>(this IEnumerable<T?> source) where T : class
{
return source.Where(x => x != null)!;
}
public static IEnumerable<T> Concat<T>(this IEnumerable<T> source, T value)
{
return source.Concat(Enumerable.Repeat(value, 1));
@ -261,7 +266,7 @@ namespace Squidex.Infrastructure
}
}
public sealed class KeyValuePairComparer<TKey, TValue> : IEqualityComparer<KeyValuePair<TKey, TValue>>
public sealed class KeyValuePairComparer<TKey, TValue> : IEqualityComparer<KeyValuePair<TKey, TValue>> where TKey : notnull
{
private readonly IEqualityComparer<TKey> keyComparer;
private readonly IEqualityComparer<TValue> valueComparer;
@ -279,7 +284,17 @@ namespace Squidex.Infrastructure
public int GetHashCode(KeyValuePair<TKey, TValue> obj)
{
return keyComparer.GetHashCode(obj.Key) ^ valueComparer.GetHashCode(obj.Value);
return keyComparer.GetHashCode(obj.Key) ^ ValueHashCode(obj);
}
private int ValueHashCode(KeyValuePair<TKey, TValue> obj)
{
if (Equals(obj.Value, null))
{
return 0;
}
return valueComparer.GetHashCode(obj.Value);
}
}
}

2
backend/src/Squidex.Infrastructure/Queries/Optimizer.cs

@ -24,7 +24,7 @@ namespace Squidex.Infrastructure.Queries
public override FilterNode<TValue>? Visit(LogicalFilter<TValue> nodeIn)
{
var pruned = nodeIn.Filters.Select(x => x.Accept(this)!).Where(x => x != null).ToList();
var pruned = nodeIn.Filters.Select(x => x.Accept(this)!).NotNull().ToList();
if (pruned.Count == 1)
{

2
backend/src/Squidex.Infrastructure/Queries/TransformVisitor.cs

@ -18,7 +18,7 @@ namespace Squidex.Infrastructure.Queries
public override FilterNode<TValue>? Visit(LogicalFilter<TValue> nodeIn)
{
var inner = nodeIn.Filters.Select(x => x.Accept(this)!).Where(x => x != null).ToList();
var inner = nodeIn.Filters.Select(x => x.Accept(this)!).NotNull().ToList();
return new LogicalFilter<TValue>(nodeIn.Type, inner);
}

3
backend/tools/Migrate_01/MigrationPath.cs

@ -11,6 +11,7 @@ using System.Linq;
using Microsoft.Extensions.DependencyInjection;
using Migrate_01.Migrations;
using Migrate_01.Migrations.MongoDb;
using Squidex.Infrastructure;
using Squidex.Infrastructure.Migrations;
namespace Migrate_01
@ -32,7 +33,7 @@ namespace Migrate_01
return (CurrentVersion, null);
}
var migrations = ResolveMigrators(version).Where(x => x != null).ToList();
var migrations = ResolveMigrators(version).NotNull().ToList();
return (CurrentVersion, migrations);
}

Loading…
Cancel
Save