Browse Source

Refactore seq extensions (#815)

* refactored foreach

* use of switch insted of ifs
pull/840/head
Marvin Huber 6 years ago
committed by GitHub
parent
commit
0b043fcb35
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 50
      src/Microsoft.Tye.Extensions/Seq/SeqExtensions.cs

50
src/Microsoft.Tye.Extensions/Seq/SeqExtensions.cs

@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System;
using System.Linq;
using System.Threading.Tasks;
@ -47,39 +48,48 @@ namespace Microsoft.Tye.Extensions.Seq
seq.Volumes.Add(new VolumeBuilder(logPath, "seq-data", "/data"));
}
foreach (var s in context.Application.Services)
foreach (var serviceBuilder in context.Application.Services)
{
if (object.ReferenceEquals(s, seq))
if (ReferenceEquals(serviceBuilder, seq))
{
continue;
}
// make seq available as a dependency of everything.
if (!s.Dependencies.Contains(seq.Name))
if (!serviceBuilder.Dependencies.Contains(seq.Name))
{
s.Dependencies.Add(seq.Name);
serviceBuilder.Dependencies.Add(seq.Name);
}
}
}
if (context.Operation == ExtensionContext.OperationKind.LocalRun)
switch (context.Operation)
{
if (context.Options!.LoggingProvider is null)
{
// For local development we hardcode the port and hostname
context.Options.LoggingProvider = "seq=http://localhost:5341";
}
}
else if (context.Operation == ExtensionContext.OperationKind.Deploy)
{
foreach (var project in context.Application.Services.OfType<DotnetProjectServiceBuilder>())
{
var sidecar = DiagnosticAgent.GetOrAddSidecar(project);
case ExtensionContext.OperationKind.LocalRun:
{
if (context.Options!.LoggingProvider is null)
{
// For local development we hardcode the port and hostname
context.Options.LoggingProvider = "seq=http://localhost:5341";
}
// Use service discovery to find seq
sidecar.Args.Add("--provider:seq=service:seq");
sidecar.Dependencies.Add("seq");
}
break;
}
case ExtensionContext.OperationKind.Deploy:
{
foreach (var project in context.Application.Services.OfType<DotnetProjectServiceBuilder>())
{
var sidecar = DiagnosticAgent.GetOrAddSidecar(project);
// Use service discovery to find seq
sidecar.Args.Add("--provider:seq=service:seq");
sidecar.Dependencies.Add("seq");
}
break;
}
default:
throw new ArgumentOutOfRangeException();
}
return Task.CompletedTask;

Loading…
Cancel
Save