/////////////////////////////////////////////////////////////////////// #region Public Methods public IStringList ToList() { IStringList list = new StringPairList(); object data = this.Data; if (data != null) { list.Add("Data", data.ToString()); } if (fileName != null) { list.Add("FileName", fileName); } if (originalText != null) { list.Add("OriginalText", originalText); } if (text != null) { list.Add("Text", text); } if (bytes != null) { list.Add("Bytes", bytes.ToString()); } return(list); }
/////////////////////////////////////////////////////////////////////// public StringPairList ToList() { StringPairList list = new StringPairList(); list.Add("findFlags", findFlags.ToString()); list.Add("loadFlags", loadFlags.ToString()); list.Add("findData", StringOps.GetStringsFromObject(findData)); list.Add("fileName", fileName); list.Add("priority", priority.ToString()); list.Add("sequence", sequence.ToString()); list.Add("operatingSystem", operatingSystemId.ToString()); list.Add("version", (version != null) ? version.ToString() : null); list.Add("patchLevel", (patchLevel != null) ? patchLevel.ToString() : null); list.Add("releaseLevel", releaseLevel.ToString()); list.Add("magic", FormatOps.Hexadecimal(magic, true)); list.Add("threaded", threaded.ToString()); list.Add("debug", debug.ToString()); list.Add("defaultThreaded", DefaultThreaded.ToString()); list.Add("matchDebug", MatchDebug.ToString()); return(list); }
/////////////////////////////////////////////////////////////////////// public StringPairList ToList() { CheckDisposed(); StringPairList list = new StringPairList(); list.Add("name", (name != null) ? name : _String.Null); list.Add("interpreter", (interpreter != null) ? interpreter.InternalToString() : _String.Null); if (!id.Equals(Guid.Empty)) { list.Add("id", id.ToString()); } list.Add("type", type.ToString()); list.Add("flags", flags.ToString()); list.Add("priority", priority.ToString()); list.Add("dateTime", dateTime.ToString()); list.Add("callback", (callback != null) ? callback.ToString() : _String.Null); list.Add("clientData", ((clientData != null) && (clientData.Data != null)) ? StringList.MakeList(clientData.Data.GetType().Name, clientData.Data) : _String.Null); return(list); }
/////////////////////////////////////////////////////////////////////// private static void AddInfo( AppDomainSetup appDomainSetup, StringPairList list, DetailFlags detailFlags ) { if (list == null) { return; } if (appDomainSetup != null) { bool empty = HostOps.HasEmptyContent(detailFlags); if (empty || (appDomainSetup.ApplicationBase != null)) { list.Add("ApplicationBase", appDomainSetup.ApplicationBase); } if (empty || (appDomainSetup.PrivateBinPath != null)) { list.Add("PrivateBinPath", appDomainSetup.PrivateBinPath); } } else { list.Add(FormatOps.DisplayNull); } }
/////////////////////////////////////////////////////////////////////////////////////////////// public IStringList ToList( string pattern, bool noCase ) { IStringList list = new StringPairList(); foreach (KeyValuePair <string, ScriptLocationIntDictionary> pair in this) { if ((pattern == null) || StringOps.Match(null, MatchMode.Glob, pair.Key, pattern, noCase)) { list.Add("Name", pair.Key); if (pair.Value != null) { // // HACK: This is a bit clumsy. // IEnumerable <IPair <string> > collection = pair.Value.ToList() as IEnumerable <IPair <string> >; if (collection != null) { foreach (IPair <string> item in collection) { list.Add(item.X, item.Y); } } } } } return(list); }
public static List <MetadataKeyword> ToKeywordList(this StringPairList source) { return(source .Select((pair => new MetadataKeyword { Vocab = pair.Item1, Value = pair.Item2 })) .ToList()); }
public static List <Extent> ToExtentList(this StringPairList source) { return(source .Select((pair => new Extent { Authority = pair.Item1, Value = pair.Item2 })) .ToList()); }
/////////////////////////////////////////////////////////////////////// public override bool EndBox( string name, StringPairList list, IClientData clientData ) { CheckDisposed(); return(true); }
/////////////////////////////////////////////////////////////////////////////////////////////// #region IBoxHost Members public override bool BeginBox( string name, StringPairList list, IClientData clientData ) { CheckDisposed(); return(false); }
/////////////////////////////////////////////////////////////////////// public StringPairList ToList() { StringPairList list = new StringPairList(); list.Add("fileName", fileName); list.Add("module", module.ToString()); list.Add("referenceCount", referenceCount.ToString()); list.Add("lockCount", lockCount.ToString()); return(list); }
/////////////////////////////////////////////////////////////////////// public IStringList ToList() { IStringList list = new StringPairList(); foreach (KeyValuePair <IScriptLocation, int> pair in this) { list.Add(pair.Key.ToList()); list.Add("HitCount", pair.Value.ToString()); } return(list); }
public void LoadData() { StringPairList DataList = new StringPairList(); DataManager.Public.PersonRewardPunishInfoModel model = new DataManager.Public.PersonRewardPunishInfoModel(); List <PersonRewardPunishInfo> ppilist = model.GetPersonRewardPunishInfos("", "", nameid, fromdate, todate, "order by RPTIME "); if (ppilist.Count > 0) { this.chartTitle.Content = ppilist[0].NAME + " 的量化数据走势图"; } double tatolScore = 0; foreach (PersonRewardPunishInfo ppi in ppilist) { string datestr = ""; try { datestr = Convert.ToDateTime(ppi.RPTIME).ToString("yyyy-MM-dd"); } catch { } foreach (StringPair tempsp in DataList.SPList) { if (tempsp.Key == datestr) { tempsp.Value = (Convert.ToDouble(tempsp.Value) + ppi.FRACTION).ToString(); continue; } } StringPair sp = new StringPair(); sp.Key = datestr; tatolScore = tatolScore + ppi.FRACTION; sp.Value = tatolScore.ToString(); DataList.SPList.Add(sp); } this.Series.DataSource = null; this.Series.DataSource = DataList.SPList; }
/////////////////////////////////////////////////////////////////////////////////////////////// public StringPairList ToList(bool scrub) { StringPairList list = new StringPairList(); list.Add("FileName", scrub ? PathOps.ScrubPath( GlobalState.GetBasePath(), fileName) : fileName); list.Add("StartLine", startLine.ToString()); list.Add("EndLine", endLine.ToString()); list.Add("ViaSource", viaSource.ToString()); return(list); }
/////////////////////////////////////////////////////////////////////// public IStringList ToList() { IStringList list = new StringPairList(); list.Add("Index", index.ToString()); list.Add("Type", (type != null) ? type.ToString() : null); list.Add("Name", name); list.Add("Counts", (counts != null) ? new IntList(counts).ToString() : null); list.Add("Input", input.ToString()); list.Add("Output", output.ToString()); return(list); }
/////////////////////////////////////////////////////////////////////// public StringPairList ToList( bool scrub ) { StringPairList list = new StringPairList(); list.Add("type", type); list.Add("text", text); list.Add("fileName", scrub ? PathOps.ScrubPath( GlobalState.GetBasePath(), fileName) : fileName); list.Add("startLine", startLine.ToString()); list.Add("endLine", endLine.ToString()); list.Add("viaSource", viaSource.ToString()); list.Add("engineMode", engineMode.ToString()); list.Add("scriptFlags", scriptFlags.ToString()); list.Add("engineFlags", engineFlags.ToString()); list.Add("substitutionFlags", substitutionFlags.ToString()); list.Add("eventFlags", eventFlags.ToString()); list.Add("expressionFlags", expressionFlags.ToString()); #if XML list.Add("blockType", blockType.ToString()); list.Add("timeStamp", timeStamp.ToString()); list.Add("publicKeyToken", publicKeyToken); list.Add("signature", ArrayOps.ToHexadecimalString(signature)); #endif #if CAS_POLICY if (!scrub) { list.Add("evidence", (evidence != null) ? evidence.ToString() : null); list.Add("hashValue", ArrayOps.ToHexadecimalString(hashValue)); list.Add("hashAlgorithm", (hashAlgorithm != null) ? hashAlgorithm.ToString() : null); } #endif return(list); }
/////////////////////////////////////////////////////////////////////// public static StringPairList GetObjectIds( AppDomain appDomain, bool all, ref Result error ) { if (appDomain != null) { try { StringPairList list = new StringPairList(); foreach (Assembly assembly in appDomain.GetAssemblies()) { if (assembly != null) { StringPairList list2 = GetObjectIds( assembly, all, ref error); if (list2 == null) { return(null); } list.AddRange(list2); } } return(list); } catch (Exception e) { error = e; } } else { error = "invalid application domain"; } return(null); }
/////////////////////////////////////////////////////////////////////// #region Internal Methods internal string ToTraceString() { IStringList list = new StringPairList(); list.Add("debug", debug.ToString()); list.Add("args", FormatOps.WrapArgumentsOrNull(true, true, args)); list.Add("code", code.ToString()); list.Add("breakpointType", breakpointType.ToString()); list.Add("breakpointName", FormatOps.WrapOrNull(breakpointName)); list.Add("token", (token != null).ToString()); list.Add("traceInfo", (traceInfo != null).ToString()); list.Add("engineFlags", FormatOps.WrapOrNull(engineFlags)); list.Add("substitutionFlags", FormatOps.WrapOrNull(substitutionFlags)); list.Add("eventFlags", FormatOps.WrapOrNull(eventFlags)); list.Add("expressionFlags", FormatOps.WrapOrNull(expressionFlags)); list.Add("headerFlags", FormatOps.WrapOrNull(headerFlags)); list.Add("clientData", FormatOps.WrapOrNull(clientData)); list.Add("arguments", FormatOps.WrapOrNull(true, true, arguments)); list.Add("exit", exit.ToString()); return(list.ToString()); }
/////////////////////////////////////////////////////////////////////// public static StringPairList GetObjectIds( Assembly assembly, bool all, ref Result error ) { if (assembly != null) { try { StringPairList list = new StringPairList(); foreach (Type type in assembly.GetTypes()) /* throw */ { bool defined = false; Guid id = GetObjectId(type, ref defined); if (all || defined || !id.Equals(Guid.Empty)) { list.Add(id.ToString(), type.FullName); } } return(list); } catch (Exception e) { error = e; } } else { error = "invalid assembly"; } return(null); }
public void should_save_keywords_in_correct_order() { // should be sorted by vocab, then value, but with distinguished jncc vocabs first! // finally, keywords with no namespace should be last var database = Mock.Of <IDocumentSession>(); var service = new RecordService(database, ValidatorStub()); var record = BasicRecord().With(r => { r.Gemini.Keywords = new StringPairList { { "a-vocab-beginning-with-a", "bravo" }, { "boring-vocab-beginning-with-b", "some-keyword" }, { "a-vocab-beginning-with-a", "alpha" }, { "http://vocab.jncc.gov.uk/jncc-category", "bravo" }, { "http://vocab.jncc.gov.uk/jncc-category", "alpha" }, { "http://vocab.jncc.gov.uk/jncc-domain", "some-domain" }, { "", "some-keyword" }, }.ToKeywordList(); }); service.Update(record, TestUser); var expected = new StringPairList { { "http://vocab.jncc.gov.uk/jncc-domain", "some-domain" }, { "http://vocab.jncc.gov.uk/jncc-category", "alpha" }, { "http://vocab.jncc.gov.uk/jncc-category", "bravo" }, { "a-vocab-beginning-with-a", "alpha" }, { "a-vocab-beginning-with-a", "bravo" }, { "boring-vocab-beginning-with-b", "some-keyword" }, { "", "some-keyword" }, }.ToKeywordList(); Mock.Get(database).Verify(db => db.Store(It.Is((Record r) => r.Gemini.Keywords.IsEqualTo(expected)))); }
/////////////////////////////////////////////////////////////////////// private static void DumpSetup( Interpreter interpreter, string friendlyName, string baseDirectory, string packagePath, bool useBasePath, AppDomainSetup appDomainSetup ) { StringPairList list = new StringPairList(); AddInfo(appDomainSetup, list, DetailFlags.DebugTrace); TraceOps.DebugTrace(String.Format( "DumpSetup: interpreter = {0}, friendlyName = {1}, " + "baseDirectory = {2}, packagePath = {3}, " + "useBasePath = {4}, appDomainSetup = {5}", FormatOps.InterpreterNoThrow(interpreter), FormatOps.WrapOrNull(friendlyName), FormatOps.WrapOrNull(baseDirectory), FormatOps.WrapOrNull(packagePath), useBasePath, list), typeof(AppDomainOps).Name, TracePriority.SecurityDebug); }
/////////////////////////////////////////////////////////////////////// internal string ToTraceString() { IStringList list = new StringPairList(); list.Add("ArgumentCallback", FormatOps.WrapOrNull( FormatOps.DelegateName(argumentCallback))); list.Add("EvaluateScriptCallback", FormatOps.WrapOrNull( FormatOps.DelegateName(evaluateScriptCallback))); list.Add("EvaluateFileCallback", FormatOps.WrapOrNull( FormatOps.DelegateName(evaluateFileCallback))); list.Add("EvaluateEncodedFileCallback", FormatOps.WrapOrNull( FormatOps.DelegateName(evaluateEncodedFileCallback))); list.Add("InteractiveLoopCallback", FormatOps.WrapOrNull( FormatOps.DelegateName(interactiveLoopCallback))); list.Add("Initialized", initialized.ToString()); list.Add("HadArgumentCallback", hadArgumentCallback.ToString()); list.Add("HadEvaluateScriptCallback", hadEvaluateScriptCallback.ToString()); list.Add("HadEvaluateFileCallback", hadEvaluateFileCallback.ToString()); list.Add("HadEvaluateEncodedFileCallback", hadEvaluateEncodedFileCallback.ToString()); list.Add("HadInteractiveLoopCallback", hadInteractiveLoopCallback.ToString()); return(list.ToString()); }
/////////////////////////////////////////////////////////////////////// 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); }
/////////////////////////////////////////////////////////////////////// #region System.Object Overrides public override string ToString() { StringPairList result = ToStringPairList(); return(result.ToString()); }
/////////////////////////////////////////////////////////////////////// #region IDebugger Members public void AddInfo( StringPairList list, DetailFlags detailFlags ) { CheckDisposed(); bool empty = HostOps.HasEmptyContent(detailFlags); if (empty || (suspendCount > 0)) { list.Add("SuspendCount", suspendCount.ToString()); } if (empty || Enabled) { list.Add("Enabled", Enabled.ToString()); } if (empty || (Loops > 0)) { list.Add("Loops", Loops.ToString()); } if (empty || (Active > 0)) { list.Add("Active", Active.ToString()); } if (empty || SingleStep) { list.Add("SingleStep", SingleStep.ToString()); } #if BREAKPOINTS if (empty || BreakOnToken) { list.Add("BreakOnToken", BreakOnToken.ToString()); } #endif if (empty || BreakOnExecute) { list.Add("BreakOnExecute", BreakOnExecute.ToString()); } if (empty || BreakOnCancel) { list.Add("BreakOnCancel", BreakOnCancel.ToString()); } if (empty || BreakOnError) { list.Add("BreakOnError", BreakOnError.ToString()); } if (empty || BreakOnReturn) { list.Add("BreakOnReturn", BreakOnReturn.ToString()); } if (empty || BreakOnTest) { list.Add("BreakOnTest", BreakOnTest.ToString()); } if (empty || BreakOnExit) { list.Add("BreakOnExit", BreakOnExit.ToString()); } if (empty || (Steps > 0)) { list.Add("Steps", Steps.ToString()); } if (empty || (Types != BreakpointType.None)) { list.Add("Types", Types.ToString()); } #if BREAKPOINTS BreakpointDictionary breakpoints = Breakpoints; if (empty || ((breakpoints != null) && (breakpoints.Count > 0))) { list.Add("Breakpoints", (breakpoints != null) ? breakpoints.Count.ToString() : FormatOps.DisplayNull); } #endif #if DEBUGGER_ARGUMENTS ArgumentList executeArguments = ExecuteArguments; if (empty || (executeArguments != null)) { list.Add("ExecuteArguments", (executeArguments != null) ? executeArguments.ToString(ToStringFlags.NameAndValue, null, false) : FormatOps.DisplayNull); } #endif if (empty || !String.IsNullOrEmpty(Command)) { list.Add("Command", FormatOps.DisplayString( FormatOps.ReplaceNewLines(FormatOps.NormalizeNewLines( Command)))); } if (empty || !String.IsNullOrEmpty(Result)) { list.Add("Result", FormatOps.DisplayString( FormatOps.ReplaceNewLines(FormatOps.NormalizeNewLines( Result)))); } QueueList <string, string> queue = Queue; if (empty || ((queue != null) && (queue.Count > 0))) { list.Add("Queue", (queue != null) ? queue.Count.ToString() : FormatOps.DisplayNull); } StringList callbackArguments = CallbackArguments; if (empty || ((callbackArguments != null) && (callbackArguments.Count > 0))) { list.Add("CallbackArguments", (callbackArguments != null) ? callbackArguments.ToString() : FormatOps.DisplayNull); } if (interpreter != null) { interpreter.GetHostDebuggerInfo(ref list, detailFlags); } else if (empty) { list.Add((IPair <string>)null); list.Add("Interpreter"); list.Add((IPair <string>)null); list.Add("Id", FormatOps.DisplayNull); } }
/////////////////////////////////////////////////////////////////////// #region Internal State Introspection Methods // // NOTE: Used by the _Hosts.Default.BuildEngineInfoList method. // public static void AddInfo( StringPairList list, DetailFlags detailFlags ) { if (list == null) { return; } lock (syncRoot) /* TRANSACTIONAL */ { bool empty = HostOps.HasEmptyContent(detailFlags); StringPairList localList = new StringPairList(); if (empty || isTracePossible) { localList.Add("IsTracePossible", isTracePossible.ToString()); } if (empty || (tracePriorities != TracePriority.None)) { localList.Add("TracePriorities", tracePriorities.ToString()); } if (empty || (defaultTracePriority != TracePriority.None)) { localList.Add("DefaultTracePriority", defaultTracePriority.ToString()); } if (empty || isTraceEnabledByDefault) { localList.Add("IsTraceEnabledByDefault", isTraceEnabledByDefault.ToString()); } if (empty || (isTraceEnabled != null)) { localList.Add("IsTraceEnabled", (isTraceEnabled != null) ? isTraceEnabled.ToString() : FormatOps.DisplayNull); } if (empty || (traceFormat != null)) { localList.Add("TraceFormat", FormatOps.DisplayString(traceFormat)); } if (empty || traceDateTime) { localList.Add("TraceDateTime", traceDateTime.ToString()); } if (empty || tracePriority) { localList.Add("TracePriority", tracePriority.ToString()); } if (empty || traceAppDomain) { localList.Add("TraceAppDomain", traceAppDomain.ToString()); } if (empty || traceInterpreter) { localList.Add("TraceInterpreter", traceInterpreter.ToString()); } if (empty || traceThreadId) { localList.Add("TraceThreadId", traceThreadId.ToString()); } if (empty || traceMethod) { localList.Add("TraceMethod", traceMethod.ToString()); } if (empty || (traceCategories != null)) { localList.Add("TraceCategories", (traceCategories != null) ? traceCategories.KeysAndValuesToString(null, false) : FormatOps.DisplayNull); } if (localList.Count > 0) { list.Add((IPair <string>)null); list.Add("Trace Information"); list.Add((IPair <string>)null); list.Add(localList); } } }
public void should_save_keywords_in_correct_order() { // should be sorted by vocab, then value, but with distinguished jncc vocabs first! // finally, keywords with no namespace should be last var database = Mock.Of<IDocumentSession>(); var service = new RecordService(database, ValidatorStub()); var record = BasicRecord().With(r => { r.Gemini.Keywords = new StringPairList { { "a-vocab-beginning-with-a", "bravo" }, { "boring-vocab-beginning-with-b", "some-keyword" }, { "a-vocab-beginning-with-a", "alpha" }, { "http://vocab.jncc.gov.uk/jncc-category", "bravo" }, { "http://vocab.jncc.gov.uk/jncc-category", "alpha" }, { "http://vocab.jncc.gov.uk/jncc-domain", "some-domain" }, { "", "some-keyword" }, }.ToKeywordList(); }); service.Upsert(record); var expected = new StringPairList { { "http://vocab.jncc.gov.uk/jncc-domain", "some-domain" }, { "http://vocab.jncc.gov.uk/jncc-category", "alpha" }, { "http://vocab.jncc.gov.uk/jncc-category", "bravo" }, { "a-vocab-beginning-with-a", "alpha" }, { "a-vocab-beginning-with-a", "bravo" }, { "boring-vocab-beginning-with-b", "some-keyword" }, { "", "some-keyword" }, }.ToKeywordList(); Mock.Get(database).Verify(db => db.Store(It.Is((Record r) => r.Gemini.Keywords.IsEqualTo(expected)))); }
/////////////////////////////////////////////////////////////////////////////////////////////// #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) { if (arguments.Count >= 2) { // // NOTE: lambdaExpr must be a two element list {args body} or a three element // list {args body namespace}. // StringList lambdaExpr = null; code = Parser.SplitList( interpreter, arguments[1], 0, Length.Invalid, true, ref lambdaExpr, ref result); if (code == ReturnCode.Ok) { if ((lambdaExpr.Count == 2) || (lambdaExpr.Count == 3)) { byte[] hashValue = arguments[1].GetHashValue(ref result); if (hashValue != null) { INamespace @namespace = null; if (lambdaExpr.Count == 3) { @namespace = NamespaceOps.Lookup( interpreter, lambdaExpr[2], true, false, ref result); if (@namespace == null) { code = ReturnCode.Error; } } if (code == ReturnCode.Ok) { // // NOTE: Parse the arguments into a list and make sure there are enough // supplied to satisfy the request. // StringList list = null; code = Parser.SplitList( interpreter, lambdaExpr[0], 0, Length.Invalid, true, ref list, ref result); if (code == ReturnCode.Ok) { StringPairList list2 = new StringPairList(); for (int argumentIndex = 0; argumentIndex < list.Count; argumentIndex++) { StringList list3 = null; code = Parser.SplitList( interpreter, list[argumentIndex], 0, Length.Invalid, true, ref list3, ref result); if (code != ReturnCode.Ok) { break; } if (list3.Count > 2) { result = String.Format( "too many fields in argument specifier \"{0}\"", list[argumentIndex]); code = ReturnCode.Error; break; } else if ((list3.Count == 0) || String.IsNullOrEmpty(list3[0])) { result = "argument with no name"; code = ReturnCode.Error; break; } else if (!Parser.IsSimpleScalarVariableName(list3[0], String.Format(Interpreter.ArgumentNotSimpleError, list3[0]), String.Format(Interpreter.ArgumentNotScalarError, list3[0]), ref result)) { code = ReturnCode.Error; break; } string argName = list3[0]; string argDefault = (list3.Count >= 2) ? list3[1] : null; list2.Add(new StringPair(argName, argDefault)); } if (code == ReturnCode.Ok) { // // NOTE: We *MUST* have the formal arguments in an actual ArgumentList // container now. The variadic and optional argument semantics // depend on it. // ArgumentList formalArguments = new ArgumentList( list2, ArgumentFlags.NameOnly); // // NOTE: Compare lambda argument count with the total outer argument // count minus the "apply" and "lambdaExpr" arguments. // bool hasArgs = formalArguments.IsVariadic(true); int totalArgs = hasArgs ? formalArguments.Count - 1 : formalArguments.Count; int optionalArgs = formalArguments.GetOptionalCount(); if ((((arguments.Count - 2) >= (totalArgs - optionalArgs)) && ((arguments.Count - 2) <= totalArgs)) || (hasArgs && ((arguments.Count - 2) >= (totalArgs - optionalArgs)))) { string name = NextName(interpreter, @namespace); ICallFrame frame = null; try { frame = interpreter.NewProcedureCallFrame( name, CallFrameFlags.Procedure | CallFrameFlags.Lambda, new ClientData(hashValue), this, arguments); VariableDictionary variables = frame.Variables; frame.ProcedureArguments = new ArgumentList(arguments[0]); for (int argumentIndex = 0; argumentIndex < formalArguments.Count; argumentIndex++) { string varName = formalArguments[argumentIndex].Name; if (!variables.ContainsKey(varName)) { ArgumentFlags flags = ArgumentFlags.None; object varValue; if (hasArgs && (argumentIndex == (formalArguments.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 + 2; 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 + 2) < 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 + 2].Flags | flags, varName, arguments[argumentIndex + 2], 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 = formalArguments[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.BeforeLambdaBody)) { code = interpreter.CheckBreakpoints( code, BreakpointType.BeforeLambdaBody, this.Name, null, null, this, null, clientData, arguments, ref result); } #endif if (code == ReturnCode.Ok) { interpreter.ReturnCode = ReturnCode.Ok; code = interpreter.EvaluateScript(lambdaExpr[1], arguments[1], ref result); #if DEBUGGER && DEBUGGER_EXECUTE if (DebuggerOps.CanHitBreakpoints(interpreter, EngineFlags.None, BreakpointType.AfterLambdaBody)) { code = interpreter.CheckBreakpoints( code, BreakpointType.AfterLambdaBody, this.Name, 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} (lambda term \"{1}\" line {2})", Environment.NewLine, FormatOps.Ellipsis(arguments[1]), 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 { result = String.Format( "wrong # args: should be \"apply lambdaExpr {0}\"", formalArguments.ToRawString(ToStringFlags.Decorated, Characters.Space.ToString())); code = ReturnCode.Error; } } } } } else { code = ReturnCode.Error; } } else { result = String.Format( "can't interpret \"{0}\" as a lambda expression", arguments[1]); code = ReturnCode.Error; } } } else { result = "wrong # args: should be \"apply lambdaExpr ?arg1 arg2 ...?\""; code = ReturnCode.Error; } } else { result = "invalid argument list"; code = ReturnCode.Error; } } else { result = "invalid interpreter"; code = ReturnCode.Error; } return(code); }
/////////////////////////////////////////////////////////////////////// // // BUGFIX: *DEADLOCK* Prevent deadlocks here by using the TryLock // pattern. // // NOTE: Used by the _Hosts.Default.WriteEngineInfo method. // public static void AddInfo( StringPairList list, DetailFlags detailFlags ) { if (list == null) { return; } bool locked = false; try { TryLock(ref locked); /* TRANSACTIONAL */ if (locked) { bool empty = HostOps.HasEmptyContent(detailFlags); StringPairList localList = new StringPairList(); if (empty || (isAvailable != null)) { localList.Add("IsAvailable", (isAvailable != null) ? isAvailable.ToString() : FormatOps.DisplayNull); } if (empty || locked) { localList.Add("Locked", locked.ToString()); } if (empty || disabled) { localList.Add("Disabled", disabled.ToString()); } if (empty || strictPath) { localList.Add("StrictPath", strictPath.ToString()); } if (empty || noReflection) { localList.Add("NoReflection", noReflection.ToString()); } if (empty || (nativeModule != IntPtr.Zero)) { localList.Add("NativeModule", nativeModule.ToString()); } if (empty || (nativeFileName != null)) { localList.Add("NativeFileName", (nativeFileName != null) ? nativeFileName : FormatOps.DisplayNull); } if (empty || ((nativeDelegates != null) && (nativeDelegates.Count > 0))) { localList.Add("NativeDelegates", (nativeDelegates != null) ? nativeDelegates.Count.ToString() : FormatOps.DisplayNull); } if (empty || (nativeGetVersion != null)) { localList.Add("NativeGetVersion", (nativeGetVersion != null) ? nativeGetVersion.ToString() : FormatOps.DisplayNull); } if (empty || (nativeAllocateMemory != null)) { localList.Add("NativeAllocateMemory", (nativeAllocateMemory != null) ? nativeAllocateMemory.ToString() : FormatOps.DisplayNull); } if (empty || (nativeFreeMemory != null)) { localList.Add("NativeFreeMemory", (nativeFreeMemory != null) ? nativeFreeMemory.ToString() : FormatOps.DisplayNull); } if (empty || (nativeFreeElements != null)) { localList.Add("NativeFreeElements", (nativeFreeElements != null) ? nativeFreeElements.ToString() : FormatOps.DisplayNull); } if (empty || (nativeSplitList != null)) { localList.Add("NativeSplitList", (nativeSplitList != null) ? nativeSplitList.ToString() : FormatOps.DisplayNull); } if (empty || (nativeJoinList != null)) { localList.Add("NativeJoinList", (nativeJoinList != null) ? nativeJoinList.ToString() : FormatOps.DisplayNull); } if (empty || (version != null)) { localList.Add("Version", (version != null) ? version : FormatOps.DisplayNull); } if (empty || (itemsFieldInfo != null)) { localList.Add("ItemsFieldInfo", (itemsFieldInfo != null) ? itemsFieldInfo.ToString() : FormatOps.DisplayNull); } if (empty || Parser.UseNativeSplitList) { localList.Add("UseNativeSplitList", Parser.UseNativeSplitList.ToString()); } if (empty || GenericOps <string> .UseNativeJoinList) { localList.Add("UseNativeJoinList", GenericOps <string> .UseNativeJoinList.ToString()); } if (localList.Count > 0) { list.Add((IPair <string>)null); list.Add("Native Utility"); list.Add((IPair <string>)null); list.Add(localList); } } else { StringPairList localList = new StringPairList(); localList.Add(FormatOps.DisplayBusy); if (localList.Count > 0) { list.Add((IPair <string>)null); list.Add("Native Utility"); list.Add((IPair <string>)null); list.Add(localList); } } } finally { ExitLock(ref locked); /* TRANSACTIONAL */ } }
/////////////////////////////////////////////////////////////////////////////////////////////// #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) { if (arguments.Count == 4) { string name = arguments[1]; StringList list = null; code = Parser.SplitList( interpreter, arguments[2], 0, Length.Invalid, true, ref list, ref result); if (code == ReturnCode.Ok) { StringPairList list2 = new StringPairList(); for (int argumentIndex = 0; argumentIndex < list.Count; argumentIndex++) { StringList list3 = null; code = Parser.SplitList( interpreter, list[argumentIndex], 0, Length.Invalid, true, ref list3, ref result); if (code != ReturnCode.Ok) { break; } if (list3.Count > 2) { result = String.Format( "too many fields in argument specifier \"{0}\"", list[argumentIndex]); code = ReturnCode.Error; break; } else if ((list3.Count == 0) || String.IsNullOrEmpty(list3[0])) { result = "argument with no name"; code = ReturnCode.Error; break; } else if (!Parser.IsSimpleScalarVariableName(list3[0], String.Format(Interpreter.ArgumentNotSimpleError, list3[0]), String.Format(Interpreter.ArgumentNotScalarError, list3[0]), ref result)) { code = ReturnCode.Error; break; } string argName = list3[0]; string argDefault = (list3.Count >= 2) ? list3[1] : null; list2.Add(new StringPair(argName, argDefault)); } if (code == ReturnCode.Ok) { lock (interpreter.SyncRoot) /* TRANSACTIONAL */ { ProcedureFlags procedureFlags = interpreter.ProcedureFlags; IProcedure procedure = RuntimeOps.NewCoreProcedure( interpreter, interpreter.AreNamespacesEnabled() ? NamespaceOps.MakeQualifiedName(interpreter, name) : ScriptOps.MakeCommandName(name), null, null, procedureFlags, new ArgumentList(list2, ArgumentFlags.NameOnly), arguments[3], ScriptLocation.Create(arguments[3]), clientData); code = interpreter.AddOrUpdateProcedureWithReplace( procedure, clientData, ref result); if (code == ReturnCode.Ok) { result = String.Empty; } } } } if (code == ReturnCode.Error) { Engine.AddErrorInformation(interpreter, result, String.Format("{0} (creating proc \"{1}\")", Environment.NewLine, name)); } } else { result = "wrong # args: should be \"proc name args body\""; code = ReturnCode.Error; } } else { result = "invalid argument list"; code = ReturnCode.Error; } } else { result = "invalid interpreter"; code = ReturnCode.Error; } return(code); }
/////////////////////////////////////////////////////////////////////// public StringPairList ToList( DetailFlags detailFlags ) { CheckDisposed(); StringPairList list = new StringPairList(); bool all = FlagOps.HasFlags( detailFlags, DetailFlags.ICallFrameToListAll, true); list.Add("flags", flags.ToString()); if (all) { list.Add("frameId", frameId.ToString()); list.Add("frameLevel", frameLevel.ToString()); } if (name != null) { list.Add("name", (name != null) /* REDUNDANT */ ? name : _String.Null); } if (all) { if ((tags != null) && (tags.Count > 0)) { list.Add("tags", (tags != null) /* REDUNDANT */ ? tags.ToString() : _String.Null); } } if ((variables != null) && (variables.Count > 0)) { list.Add("vars", (variables != null) /* REDUNDANT */ ? variables.Count.ToString() : _String.Null); } if ((arguments != null) && (arguments.Count > 0)) { list.Add("args", (arguments != null) /* REDUNDANT */ ? arguments.Count.ToString() : _String.Null); } if (all) { list.Add("ownArgs", ownArguments.ToString()); } if ((procedureArguments != null) && (procedureArguments.Count > 0)) { list.Add("procArgs", (procedureArguments != null) /* REDUNDANT */ ? procedureArguments.Count.ToString() : _String.Null); } if (all) { list.Add("index", index.ToString()); } list.Add("level", level.ToString()); return(list); }