public static object EvaluateArguments(ExecutionState state, object o, List<ExpressionArgument> args, Token contextToken)
 {
     if (o == null)
     {
         if(contextToken.Previous != null)
             throw new InstructionExecutionException("\"" + contextToken.Previous.Value + "\" is not a keyword and has not been assigned a value as a variable. As such, it cannot evaluate the specified argument list.", contextToken.Previous);
         throw new InstructionExecutionException("The value here is null, which isn't able to process an argument list.", contextToken);
     }
     if (o is IList)
     {
         if (args.Count > 1)
             throw new InstructionExecutionException("I can't evaluate the arguments for this list because you've specified more than one argument. The only argument you can specify for a list is a numeric expression indicating which list item you're referring to.", contextToken);
         object n = TokenParser.VerifyUnderlyingType(args[0].Expression.Evaluate(state, args[0].Token));
         if (!(n is decimal))
             return ((IList)o).Contains(n);
         int index = Convert.ToInt32(n);
         if(index >= ((IList)o).Count)
             throw new InstructionExecutionException("The index specified here is higher than the highest index in the list. Remember, the lowest index is 0 and the highest is one less than the total number of items in the list.", args[0].Token);
         return ((IList)o)[index];
     }
     if (o is IDictionary)
     {
         if(args.Count > 1)
             throw new InstructionExecutionException("I can't evaluate the arguments for this collection because you've specified more than one argument. The only argument you can specify for a list is an expression indicating the name or key of the item you're referring to.", contextToken);
         object n = TokenParser.VerifyUnderlyingType(args[0].Expression.Evaluate(state, args[0].Token));
         if (!((IDictionary)o).Contains(n))
             return null;
         return ((IDictionary)o)[n];
     }
     throw new InstructionExecutionException("This type of object isn't able to process an argument list. (Underlying type: " + o.GetType().Name, contextToken);
 }
 public static object EvaluateProperty(object o, string propertyName, Token propertyNameToken)
 {
     if (o == null)
     {
         if (propertyNameToken.Previous != null)
             if (propertyNameToken.Previous.Previous != null)
                 throw new InstructionExecutionException("\"" + propertyNameToken.Previous.Previous.Value + "\" is not a keyword and has not been assigned a value as a variable. As such, it cannot evaluate the specified property.", propertyNameToken.Previous.Previous);
         throw new InstructionExecutionException("The value here is null, which can't have a property.", propertyNameToken);
     }
     if (o is string)
     {
         switch (propertyName)
         {
             case "length": return ((string)o).Length;
         }
     }
     else if(o is IList)
     {
         switch (propertyName)
         {
             case "count": return ((IList)o).Count;
         }
     }
     else if (o is IDictionary)
     {
         switch (propertyName)
         {
             case "count": return ((IDictionary)o).Count;
         }
     }
     throw new InstructionExecutionException("I can't evaluate this property because the value that it pertains to does not have script support for this property name. (Underlying type: " + o.GetType().Name + ")", propertyNameToken);
 }
		public SprocketScript(string source, string descriptiveName, string scriptIdentificationString)
		{
			this.source = source;
			this.identifier = new ExecutionState.ScriptRecursionIdentifier(descriptiveName, scriptIdentificationString);

			TokenList tokens;
			try
			{
				tokens = Tokeniser.Extract(source);
			}
			catch (TokeniserException ex)
			{
				Token falseToken = new Token(source.Substring(ex.Position, 1), TokenType.FreeText, ex.Position);
				Token token = new Token(GetErrorHTML(ex.Message, falseToken, null), TokenType.FreeText, 0);
				tokens = new TokenList(new List<Token>(new Token[] { token }));
				instruction = new ShowInstruction();
				instruction.Build(tokens);
				hasError = true;
				exception = ex;
				return;
			}

			try
			{
				instruction = TokenParser.BuildInstruction(tokens);
			}
			catch (TokenParserException ex)
			{
				Token token = new Token(GetErrorHTML(ex.Message, ex.Token, null), TokenType.FreeText, 0);
				tokens = new TokenList(new List<Token>(new Token[] { token }));
				instruction = new ShowInstruction();
				instruction.Build(tokens);
				hasError = true;
			}
		}
示例#4
0
 public object Evaluate(ExecutionState state, Token contextToken)
 {
     if (expr is IArgumentListEvaluatorExpression)
         return ((IArgumentListEvaluatorExpression)expr).Evaluate(token, args, state);
     object o = expr.Evaluate(state, token);
     return SystemTypeEvaluator.EvaluateArguments(state, o, args, token);
 }
		public void Build(TokenList tokens)
		{
			instructionListToken = tokens.Current;
			if(isStandardSection)
				tokens.Advance(); // only advance past the section token if 

			// if the current token is the name of the instruction list, store it
			if (tokens.Current != null)
				if (tokens.Current.TokenType == TokenType.QuotedString)
				{
					name = tokens.Current.Value;
					tokens.Advance();
				}

			// read each instruction, one by one until the end of the instruction list is reached
			while (tokens.Current != null)
			{
				// if we've reached a token indicating the end of this instruction block, advance past the ending token and return
				if ((!isLoopBlock && Token.IsEnd(tokens.Current)) ||
					(isLoopBlock && Token.IsLoop(tokens.Current)) ||
					(acceptELSEInPlaceOfEND && (Token.IsElse(tokens.Current) || Token.IsElseIf(tokens.Current))))
				{
					// record the type of terminating token then advance past it
					switch (tokens.Current.Value)
					{
						case "else": terminator = TerminatorType.Else; break;
						case "elseif": terminator = TerminatorType.ElseIf; break;
						case "loop": terminator = TerminatorType.Loop; break;
					}
					tokens.Advance();
					return;
				}
				list.Add(TokenParser.BuildInstruction(tokens));
			}
		}
        public object EvaluateProperty(string propertyName, Token token, ExecutionState state)
        {
            switch (propertyName)
            {
                case "action":
                    return PayPal.PayPalPostURL;

                case "subscribetest":

                    PaypalSubscription pps = new PaypalSubscription();
                    pps.CustomValue = Guid.NewGuid().ToString();
                    pps.ItemName = "Test Subscription";
                    pps.ItemNumber = 400;
                    pps.NotifyURL = "http://snowdevil78.dyndns.org/prospector/public/paypal-ipn-process/";
                    pps.SubscriptionPeriodSize = 3;
                    pps.SubscriptionPeriodUnit = PayPalSubscriptionPeriodUnit.Day;
                    pps.SubscriptionPrice = 10;
                    pps.TrialPeriodSize = 0;
                    pps.EditMode = PayPalSubscriptionEditMode.ModifyOnly;
                    return pps.GetFormFields();

                default:
                    throw new InstructionExecutionException("\"" + propertyName + "\" is not a valid property of this object", token);
            }
        }
 public object Evaluate(Token contextToken, List<ExpressionArgument> args, ExecutionState state)
 {
     string catset = (args[0].Expression.Evaluate(state, args[0].Token) ?? "").ToString();
     string catname = (args[1].Expression.Evaluate(state, args[1].Token) ?? "").ToString();
     int pageSize = Convert.ToInt32(TokenParser.VerifyUnderlyingType(args[2].Expression.Evaluate(state, args[2].Token)) ?? 0);
     int pageNumber = Convert.ToInt32(TokenParser.VerifyUnderlyingType(args[3].Expression.Evaluate(state, args[3].Token)) ?? 0);
     string sort = (args[4].Expression.Evaluate(state, args[4].Token) ?? "").ToString();
     PageResultSetOrder pageOrder;
     switch (sort)
     {
         case "random": pageOrder = PageResultSetOrder.Random; break;
         case "publishdate ascending": pageOrder = PageResultSetOrder.PublishDateAscending; break;
         default: pageOrder = PageResultSetOrder.PublishDateDescending; break;
     }
     PageSearchOptions options = new PageSearchOptions();
     options.Draft = false;
     options.Deleted = false;
     options.Hidden = false;
     options.PageSize = pageSize;
     options.PageNumber = pageNumber;
     options.PageOrder = pageOrder;
     options.SetCategory(catset, catname);
     PageResultSet pages = ContentManager.Instance.DataProvider.ListPages(options);
     pages.LoadContentForPages();
     return pages;
 }
		public void Build(TokenList tokens)
		{
			// store the "list each [variable] in [list_expression]" tokens
			token = tokens.Current;
			Token eachToken = tokens.Peek(1);
			iteratorToken = tokens.Peek(2);
			Token inToken = tokens.Peek(3);
			listToken = tokens.Peek(4); // the first token of the list expression
			tokens.Advance(4);

			// make sure the "each" token is actually the word "each"
			if (eachToken.Value != "each" || eachToken.TokenType != TokenType.Word)
				throw new TokenParserException("\"list\" must be followed by the word \"each\".", eachToken);

			// validate the various tokens
			if (iteratorToken.TokenType != TokenType.Word)
				throw new TokenParserException("You must specify a word here that can be used as a variable, e.g. \"list each item in whatever\"", iteratorToken);
			if (TokenParser.IsReservedWord(iteratorToken.Value))
				throw new TokenParserException("You can't use \"" + iteratorToken.Value + "\" as a variable name. It is the keyword for either an expression or an instruction.", iteratorToken);
			if (inToken.Value != "in" || inToken.TokenType != TokenType.Word)
				throw new TokenParserException("\"list each [something] must be followed by the word \"in\".", inToken);

			// build the list expression and the subsequent instruction list to loop through
			expr = TokenParser.BuildExpression(tokens);
			instructions = new InstructionList();
			instructions.IsLoopBlock = true;
			instructions.Build(tokens);
		}
		public TokenParserException(string message, Token token)
			: base(message)
		{
			if (token == null)
				throw new NullReferenceException("Can't throw a TokenParserException without a non-null token reference.");
			this.token = token;
		}
示例#10
0
        public object Evaluate(Token contextToken, List<ExpressionArgument> args, ExecutionState state)
        {
            string descendentPath;
            string[] sections;
            GetDescendentPath(out descendentPath, out sections);
            switch (args.Count)
            {
                case 0:
                    return descendentPath;

                case 1:
                    {
                        object o = TokenParser.VerifyUnderlyingType(args[0].Expression.Evaluate(state, args[0].Token));
                        if (o is decimal)
                        {
                            int n = Convert.ToInt32(o);
                            if (n >= sections.Length)
                                throw new InstructionExecutionException("The argument you specified for the \"descendentpath\" expression equates to the number " + n + ", which is too high. Remember, the first component in the path is index zero (0). The second is one (1), and so forth.", args[0].Token);
                            return sections[n];
                        }
                        throw new InstructionExecutionException("You specified an argument for the \"descendentpath\" expression, but it isn't equating to a number. I need a number to know which bit of the path you are referring to.", args[0].Token);
                    }

                default:
                    throw new TokenParserException("the \"descendentpath\" expression must contain no more than one argument, and it should be a number specifying which querystring element you want, or a string (word) specifying the name of the querystring parameter you want.", args[1].Token);
            }
        }
		public object Evaluate(Token contextToken, List<ExpressionArgument> args, ExecutionState state)
		{
			object o = state.HasVariable(variableToken.Value) ? state.GetVariable(variableToken.Value) : null;
			if (o is IArgumentListEvaluatorExpression)
				return ((IArgumentListEvaluatorExpression)o).Evaluate(contextToken, args, state);
			else
				return SystemTypeEvaluator.EvaluateArguments(state, o, args, contextToken);
		}
 public object Evaluate(Token contextToken, List<ExpressionArgument> args, ExecutionState state)
 {
     if(args.Count == 0)
         throw new InstructionExecutionException("The \"editfield\" expression requires an argument specifying the name of an edit field to retrieve", contextToken);
     if(args.Count > 1)
         throw new InstructionExecutionException("The \"editfield\" expression takes a single argument specifying the name of an edit field to retrieve. You've specified more than one argument.", contextToken);
     return "[todo: render content node output]";
 }
		public object Evaluate(ExecutionState state, Token contextToken)
		{
			TimeSpan ts = SprocketDate.Now.Subtract((DateTime)CurrentRequest.Value["RequestSpeedExpression.Start"]);
			string s = ts.TotalSeconds.ToString("0.####") + "s";
			if (s == "0s")
				return "instant";
			return s;
		}
		public object Evaluate(ExecutionState state, Token contextToken)
		{
			if (expr != null)
				o = expr.Evaluate(state, contextToken);
			if (o == null)
				return new SoftBoolean(false);
			return new SoftBoolean(!(o.Equals(0m) || o.Equals("") || o.Equals(false)));
		}
		public void PrepareExpression(Token expressionToken, List<Token> tokens, ref int nextIndex, Stack<int?> precedenceStack)
		{
			Token token = expressionToken;
			if (token.Value == "true")
				o = true;
			else
				o = false;
		}
		public object EvaluateProperty(string propertyName, Token token, ExecutionState state)
		{
			switch (propertyName)
			{
				case "length": return text.Length;
				default: return VariableExpression.InvalidProperty;
			}
		}
		public object Evaluate(ExecutionState state, Token contextToken)
		{
			// ensure that the variable has been set to some value first
			if(!state.HasVariable(variableToken.Value))
				throw new InstructionExecutionException("I can't evaluate the word \"" + variableToken.Value + "\". Either it doesn't mean anything or you forgot to assign it a value.", variableToken);

			return state.GetVariable(variableToken.Value);
		}
示例#18
0
 public object Evaluate(ExecutionState state, Token contextToken)
 {
     string descendentPath;
     string[] sections;
     GetDescendentPath(out descendentPath, out sections);
         sections = new string[0];
     return descendentPath;
 }
		private static void AddToken(List<Token> list, Token token)
		{
			list.Add(token);
			if (list.Count == 1) return;
			Token p = list[list.Count - 2];
			p.Next = token;
			token.Previous = p;
		}
		public object Evaluate(Token contextToken, List<ExpressionArgument> args, ExecutionState state)
		{
			if (args.Count != 1)
				throw new InstructionExecutionException("An argument was expected specifying which forum category to load from.", contextToken);
			object o = args[0].Expression.Evaluate(state, args[0].Token);
			if(o == null)
				throw new InstructionExecutionException("The specified argument equates to null. It needs to equate to the forum's category code.", args[0].Token);
			return ForumHandler.DataLayer.ListForumSummary(o.ToString());
		}
示例#21
0
        public void Build(TokenList tokens)
        {
            token = tokens.Current;
            // advance past the instruction token/symbol
            tokens.Advance();

            // build the expression to evaluate and display at execution time
            expression = TokenParser.BuildExpression(tokens);
        }
 public object Evaluate(Token contextToken, List<ExpressionArgument> args, ExecutionState state)
 {
     if (args.Count == 0)
         throw new InstructionExecutionException("An argument was expected specifying which forum to load from.", contextToken);
     object o = args[0].Expression.Evaluate(state, args[0].Token);
     if(o == null)
         throw new InstructionExecutionException("The first argument equates to null. It needs to equate to the forum's id.", args[0].Token);
     long id;
     try
     {
         if(o is string)
             id = long.Parse((string)o);
         else
             id = Convert.ToInt64(o);
     }
     catch
     {
         throw new InstructionExecutionException("The first argument needs to equate to a 64 bit number. (Underlying type: " + o.GetType().FullName + ")", args[0].Token);
     }
     int total;
     if (args.Count == 1)
     {
         List<ForumTopicSummary> list = ForumHandler.DataLayer.ListForumTopicSummary(id, WebAuthentication.IsLoggedIn ? (long?)SecurityProvider.CurrentUser.UserID : null,
             null, 0, 1, null, false, false, out total);
         return new ForumTopicPageSummary(total, 1, 0, list);
     }
     else
     {
         if (args.Count != 3)
             throw new InstructionExecutionException("Expected either one or three arguments: (forum_id) or (forum_id, current_page, topics_per_page)", contextToken);
         int page, perPage;
         o = args[1].Expression.Evaluate(state, args[1].Token);
         try
         {
             if (o is string) page = int.Parse((string)o);
             else page = Convert.ToInt32(o);
         }
         catch
         {
             throw new InstructionExecutionException("The second argument needs to equate to a number. (Underlying type: " + o.GetType().FullName + ")", args[1].Token);
         }
         o = args[2].Expression.Evaluate(state, args[2].Token);
         try
         {
             if (o is string) perPage = int.Parse((string)o);
             else perPage = Convert.ToInt32(o);
         }
         catch
         {
             throw new InstructionExecutionException("The third argument needs to equate to a number. (Underlying type: " + o.GetType().FullName + ")", args[2].Token);
         }
         List<ForumTopicSummary> list = ForumHandler.DataLayer.ListForumTopicSummary(
             id, WebAuthentication.IsLoggedIn ? (long?)SecurityProvider.CurrentUser.UserID : null,
             null, perPage, page, null, false, false, out total);
         return new ForumTopicPageSummary(total, page, perPage, list);
     }
 }
示例#23
0
 public object EvaluateProperty(string propertyName, Token token, ExecutionState state)
 {
     switch (propertyName)
     {
         case "text": return text;
         case "isdefault": return IsDefault;
     }
     throw new InstructionExecutionException("\"" + propertyName + "\" is not a valid property for CategorySet.", token);
 }
 public object Evaluate(Token contextToken, List<ExpressionArgument> args, ExecutionState state)
 {
     foreach (ExpressionArgument arg in args)
     {
         string s = args[0].Expression.Evaluate(state, arg.Token) as string;
         if (FormValues.IsError(s))
             return FormValues.Get(s).Message;
     }
     return "";
 }
 public object Evaluate(Token contextToken, List<ExpressionArgument> args, ExecutionState state)
 {
     if (args.Count != 1)
         throw new InstructionExecutionException("Exactly one argument should be here, specifying the name of the field to retrieve", contextToken);
     string name = (TokenParser.VerifyUnderlyingType(args[0].Expression.Evaluate(state, args[0].Token)) ?? "").ToString();
     EditFieldInfo info;
     if (!fieldsByName.TryGetValue(name, out info))
         throw new InstructionExecutionException("The field \"" + name + "\" does not exist for the referenced page.", args[0].Token);
     return info;
 }
 public object EvaluateProperty(string propertyName, Token token, ExecutionState state)
 {
     switch (propertyName)
     {
         case "field_list": return fieldList;
         case "section_definition": return def;
         case "fields_by_name": return fieldsByName;
     }
     throw new InstructionExecutionException("\"" + propertyName + "\" is not a valid property of this object.", token);
 }
		public object Evaluate(ExecutionState state, Token contextToken)
		{
			if (ContentManager.PageStack.Count == 0)
				throw new InstructionExecutionException("I can't retrieve information for the current page because there is not a specific page entry defined for the current request. (definitions.xml)", contextToken);
			Token t = state.SourceToken;
			state.SourceToken = contextToken.Next;
			string s = ContentManager.PageStack.Peek().Render(state);
			state.SourceToken = t;
			return s;
		}
        public object Evaluate(ExecutionState state, Token contextToken)
        {
            if (CurrentRequest.Value["CurrentForumOrTopicPageExpression_Value"] != null)
                return (int)CurrentRequest.Value["CurrentForumOrTopicPageExpression_Value"];

            ReferencedForum rf = ReferencedForum.Current;

            CurrentRequest.Value["CurrentForumOrTopicPageExpression_Value"] = rf.Page;
            return rf.Page;
        }
 public object EvaluateProperty(string propertyName, Token token, ExecutionState state)
 {
     switch (propertyName)
     {
         case "length": return value.Length;
         case "name": return name;
         case "value": return value;
         default: throw new InstructionExecutionException("\"" + propertyName + "\" is not a property of this variable", token);
     }
 }
 public object EvaluateProperty(string propertyName, Token token, ExecutionState state)
 {
     switch (propertyName)
     {
         case "label":
             return Label;
         case "hint":
             return Hint;
     }
     throw new InstructionExecutionException("\"" + propertyName + "\" is not a valid property for this object", token);
 }