Browse Source

Refactore seq extensions (#815)

* refactored foreach

* use of switch insted of ifs
finitereality/replica-status-colors
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. // The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information. // See the LICENSE file in the project root for more information.
using System;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
@ -47,39 +48,48 @@ namespace Microsoft.Tye.Extensions.Seq
seq.Volumes.Add(new VolumeBuilder(logPath, "seq-data", "/data")); 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; continue;
} }
// make seq available as a dependency of everything. // 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) case ExtensionContext.OperationKind.LocalRun:
{ {
// For local development we hardcode the port and hostname if (context.Options!.LoggingProvider is null)
context.Options.LoggingProvider = "seq=http://localhost:5341"; {
} // 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);
// Use service discovery to find seq break;
sidecar.Args.Add("--provider:seq=service:seq"); }
sidecar.Dependencies.Add("seq"); 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; return Task.CompletedTask;

Loading…
Cancel
Save