Пример #1
0
        public static async Task <NamedPipeClientChannel> ConnectAsync(
            string pipeFile,
            MessageProtocolType messageProtocolType,
            ILogger logger)
        {
            string pipeName = System.IO.Path.GetFileName(pipeFile);

            var options = PipeOptions.Asynchronous;

            // on macOS and Linux, the named pipe name is prefixed by .NET Core
            if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
            {
                pipeName = pipeFile.Split(new [] { NAMED_PIPE_UNIX_PREFIX }, StringSplitOptions.None)[1];
                options |= (PipeOptions)CurrentUserOnly;
            }

            var pipeClient =
                new NamedPipeClientStream(
                    ".",
                    pipeName,
                    PipeDirection.InOut,
                    options);

            await pipeClient.ConnectAsync();

            var clientChannel = new NamedPipeClientChannel(pipeClient, logger);

            clientChannel.Start(messageProtocolType);

            return(clientChannel);
        }
Пример #2
0
        public static async Task <NamedPipeClientChannel> Connect(
            string pipeFile,
            MessageProtocolType messageProtocolType,
            ILogger logger)
        {
            string pipeName = System.IO.Path.GetFileName(pipeFile);

            // on macOS and Linux, the named pipe name is prefixed by .NET Core
            if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
            {
                pipeName = pipeFile.Split(new [] { NAMED_PIPE_UNIX_PREFIX }, StringSplitOptions.None)[1];
            }

            var pipeClient =
                new NamedPipeClientStream(
                    ".",
                    pipeName,
                    PipeDirection.InOut,
                    PipeOptions.Asynchronous);

#if CoreCLR
            await pipeClient.ConnectAsync();
#else
            while (!pipeClient.IsConnected)
            {
                try
                {
                    // Wait for 500 milliseconds so that we don't tie up the thread
                    pipeClient.Connect(500);
                }
                catch (TimeoutException)
                {
                    // Connect timed out, wait and try again
                    await Task.Delay(1000);

                    continue;
                }
            }
#endif
            var clientChannel = new NamedPipeClientChannel(pipeClient, logger);
            clientChannel.Start(messageProtocolType);

            return(clientChannel);
        }
        public static async Task <NamedPipeClientChannel> Connect(
            string pipeName,
            MessageProtocolType messageProtocolType,
            ILogger logger)
        {
            var pipeClient =
                new NamedPipeClientStream(
                    ".",
                    pipeName,
                    PipeDirection.InOut,
                    PipeOptions.Asynchronous);

#if CoreCLR
            await pipeClient.ConnectAsync();
#else
            while (!pipeClient.IsConnected)
            {
                try
                {
                    // Wait for 500 milliseconds so that we don't tie up the thread
                    pipeClient.Connect(500);
                }
                catch (TimeoutException)
                {
                    // Connect timed out, wait and try again
                    await Task.Delay(1000);

                    continue;
                }
            }
#endif
            var clientChannel = new NamedPipeClientChannel(pipeClient, logger);
            clientChannel.Start(messageProtocolType);

            return(clientChannel);
        }