当前位置: 首页>>代码示例>>C#>>正文


C# NamedPipeClientStream.Connect方法代码示例

本文整理汇总了C#中NamedPipeClientStream.Connect方法的典型用法代码示例。如果您正苦于以下问题:C# NamedPipeClientStream.Connect方法的具体用法?C# NamedPipeClientStream.Connect怎么用?C# NamedPipeClientStream.Connect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在NamedPipeClientStream的用法示例。


在下文中一共展示了NamedPipeClientStream.Connect方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: InvalidConnectTimeout_Throws_ArgumentOutOfRangeException

 public void InvalidConnectTimeout_Throws_ArgumentOutOfRangeException()
 {
     using (NamedPipeClientStream client = new NamedPipeClientStream("client1"))
     {
         Assert.Throws<ArgumentOutOfRangeException>("timeout", () => client.Connect(-111));
         Assert.Throws<ArgumentOutOfRangeException>("timeout", () => { client.ConnectAsync(-111); });
     }
 }
开发者ID:ESgarbi,项目名称:corefx,代码行数:8,代码来源:NamedPipeTest.Specific.cs

示例2: ConnectToNonExistentServer_Throws_TimeoutException

 public async Task ConnectToNonExistentServer_Throws_TimeoutException()
 {
     using (NamedPipeClientStream client = new NamedPipeClientStream(".", "notthere"))
     {
         var ctx = new CancellationTokenSource();
         Assert.Throws<TimeoutException>(() => client.Connect(60));  // 60 to be over internal 50 interval
         await Assert.ThrowsAsync<TimeoutException>(() => client.ConnectAsync(50));
         await Assert.ThrowsAsync<TimeoutException>(() => client.ConnectAsync(60, ctx.Token)); // testing Token overload; ctx is not canceled in this test
     }
 }
开发者ID:ESgarbi,项目名称:corefx,代码行数:10,代码来源:NamedPipeTest.Specific.cs

示例3: ClientConnectAsID

 private static int ClientConnectAsID(string pipeName, string pairIDString)
 {
     uint pairID = uint.Parse(pairIDString);
     using (var inbound = new NamedPipeClientStream(".", pipeName, PipeDirection.In))
     {
         Assert.NotEqual(-1, seteuid(pairID));
         inbound.Connect();
     }
     return SuccessExitCode;
 }
开发者ID:dotnet,项目名称:corefx,代码行数:10,代码来源:NamedPipeTest.RunAsClient.cs

示例4: CreateServerClientPair

        protected override ServerClientPair CreateServerClientPair()
        {
            ServerClientPair ret = new ServerClientPair();
            string pipeName = GetUniquePipeName();
            var readablePipe = new NamedPipeServerStream(pipeName, PipeDirection.InOut, 1, PipeTransmissionMode.Byte, PipeOptions.Asynchronous);
            var writeablePipe = new NamedPipeClientStream(".", pipeName, PipeDirection.InOut, PipeOptions.Asynchronous);

            Task serverConnect = Task.Factory.FromAsync(readablePipe.BeginWaitForConnection, readablePipe.EndWaitForConnection, null);
            writeablePipe.Connect();
            serverConnect.Wait();

            ret.readablePipe = readablePipe;
            ret.writeablePipe = writeablePipe;
            return ret;
        }
开发者ID:dotnet,项目名称:corefx,代码行数:15,代码来源:NamedPipeTest.Read.netstandard17.cs

示例5: RunAsClient_Windows

        public async Task RunAsClient_Windows()
        {
            string pipeName = Path.GetRandomFileName();
            using (var server = new NamedPipeServerStream(pipeName))
            using (var client = new NamedPipeClientStream(".", pipeName, PipeDirection.InOut, PipeOptions.None, TokenImpersonationLevel.Impersonation))
            {
                Task serverTask = server.WaitForConnectionAsync();

                client.Connect();
                await serverTask;

                bool ran = false;
                server.RunAsClient(() => ran = true);
                Assert.True(ran, "Expected delegate to have been invoked");
            }
        }
开发者ID:dotnet,项目名称:corefx,代码行数:16,代码来源:NamedPipeTest.RunAsClient.cs

示例6: ConnectWithConflictingDirections_Throws_UnauthorizedAccessException

        [PlatformSpecific(PlatformID.Windows)] // Unix implementation uses bidirectional sockets
        public void ConnectWithConflictingDirections_Throws_UnauthorizedAccessException()
        {
            string serverName1 = GetUniquePipeName();
            using (NamedPipeServerStream server = new NamedPipeServerStream(serverName1, PipeDirection.Out))
            using (NamedPipeClientStream client = new NamedPipeClientStream(".", serverName1, PipeDirection.Out))
            {
                Assert.Throws<UnauthorizedAccessException>(() => client.Connect());
                Assert.False(client.IsConnected);
            }

            string serverName2 = GetUniquePipeName();
            using (NamedPipeServerStream server = new NamedPipeServerStream(serverName2, PipeDirection.In))
            using (NamedPipeClientStream client = new NamedPipeClientStream(".", serverName2, PipeDirection.In))
            {
                Assert.Throws<UnauthorizedAccessException>(() => client.Connect());
                Assert.False(client.IsConnected);
            }
        }
开发者ID:ESgarbi,项目名称:corefx,代码行数:19,代码来源:NamedPipeTest.Specific.cs

示例7: NameTooLong_MaxLengthPerPlatform

        public void NameTooLong_MaxLengthPerPlatform()
        {
            // Increase a name's length until it fails
            ArgumentOutOfRangeException e = null;
            string name = Path.GetRandomFileName();
            for (int i = 0; ; i++)
            {
                try
                {
                    name += 'c';
                    using (var s = new NamedPipeServerStream(name))
                    using (var c = new NamedPipeClientStream(name))
                    {
                        Task t = s.WaitForConnectionAsync();
                        c.Connect();
                        t.GetAwaiter().GetResult();
                    }
                }
                catch (ArgumentOutOfRangeException exc)
                {
                    e = exc;
                    break;
                }
            }
            Assert.NotNull(e);
            Assert.NotNull(e.ActualValue);

            // Validate the length was expected
            string path = (string)e.ActualValue;
            if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
            {
                Assert.Equal(108, path.Length);
            }
            else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
            {
                Assert.Equal(104, path.Length);
            }
            else
            {
                Assert.InRange(path.Length, 92, int.MaxValue);
            }
        }
开发者ID:ESgarbi,项目名称:corefx,代码行数:42,代码来源:NamedPipeTest.Specific.cs

示例8: Unix_GetImpersonationUserName_Succeed

        public async Task Unix_GetImpersonationUserName_Succeed()
        {
            string pipeName = GetUniquePipeName();

            using (var server = new NamedPipeServerStream(pipeName))
            using (var client = new NamedPipeClientStream(".", pipeName, PipeDirection.InOut, PipeOptions.None, TokenImpersonationLevel.Impersonation))
            {
                Task serverTask = server.WaitForConnectionAsync();

                client.Connect();
                await serverTask;

                string name = server.GetImpersonationUserName();
                Assert.NotNull(name);
                Assert.False(string.IsNullOrWhiteSpace(name));
            }
        }
开发者ID:ESgarbi,项目名称:corefx,代码行数:17,代码来源:NamedPipeTest.Specific.cs

示例9: Windows_GetImpersonationUserName_Succeed

        [PlatformSpecific(PlatformID.Windows)] // Win32 P/Invokes to verify the user name
        public async Task Windows_GetImpersonationUserName_Succeed()
        {
            string pipeName = GetUniquePipeName();

            using (var server = new NamedPipeServerStream(pipeName))
            {
                using (var client = new NamedPipeClientStream(".", pipeName, PipeDirection.InOut, PipeOptions.None, TokenImpersonationLevel.Impersonation))
                {
                    string expectedUserName;
                    Task serverTask = server.WaitForConnectionAsync();

                    client.Connect();
                    await serverTask;

                    Assert.True(Interop.TryGetImpersonationUserName(server.SafePipeHandle, out expectedUserName), "GetNamedPipeHandleState failed");
                    Assert.Equal(expectedUserName, server.GetImpersonationUserName());
                }
            }
        }
开发者ID:ESgarbi,项目名称:corefx,代码行数:20,代码来源:NamedPipeTest.Specific.cs

示例10: Context

 public Context(Session session, int id, bool isMainThread)
 {
     mIsMainThread = isMainThread;
     mSession = session;
     mKey = mSession.mKey + "\\" + id.ToString("x8");
     mPipe = new NamedPipeClientStream(".", mKey, PipeDirection.InOut);
     mPipe.Connect();
     mReader = new BinaryReader(mPipe);
     mWriter = new BinaryWriter(mPipe);
 }
开发者ID:modulexcite,项目名称:managed-lzma,代码行数:10,代码来源:Trace.cs

示例11: ClientConnectWrongConflictingDirection

        public static void ClientConnectWrongConflictingDirection()
        {
            const string serverName1 = "testServer4";

            using (NamedPipeServerStream server = new NamedPipeServerStream(serverName1, PipeDirection.Out))
            using (NamedPipeClientStream client = new NamedPipeClientStream(".", serverName1, PipeDirection.Out))
            {
                Assert.Throws<UnauthorizedAccessException>(() => client.Connect());

                Assert.False(client.IsConnected);
            }

            const string serverName2 = "testServer5";

            using (NamedPipeServerStream server = new NamedPipeServerStream(serverName2, PipeDirection.In))
            using (NamedPipeClientStream client = new NamedPipeClientStream(".", serverName2, PipeDirection.In))
            {
                Assert.Throws<UnauthorizedAccessException>(() => client.Connect());

                Assert.False(client.IsConnected);
            }
        }
开发者ID:nuskarthik,项目名称:corefx,代码行数:22,代码来源:NamedPipesThrowsTests.cs

示例12: ClientAllReadyConnectedThrows

        public static async Task ClientAllReadyConnectedThrows()
        {
            using (NamedPipeServerStream server = new NamedPipeServerStream("testServer1", PipeDirection.InOut, 1, PipeTransmissionMode.Byte, PipeOptions.Asynchronous))
            using (NamedPipeClientStream client = new NamedPipeClientStream(".", "testServer1", PipeDirection.InOut, PipeOptions.Asynchronous))
            {
                byte[] buffer = new byte[] { 0, 0, 0, 0 };

                Task clientConnect1 = client.ConnectAsync();
                server.WaitForConnection();
                await clientConnect1;

                Assert.True(client.IsConnected);
                Assert.True(server.IsConnected);

                Assert.Throws<InvalidOperationException>(() => client.Connect());

                var ctx = new CancellationTokenSource();
                if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) // [ActiveIssue(812, PlatformID.AnyUnix)] - the cancellation token is ignored after the operation is initiated, due to base Stream's implementation
                {
                    Task clientReadToken = client.ReadAsync(buffer, 0, buffer.Length, ctx.Token);
                    ctx.Cancel();
                    await Assert.ThrowsAnyAsync<OperationCanceledException>(() => clientReadToken);
                }
                ctx.Cancel();
                Assert.True(client.ReadAsync(buffer, 0, buffer.Length, ctx.Token).IsCanceled);

                var ctx1 = new CancellationTokenSource();
                if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) // [ActiveIssue(812, PlatformID.AnyUnix)] - the cancellation token is ignored after the operation is initiated, due to base Stream's implementation
                {
                    Task serverReadToken = server.ReadAsync(buffer, 0, buffer.Length, ctx1.Token);
                    ctx1.Cancel();
                    await Assert.ThrowsAnyAsync<OperationCanceledException>(() => serverReadToken);
                }
                ctx1.Cancel();
                Assert.True(server.ReadAsync(buffer, 0, buffer.Length, ctx1.Token).IsCanceled);
            }
        }
开发者ID:nuskarthik,项目名称:corefx,代码行数:37,代码来源:NamedPipesThrowsTests.cs

示例13: ClientTryConnectedThrows

        public static async Task ClientTryConnectedThrows()
        {
            using (NamedPipeClientStream client = new NamedPipeClientStream(".", "notthere"))
            {
                var ctx = new CancellationTokenSource();

                if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) // [ActiveIssue(812, PlatformID.AnyUnix)] - Unix implementation currently ignores timeout and cancellation token once the operation has been initiated
                {
                    Assert.Throws<TimeoutException>(() => client.Connect(60));  // 60 to be over internal 50 interval
                    await Assert.ThrowsAsync<TimeoutException>(() => client.ConnectAsync(50));
                    await Assert.ThrowsAsync<TimeoutException>(() => client.ConnectAsync(60, ctx.Token));

                    Task clientConnectToken = client.ConnectAsync(ctx.Token);
                    ctx.Cancel();
                    await Assert.ThrowsAnyAsync<OperationCanceledException>(() => clientConnectToken);
                }

                ctx.Cancel();
                await Assert.ThrowsAnyAsync<OperationCanceledException>(() => client.ConnectAsync(ctx.Token));
            }
        }
开发者ID:nuskarthik,项目名称:corefx,代码行数:21,代码来源:NamedPipesThrowsTests.cs

示例14: Windows_MessagePipeTransissionMode

        public void Windows_MessagePipeTransissionMode()
        {
            byte[] msg1 = new byte[] { 5, 7, 9, 10 };
            byte[] msg2 = new byte[] { 2, 4 };
            byte[] received1 = new byte[] { 0, 0, 0, 0 };
            byte[] received2 = new byte[] { 0, 0 };
            byte[] received3 = new byte[] { 0, 0, 0, 0 }; ;
            string pipeName = GetUniquePipeName();

            using (NamedPipeServerStream server = new NamedPipeServerStream(pipeName, PipeDirection.InOut, 1, PipeTransmissionMode.Message))
            {
                using (NamedPipeClientStream client = new NamedPipeClientStream(".", pipeName, PipeDirection.InOut, PipeOptions.None, Security.Principal.TokenImpersonationLevel.Identification))
                {
                    server.ReadMode = PipeTransmissionMode.Message;
                    Assert.Equal(PipeTransmissionMode.Message, server.ReadMode);

                    Task clientTask = Task.Run(() =>
                    {
                        client.Connect();

                        client.Write(msg1, 0, msg1.Length);
                        client.Write(msg2, 0, msg2.Length);
                        client.Write(msg1, 0, msg1.Length);

                        int serverCount = client.NumberOfServerInstances;
                        Assert.Equal(1, serverCount);
                    });

                    server.WaitForConnection();
                    int len1 = server.Read(received1, 0, msg1.Length);
                    Assert.True(server.IsMessageComplete);
                    Assert.Equal(msg1.Length, len1);
                    Assert.Equal(msg1, received1);

                    int len2 = server.Read(received2, 0, msg2.Length);
                    Assert.True(server.IsMessageComplete);
                    Assert.Equal(msg2.Length, len2);
                    Assert.Equal(msg2, received2);

                    int len3 = server.Read(received3, 0, msg1.Length - 1);  // read one less than message
                    Assert.False(server.IsMessageComplete);
                    Assert.Equal(msg1.Length - 1, len3);

                    int len4 = server.Read(received3, len3, received3.Length - len3);
                    Assert.True(server.IsMessageComplete);
                    Assert.Equal(msg1.Length, len3 + len4);
                    Assert.Equal(msg1, received3);

                    string userName = server.GetImpersonationUserName();    // not sure what to test here that will work in all cases
                }
            }
        }
开发者ID:GreenDamTan,项目名称:corefx,代码行数:52,代码来源:NamedPipeTest.Specific.cs

示例15: PipeThread

            private void PipeThread(object id)
            {
                try
                {
                    using (var pipe = new NamedPipeClientStream(".", (string)id + "\\root", PipeDirection.In))
                    {
                        pipe.Connect();

                        BinaryReader rd = new BinaryReader(pipe);

                        for (;;)
                        {
                            lock (mSync)
                                if (mShutdown)
                                    return;

                            int op = pipe.ReadByte();
                            if (op < 0)
                                return;

                            ProcessPipeThreadEvent(rd, op);
                        }
                    }
                }
                catch (Exception ex)
                {
                    lock (mSync)
                        mError.Add(ex);
                }
            }
开发者ID:modulexcite,项目名称:managed-lzma,代码行数:30,代码来源:Trace.cs


注:本文中的NamedPipeClientStream.Connect方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。