Exemplo n.º 1
0
        static int Main(string[] args)
        {
            if (args.Length > 0)
            {
                if (args[0].Equals("infinite"))
                {
                    // To avoid potential issues with orphaned processes (say, the test exits before
                    // exiting the process), we'll say "infinite" is actually 100 seconds.
                    Sleep(100 * 1000);
                }
                else if (args[0].Equals("error"))
                {
                    Console.Error.WriteLine(Name + " started error stream");
                    Console.Error.WriteLine(Name + " closed error stream");
                    Sleep();
                }
                else if (args[0].Equals("input"))
                {
                    string str = Console.ReadLine();
                }
                else if (args[0].Equals("stream"))
                {
                    Console.WriteLine(Name + " started");
                    Console.WriteLine(Name + " closed");
                    Sleep();
                }
                else if (args[0].Equals("byteAtATime"))
                {
                    var stdout = Console.OpenStandardOutput();
                    var bytes = new byte[] { 97, 0 }; //Encoding.Unicode.GetBytes("a");

                    for (int i = 0; i != bytes.Length; ++i)
                    {
                        stdout.WriteByte(bytes[i]);
                        stdout.Flush();
                        Sleep(100);
                    }
                }
                else if (args[0].Equals("ipc"))
                {
                    using (var inbound = new AnonymousPipeClientStream(PipeDirection.In, args[1]))
                    using (var outbound = new AnonymousPipeClientStream(PipeDirection.Out, args[2]))
                    {
                        // Echo 10 bytes from inbound to outbound
                        for (int i = 0; i < 10; i++)
                        {
                            int b = inbound.ReadByte();
                            outbound.WriteByte((byte)b);
                        }
                    }
                }
                else
                {
                    Console.WriteLine(string.Join(" ", args));
                }
            }
            return 100;
        }
Exemplo n.º 2
0
 private static int PingPong_OtherProcess(string inHandle, string outHandle)
 {
     // Create the clients associated with the supplied handles
     using (var inbound = new AnonymousPipeClientStream(PipeDirection.In, inHandle))
     using (var outbound = new AnonymousPipeClientStream(PipeDirection.Out, outHandle))
     {
         // Repeatedly read then write a byte from and to the server
         for (int i = 0; i < 10; i++)
         {
             int b = inbound.ReadByte();
             outbound.WriteByte((byte)b);
         }
     }
     return SuccessExitCode;
 }