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()); } } } }
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."); }
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) }); } }
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) }); } }
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) }); } }
public AutomationRequest(AutomationRequestInput Input) { this.Input = Input; this.Complete = new ManualResetEventSlim(false); }