public virtual void Dispose() { Params.Dispose(); Stdin.Dispose(); Stdout.Dispose(); Stderr.Dispose(); }
public Option <InterpreterResult> TryRun() { Guard.IsNotNull(Source, nameof(Source)); using MemoryOwner <Brainf_ckOperation>?operations = Brainf_ckParser.TryParse <Brainf_ckOperation>(Source.Value.Span, out SyntaxValidationResult validationResult); if (!validationResult.IsSuccess) { return(Option <InterpreterResult> .From(validationResult)); } if (InitialState is TuringMachineState initialState) { Guard.IsNull(MemorySize, nameof(MemorySize)); Guard.IsNull(OverflowMode, nameof(OverflowMode)); initialState = (TuringMachineState)initialState.Clone(); } else { int size = MemorySize ?? Specs.DefaultMemorySize; Guard.IsBetweenOrEqualTo(size, Specs.MinimumMemorySize, Specs.MaximumMemorySize, nameof(MemorySize)); initialState = new TuringMachineState(size, OverflowMode ?? Specs.DefaultOverflowMode); } InterpreterResult result = Brainf_ckInterpreter.Release.Run( operations !.Span, Stdin.GetValueOrDefault().Span, initialState, ExecutionToken); return(Option <InterpreterResult> .From(validationResult, result)); }
public Option <InterpreterSession> TryRun() { Guard.IsNotNull(Source, nameof(Source)); if (InitialState is TuringMachineState initialState) { Guard.IsNull(MemorySize, nameof(MemorySize)); Guard.IsNull(OverflowMode, nameof(OverflowMode)); initialState = (TuringMachineState)initialState.Clone(); } else { int size = MemorySize ?? Specs.DefaultMemorySize; Guard.IsBetweenOrEqualTo(size, Specs.MinimumMemorySize, Specs.MaximumMemorySize, nameof(MemorySize)); initialState = new TuringMachineState(size, OverflowMode ?? Specs.DefaultOverflowMode); } return(Brainf_ckInterpreter.Debug.TryCreateSession( Source.Value.Span, Breakpoints.Span, Stdin.GetValueOrDefault(), initialState, ExecutionToken, DebugToken)); }
public void Dispose() { Stdin.Dispose(); Stdout.Dispose(); Stderr.Dispose(); CloseCore(); }
public virtual void Dispose() { Params.Dispose(); Stdin.Dispose(); Stdout.Dispose(); Stderr.Dispose(); RecordFactory.Dispose(); }
/// <summary> /// If you don't have a request body to send, don't write to <see cref="Stdin"/> and call this method. It will also dispose /// <see cref="Stdin"/>. /// </summary> public void SendEmptyStdin() { using (var emptyStdin = new StdinRecord(RequestId)) { Send(emptyStdin); } Stdin.Dispose(); }
// [Test(Description = "Test using next")] public void TestMultiline1() { using (StreamReader sr = new StreamReader("Multiline1.txt")) { List <JObject> events = new List <JObject>(); Console.SetIn(sr); Stdin sin = new Stdin(); sin.CodecArguments = new CodecArguments(); sin.CodecArguments.Pattern = "\\\\$"; sin.CodecArguments.What = CodecArguments.WhatType.next; sin.CodecArguments.Type = CodecArguments.CodecType.multiline; var cancelTokenSource = new CancellationTokenSource(); using (var syncHandle = new ManualResetEventSlim()) { try { StdinListener sl = new StdinListener(sin, cancelTokenSource.Token); sl.OnMessageRecieved += o => { events.Add(o); if (events.Count >= 6) { cancelTokenSource.Cancel(); } }; if (!cancelTokenSource.Token.IsCancellationRequested) { syncHandle.Wait(TimeSpan.FromSeconds(10000), cancelTokenSource.Token); } } catch (OperationCanceledException) { } } Assert.AreEqual(events.Count, 6); Assert.AreEqual(events[0]["message"].ToString(), "multiline1 \\\nml1_1 \\\nml1_2 \\\nml1_2 "); Assert.AreEqual(events[1]["message"].ToString(), "singleline1"); Assert.AreEqual(events[2]["message"].ToString(), "singleline2"); Assert.AreEqual(events[3]["message"].ToString(), "multiline2 \\\nml2_1 \\\nml2_2"); Assert.AreEqual(events[4]["message"].ToString(), "multiline3 \\\nml3_1 \\\nml3_2"); Assert.AreEqual(events[5]["message"].ToString(), "singleline3"); } }
// [Test(Description = "Test using previous")] public void TestMultiline2() { using (StreamReader sr = new StreamReader("Multiline2.txt")) { List <JObject> events = new List <JObject>(); Console.SetIn(sr); Stdin sin = new Stdin(); sin.CodecArguments = new CodecArguments(); sin.CodecArguments.Pattern = "^(\\d{4}-\\d{2}-\\d{2}\\s\\d{2}:\\d{2}:\\d{2},\\d{3})(.*)$"; sin.CodecArguments.What = CodecArguments.WhatType.previous; sin.CodecArguments.Type = CodecArguments.CodecType.multiline; sin.CodecArguments.Negate = true; var cancelTokenSource = new CancellationTokenSource(); using (var syncHandle = new ManualResetEventSlim()) { try { StdinListener sl = new StdinListener(sin, cancelTokenSource.Token); sl.OnMessageRecieved += o => { events.Add(o); if (events.Count >= 4) { cancelTokenSource.Cancel(); } }; if (!cancelTokenSource.Token.IsCancellationRequested) { syncHandle.Wait(TimeSpan.FromSeconds(10000), cancelTokenSource.Token); } } catch (OperationCanceledException) { } } Assert.AreEqual(events.Count, 4); Assert.AreEqual(events[0]["message"].ToString(), "2015-01-07 13:14:26,572 TEST DEBUG [THREAD : 25] - Sending message to TServer - tcp://10.1111.11.111:1111\n'RequestAttachUserData' ('30')\nmessage attributes:\nAttributeConnID [long] = 00890\nAttributeReferenceID [int] = 88\nAttributeThisDN [str] = \"2214\"\nAttributeUserData [bstr] = KVList: \n\t\t'ActivityID' [str] = \"1-XXXXXX\""); Assert.AreEqual(events[1]["message"].ToString(), "2015-01-07 13:14:26,574 TEST DEBUG [THREAD : 25] - Writing message RequestAttachUserData in 'proxy1' via '.StatePrimary proxy: proxy1'"); Assert.AreEqual(events[2]["message"].ToString(), "2015-01-07 13:14:26,575 TEST DEBUG [THREAD : 25] - sending RequestAttachUserData to Test.Platform.Commons.Connection.CommonConnection"); Assert.AreEqual(events[3]["message"].ToString(), "2015-01-07 13:20:31,665 TEST DEBUG [THREAD : SelectorThread] - Proxy got message 'EventOnHook' ('87')\nmessage attributes:\nAttributeEventSequenceNumber [long] = 4899493\nTime = ComplexClass(TimeStamp):\n\tAttributeTimeinuSecs [int] = 573000\n\tAttributeTimeinSecs [int] = 1420644031\nAttributeThisDN [str] = \"2214\"\n. Processing with state .StatePrimary proxy: proxy1"); } }
/// <summary> /// Returns true if TesExecutor instances are equal /// </summary> /// <param name="other">Instance of TesExecutor to be compared</param> /// <returns>Boolean</returns> public bool Equals(TesExecutor other) { if (other is null) { return(false); } if (ReferenceEquals(this, other)) { return(true); } return (( Image == other.Image || Image != null && Image.Equals(other.Image) ) && ( Command == other.Command || Command != null && Command.SequenceEqual(other.Command) ) && ( Workdir == other.Workdir || Workdir != null && Workdir.Equals(other.Workdir) ) && ( Stdin == other.Stdin || Stdin != null && Stdin.Equals(other.Stdin) ) && ( Stdout == other.Stdout || Stdout != null && Stdout.Equals(other.Stdout) ) && ( Stderr == other.Stderr || Stderr != null && Stderr.Equals(other.Stderr) ) && ( Env == other.Env || Env != null && Env.SequenceEqual(other.Env) )); }
/// <summary> /// After writing to the output Streams, you have to end the request with a Status Code and a protocol status. /// Use this method to do that before disposing this object. /// </summary> /// <param name="appStatus">The Application status. Use 0 for success and anything else for error.</param> public void SendEndRequest(int appStatus, ProtocolStatus protocolStatus) { // Flush stuff before doing this! Data.Dispose(); Params.Dispose(); Stdin.Dispose(); Stdout.Dispose(); Stderr.Dispose(); var rec = new EndRequestRecord(RequestId); rec.AppStatus = appStatus; rec.ProtocolStatus = protocolStatus; Send(rec); }
/// <summary> /// This method is called internally when data is received and fed to this Request. It basically sets this request's properties /// or appends data to the streams. Override it and call the base method itself to implement your own logics and checking. /// </summary> protected virtual void AddReceivedRecord(RecordBase rec) { if (rec == null) { throw new ArgumentNullException("rec"); } switch (rec.RecordType) { case RecordType.FCGIBeginRequest: // Make sure we are not getting a BeginRequest once again, as this could be serious. if (BeginRequestReceived) { throw new InvalidOperationException("A BeginRequest Record has already been received by this Request"); } BeginRequestReceived = true; RequestId = ((BeginRequestRecord)rec).RequestId; break; case RecordType.FCGIEndRequest: // Make sure we are not getting a BeginRequest once again, as this could be serious. if (EndRequestReceived) { throw new InvalidOperationException("An EndRequest Record has already been received by this Request"); } EndRequestReceived = true; break; case RecordType.FCGIParams: Params.AppendStream(((StreamRecordBase)rec).Contents); break; case RecordType.FCGIStdin: Stdin.AppendStream(((StreamRecordBase)rec).Contents); break; case RecordType.FCGIStdout: Stdout.AppendStream(((StreamRecordBase)rec).Contents); break; case RecordType.FCGIStderr: Stderr.AppendStream(((StreamRecordBase)rec).Contents); break; } }
/// <summary> /// Gets the hash code /// </summary> /// <returns>Hash code</returns> public override int GetHashCode() { unchecked // Overflow is fine, just wrap { var hashCode = 41; // Suitable nullity checks etc, of course :) if (Image != null) { hashCode = hashCode * 59 + Image.GetHashCode(); } if (Command != null) { hashCode = hashCode * 59 + Command.GetHashCode(); } if (Workdir != null) { hashCode = hashCode * 59 + Workdir.GetHashCode(); } if (Stdin != null) { hashCode = hashCode * 59 + Stdin.GetHashCode(); } if (Stdout != null) { hashCode = hashCode * 59 + Stdout.GetHashCode(); } if (Stderr != null) { hashCode = hashCode * 59 + Stderr.GetHashCode(); } if (Env != null) { hashCode = hashCode * 59 + Env.GetHashCode(); } return(hashCode); } }
public void CloseStreams() { Stdin.Close(); Stdout.Close(); Stderr.Close(); }