protected override object Evaluate(IExpression left, IExpression right, ExecutionState state)
 {
     object b = TokenParser.VerifyUnderlyingType(right.Evaluate(state, token));
     object a = TokenParser.VerifyUnderlyingType(left.Evaluate(state, token));
     decimal x, y;
     //typeof(decimal).IsAssignableFrom(typeof(a))
     if (a is decimal)
         x = (decimal)a;
     else
     {
         //if(a is int || a is long || a is double || a is float || a is short
         TypeConverter tc = TypeDescriptor.GetConverter(a);
         if (!tc.CanConvertTo(typeof(decimal)))
             return string.Concat(a, b);
         x = (decimal)tc.ConvertTo(a, typeof(decimal));
     }
     if (b is decimal)
         y = (decimal)b;
     else
     {
         TypeConverter tc = TypeDescriptor.GetConverter(b);
         if (!tc.CanConvertTo(typeof(decimal)))
             return string.Concat(a, b);
         y = (decimal)tc.ConvertTo(b, typeof(decimal));
     }
     return x + y;
 }
        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;
 }
Example #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 IList GetList(ExecutionState state)
 {
     List<QSComponent> list = new List<QSComponent>();
     foreach (string s in HttpContext.Current.Request.QueryString.Keys)
         list.Add(new QSComponent(s, HttpContext.Current.Request.QueryString[s]));
     return list;
 }
		public object Evaluate(ExecutionState state)
		{
			// attempt to load the specified ForumCategory
			object value = TokenParser.VerifyUnderlyingType(args[0].Expression.Evaluate(state));

			if (value is decimal)
				forumCategory = ForumHandler.DataLayer.SelectForumCategory((long)value);
			else if (value is string)
				forumCategory = ForumHandler.DataLayer.SelectForumCategoryByCode((string)value);
			else
				throw new InstructionExecutionException("Could not load an instance of \"forumcategory\" because the argument did not equate to the right kind of value.", args[0].Token);

			// return the relevant value
			switch (propertyType)
			{
				case PropertyType.ForumCategoryID: return forumCategory.ForumCategoryID;
				case PropertyType.ClientSpaceID: return forumCategory.ClientSpaceID;
				case PropertyType.CategoryCode: return forumCategory.CategoryCode;
				case PropertyType.Name: return forumCategory.Name;
				case PropertyType.URLToken: return forumCategory.URLToken;
				case PropertyType.DateCreated: return forumCategory.DateCreated;
				case PropertyType.Rank: return forumCategory.Rank;
				case PropertyType.InternalUseOnly: return forumCategory.InternalUseOnly;
				case PropertyType.ForumList: return GetForums();
				case PropertyType.None:
					if (forumCategory == null)
						return null;
					return this;
				default: return "[ForumCategory]";
			}
		}
Example #7
0
 internal override void Render(ExecutionState state, Dictionary<string, SprocketScript> overrides)
 {
     script.SetOverrides(overrides);
     if (!script.Execute(state))
         state.Output.Write(state.ErrorHTML);
     script.RestoreOverrides();
 }
        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 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 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;
		}
Example #11
0
 public object Evaluate(ExecutionState state, Token contextToken)
 {
     string descendentPath;
     string[] sections;
     GetDescendentPath(out descendentPath, out sections);
         sections = new string[0];
     return descendentPath;
 }
 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)
		{
			// 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);
		}
		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(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 object EvaluateProperty(string propertyName, Token token, ExecutionState state)
		{
			switch (propertyName)
			{
				case "length": return text.Length;
				default: return VariableExpression.InvalidProperty;
			}
		}
		protected override object Evaluate(IExpression left, IExpression right, ExecutionState state)
		{
			if (!(left is BooleanExpression))
				left = new BooleanExpression(left);
			if (!(right is BooleanExpression))
				right = new BooleanExpression(right);
			return left.Evaluate(state, token).Equals(true) && right.Evaluate(state, token).Equals(true);
		}
		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());
		}
 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);
     }
 }
Example #20
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 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 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 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(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 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 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 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);
 }
Example #28
0
 public object Evaluate(ExecutionState state, Token contextToken)
 {
     throw new InstructionExecutionException("Can't render this page expression by itself because to do so would cause infinite recursion.", 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(Token contextToken, List<ExpressionArgument> args, ExecutionState state)
		{
			if (args.Count != 1)
				throw new InstructionExecutionException("There should be only one argument in the argument list and it should specify the code name of the page to retrieve.", contextToken);
			object argval = args[0].Expression.Evaluate(state, args[0].Token);
			if (argval == null)
				throw new InstructionExecutionException("The argument you specified equates to null. I need a non-null value in order to retrieve the page you want.", args[0].Token);
			PageEntry page = ContentManager.Pages.FromPageCode(argval.ToString());
			if(page == null)
				throw new InstructionExecutionException("The argument you specified equates to \"" + argval.ToString() + "\", which is not the code name for any existing page.", args[0].Token);
			return page;
		}
 public object Evaluate(Token contextToken, List<ExpressionArgument> args, ExecutionState state)
 {
     if (args.Count != 1)
         throw new InstructionExecutionException("An argument was expected specifying which forum to load.", 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 code name.", args[0].Token);
     Forum forum = ForumHandler.DataLayer.SelectForumByURLToken(o.ToString());
     if (forum == null)
         forum = ForumHandler.DataLayer.SelectForumByCode(o.ToString());
     return forum;
 }
Example #31
0
 public object Evaluate(ExecutionState state, Token contextToken)
 {
     return(Evaluate(left, right, state));
 }
Example #32
0
 protected abstract object Evaluate(IExpression left, IExpression right, ExecutionState state);
Example #33
0
 public void Execute(ExecutionState state)
 {
     state.Variables[varNameToken.Value] = expr.Evaluate(state, varNameToken);
 }
Example #34
0
 public void Execute(ExecutionState state)
 {
     if (true)
     {
     }
 }