コード例 #1
0
        void RunTcp()
        {
            for (;;)
            {
                try
                {
                    IAsyncResult TCPResult = Listener.BeginAcceptTcpClient(null, null);

                    int WaitResult = WaitHandle.WaitAny(new WaitHandle[] { ShutdownEvent, TCPResult.AsyncWaitHandle });

                    // Shutting down
                    if (WaitResult == 0)
                    {
                        break;
                    }

                    try
                    {
                        TcpClient Client = Listener.EndAcceptTcpClient(TCPResult);

                        Log.WriteLine("Accepted connection from {0}", Client.Client.RemoteEndPoint);

                        NetworkStream Stream = Client.GetStream();

                        AutomationRequestInput Input = AutomationRequestInput.Read(Stream);
                        Log.WriteLine("Received input: {0} (+{1} bytes)", Input.Type, Input.Data.Length);

                        AutomationRequestOutput Output;
                        using (AutomationRequest Request = new AutomationRequest(Input))
                        {
                            PostRequest(Request);
                            Request.Complete.Wait();
                            Output = Request.Output;
                        }

                        Output.Write(Stream);
                        Log.WriteLine("Sent output: {0} (+{1} bytes)", Output.Result, Output.Data.Length);
                    }
                    catch (Exception Ex)
                    {
                        Log.WriteLine("Exception: {0}", Ex.ToString());
                    }
                    finally
                    {
                        TCPResult = null;
                        Log.WriteLine("Closed connection.");
                    }
                }
                catch (Exception Ex)
                {
                    if (!bDisposing)
                    {
                        Log.WriteLine("Exception: {0}", Ex.ToString());
                    }
                }
            }
        }
コード例 #2
0
        public void Run()
        {
            try
            {
                for (;;)
                {
                    TcpClient Client = CurrentClient = Listener.AcceptTcpClient();
                    try
                    {
                        Log.WriteLine("Accepted connection from {0}", Client.Client.RemoteEndPoint);

                        NetworkStream Stream = Client.GetStream();

                        AutomationRequestInput Input = AutomationRequestInput.Read(Stream);
                        Log.WriteLine("Received input: {0} (+{1} bytes)", Input.Type, Input.Data.Length);

                        AutomationRequestOutput Output;
                        using (AutomationRequest Request = new AutomationRequest(Input))
                        {
                            PostRequest(Request);
                            Request.Complete.Wait();
                            Output = Request.Output;
                        }

                        Output.Write(Stream);
                        Log.WriteLine("Sent output: {0} (+{1} bytes)", Output.Result, Output.Data.Length);
                    }
                    catch (Exception Ex)
                    {
                        Log.WriteLine("Exception: {0}", Ex.ToString());
                    }
                    finally
                    {
                        Client.Close();
                        Log.WriteLine("Closed connection.");
                    }
                    CurrentClient = null;
                }
            }
            catch (Exception Ex)
            {
                if (!bDisposing)
                {
                    Log.WriteLine("Exception: {0}", Ex.ToString());
                }
            }
            Log.WriteLine("Closing socket.");
        }
コード例 #3
0
        public static UriResult OpenIssue(int Id)
        {
            using (MemoryStream InputDataStream = new MemoryStream())
            {
                using (BinaryWriter Writer = new BinaryWriter(InputDataStream))
                {
                    Writer.Write(Id);
                }

                AutomationRequestInput Input = new AutomationRequestInput(AutomationRequestType.OpenIssue, InputDataStream.GetBuffer());
                return(new UriResult()
                {
                    Success = true, Request = new AutomationRequest(Input)
                });
            }
        }
コード例 #4
0
        public static UriResult OpenProject(string Stream, string Project, bool Sync = false)
        {
            // Create the request
            using (MemoryStream InputDataStream = new MemoryStream())
            {
                using (BinaryWriter Writer = new BinaryWriter(InputDataStream))
                {
                    Writer.Write(Stream);
                    Writer.Write(Project);
                }

                AutomationRequestInput Input = new AutomationRequestInput(Sync ? AutomationRequestType.SyncProject : AutomationRequestType.OpenProject, InputDataStream.GetBuffer());
                return(new UriResult()
                {
                    Success = true, Request = new AutomationRequest(Input)
                });
            }
        }
コード例 #5
0
        public static UriResult Execute(string Stream, int Changelist, string Command, string Project = "")
        {
            using (MemoryStream InputDataStream = new MemoryStream())
            {
                using (BinaryWriter Writer = new BinaryWriter(InputDataStream))
                {
                    Writer.Write(Stream);
                    Writer.Write(Changelist);
                    Writer.Write(Command);
                    Writer.Write(Project);
                }

                AutomationRequestInput Input = new AutomationRequestInput(AutomationRequestType.ExecCommand, InputDataStream.GetBuffer());
                return(new UriResult()
                {
                    Success = true, Request = new AutomationRequest(Input)
                });
            }
        }
コード例 #6
0
 public AutomationRequest(AutomationRequestInput Input)
 {
     this.Input    = Input;
     this.Complete = new ManualResetEventSlim(false);
 }