Skip to content

Commit

Permalink
CSharpier format
Browse files Browse the repository at this point in the history
  • Loading branch information
gstraccini[bot] committed Jan 22, 2024
1 parent 553d3f0 commit 93a85e1
Show file tree
Hide file tree
Showing 7 changed files with 114 additions and 162 deletions.
20 changes: 8 additions & 12 deletions Src/CrispyWaffle.ElasticSearch/Helpers/Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ public static T Alias<T>(this T index, string alias, string indexName = null)
indexName = GetIndexName<T>();
}

_connector.Client.Indices.BulkAlias(
a => a.Add(add => add.Index(indexName).Alias(alias))
_connector.Client.Indices.BulkAlias(a =>

Check warning on line 67 in Src/CrispyWaffle.ElasticSearch/Helpers/Extensions.cs

View check run for this annotation

Codecov / codecov/patch

Src/CrispyWaffle.ElasticSearch/Helpers/Extensions.cs#L67

Added line #L67 was not covered by tests
a.Add(add => add.Index(indexName).Alias(alias))
);
return index;
}
Expand Down Expand Up @@ -126,17 +126,13 @@ int daysBefore
)
where T : class, new()
{
var result = _connector.Client.DeleteByQuery<T>(
d =>
d.Index(indexPattern)
.Query(
q =>
q.DateRange(
g =>
g.Field(field)
.LessThan(DateMath.Now.Subtract($@"{daysBefore}d"))
)
var result = _connector.Client.DeleteByQuery<T>(d =>

Check warning on line 129 in Src/CrispyWaffle.ElasticSearch/Helpers/Extensions.cs

View check run for this annotation

Codecov / codecov/patch

Src/CrispyWaffle.ElasticSearch/Helpers/Extensions.cs#L129

Added line #L129 was not covered by tests
d.Index(indexPattern)
.Query(q =>

Check warning on line 131 in Src/CrispyWaffle.ElasticSearch/Helpers/Extensions.cs

View check run for this annotation

Codecov / codecov/patch

Src/CrispyWaffle.ElasticSearch/Helpers/Extensions.cs#L131

Added line #L131 was not covered by tests
q.DateRange(g =>
g.Field(field).LessThan(DateMath.Now.Subtract($@"{daysBefore}d"))

Check warning on line 133 in Src/CrispyWaffle.ElasticSearch/Helpers/Extensions.cs

View check run for this annotation

Codecov / codecov/patch

Src/CrispyWaffle.ElasticSearch/Helpers/Extensions.cs#L133

Added line #L133 was not covered by tests
)
)

Check warning on line 135 in Src/CrispyWaffle.ElasticSearch/Helpers/Extensions.cs

View check run for this annotation

Codecov / codecov/patch

Src/CrispyWaffle.ElasticSearch/Helpers/Extensions.cs#L135

Added line #L135 was not covered by tests
);

return result.Deleted;
Expand Down
17 changes: 7 additions & 10 deletions Src/CrispyWaffle.ElasticSearch/Log/ElasticSearchLogProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,17 +104,14 @@ private Task GarbageCollector()
}

var retentionDays = _logRetentionDays;
_client.DeleteByQuery<LogMessage>(
d =>
d.Index(_indexName)
.Query(
q =>
q.DateRange(
g =>
g.Field(f => f.Date)
.LessThan(DateMath.Now.Subtract($@"{retentionDays}d"))
)
_client.DeleteByQuery<LogMessage>(d =>

Check warning on line 107 in Src/CrispyWaffle.ElasticSearch/Log/ElasticSearchLogProvider.cs

View check run for this annotation

Codecov / codecov/patch

Src/CrispyWaffle.ElasticSearch/Log/ElasticSearchLogProvider.cs#L107

Added line #L107 was not covered by tests
d.Index(_indexName)
.Query(q =>

Check warning on line 109 in Src/CrispyWaffle.ElasticSearch/Log/ElasticSearchLogProvider.cs

View check run for this annotation

Codecov / codecov/patch

Src/CrispyWaffle.ElasticSearch/Log/ElasticSearchLogProvider.cs#L109

Added line #L109 was not covered by tests
q.DateRange(g =>
g.Field(f => f.Date)
.LessThan(DateMath.Now.Subtract($@"{retentionDays}d"))

Check warning on line 112 in Src/CrispyWaffle.ElasticSearch/Log/ElasticSearchLogProvider.cs

View check run for this annotation

Codecov / codecov/patch

Src/CrispyWaffle.ElasticSearch/Log/ElasticSearchLogProvider.cs#L111-L112

Added lines #L111 - L112 were not covered by tests
)
)

Check warning on line 114 in Src/CrispyWaffle.ElasticSearch/Log/ElasticSearchLogProvider.cs

View check run for this annotation

Codecov / codecov/patch

Src/CrispyWaffle.ElasticSearch/Log/ElasticSearchLogProvider.cs#L114

Added line #L114 was not covered by tests
);
return null;
}
Expand Down
4 changes: 2 additions & 2 deletions Src/CrispyWaffle.Elmah/ElmahExceptionHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ private void HandleInternal(Exception exception)
);

foreach (
var additionalProvider in _additionalProviders.Where(
p => p.Item2 == ExceptionLogType.Full
var additionalProvider in _additionalProviders.Where(p =>
p.Item2 == ExceptionLogType.Full
)
)
{
Expand Down
69 changes: 29 additions & 40 deletions Src/CrispyWaffle/Composition/ServiceLocator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,9 @@ static ServiceLocator()
TypesCache = AppDomain
.CurrentDomain.GetAssemblies()
.SelectMany(a => a.GetTypes())
.Where(
a =>
a != null
&& a.Name.IndexOf(@"_canon", StringComparison.InvariantCultureIgnoreCase)
== -1
.Where(a =>
a != null
&& a.Name.IndexOf(@"_canon", StringComparison.InvariantCultureIgnoreCase) == -1
)
.ToList();
var cancellationToken = typeof(CancellationToken);
Expand Down Expand Up @@ -526,13 +524,9 @@ private static ConstructorInfo ResolveMultipleConstructors(
)
{
var candidates = constructors
.Where(
c =>
c.GetParameters()
.All(
p =>
!p.ParameterType.IsSimpleType() && p.ParameterType != parentType
)
.Where(c =>
c.GetParameters()
.All(p => !p.ParameterType.IsSimpleType() && p.ParameterType != parentType)
)
.ToList();

Expand All @@ -545,22 +539,20 @@ private static ConstructorInfo ResolveMultipleConstructors(
default:
return candidates
.OrderByDescending(c => c.GetParameters().Length)
.First(
c =>
c.GetParameters()
.Select((p, i) => new { p.ParameterType, Index = i })
.All(
p =>
(
parentType == null
? GetInstance(p.ParameterType)
: GetInstanceWithContext(
p.ParameterType,
parentType,
p.Index
)
) != null
)
.First(c =>
c.GetParameters()
.Select((p, i) => new { p.ParameterType, Index = i })
.All(p =>
(
parentType == null
? GetInstance(p.ParameterType)
: GetInstanceWithContext(
p.ParameterType,
parentType,
p.Index
)
) != null
)
);
}
}
Expand All @@ -574,11 +566,10 @@ private static ConstructorInfo ResolveMultipleConstructors(
private static object TryAutoRegistration(Type type)
{
var types = TypesCache
.Where(
t =>
!t.IsAbstract
&& type.IsAssignableFrom(t)
&& t.GetConstructors().Any(c => !c.GetParameters().Any())
.Where(t =>
!t.IsAbstract
&& type.IsAssignableFrom(t)
&& t.GetConstructors().Any(c => !c.GetParameters().Any())
)
.ToList();
if (types.Count == 0)
Expand Down Expand Up @@ -713,13 +704,11 @@ public static void DisposeAllRegistrations()
var type = typeof(IDisposable);
var instances = _registrationsCalls
.Where(call => call.Value > 0)
.SelectMany(
call =>
_registrations.Where(
implementation =>
type.IsAssignableFrom(implementation.Key)
&& call.Key.IsAssignableFrom(implementation.Key)
)
.SelectMany(call =>
_registrations.Where(implementation =>

Check warning on line 708 in Src/CrispyWaffle/Composition/ServiceLocator.cs

View check run for this annotation

Codecov / codecov/patch

Src/CrispyWaffle/Composition/ServiceLocator.cs#L707-L708

Added lines #L707 - L708 were not covered by tests
type.IsAssignableFrom(implementation.Key)
&& call.Key.IsAssignableFrom(implementation.Key)
)

Check warning on line 711 in Src/CrispyWaffle/Composition/ServiceLocator.cs

View check run for this annotation

Codecov / codecov/patch

Src/CrispyWaffle/Composition/ServiceLocator.cs#L710-L711

Added lines #L710 - L711 were not covered by tests
)
.ToList();

Expand Down
60 changes: 26 additions & 34 deletions Src/CrispyWaffle/Extensions/EnumExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,26 +29,22 @@ public static T GetEnumByHumanReadableAttribute<T>(string humanReadableValue)
}

var field = type.GetFields()
.Select(
f =>
new
{
Field = f,
Attr = Attribute.GetCustomAttribute(f, typeof(HumanReadableAttribute))
as HumanReadableAttribute
}
)
.Where(
item =>
item.Attr != null
&& item.Attr.StringValue.Equals(
humanReadableValue,
StringComparison.OrdinalIgnoreCase
)
|| item.Field.Name.Equals(
.Select(f => new
{
Field = f,
Attr = Attribute.GetCustomAttribute(f, typeof(HumanReadableAttribute))
as HumanReadableAttribute
})
.Where(item =>
item.Attr != null
&& item.Attr.StringValue.Equals(
humanReadableValue,
StringComparison.OrdinalIgnoreCase
)
|| item.Field.Name.Equals(
humanReadableValue,
StringComparison.OrdinalIgnoreCase
)
)
.Select(item => item.Field)
.SingleOrDefault();
Expand Down Expand Up @@ -86,23 +82,19 @@ public static T GetEnumByInternalValueAttribute<T>(string internalValue)
}

var field = type.GetFields()
.Select(
f =>
new
{
Field = f,
Attr = Attribute.GetCustomAttribute(f, typeof(InternalValueAttribute))
as InternalValueAttribute
}
)
.Where(
item =>
item.Attr != null
&& item.Attr.InternalValue.Equals(
internalValue,
StringComparison.OrdinalIgnoreCase
)
|| item.Field.Name.Equals(internalValue, StringComparison.OrdinalIgnoreCase)
.Select(f => new
{
Field = f,
Attr = Attribute.GetCustomAttribute(f, typeof(InternalValueAttribute))
as InternalValueAttribute
})
.Where(item =>
item.Attr != null
&& item.Attr.InternalValue.Equals(
internalValue,
StringComparison.OrdinalIgnoreCase
)
|| item.Field.Name.Equals(internalValue, StringComparison.OrdinalIgnoreCase)
)
.Select(item => item.Field)
.SingleOrDefault();
Expand Down
4 changes: 2 additions & 2 deletions Src/CrispyWaffle/Log/Handlers/DefaultExceptionHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,8 @@ private static void HandleInternal(Exception exception)
);

foreach (
var additionalProvider in _additionalProviders.Where(
p => p.Item2 == ExceptionLogType.Full
var additionalProvider in _additionalProviders.Where(p =>
p.Item2 == ExceptionLogType.Full

Check warning on line 125 in Src/CrispyWaffle/Log/Handlers/DefaultExceptionHandler.cs

View check run for this annotation

Codecov / codecov/patch

Src/CrispyWaffle/Log/Handlers/DefaultExceptionHandler.cs#L125

Added line #L125 was not covered by tests
)
)
{
Expand Down
Loading

0 comments on commit 93a85e1

Please sign in to comment.