本文整理汇总了C#中Sprocket.Web.CMS.Script.Token类的典型用法代码示例。如果您正苦于以下问题:C# Token类的具体用法?C# Token怎么用?C# Token使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Token类属于Sprocket.Web.CMS.Script命名空间,在下文中一共展示了Token类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: EvaluateArguments
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);
}
示例2: EvaluateProperty
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);
}
示例3: SprocketScript
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: Evaluate
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);
}
示例5: Build
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));
}
}
示例6: EvaluateProperty
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);
}
}
示例7: Evaluate
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;
}
示例8: Build
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);
}
示例9: TokenParserException
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: Evaluate
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);
}
}
示例11: Evaluate
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);
}
示例12: Evaluate
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]";
}
示例13: Evaluate
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;
}
示例14: Evaluate
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)));
}
示例15: PrepareExpression
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;
}