Beispiel #1
0
		public override IBELObject Expose(ExecutionContext ctx)
		{
			BELArray a = new BELArray();
			foreach (ExposableParseTreeNode each in _Array)
				a.Add(each.Expose(ctx));
			return a;
		}
Beispiel #2
0
		public IBELObject ValueOf(string symbol, ArrayList args, ExecutionContext ctx)
		{
			IBELObject answer = (IBELObject)_Table[symbol];
			if (answer == null)
				return null;		// not found
			if (args != null && args.Count > 0)
				throw new ExecutionException(symbol + " is a temporary variable, not a function; no arguments allowed");
			return answer;
		}
Beispiel #3
0
		public override IBELObject ValueOf(string name, System.Collections.ArrayList arguments, ExecutionContext ctx)
		{
			IBELObject answer = DynamicTopicFor(name);
			if (answer == null)
				return null;
			if (arguments != null && arguments.Count > 0)
				throw new ArgumentException("Arguments not allowed for topic names in namespaces");
			return answer;
		}
Beispiel #4
0
 public IBELObject ValueOf(string symbol, ArrayList args, ExecutionContext ctx)
 {
     IBELObject answer;
     foreach (IValueSource each in _With)
     {
         answer = each.ValueOf(symbol, args,ctx);
         if (answer != null)
             return answer;
     }
     return null;
 }
Beispiel #5
0
		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;
		}
Beispiel #6
0
 public override IBELObject Expose(ExecutionContext ctx)
 {
     try
     {
         ctx.PushLocation(Location);
         return new BELString(Value);
     }
     finally
     {
         ctx.PopLocation();
     }
 }
Beispiel #7
0
        public override IBELObject ValueOf(string name, System.Collections.ArrayList arguments, ExecutionContext ctx)
        {
            TopicPropertyCollection members = ctx.CurrentFederation.GetTopicProperties(Name);
            if (!members.Contains(name))
            {
                return null;
            }
            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;
        }
Beispiel #8
0
		public IBELObject Value(ExecutionContext ctx, ArrayList args)
		{
			if (ParseTree == null)
				return UndefinedObject.Instance;
			BlockScope blockScope = new BlockScope(ContainingScope);
			if (args != null)
			{
				if (args.Count != ParameterCount)
					throw new ArgumentException("Incorrect number of parameters for block.  Need " + ParameterCount + "; got " + args.Count);
				// Determine desired types
				ArrayList neededTypes = new ArrayList();
				foreach (BlockParameter parm in Parameters)
				{
					if (parm.TypeName == null) 
					{
						neededTypes.Add(null);	 // they said it could be anything
						continue;
					}
					BELType t = (BELType)(ctx.TypeRegistry.Registry[parm.TypeName]);
					if (t == null)
						throw new ArgumentException("Block parameter (" + parm.Identifier + ") requires unknown type (" + parm.TypeName + ")");
					neededTypes.Add(t);
				}

				// Check types, as requested
				ArrayList convertedArgs = new ArrayList();
				for(int i = 0; i < ParameterCount; i++)
				{
					BlockParameter bp = (BlockParameter)(Parameters[i]);
					convertedArgs.Add(BELType.ConvertToBELObjectIfNeeded(args[i]));
					if (bp.TypeName == null)
						continue; 	 // they said it could be anything
					IBELObject arg = (IBELObject)(convertedArgs[i]); 
					Type parmType = ((BELType)(neededTypes[i])).CLRType;
					if (!parmType.IsAssignableFrom(arg.GetType()))
						throw new MemberInvocationException(ctx.CurrentLocation, "Block parameter " + bp.Identifier + " is not of the correct type (was " 
							+ ExternalTypeNameForType(arg.GetType()) + 
							", but needed " + ExternalTypeNameForType(parmType) + ")");
				}
				
				// OK, we have them and they're type correct and converted to CLR types where needed.  Add them into the block scope
				for(int i = 0; i < ParameterCount; i++)
				{
					BlockParameter bp = (BlockParameter)(Parameters[i]);
					blockScope.AddParameter(bp.Identifier, (IBELObject)(convertedArgs[i]));
				}
			}
			ctx.PushScope(blockScope);
			IBELObject answer = ParseTree.Expose(ctx);
			ctx.PopScope();
			return answer;
		}
Beispiel #9
0
		public static FormSelectFieldPresentation ComboSelectField(ExecutionContext context, string fieldName, ArrayList options,
			[ExposedParameter(true)] string selectedOption, [ExposedParameter(true)] ArrayList values,
			[ExposedParameter(true)] object selectedValue)
		{
			if (true == context.TopFrame.WasParameterSupplied(4))
			{
				if (options.Count != values.Count)
				{
					throw new ArgumentException("The values array does not contain the same number of items as the options array", "values");
				}
			}
			return new FormSelectFieldPresentation(fieldName, 1, false, options, selectedOption, values, selectedValue);
		}
Beispiel #10
0
		public override IBELObject Expose(ExecutionContext ctx)
		{
			ArrayList parameters = null;

			if (Parameters != null)
			{
				parameters = new ArrayList();
				foreach (BlockParameterPTN p in Parameters.Parameters)
				{
					parameters.Add(new BlockParameter(p.Type, p.Identifier));
				}
			}
			return new Block(ParseTree, parameters, ctx.CurrentScope);
		}
Beispiel #11
0
		public static DateTime Instance(ExecutionContext ctx, int year, int month, int day, 
			[ExposedParameter(true)] int hour, [ExposedParameter(true)] int minute, 
			[ExposedParameter(true)] int second, [ExposedParameter(true)] int millisecond)
		{
			if (false == ctx.TopFrame.WasParameterSupplied(4))
				hour = 0;
			if (false == ctx.TopFrame.WasParameterSupplied(5))
				minute = 0;
			if (false == ctx.TopFrame.WasParameterSupplied(6))
				second = 0;
			if (false == ctx.TopFrame.WasParameterSupplied(7))
				millisecond = 0;
			return Instance2(year, month, day, hour, minute, second, millisecond);
		}
Beispiel #12
0
		public static TimeSpan Instance(ExecutionContext ctx, [ExposedParameter(true)] int days, 
			[ExposedParameter(true)] int hours, [ExposedParameter(true)] int minutes, 
			[ExposedParameter(true)] int seconds, [ExposedParameter(true)]int milliseconds)
		{
			if (false == ctx.TopFrame.WasParameterSupplied(1))
				days = 0;
			if (false == ctx.TopFrame.WasParameterSupplied(2))
				hours = 0;
			if (false == ctx.TopFrame.WasParameterSupplied(3))
				minutes = 0;
			if (false == ctx.TopFrame.WasParameterSupplied(4))
				seconds = 0;
			if (false == ctx.TopFrame.WasParameterSupplied(5))
				milliseconds = 0;

			return Instance2(days, hours, minutes, seconds, milliseconds);
		}
Beispiel #13
0
		private void button3_Click(object sender, System.EventArgs e)
		{
			Federation fed = new Federation(textBoxFederationPath.Text, OutputFormat.Testing, null);
			BehaviorInterpreter interpreter = new BehaviorInterpreter("Input Form", textBoxInput.Text, CurrentFederation, 1, this);
					
			ClearCacheView();

			if (Parse(interpreter) == null)
			{
				Fail("Unable to run; parse failed:" + interpreter.ErrorString);
				tabControl.SelectedTab = tabParser;
			}

			// Begin execution
			tabControl.SelectedTab = tabOutput;
			ExecutionContext ctx = new ExecutionContext(CurrentTopicContext);
			string final = null;
			if (!interpreter.EvaluateToPresentation(CurrentTopicContext, new Hashtable()))
			{
				Fail(interpreter.ErrorString);
				return;
			}
			WikiOutput output = WikiOutput.ForFormat(OutputFormat.Testing, null);
			interpreter.Value.ToPresentation(this).OutputTo(output);
			final = output.ToString();
			Success(final);
			UpdateCacheView(interpreter.CacheRules);
		}
		public IBELObject ValueOf(string name, ArrayList arguments, ExecutionContext ctx)
		{
			BELMember mi = Type.BELMembers[name] as BELMember;
			if (mi== null)
				return null;

			ParameterInfo []parms = mi.MethodInfo.GetParameters();
			int need = parms.Length;
			int got = (arguments == null) ? 0 : arguments.Count;
			bool needExecutionContext = mi.NeedsExecutionContext;
			if (needExecutionContext && (parms.Length == 0 || parms[0].ParameterType != typeof(ExecutionContext)))
				throw new ImplementationException("Incorrectly defined ExposedMethod property or function.  First parameter of " + mi.MethodInfo.DeclaringType.FullName + "." + mi.MethodInfo.Name + " must be an ExecutionContext");
			if (needExecutionContext)
				need--;
			if (got > need && !(mi.ExposedMethod.AllowsVariableArguments))
				throw new MemberInvocationException(ctx.CurrentLocation, "Incorrect number of arguments (too many) for " + ExternalTypeName + "." + name + " (need " + need + ", got " + got + ")");

			// Figure out what arguments we should be passing
			ArrayList args = new ArrayList();
			InvocationFrame invocationFrame = new InvocationFrame();
			if (needExecutionContext)
				args.Add(ctx);
			
			ArrayList parameterPresentFlags = null;
			if (needExecutionContext)
			{
				parameterPresentFlags = new ArrayList();
				parameterPresentFlags.Add(true);		// we know for sure the first arg is supplied; it's the execution context :-)					
			}
			int offset = (needExecutionContext ? 1 : 0);
			for (int each = offset; each < parms.Length; each++)
			{
				object arg = null;
				
				if (arguments != null && (each - offset) < arguments.Count)
					arg = (ParseTreeNode)(arguments[each - offset]);
				if (!BELMember.IsOptionalParameter(parms[each]) && arg == null)
					throw new MemberInvocationException(ctx.CurrentLocation, "Missing argument " + (each - offset) + " for " + ExternalTypeName + "." + name);
				if (parameterPresentFlags != null)
					parameterPresentFlags.Add(arg != null);
				if (mi.ExposedMethod.IsCustomArgumentProcessor)
				{
					args.Add(arg);
				}
				else
				{
					if (arg == null)
						args.Add(AbsentValueForParameter(parms[each]));
					else
						args.Add(ConvertFromBELObjectIfNeeded(((ExposableParseTreeNode)arg).Expose(ctx)));
				}
			}
			invocationFrame.WasParameterSuppliedFlags = parameterPresentFlags;

			// If we have extras (beyond those needed) and they're allowed, stash them in the MIC, too
			if (mi.ExposedMethod.AllowsVariableArguments)
			{
				ArrayList extras = new ArrayList();
				int extraCount = got - need;
				if (arguments != null)
				{
					for (int i = need; i < got; i++)
					{
						object arg = arguments[i];
						if (mi.ExposedMethod.IsCustomArgumentProcessor)
						{
							extras.Add(arg);
						}
						else
						{
							if (arg == null)
								extras.Add(null);
							else
								extras.Add(ConvertFromBELObjectIfNeeded(((ExposableParseTreeNode)arg).Expose(ctx)));
						}
					}						
				}
				invocationFrame.ExtraArguments = extras;
			}

			// Check types
			for (int each = 0; each < parms.Length; each++)
			{
				bool bad = false;
				if (args[each] == null)
				{
					if (parms[each].ParameterType.IsValueType)
						bad = true;
				}
				else
				{
					if (!parms[each].ParameterType.IsAssignableFrom(args[each].GetType()))
						bad = true;
				}
				if (bad)
					throw new MemberInvocationException(ctx.CurrentLocation, "Argument " + (each + 1) + " for " + ExternalTypeName + "." + name + " is not of the correct type (was " 
						+ ExternalTypeNameForType(args[each].GetType()) + 
						", but needed " + ExternalTypeNameForType(parms[each].ParameterType) + ")");
			}

			// And now, invoke away!!
			object result = null;
			invocationFrame.PushScope(ctx.CurrentScope); // the new frame starts with the same scope as this one
			ctx.PushFrame(invocationFrame);
			if (Federation.GetPerformanceCounter(Federation.PerformanceCounterNames.MethodInvocation) != null)
				Federation.GetPerformanceCounter(Federation.PerformanceCounterNames.MethodInvocation).Increment();
			try
			{
				result = mi.MethodInfo.Invoke(this, args.ToArray());
			}
			catch (TargetInvocationException ex)
			{
				throw ex.InnerException;
			}
			ctx.PopFrame();
			if (mi.ExposedMethod.CachePolicy == ExposedMethodFlags.CachePolicyNever)
				ctx.AddCacheRule(new CacheRuleNever());
			return Wrap(result);
		}
Beispiel #15
0
		public static LabelPresentation Label(ExecutionContext ctx, string forId, string text, [ExposedParameter(true)] string attributes)
		{
			return new LabelPresentation(forId, text, attributes);
		}
Beispiel #16
0
		public static FormStartPresentation FormStart(ExecutionContext context, string URI, string method, [ExposedParameter(true)] string attributes)
		{
			return new FormStartPresentation(URI, method, attributes);
		}
Beispiel #17
0
		public override IBELObject Expose(ExecutionContext ctx)
		{
			return new BELInteger(AsInteger);
		}
Beispiel #18
0
		public override IBELObject ValueOf(string name, ArrayList arguments, ExecutionContext ctx)
		{
			IBELObject answer = (IBELObject)(Registry[name]);
			if (answer == null)
				return null;
			if (arguments != null && arguments.Count > 0)
				throw new ArgumentException("No arguments allowed when accessing types in the type registry.");
			return answer;
		}
Beispiel #19
0
		public IPresentation ToPresentation(ExecutionContext ctx)
		{
			return ToOutputSequence().ToPresentation(ctx.Presenter);
		}
Beispiel #20
0
		public BELArray Select(ExecutionContext ctx, Block block)
		{
			BELArray answer = new BELArray();
			
			foreach (IBELObject each in Array)
			{
				ArrayList parms = new ArrayList();
				parms.Add(each);
				IBELObject objValue = block.Value(ctx, parms);
				BELBoolean test = objValue as BELBoolean;
				if (test == null)
					throw new ExecutionException("Select block must evaluate to a boolean.  Got " + BELType.BELTypeForType(objValue.GetType()).ExternalTypeName + " instead.");
				if (test.Value)
					answer.Add(each);
			}
			return answer;
		}
Beispiel #21
0
		public BELArray SortBy(ExecutionContext ctx, Block block)
		{
			ArrayList answer = new ArrayList(Array);
			try 
			{
				answer.Sort(new CustomSorter(block, ctx));
			}
			catch (InvalidOperationException e)
			{
				throw e.InnerException;
			}

			return new BELArray(answer);
		}
Beispiel #22
0
 public IBELObject Value(ExecutionContext ctx)
 {
     return Value(ctx, null);
 }
Beispiel #23
0
		public BELArray Collect(ExecutionContext ctx, Block block)
		{
			BELArray answer = new BELArray();
			
			foreach (IBELObject each in Array)
			{
				ArrayList parms = new ArrayList();
				parms.Add(each);
				answer.Add(block.Value(ctx, parms));
			}
			return answer;
		}
Beispiel #24
0
 public IBELObject ExposedValue(ExecutionContext ctx)
 {
     return Value(ctx, ctx.TopFrame.ExtraArguments);
 }
Beispiel #25
0
		public static FormSubmitButtonPresentation SubmitButton(ExecutionContext ctx, string fieldName, string label, [ExposedParameter(true)] string attributes)
		{
			return new FormSubmitButtonPresentation(fieldName, label, attributes);
		}
Beispiel #26
0
 public IBELObject WhileTrue(ExecutionContext ctx, Block block)
 {
     if (ParameterCount != 0)
         throw new ArgumentException("Conditional block for WhileTrue can't accept parameters.");
     return Loop(ctx, block, true);
 }
Beispiel #27
0
        public string TableOfContents(ExecutionContext ctx, string style, [ExposedParameter(true)] int maxDepth)
        {
            StringBuilder strbldr = new StringBuilder();
            string _spaces = "                                                                "; //64 spaces = (7 + 1) x 8 spaces
            string _style;
            string _topic = ctx.CurrentTopicName.LocalName;

            int _maxDepth = 7;
            if (maxDepth >= 1 && maxDepth <= 7)
            {
                _maxDepth = maxDepth - 1;
            }

            string _headers = Federation.GetTopicHeaders(TopicRevision);
            if (style.ToLower().Equals("numeric"))
            {
                _style = "1.";
            }
            else
            {
                _style = "*";
            }

            string[] hdrLine = _headers.Split(new char[] { '\n' });
            int first = 0;

            for (int x = 0; x < hdrLine.Length - 1; x++)
            {
                string tempIn = hdrLine[x].Trim();
                int maxWidth = tempIn.Length > 6 ? 7 : tempIn.Length;
                int y = tempIn.Substring(0,maxWidth).LastIndexOf('!'); //ensure y has max value of 7 and only uses chars at the start of the Header
                int a = y;
                if (first == 0)
                {
                    first = y - 1;
                    y = y - first;
                }
                else
                {
                    y = y - first;
                }
                if (y <= _maxDepth)
                {
                    string temp = tempIn.Substring(a + 1, tempIn.Length - a - 1);
                    while (temp.Contains("\"\""))
                    {
                        int z = temp.IndexOf("\"\"");
                        if (z == 0)
                        {
                            temp = temp.Substring(2);
                        }
                        else
                        {
                            temp = temp.Substring(0, z) + temp.Substring(z + 2);
                        }

                    }

                    if (TopicRevision.LocalName == _topic)
                    {
                        temp = @"@@Presentations.Link([""#"",""" + HttpUtility.HtmlEncode(temp) + @"""].ToOneString,""" + temp + @""")@@";
                    }
                    else
                    {
                        temp = @"@@Presentations.Link(federation.LinkMaker.SimpleLinkTo([""default.aspx/"",""" + TopicRevision.Namespace + @""",""/"",""" + TopicRevision.LocalName + @""","".html#"",""" + HttpUtility.HtmlEncode(temp) + @"""].ToOneString),""" + temp + @""")@@";
                    }
                    strbldr.AppendLine(_spaces.Substring(1, (y * 8)) + _style + temp);
                }
            }
            return strbldr.ToString();
        }
Beispiel #28
0
			public CustomSorter(Block b, ExecutionContext c)
			{
				block = b;
				ctx = c;
			}
Beispiel #29
0
 IBELObject Loop(ExecutionContext ctx, Block block, bool halt)
 {
     while (true)
     {
         IBELObject objValue = Value(ctx);
         BELBoolean test = objValue as BELBoolean;
         if (test == null)
             throw new ExecutionException(ctx.CurrentLocation, "WhileTrue/WhileFalse block must evaluate to a boolean.  Got " + BELType.BELTypeForType(objValue.GetType()).ExternalTypeName + " instead.");
         if (test.Value == halt)
             break;
     }
     return BELString.Empty;
 }
Beispiel #30
0
 public IBELObject ValueOf(string symbol, ArrayList args, ExecutionContext ctx)
 {
     return Topic.ValueOf(symbol, args, ctx);
 }