From 0b043fcb354d6d195846276fcd53326375f4cdcc Mon Sep 17 00:00:00 2001 From: Marvin Huber Date: Tue, 1 Dec 2020 18:46:22 +0100 Subject: [PATCH] Refactore seq extensions (#815) * refactored foreach * use of switch insted of ifs --- .../Seq/SeqExtensions.cs | 50 +++++++++++-------- 1 file changed, 30 insertions(+), 20 deletions(-) diff --git a/src/Microsoft.Tye.Extensions/Seq/SeqExtensions.cs b/src/Microsoft.Tye.Extensions/Seq/SeqExtensions.cs index d259c98c..b9d28a51 100644 --- a/src/Microsoft.Tye.Extensions/Seq/SeqExtensions.cs +++ b/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()) - { - 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()) + { + 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;