/////////////////////////////////////////////////////////////////////// internal StringList GetWatchpoints() { StringList result = new StringList(); foreach (KeyValuePair <string, IVariable> pair in this) { IVariable variable = pair.Value; if (variable == null) { continue; } VariableFlags flags = EntityOps.GetWatchpointFlags( variable.Flags); if (flags != VariableFlags.None) { // // NOTE: Two element sub-list of name and watch types. // result.Add(new StringList( variable.Name, flags.ToString()).ToString()); } } return(result); }
public Default( ILambdaData lambdaData ) { kind = IdentifierKind.Lambda; id = AttributeOps.GetObjectId(this); group = AttributeOps.GetObjectGroup(this); if (lambdaData != null) { EntityOps.MaybeSetGroup( this, lambdaData.Group); name = lambdaData.Name; description = lambdaData.Description; flags = lambdaData.Flags; clientData = lambdaData.ClientData; arguments = lambdaData.Arguments; body = lambdaData.Body; location = lambdaData.Location; token = lambdaData.Token; } callback = null; }
public Default( IPackageData packageData ) { kind = IdentifierKind.Package; id = AttributeOps.GetObjectId(this); group = AttributeOps.GetObjectGroup(this); if (packageData != null) { EntityOps.MaybeSetGroup( this, packageData.Group); name = packageData.Name; description = packageData.Description; indexFileName = packageData.IndexFileName; provideFileName = packageData.ProvideFileName; flags = packageData.Flags; clientData = packageData.ClientData; loaded = packageData.Loaded; VersionStringDictionary ifNeeded = packageData.IfNeeded; if (ifNeeded != null) { this.ifNeeded = ifNeeded; // use (or "attach to") their versions. } else { this.ifNeeded = new VersionStringDictionary(); // brand new package, create new list. } token = packageData.Token; } }
public void EntityIsNotNullAfterCreate() { EntityOps entityOps = new EntityOps(DbInit.DBInit().Context); Person person = entityOps.CreateAndGetPersoFromRelatedCollection(saveChanges: true); Assert.IsNotNull(person); }
public Default( IOperatorData operatorData ) { kind = IdentifierKind.Operator; id = AttributeOps.GetObjectId(this); group = AttributeOps.GetObjectGroup(this); if (operatorData != null) { EntityOps.MaybeSetGroup( this, operatorData.Group); name = operatorData.Name; description = operatorData.Description; clientData = operatorData.ClientData; typeName = operatorData.TypeName; lexeme = operatorData.Lexeme; operands = operatorData.Operands; types = operatorData.Types; flags = operatorData.Flags; plugin = operatorData.Plugin; token = operatorData.Token; } }
/////////////////////////////////////////////////////////////////////// internal StringList GetDefined( Interpreter interpreter, string pattern ) { StringList result = new StringList(); foreach (KeyValuePair <string, IVariable> pair in this) { IVariable variable = pair.Value; if (variable == null) { continue; } if (EntityOps.IsUndefined(variable)) { continue; } string name = variable.Name; if ((pattern == null) || StringOps.Match( interpreter, StringOps.DefaultMatchMode, name, pattern, false)) { result.Add(name); } } return(result); }
public void EntityIsNullAfterDelete() { EntityOps entityOps = new EntityOps(DbInit.DBInit().Context); Person newPerson = entityOps.CreateAndSavePerson(); Person deletedPerson = entityOps.DeleteAndGetPersonFromRelatedCollection(newPerson.Id, saveChanges: true); Assert.IsNull(deletedPerson); }
/////////////////////////////////////////////////////////////////////////////////////////////// #region System.Object Overrides public override string ToString() { // CheckDisposed(); /* EXEMPT: During disposal. */ string result = EntityOps.GetNameNoThrow(execute); return((result != null) ? result : String.Empty); }
public void EntityIsNullAfterCreateNotExpectedBehaviour() { EntityOps entityOps = new EntityOps(DbInit.DBInit().Context); Person person = entityOps.CreateAndGetPersoFromRelatedCollection(); string error = @"Person received from collection of team is null. We need it not null. SaveChanges or DetectChagnes helps but frequent execution of save make app slow"; Assert.IsNotNull(person, error); }
/////////////////////////////////////////////////////////////////////// internal StringList GetLocals( Interpreter interpreter, string pattern ) { if (pattern != null) { pattern = ScriptOps.MakeVariableName(pattern); } StringList result = new StringList(); foreach (KeyValuePair <string, IVariable> pair in this) { IVariable variable = pair.Value; if (variable == null) { continue; } if (EntityOps.IsUndefined(variable) || EntityOps.IsLink(variable)) { continue; } ICallFrame frame = CallFrameOps.FollowNext(variable.Frame); if (interpreter != null) { if (interpreter.IsGlobalCallFrame(frame)) { continue; } if (Interpreter.IsNamespaceCallFrame(frame)) { continue; } } string name = variable.Name; if ((pattern == null) || StringOps.Match( interpreter, StringOps.DefaultMatchMode, name, pattern, false)) { result.Add(name); } } return(result); }
/////////////////////////////////////////////////////////////////////// protected virtual long GetValueToken( TValue value, long?token ) { if (token != null) { return((long)token); } return(EntityOps.GetTokenNoThrow(value)); }
/////////////////////////////////////////////////////////////////////// internal static bool MaybeDispose( IEvent @event /* in */ ) { if (@event != null) { EventFlags flags = EntityOps.GetFlagsNoThrow(@event); if (FlagOps.HasFlags( flags, EventFlags.FireAndForget, true)) { return(Dispose(@event)); } } return(false); }
/////////////////////////////////////////////////////////////////////// internal int SetUndefined( Interpreter interpreter, string pattern, bool undefined ) { int result = 0; foreach (KeyValuePair <string, IVariable> pair in this) { IVariable variable = pair.Value; if (variable == null) { continue; } // // NOTE: This method is EXEMPT from the normal requirement // that all the variables operated on must be defined. // // if (EntityOps.IsUndefined(variable)) // continue; string name = variable.Name; if ((pattern == null) || StringOps.Match( interpreter, StringOps.DefaultMatchMode, name, pattern, false)) { if (EntityOps.IsUndefined(variable) == undefined) { continue; } if (EntityOps.SetUndefined(variable, undefined)) { result++; } } } return(result); }
/////////////////////////////////////////////////////////////////////// #region Protected Helper Methods protected virtual long GetKeyToken( TKey key, long?token ) { if (token != null) { return((long)token); } TValue value; if (base.TryGetValue(key, out value)) { return(EntityOps.GetTokenNoThrow(value)); } return(0); }
/////////////////////////////////////////////////////////////////////// #region Private Methods internal int SetReadOnly( Interpreter interpreter, string pattern, bool readOnly ) { int result = 0; foreach (KeyValuePair <string, IVariable> pair in this) { IVariable variable = pair.Value; if (variable == null) { continue; } if (EntityOps.IsUndefined(variable)) { continue; } string name = variable.Name; if ((pattern == null) || StringOps.Match( interpreter, StringOps.DefaultMatchMode, name, pattern, false)) { if (EntityOps.IsReadOnly(variable) == readOnly) { continue; } if (EntityOps.SetReadOnly(variable, readOnly)) { result++; } } } return(result); }
public Default( IObjectTypeData objectTypeData ) { kind = IdentifierKind.ObjectType; id = AttributeOps.GetObjectId(this); group = AttributeOps.GetObjectGroup(this); if (objectTypeData != null) { EntityOps.MaybeSetGroup( this, objectTypeData.Group); name = objectTypeData.Name; description = objectTypeData.Description; clientData = objectTypeData.ClientData; type = objectTypeData.Type; token = objectTypeData.Token; } }
public Default( IResolveData resolveData ) { kind = IdentifierKind.Resolve; id = AttributeOps.GetObjectId(this); group = AttributeOps.GetObjectGroup(this); if (resolveData != null) { EntityOps.MaybeSetGroup( this, resolveData.Group); name = resolveData.Name; description = resolveData.Description; clientData = resolveData.ClientData; interpreter = resolveData.Interpreter; token = resolveData.Token; } }
public Default( ITraceData traceData ) { kind = IdentifierKind.Trace; // // VIRTUAL: Id of the deepest derived class. // id = AttributeOps.GetObjectId(this); // // VIRTUAL: Group of the deepest derived class. // group = AttributeOps.GetObjectGroup(this); // // NOTE: Is the supplied trace data valid? // if (traceData != null) { EntityOps.MaybeSetGroup( this, traceData.Group); name = traceData.Name; description = traceData.Description; typeName = traceData.TypeName; methodName = traceData.MethodName; bindingFlags = traceData.BindingFlags; methodFlags = traceData.MethodFlags; token = traceData.Token; traceFlags = traceData.TraceFlags; plugin = traceData.Plugin; clientData = traceData.ClientData; } callback = null; }
public Default( ISubCommandData subCommandData ) { kind = IdentifierKind.SubCommand; // // VIRTUAL: Id of the deepest derived class. // id = AttributeOps.GetObjectId(this); // // VIRTUAL: Group of the deepest derived class. // group = AttributeOps.GetObjectGroup(this); // // NOTE: Is the supplied command data valid? // if (subCommandData != null) { EntityOps.MaybeSetGroup( this, subCommandData.Group); name = subCommandData.Name; description = subCommandData.Description; commandFlags = subCommandData.CommandFlags; subCommandFlags = subCommandData.Flags; command = subCommandData.Command; clientData = subCommandData.ClientData; token = subCommandData.Token; } callback = null; subCommands = null; syntax = null; }
public Default( IObjectData objectData, object value, IClientData valueData ) { kind = IdentifierKind.Object; id = AttributeOps.GetObjectId(this); group = AttributeOps.GetObjectGroup(this); if (objectData != null) { EntityOps.MaybeSetGroup( this, objectData.Group); name = objectData.Name; description = objectData.Description; clientData = objectData.ClientData; type = objectData.Type; objectFlags = objectData.ObjectFlags; referenceCount = objectData.ReferenceCount; temporaryReferenceCount = objectData.TemporaryReferenceCount; #if NATIVE && TCL interpName = objectData.InterpName; #endif #if DEBUGGER && DEBUGGER_ARGUMENTS executeArguments = objectData.ExecuteArguments; #endif token = objectData.Token; } this.value = value; this.valueData = valueData; }
public Default( IFunctionData functionData ) { kind = IdentifierKind.Function; id = AttributeOps.GetObjectId(this); group = AttributeOps.GetObjectGroup(this); if (functionData != null) { EntityOps.MaybeSetGroup( this, functionData.Group); name = functionData.Name; description = functionData.Description; clientData = functionData.ClientData; typeName = functionData.TypeName; arguments = functionData.Arguments; types = functionData.Types; flags = functionData.Flags; plugin = functionData.Plugin; token = functionData.Token; } }
/////////////////////////////////////////////////////////////////////////////////////////////// #region IEnumerable Members public IEnumerator GetEnumerator() { // // NOTE: Make sure that the variable they supplied is valid before we try to // use it as the basis of our enumerator. // if (interpreter != null) { // // HACK: Handle the global "env" array specially. We must do this because // our global "env" array has no backing storage (unlike Tcl's) and // we do not have a trace operation for "get names" or "get names // and values". // if (interpreter.IsEnvironmentVariable(variable)) { IDictionary environment = Environment.GetEnvironmentVariables(); if (environment != null) { return(environment.Keys.GetEnumerator()); } else { DebugOps.Complain(interpreter, ReturnCode.Error, "environment variables unavailable"); } } else if (interpreter.IsTestsVariable(variable)) { Result error = null; StringDictionary tests = interpreter.GetAllTestInformation( false, ref error); if (tests != null) { return((IEnumerator)tests.Keys.GetEnumerator()); } else { DebugOps.Complain(interpreter, ReturnCode.Error, error); } } else if (interpreter.IsSystemArrayVariable(variable)) { ReturnCode code; StringList keys = null; Result error = null; code = MarshalOps.GetArrayElementKeys( interpreter, EntityOps.GetSystemArray(variable), StringOps.DefaultMatchMode, null, false, ref keys, ref error); if (code == ReturnCode.Ok) { return(keys.GetEnumerator()); } else { DebugOps.Complain(interpreter, code, error); } } else { #if DATA DatabaseVariable databaseVariable = null; if (interpreter.IsDatabaseVariable(variable, ref databaseVariable)) { Result error = null; ObjectDictionary database = databaseVariable.GetList( interpreter, true, false, ref error); if (database != null) { return((IEnumerator)database.Keys.GetEnumerator()); } else { DebugOps.Complain(interpreter, ReturnCode.Error, error); } } else #endif { if (variable != null) { ElementDictionary arrayValue = variable.ArrayValue; if ((arrayValue != null) && (arrayValue.Keys != null)) { return(arrayValue.Keys.GetEnumerator()); } } } } } // // NOTE: While the MSDN documentation does not seem to prohibit returning // null here, there may be components and/or applications that would // consider it "bad form"; therefore, we simply return an enumerator // that does nothing. // return(new NullEnumerator <object>()); }
/////////////////////////////////////////////////////////////////////// public bool ChangeFlags( string key, VariableFlags initialValue, VariableFlags changeValue, bool create, bool add, ref bool notify ) { if ((key != null) && (elementFlags != null)) { VariableFlags oldValue; VariableFlags newValue; if (elementFlags.TryGetValue(key, out oldValue)) { if (add) { newValue = oldValue | changeValue; elementFlags[key] = newValue; if (notify && EntityOps.OnFlagsChanged( variableEvent, oldValue, newValue)) { notify = false; } return(true); } else { newValue = oldValue & ~changeValue; if (newValue != VariableFlags.None) { elementFlags[key] = newValue; if (notify && EntityOps.OnFlagsChanged( variableEvent, oldValue, newValue)) { notify = false; } return(true); } if (notify && EntityOps.OnFlagsChanged( variableEvent, oldValue, newValue)) { notify = false; } return(elementFlags.Remove(key)); } } else if (create) { newValue = add ? (initialValue | changeValue) : VariableFlags.None; elementFlags.Add(key, newValue); if (notify && EntityOps.OnFlagsChanged( variableEvent, oldValue, newValue)) { notify = false; } return(true); } } return(false); }
/////////////////////////////////////////////////////////////////////// public ReturnCode FireTraces( BreakpointType breakpointType, Interpreter interpreter, ITraceInfo traceInfo, ref Result result ) { ReturnCode code = ReturnCode.Ok; if (traces != null) { // // NOTE: Save the current variable flags. // VariableFlags savedFlags = flags; // // NOTE: Prevent endless trace recursion. // flags |= VariableFlags.NoTrace; try { // // NOTE: Process each trace (as long as they all continue // to succeed). // foreach (ITrace trace in traces) { if ((trace != null) && !EntityOps.IsDisabled(trace)) { // // NOTE: If possible, set the Trace property of the // TraceInfo to the one we are about to execute. // if (traceInfo != null) { traceInfo.Trace = trace; } // // NOTE: Since variable traces can basically do anything // they want, we wrap them in a try block to prevent // exceptions from escaping. // interpreter.EnterTraceLevel(); try { code = trace.Execute( breakpointType, interpreter, traceInfo, ref result); } catch (Exception e) { // // NOTE: Translate exceptions to a failure return. // result = String.Format( "caught exception while firing variable trace: {0}", e); code = ReturnCode.Error; } finally { interpreter.ExitTraceLevel(); } // // NOTE: Check for exception results specially because we // treat "Break" different from other return codes. // if (code == ReturnCode.Break) { // // NOTE: Success; however, skip processing further // traces for this variable operation. // code = ReturnCode.Ok; break; } else if (code != ReturnCode.Ok) { // // NOTE: Some type of failure (or exception), stop // processing for this variable operation. // break; } } } } finally { // // NOTE: Restore the saved variable flags. // flags = savedFlags; } } return(code); }
/////////////////////////////////////////////////////////////////////// #region INotify Members public override ReturnCode Notify( Interpreter interpreter, IScriptEventArgs eventArgs, IClientData clientData, ArgumentList arguments, ref Result result ) { if (eventArgs == null) { return(ReturnCode.Ok); } if (!FlagOps.HasFlags( eventArgs.NotifyTypes, NotifyType.CallFrame, false)) { return(ReturnCode.Ok); } NotifyFlags notifyFlags = eventArgs.NotifyFlags; if (!FlagOps.HasFlags(notifyFlags, NotifyFlags.Popped | NotifyFlags.Deleted, false)) { return(ReturnCode.Ok); } IClientData eventClientData = eventArgs.ClientData; if (eventClientData == null) { return(ReturnCode.Ok); } ICallFrame newFrame = eventClientData.Data as ICallFrame; if (newFrame == null) { return(ReturnCode.Ok); } // // NOTE: Make sure the variables in this frame actually BELONG // to this frame. Also, we do not handle the global call // frame. // if (!FlagOps.HasFlags(notifyFlags, NotifyFlags.Force, true) && !CallFrameOps.IsNonGlobalVariable(newFrame)) { return(ReturnCode.Ok); } // // NOTE: If this is a [scope] created call frame, we do NOT want // to change any reference counts unless the call frame is // being deleted, not simply popped. // if (!FlagOps.HasFlags(notifyFlags, NotifyFlags.Deleted, true) && CallFrameOps.IsScope(newFrame)) { return(ReturnCode.Ok); } // // NOTE: Grab the variables for this call frame. If there are // none, we are done. // VariableDictionary variables = newFrame.Variables; if (variables == null) { return(ReturnCode.Ok); } // // NOTE: Process each variable in the call frame to adjust all // all the reference counts. After this point, we need // the interpreter context for the event. // Interpreter eventInterpreter = eventArgs.Interpreter; if (eventInterpreter == null) { return(ReturnCode.Ok); } foreach (KeyValuePair <string, IVariable> pair in variables) { // // NOTE: Grab the variable and make sure the variable it is // valid. // IVariable variable = pair.Value; if (variable == null) { continue; } // // NOTE: For unset operations, ObjectTraceCallback uses only // the "traceInfo.Variable" and "traceInfo.oldValue" // members of the ITraceInfo object instance. If the // number of trace and/or watch levels exceeds one, // force creation of a new TraceInfo object here; // otherwise, we may interfere with the setting of an // unrelated variable value. // ITraceInfo traceInfo = ScriptOps.NewTraceInfo( interpreter, null, BreakpointType.BeforeVariableUnset, newFrame, variable, pair.Key, null, VariableFlags.None, variable.Value, null, null, null, null, interpreter.NeedNewTraceInfo(VariableFlags.None), false, !EntityOps.IsNoPostProcess(variable), ReturnCode.Ok); // // HACK: Manually invoke the Interpreter.ObjectTraceCallback // static (trace callback) method, in order to handle // contained object reference(s), if any. After this // method returns, the entire call frame will be going // away, along with any object references contained // within it. // ReturnCode code = Interpreter.ObjectTraceCallback( traceInfo.BreakpointType, eventInterpreter, traceInfo, ref result); if (code != ReturnCode.Ok) { return(code); } } return(ReturnCode.Ok); }
/////////////////////////////////////////////////////////////////////// #region IExecute Members public override ReturnCode Execute( Interpreter interpreter, IClientData clientData, ArgumentList arguments, ref Result result ) { ReturnCode code = ReturnCode.Ok; if (interpreter != null) { if (arguments != null) { IScriptLocation location = null; code = ScriptOps.GetAndCheckProcedureLocation( interpreter, this, ref location, ref result); if (code == ReturnCode.Ok) { string procedureName = this.Name; ArgumentList procedureArguments = this.Arguments; if (procedureArguments != null) { bool hasArgs = procedureArguments.IsVariadic(true); int totalArgs = hasArgs ? procedureArguments.Count - 1 : procedureArguments.Count; int optionalArgs = procedureArguments.GetOptionalCount(); if ((arguments.Count > 0) && ((((arguments.Count - 1) >= (totalArgs - optionalArgs)) && ((arguments.Count - 1) <= totalArgs)) || (hasArgs && ((arguments.Count - 1) >= (totalArgs - optionalArgs))))) { ICallFrame frame = null; try { frame = interpreter.NewProcedureCallFrame( procedureName, CallFrameFlags.Procedure, null, this, arguments); VariableDictionary variables = frame.Variables; frame.ProcedureArguments = new ArgumentList(arguments[0]); for (int argumentIndex = 0; argumentIndex < procedureArguments.Count; argumentIndex++) { string varName = procedureArguments[argumentIndex].Name; if (!variables.ContainsKey(varName)) { ArgumentFlags flags = ArgumentFlags.None; object varValue; if (hasArgs && (argumentIndex == (procedureArguments.Count - 1))) { // // NOTE: This argument is part of an argument list. // flags |= ArgumentFlags.ArgumentList; // // NOTE: Build the list for the final formal argument value, // which consists of all the remaining argument values. // ArgumentList argsArguments = new ArgumentList(); for (int argsArgumentIndex = argumentIndex + 1; argsArgumentIndex < arguments.Count; argsArgumentIndex++) { // // NOTE: Sync up the argument name and flags for use when // debugging (below). // Argument argsArgument = Argument.GetOrCreate( interpreter, arguments[argsArgumentIndex].Flags | flags, String.Format("{0}{1}{2}", varName, Characters.Space, argsArguments.Count), arguments[argsArgumentIndex], interpreter.HasNoCacheArgument()); argsArguments.Add(argsArgument); } varValue = argsArguments; } else { if ((argumentIndex + 1) < arguments.Count) { // // NOTE: Sync up the argument name for use when // debugging (below) and use the value // supplied by the caller. // varValue = Argument.GetOrCreate(interpreter, arguments[argumentIndex + 1].Flags | flags, varName, arguments[argumentIndex + 1], interpreter.HasNoCacheArgument()); } else { // // NOTE: We cannot sync up the argument name here // because we are out-of-bounds on that list // and it cannot be extended (i.e. it would // break [info level]); therefore, we punt // on that for now. Use the default value // for this argument, if any; otherwise, use // an empty string. // object @default = procedureArguments[argumentIndex].Default; varValue = (@default != null) ? @default : Argument.NoValue; } } code = interpreter.SetVariableValue2(VariableFlags.Argument, frame, varName, varValue, ref result); if (code != ReturnCode.Ok) { break; } // // BUGFIX: Now, also keep track of this argument in the procedure // arguments list. Primarily because we do not want to // have to redo this logic later (i.e. for [scope]). // frame.ProcedureArguments.Add(Argument.GetOrCreate( interpreter, flags, varName, varValue, interpreter.HasNoCacheArgument())); } } // // NOTE: Make sure we succeeded in creating the call frame. // if (code == ReturnCode.Ok) { ICallFrame savedFrame = null; interpreter.PushProcedureCallFrame(frame, true, ref savedFrame); try { #if DEBUGGER && DEBUGGER_EXECUTE if (DebuggerOps.CanHitBreakpoints(interpreter, EngineFlags.None, BreakpointType.BeforeProcedureBody)) { code = interpreter.CheckBreakpoints( code, BreakpointType.BeforeProcedureBody, procedureName, null, null, this, null, clientData, arguments, ref result); } #endif if (code == ReturnCode.Ok) { bool locked = false; try { bool atomic = EntityOps.IsAtomic(this); if (atomic) { interpreter.InternalTryLock(ref locked); /* TRANSACTIONAL */ } if (!atomic || locked) { #if ARGUMENT_CACHE || PARSE_CACHE EngineFlags savedEngineFlags = EngineFlags.None; bool nonCaching = EntityOps.IsNonCaching(this); if (nonCaching) { interpreter.BeginProcedureBodyNoCaching( ref savedEngineFlags); } try { #endif string body = this.Body; interpreter.ReturnCode = ReturnCode.Ok; code = interpreter.EvaluateScript( body, location, ref result); #if ARGUMENT_CACHE || PARSE_CACHE } finally { if (nonCaching) { interpreter.EndProcedureBodyNoCaching( ref savedEngineFlags); } } #endif } else { result = "could not lock interpreter"; code = ReturnCode.Error; } } finally { interpreter.InternalExitLock(ref locked); /* TRANSACTIONAL */ } #if DEBUGGER && DEBUGGER_EXECUTE if (DebuggerOps.CanHitBreakpoints(interpreter, EngineFlags.None, BreakpointType.AfterProcedureBody)) { code = interpreter.CheckBreakpoints( code, BreakpointType.AfterProcedureBody, procedureName, null, null, this, null, clientData, arguments, ref result); } #endif // // BUGFIX: If an opaque object handle is being returned, add // a reference to it now. // if ((code == ReturnCode.Ok) || (code == ReturnCode.Return)) { code = interpreter.AddObjectReference( code, result, ObjectReferenceType.Return, ref result); } if (code == ReturnCode.Return) { code = Engine.UpdateReturnInformation(interpreter); } else if (code == ReturnCode.Error) { Engine.AddErrorInformation(interpreter, result, String.Format("{0} (procedure \"{1}\" line {2})", Environment.NewLine, FormatOps.Ellipsis(procedureName), Interpreter.GetErrorLine(interpreter))); } } } finally { /* IGNORED */ interpreter.PopProcedureCallFrame(frame, ref savedFrame); } } } finally { if (frame != null) { IDisposable disposable = frame as IDisposable; if (disposable != null) { disposable.Dispose(); disposable = null; } frame = null; } } } else { if (procedureArguments.Count > 0) { result = String.Format( "wrong # args: should be \"{0} {1}\"", Parser.Quote(procedureName), procedureArguments.ToRawString(ToStringFlags.Decorated, Characters.Space.ToString())); } else { result = String.Format( "wrong # args: should be \"{0}\"", Parser.Quote(procedureName)); } code = ReturnCode.Error; } } else { result = "invalid procedure argument list"; code = ReturnCode.Error; } } } else { result = "invalid argument list"; code = ReturnCode.Error; } } else { result = "invalid interpreter"; code = ReturnCode.Error; } return(code); }
/// <summary> /// This is the constructor used by the core library to create an /// instance of the plugin, passing the necessary data to be used /// for initializing the plugin. /// </summary> /// /// <param name="pluginData"> /// An instance of the plugin data component used to hold the data /// necessary to fully initialize the plugin instance. This /// parameter may be null. Derived plugins are free to override /// this constructor; however, they are very strongly encouraged to /// call this constructor (i.e. the base class constructor) in that /// case. /// </param> public Default( IPluginData pluginData ) { kind = IdentifierKind.Plugin; // // VIRTUAL: Id of the deepest derived class. // id = AttributeOps.GetObjectId(this); // // VIRTUAL: Group of the deepest derived class. // group = AttributeOps.GetObjectGroup(this); // // NOTE: Is the supplied plugin data valid? // if (pluginData != null) { EntityOps.MaybeSetGroup( this, pluginData.Group); name = pluginData.Name; description = pluginData.Description; flags = pluginData.Flags; clientData = pluginData.ClientData; version = pluginData.Version; uri = pluginData.Uri; appDomain = pluginData.AppDomain; assembly = pluginData.Assembly; assemblyName = pluginData.AssemblyName; fileName = pluginData.FileName; typeName = pluginData.TypeName; } // // NOTE: Are we going to use their command list or create an // entirely new list? // if ((pluginData != null) && (pluginData.Commands != null)) { commands = pluginData.Commands; } else { commands = new CommandDataList(); } // // NOTE: Are we going to use their policy list or create an // entirely new list? // if ((pluginData != null) && (pluginData.Policies != null)) { policies = pluginData.Policies; } else { policies = new PolicyDataList(); } // // NOTE: Are we going to use their command tokens or create an // entirely new list? // if ((pluginData != null) && (pluginData.CommandTokens != null)) { commandTokens = pluginData.CommandTokens; } else { commandTokens = new LongList(); } // // NOTE: Are we going to use their command tokens or create an // entirely new list? // if ((pluginData != null) && (pluginData.FunctionTokens != null)) { functionTokens = pluginData.FunctionTokens; } else { functionTokens = new LongList(); } // // NOTE: Are we going to use their policy tokens or create an // entirely new list? // if ((pluginData != null) && (pluginData.PolicyTokens != null)) { policyTokens = pluginData.PolicyTokens; } else { policyTokens = new LongList(); } // // NOTE: Are we going to use their trace tokens or create an // entirely new list? // if ((pluginData != null) && (pluginData.TraceTokens != null)) { traceTokens = pluginData.TraceTokens; } else { traceTokens = new LongList(); } // // NOTE: Are we going to use the resource manager they specified or // create a new one based on the plugin name and assembly? // if ((pluginData != null) && (pluginData.ResourceManager != null)) { resourceManager = pluginData.ResourceManager; } else { // // NOTE: If the assembly is null we are probably loaded into an // isolated application domain. Therefore, in that case, // and only in that case, since we are executing in the // target application domain, load the assembly based on // the assembly name and then use that to create the // resource manager. However, do not simply set the // assembly field of this plugin to any non-null value // because we do not want to cause issues with the // interpreter plugin manager later. Also, skip attempts // to create a resource manager if the NoResources flag // has been set on the plugin. // if (!FlagOps.HasFlags(flags, PluginFlags.NoResources, true)) { if (assembly != null) { resourceManager = RuntimeOps.NewResourceManager( assembly); } else if (assemblyName != null) { resourceManager = RuntimeOps.NewResourceManager( assemblyName); } } } // // NOTE: Are we going to use the auxiliary data they specified or // create a new one? // if ((pluginData != null) && (pluginData.AuxiliaryData != null)) { auxiliaryData = pluginData.AuxiliaryData; } else { if (!FlagOps.HasFlags( flags, PluginFlags.NoAuxiliaryData, true)) { auxiliaryData = new ObjectDictionary(); } } // // NOTE: Also store the plugin token (which may be zero at this // point). // if (pluginData != null) { token = pluginData.Token; } }
/////////////////////////////////////////////////////////////////////// public StringPairList ToStringPairList() { StringPairList result = new StringPairList(); if (variable != null) { result.Add(variable.Kind.ToString()); result.Add((IPair <string>)null); if (variable.Name != null) { result.Add("name", variable.Name); } else { result.Add("name", String.Empty); } if (EntityOps.IsArray2(variable)) { ElementDictionary arrayValue = variable.ArrayValue; if (arrayValue != null) { result.Add("<array>"); if (index != null) { object value; if (arrayValue.TryGetValue(index, out value)) { if (value != null) { result.Add("value", StringOps.GetStringFromObject( value, null, !(value is TraceInfo))); } else { result.Add("value", FormatOps.DisplayNull); } } else { result.Add("value", "<noValue>"); } } else { result.Add("value", "<noIndex>"); } } else { result.Add("<noArray>"); } } else { object value = variable.Value; if (value != null) { result.Add("value", StringOps.GetStringFromObject(value)); } else { result.Add("value", "<noValue>"); } } result.Add("flags", variable.Flags.ToString()); result.Add((IPair <string>)null); } result.Add("TraceInfo"); result.Add((IPair <string>)null); if (trace != null) { result.Add("trace", trace.ToString()); } else { result.Add("trace", "<noTrace>"); } result.Add("breakpointType", breakpointType.ToString()); if (frame != null) { result.Add("frame", (frame.Name != null) ? frame.Name : "<noFrameName>"); } else { result.Add("frame", "<noFrame>"); } if (name != null) { result.Add("name", name); } else { result.Add("name", "<noName>"); } if (index != null) { result.Add("index", index); } else { result.Add("index", "<noIndex>"); } result.Add("flags", flags.ToString()); if (oldValue != null) { result.Add("oldValue", StringOps.GetStringFromObject(oldValue)); } else { result.Add("oldValue", "<noOldValue>"); } if (newValue != null) { result.Add("newValue", StringOps.GetStringFromObject(newValue)); } else { result.Add("newValue", "<noNewValue>"); } if (oldValues != null) { result.Add("oldValues", oldValues.ToString()); } else { result.Add("oldValues", "<noOldValues>"); } if (newValues != null) { result.Add("newValues", newValues.ToString()); } else { result.Add("newValues", "<noNewValues>"); } if (list != null) { result.Add("list", list.ToString()); } else { result.Add("list", "<noList>"); } result.Add("cancel", cancel.ToString()); result.Add("postProcess", postProcess.ToString()); result.Add("returnCode", returnCode.ToString()); return(result); }