public override IBELObject ValueOf(string name, System.Collections.ArrayList arguments, ExecutionContext ctx) { Hashtable members = ctx.CurrentFederation.GetTopicProperties(Name); string val = (string)(members[name]); if (val == null) return null; val = val.Trim(); bool isBlock = val.StartsWith("{"); if (!isBlock) return new BELString(val); // It's a block, so fire up the interpreter if (!val.EndsWith("}")) throw new ExecutionException("Topic member " + name + " defined in " + Name.Fullname + " is not well-formed; missing closing '}' for code block."); ContentBase cb = CurrentFederation.ContentBaseForTopic(Name); TopicContext newContext = new TopicContext(ctx.CurrentFederation, cb, CurrentTopicInfo); BehaviorInterpreter interpreter = new BehaviorInterpreter(val, CurrentFederation, CurrentFederation.WikiTalkVersion, ctx.Presenter); if (!interpreter.Parse()) throw new ExecutionException("Parsing error evaluating topic member " + name + " defined in " + Name.Fullname + ": " + interpreter.ErrorString); IBELObject b1 = interpreter.EvaluateToObject(newContext, ctx.ExternalWikiMap); if (b1 == null) throw new ExecutionException("Error while evaluating topic member " + name + " defined in " + Name.Fullname + ": " + interpreter.ErrorString); Block block = (Block)b1; ArrayList evaluatedArgs = new ArrayList(); foreach (object each in arguments) { IBELObject add = null; if (each != null && each is IBELObject) add = each as IBELObject; else { ExposableParseTreeNode ptn = each as ExposableParseTreeNode; add = ptn.Expose(ctx); } evaluatedArgs.Add(add); } InvocationFrame invocationFrame = new InvocationFrame(); ctx.PushFrame(invocationFrame); TopicScope topicScope = new TopicScope(null, this); ctx.PushScope(topicScope); // make sure we can use local references IBELObject answer = block.Value(ctx, evaluatedArgs); ctx.PopScope(); ctx.PopFrame(); // make sure to transfer any new cache rules // BELTODO - want a test case for this foreach (CacheRule r in interpreter.CacheRules) ctx.AddCacheRule(r); return answer; }
private IBELObject BorderPropertyFromTopic(AbsoluteTopicName relativeToTopic, AbsoluteTopicName abs, Border border, CompositeCacheRule rule) { ContentBase cb = ContentBaseForTopic(abs); if (cb == null) { return null; } rule.Add(cb.CacheRuleForAllPossibleInstancesOfTopic(abs)); if (!cb.TopicExists(abs)) { return null; } // OK, looks like the topic exist -- let's see if the property is there string borderPropertyName = BorderPropertyName(border); string prop = GetTopicProperty(abs, borderPropertyName); if (prop == null || prop == "") { return null; } // Yup, so evaluate it! string code = "federation.GetTopic(\"" + abs.Fullname + "\")." + borderPropertyName + "(federation.GetTopicInfo(\"" + relativeToTopic + "\"))"; BehaviorInterpreter interpreter = new BehaviorInterpreter(code, this, this.WikiTalkVersion, null); if (!interpreter.Parse()) { throw new Exception("Border property expression failed to parse."); } TopicContext topicContext = new TopicContext(this, this.ContentBaseForTopic(abs), new TopicInfo(this, abs)); IBELObject obj = interpreter.EvaluateToObject(topicContext, null); if (interpreter.ErrorString != null) { obj = new BELString(interpreter.ErrorString); } foreach (CacheRule r in interpreter.CacheRules) { rule.Add(r); } return obj; }
public override IBELObject ValueOf(string name, System.Collections.ArrayList arguments, ExecutionContext ctx) { TopicPropertyCollection members = ctx.CurrentFederation.GetTopicProperties(Name); string val = members[name].LastValue; if (val == null) return null; val = val.Trim(); bool isBlock = val.StartsWith("{"); if (!isBlock) return new BELString(val); // It's a block, so fire up the interpreter if (!val.EndsWith("}")) throw new ExecutionException(ctx.CurrentLocation, "Topic member " + name + " defined in " + Name.DottedName + " is not well-formed; missing closing '}' for code block."); NamespaceManager cb = CurrentFederation.NamespaceManagerForTopic(Name); TopicContext newContext = new TopicContext(ctx.CurrentFederation, cb, CurrentTopicInfo); BehaviorInterpreter interpreter = new BehaviorInterpreter(Name.DottedName + "#" + name, val, CurrentFederation, CurrentFederation.WikiTalkVersion, ctx.Presenter); if (!interpreter.Parse()) throw new ExecutionException(ctx.CurrentLocation, "Syntax error in " + interpreter.ErrorString); IBELObject b1 = interpreter.EvaluateToObject(newContext, ctx.ExternalWikiMap); if (b1 == null) throw new ExecutionException(ctx.CurrentLocation, "Execution error in " + interpreter.ErrorString); Block block = (Block) b1; ArrayList evaluatedArgs = new ArrayList(); foreach (object each in arguments) { IBELObject add = null; if (each != null && each is IBELObject) add = each as IBELObject; else { ExposableParseTreeNode ptn = each as ExposableParseTreeNode; add = ptn.Expose(ctx); } evaluatedArgs.Add(add); } InvocationFrame invocationFrame = new InvocationFrame(); ctx.PushFrame(invocationFrame); TopicScope topicScope = new TopicScope(null, this); ctx.PushScope(topicScope); // make sure we can use local references IBELObject answer = block.Value(ctx, evaluatedArgs); ctx.PopScope(); ctx.PopFrame(); return answer; }
private IBELObject BorderPropertyFromTopic(QualifiedTopicRevision relativeToTopic, QualifiedTopicRevision abs, Border border) { NamespaceManager namespaceManager = NamespaceManagerForTopic(abs); if (namespaceManager == null) { return null; } if (!namespaceManager.TopicExists(abs.LocalName, ImportPolicy.DoNotIncludeImports)) { return null; } // OK, looks like the topic exist -- let's see if the propertyName is there string borderPropertyName = BorderPropertyName(border); string prop = GetTopicPropertyValue(abs, borderPropertyName); if (prop == null || prop == "") { return null; } // Yup, so evaluate it! string code = "federation.GetTopic(\"" + abs.DottedName + "\")." + borderPropertyName + "(federation.GetTopicInfo(\"" + relativeToTopic + "\"))"; BehaviorInterpreter interpreter = new BehaviorInterpreter(abs.DottedName + "#" + borderPropertyName, code, this, this.WikiTalkVersion, null); if (!interpreter.Parse()) { throw new Exception("Border property expression failed to parse."); } TopicContext topicContext = new TopicContext(this, this.NamespaceManagerForTopic(abs), new TopicVersionInfo(this, abs)); IBELObject obj = interpreter.EvaluateToObject(topicContext, null); if (interpreter.ErrorString != null) { obj = new BELString(interpreter.ErrorString); } return obj; }