< Summary - CoreWCF Coverage — PR #1766

Information
Class: CoreWCF.Channels.NamedPipeTransportManager
Assembly: CoreWCF.NetNamedPipe
File(s): /home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.NetNamedPipe/src/CoreWCF/Channels/NamedPipeTransportManager.cs
Line coverage
0%
Covered lines: 0
Uncovered lines: 19
Coverable lines: 19
Total lines: 55
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 4
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Cyclomatic complexity NPath complexity Sequence coverage
.ctor(...)100%110%
BindAsync()0%220%
StopAsync()0%220%

File(s)

/home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.NetNamedPipe/src/CoreWCF/Channels/NamedPipeTransportManager.cs

#LineLine coverage
 1// Licensed to the .NET Foundation under one or more agreements.
 2// The .NET Foundation licenses this file to you under the MIT license.
 3
 4using System;
 5using System.Collections.Generic;
 6using System.Runtime.Versioning;
 7using System.Threading;
 8using System.Threading.Tasks;
 9using CoreWCF.Runtime;
 10using Microsoft.Extensions.Logging;
 11
 12namespace CoreWCF.Channels
 13{
 14    [SupportedOSPlatform("windows")]
 15    internal class NamedPipeTransportManager
 16    {
 17        private readonly ILogger<NamedPipeTransportManager> _logger;
 18        private readonly ILoggerFactory _loggerFactory;
 19        private readonly Dictionary<Uri, NamedPipeListener> _listeners;
 20
 021        public NamedPipeTransportManager(ILoggerFactory loggerFactory)
 22        {
 023            _loggerFactory = loggerFactory;
 024            _logger = _loggerFactory.CreateLogger<NamedPipeTransportManager>();
 025            _listeners = new Dictionary<Uri, NamedPipeListener>();
 026        }
 27
 28        internal async Task BindAsync(List<NamedPipeListenOptions> listenOptions, CancellationToken cancellationToken)
 29        {
 30            Fx.Assert(listenOptions.Count > 0, "We must have at least one listen option to bind to");
 031            foreach (var listenOption in listenOptions)
 32            {
 033                var listener = new NamedPipeListener(listenOption);
 034                await listener.BindAsync(cancellationToken);
 035                listener.StartAccepting();
 036                _logger.LogInformation("Started accepting new NetNamedPipe connections for uri {baseUri}", listenOption.
 037                _listeners.Add(listenOption.BaseAddress, listener);
 038            }
 039        }
 40
 41        internal async Task StopAsync(CancellationToken cancellationToken)
 42        {
 043            foreach(var pair in _listeners)
 44            {
 045                var listenerBaseAddress = pair.Key;
 046                var listener = pair.Value;
 047                _logger.LogInformation("Stopping NetNamedPipe for uri {baseUri}", listenerBaseAddress);
 48                // Might want to consider not awaiting, but collecting Task's in array and then calling
 49                // Task.WhenAll as this currently stops them sequentially. This is probably fine as
 50                // stopping should be a quick action.
 051                await listener.StopAsync(cancellationToken);
 52            }
 053        }
 54    }
 55}