/////////////////////////////////////////////////////////////////////// public int AddTraces( TraceList traces ) { int result = 0; /* IGNORED */ ResetTraces(true, false); if (this.traces != null) { foreach (ITrace trace in traces) { if (trace == null) { continue; } this.traces.Add(trace); result++; } } return(result); }
/////////////////////////////////////////////////////////////////////// #region IState Members (Optional) /// <summary> /// Optionally initializes any state information required by the /// command. /// </summary> /// <param name="interpreter"> /// The interpreter context we are executing in. /// </param> /// <param name="clientData"> /// The extra data supplied when this command was initially created, if /// any. /// </param> /// <param name="result"> /// Upon success, this must contain the result of the command. /// Upon failure, this must contain an appropriate error message. /// </param> /// <returns> /// ReturnCode.Ok on success, ReturnCode.Error on failure. /// </returns> public override ReturnCode Initialize( Interpreter interpreter, /* in */ IClientData clientData, /* in */ ref Result result /* out */ ) { // // NOTE: We require a valid interpreter context. // if (interpreter == null) { result = "invalid interpreter"; return(ReturnCode.Error); } // // NOTE: Does the variable we are interested in already exist? // If so, skip adding it; unfortunately, this means that // we cannot add the variable trace. // VariableFlags varFlags = VariableFlags.GlobalOnly; string varName = GetType().Name; if (interpreter.DoesVariableExist( varFlags, varName) != ReturnCode.Ok) { // // NOTE: Grab the plugin that owns us. // IPlugin plugin = this.Plugin; // // NOTE: Add a variable that has our custom variable trace // callback. // TraceList traces = new TraceList( clientData, TraceFlags.None, plugin, new TraceCallback[] { PluginTraceCallback } ); if (interpreter.AddVariable( varFlags, varName, traces, true, ref result) == ReturnCode.Ok) { addedVariable = true; } else { return(ReturnCode.Error); } } return(base.Initialize(interpreter, clientData, ref result)); }
internal DefaultContext() { AcceptedDenomitationList.Add(CoinType.Quarter); AcceptedDenomitationList.Add(CoinType.Nickel); AcceptedDenomitationList.Add(CoinType.Dime); AvailableBins.Deposit(CreateDefaultBins()); CoinInventory.Deposit(CreateDefaultCoinInventory()); TotalDeposit = 0; TraceList.Clear(); }
/////////////////////////////////////////////////////////////////////// internal Variable( ICallFrame frame, string name, VariableFlags flags, string qualifiedName, TraceList traces, EventWaitHandle @event ) : this(frame, name, flags, qualifiedName, (string)null, @event) { this.traces = traces; }
/////////////////////////////////////////////////////////////////////// public void Reset( EventWaitHandle @event ) { flags = VariableFlags.None; qualifiedName = null; link = null; linkIndex = null; value = null; arrayValue = null; traces = null; // BUGBUG: Is this correct (i.e. does Tcl do this)? this.@event = @event; }
private static void DumpList(TraceList list, TraceExtensions.DumpStyle style) { foreach (var trace in list) { try { Cout.WriteLine(trace.ToString(style)); } catch (Exception ex) { Cout.Error.WriteLine(ex); } } }
protected override void OnProcessOutputSchema(MutableObject newSchema) { var headerMutable = Header.GetFirstValue(newSchema); foreach (var entry in TraceList.GetEntries(newSchema)) { ExecutionHeaderTarget.SetValue(headerMutable, entry); foreach (var traceSchema in TraceList.GetValue(entry)) { TraceState.TransmitSchema(traceSchema); } } DefaultState.TransmitSchema(newSchema); }
internal static void AddTraceToTraceList(TraceDto trace) { if (TraceList.ContainsKey(trace.Writer)) { TraceList[trace.Writer].Enqueue(trace); } else { var traceWriterList = new ConcurrentQueue <TraceDto>(); traceWriterList.Enqueue(trace); TraceList.Add(trace.Writer, traceWriterList); } CalculateWriterSize(trace); SparseWriter(trace.Writer); }
private void ListView_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e) { if (!IsAutoScrollEnabled) { return; } switch (e.Action) { case NotifyCollectionChangedAction.Add: TraceList.ScrollIntoView(e.NewItems[0]); break; case NotifyCollectionChangedAction.Reset: TraceList.ScrollIntoView(TraceList.Items.GetItemAt(TraceList.Items.Count - 1)); break; } }
public string Execute(Dictionary <string, string> parameterList) { if (ExecuteFunction == null) { return("Error function, no valid function registered!"); } try { var s = ExecuteFunction(parameterList); TraceList.Add(DateTime.UtcNow, s); if (TraceList.Count > TraceCount) { var d = TraceList.FirstOrDefault(); TraceList.Remove(d.Key); } return(s); } catch (Exception ex) { return(ex.Message); } }
/////////////////////////////////////////////////////////////////////// private TraceList ResetTraces( bool initialize, bool clear ) { if (traces != null) { if (clear) { TraceList oldTraces = new TraceList(traces); traces.Clear(); return(oldTraces); } } else if (initialize) { traces = new TraceList(); } return(null); }
public override IEnumerator ReceivePayload(VisualPayload payload) { var headerMutable = Header.GetFirstValue(payload.Data); IEnumerator iterator; foreach (var entry in TraceList.GetEntries(payload.Data)) { ExecutionHeaderTarget.SetValue(headerMutable, entry); foreach (var traceMutable in TraceList.GetValue(entry)) { var traceVisualDescription = new VisualDescription(payload.VisualData.Bound.CreateDependingBound(Name)); VisualPayload tracePayload = new VisualPayload(traceMutable, traceVisualDescription); iterator = TraceState.Transmit(tracePayload); while (iterator.MoveNext()) { yield return(null); } } } }
public DbDataReader ExecuteReader() { ExecutorMethod = "ExecuteReader"; TraceList.Add(this); return((TestDataReader)ExpectedCommandResult); }
public DbDataReader ExecuteReader(CommandBehavior behavior) { ExecutorMethod = $"ExecuteReader(CommandBehavior.{behavior})"; TraceList.Add(this); return((TestDataReader)ExpectedCommandResult); }
/////////////////////////////////////////////////////////////////////// /// <summary> /// This method creates and initializes an interpreter, uses it to /// perform several tests, and then returns. The created interpreter /// is disposed automatically before returning. /// </summary> /// <param name="args"> /// The command line arguments received from the calling assembly. /// </param> /// <returns> /// Zero for success, non-zero on error. /// </returns> private static ExitCode Test( IEnumerable <string> args /* in */ ) { // // NOTE: This variable will contain the interpreter exit code // (either via exiting the interactive loop or from an // explicit call to the [exit] command). // ExitCode exitCode; // // NOTE: The "interpreter result" that is passed to various // methods. The interpreter itself does *NOT* store this // result internally and that behavior is a significant // difference from native Tcl. // Result result = null; // // NOTE: Do we want to intercept all variable accesses for the // interpreter? // TraceList traces = new TraceList(new TraceCallback[] { TraceCallback }); // // NOTE: First, we create a new interpreter, using some reasonable // flags and passing in the command line arguments provided // to this method. // using (Interpreter interpreter = Interpreter.Create( args, CreateFlags.Default & ~CreateFlags.ThrowOnError, traces, ref result)) { // // NOTE: Was the interpreter created successfully? // if (interpreter != null) { // // NOTE: Override the default script binder with the one // implemented by this sample application. // interpreter.Binder = new Class9( interpreter, interpreter.Binder as IScriptBinder); // // NOTE: Create instances of our custom command classes. // These instances will be used when registering the // custom commands in the interpreter. // Class2 class2 = new Class2(new CommandData( "class2", null, "This would describe the command.", new ClientData(typeof(Class1)), typeof(Class2).FullName, CommandFlags.None, null, 0)); Class12 class12 = new Class12(new CommandData( "class12", null, "This would describe the command.", null, typeof(Class12).FullName, CommandFlags.None, new Class3(null), 0)); // // NOTE: These tokens will represent the custom command // registered with the interpreter. These tokens can // later be used to remove the commands, even if they // have been renamed. // long token2 = 0; long token12 = 0; // // NOTE: Next, we [optionally] register our custom commands // in the interpreter. Normally, the return codes // should be checked here; however, in this example, // they are ignored. // /* IGNORED */ interpreter.AddCommand( class2, null, ref token2, ref result); /* IGNORED */ interpreter.AddCommand( class12, null, ref token12, ref result); // // NOTE: Next, we can evaluate one or more scripts of our // choosing, which may or may not refer to custom // commands registered in the interpreter by us or // other parties. // // NOTE: To test the custom script binder, use the script: // // object invoke Sample.Class2 TestMethod class2 // ReturnCode code2; Result result2 = null; int errorLine2 = 0; code2 = Engine.EvaluateScript(interpreter, "set x 1; unset x; class2 test; # <-- script text", ref result2, ref errorLine2); ReturnCode code12; Result result12 = null; int errorLine12 = 0; code12 = Engine.EvaluateScript(interpreter, "list [class12 example1] [class12 example2] " + "[class12 example3] [class12 options]; # ensemble", ref result12, ref errorLine12); // // NOTE: Fetch the interpreter exit code (typically zero // for "success" and non-zero for "failure"). In the // event this indicates success and the return code // indicates failure, the return code will override // this value to produce the final exit code for this // method. This is an example of what could be done // and is entirely optional. // exitCode = interpreter.ExitCode; // // NOTE: Grab the interpreter host now since we will need // it several times below to display various pieces // of information. // IHost host = interpreter.Host; // // NOTE: Show number of variable traces that were fired. // if ((getTraces > 0) || (setTraces > 0) || (unsetTraces > 0)) { if (host != null) { host.Clear(); host.WriteLine(String.Format( "read = {0}", getTraces)); host.WriteLine(String.Format( "write = {0}", setTraces)); host.WriteLine(String.Format( "delete = {0}", unsetTraces)); host.WriteLine(); host.WriteLine("Press any key to continue..."); host.Pause(); } else { // // NOTE: Do something else here... Such as log the // trace counts. // } } // // NOTE: This section of code attempts to demonstrate how // script errors *could* be handled. // if (Utility.IsSuccess(code2, false) && Utility.IsSuccess(code12, false)) { // // NOTE: Always check for a valid interpreter hosting // environment before using it as it is not // guaranteed to always be available. // if (host != null) { // // NOTE: Display the script evaluation result along // with its return code using the interpreter // host. This is an example of what could be // done and is entirely optional. // host.Clear(); host.WriteLine(String.Format( "SUCCESS, code2 = {0}", code2)); host.WriteResultLine(code2, result2); host.WriteLine(String.Format( "SUCCESS, code12 = {0}", code12)); host.WriteResultLine(code12, result12); host.WriteLine(); host.WriteLine("Press any key to continue..."); host.Pause(); } else { // // NOTE: Do something else here... Such as log the // success. // } } else { // // NOTE: Always check for a valid interpreter hosting // environment before using it as it is not // guaranteed to always be available. // if (host != null) { // // NOTE: Display the script evaluation result along // with its return code using the interpreter // host. This is an example of what could be // done and is entirely optional. // host.Clear(); host.WriteLine(String.Format( "{0}, code2 = {1}", Utility.IsSuccess(code2, false) ? "SUCCESS" : "FAILURE", code2)); host.WriteResultLine(code2, result2, errorLine2); host.WriteLine(String.Format( "{0}, code12 = {1}", Utility.IsSuccess(code12, false) ? "SUCCESS" : "FAILURE", code12)); host.WriteResultLine(code12, result12, errorLine12); host.WriteLine(); host.WriteLine("Press any key to continue..."); host.Pause(); } else { // // NOTE: Do something else here... Such as log the // failure. // } // // NOTE: If the exit code is success and the return code // indicates an error, allow the return code to // override the exit code. This is an example of // what could be done and is entirely optional. // if (exitCode == Utility.SuccessExitCode()) { if (Utility.IsSuccess(code2, false)) { exitCode = Utility.ReturnCodeToExitCode(code12); } else { exitCode = Utility.ReturnCodeToExitCode(code2); } } } // // NOTE: Finally, if applicable, remove the custom commands // we previously registered in the interpreter. // if (token12 != 0) { /* IGNORED */ interpreter.RemoveCommand(token12, null, ref result); } if (token2 != 0) { /* IGNORED */ interpreter.RemoveCommand(token2, null, ref result); } } else { #if CONSOLE // // NOTE: Creation of the interpreter failed. Attempt to // display the reason why to the system console. // Console.WriteLine(Utility.FormatResult( ReturnCode.Error, result)); #endif exitCode = Utility.FailureExitCode(); } } return(exitCode); }
public void Init() { instance = new TraceList(); }
public object ExecuteScalar() { ExecutorMethod = "ExecuteScalar"; TraceList.Add(this); return(ExpectedCommandResult); }
public int ExecuteNonQuery() { ExecutorMethod = "ExecuteNonQuery"; TraceList.Add(this); return(0); }