public BaseApiController() { LoginID = HttpContext.Current.Session["Username"]; if (LoginID != null) { TokenValue = HttpContext.Current.Session[LoginID.ToString()] ?? ""; HttpContext.Current.Request.Headers.Add("TokenValue", TokenValue.ToString()); } }
public void HandleTokenParam() { var p1 = new TokenValue("NOK", "http://somewhere.nl/codes"); Assert.AreEqual("http://somewhere.nl/codes|NOK", p1.ToString()); var p2 = new TokenValue("y|n", "http://some|where.nl/codes"); Assert.AreEqual(@"http://some\|where.nl/codes|y\|n", p2.ToString()); var p3 = new TokenValue("NOK", matchAnyNamespace: true); Assert.AreEqual("NOK", p3.ToString()); var p4 = new TokenValue("NOK", matchAnyNamespace: false); Assert.AreEqual("|NOK", p4.ToString()); var p5 = TokenValue.Parse("http://somewhere.nl/codes|NOK"); Assert.AreEqual("http://somewhere.nl/codes", p5.Namespace); Assert.AreEqual("NOK", p5.Value); Assert.IsFalse(p4.AnyNamespace); var p6 = TokenValue.Parse(@"http://some\|where.nl/codes|y\|n"); Assert.AreEqual(@"http://some|where.nl/codes", p6.Namespace); Assert.AreEqual("y|n", p6.Value); Assert.IsFalse(p6.AnyNamespace); var p7 = TokenValue.Parse("|NOK"); Assert.AreEqual(null, p7.Namespace); Assert.AreEqual("NOK", p7.Value); Assert.IsFalse(p7.AnyNamespace); var p8 = TokenValue.Parse("NOK"); Assert.AreEqual(null, p8.Namespace); Assert.AreEqual("NOK", p8.Value); Assert.IsTrue(p8.AnyNamespace); var crit = Criterium.Parse("paramX=|NOK"); var p9 = ((UntypedValue)crit.Operand).AsTokenValue(); Assert.AreEqual("NOK", p9.Value); Assert.IsFalse(p9.AnyNamespace); }
/// <summary> /// 构造函数赋值 /// </summary> public BaseApiController() { TokenValue = HttpContext.Current.Session[LoginID] ?? ""; HttpContext.Current.Request.Headers.Add("TokenValue", TokenValue.ToString()); }
public CodeStatement ParseStatement() { if (IsKeyword("var")) { GetNextToken(); CodeTypeReference type = ParseType(); string name = EatKeyword(); if (TokenType == CDILToken.Assign) { Expect(CDILToken.Assign); CodeExpression expr = ParseExpression(); return(new CodeVariableDeclarationStatement(type, name, expr)); } else { return(new CodeVariableDeclarationStatement(type, name)); } } if (IsKeyword("call")) { GetNextToken(); return(new CodeExpressionStatement(ParseExpression())); } if (IsKeyword("return")) { CodeMethodReturnStatement retVal; GetNextToken(); retVal = new CodeMethodReturnStatement(); if (TokenType != CDILToken.Semicolon && TokenType != CDILToken.EOF) { retVal.Expression = ParseExpression(); } return(retVal); } if (IsKeyword("throw")) { CodeThrowExceptionStatement retVal; GetNextToken(); retVal = new CodeThrowExceptionStatement(); if (TokenType != CDILToken.Semicolon && TokenType != CDILToken.EOF) { retVal.ToThrow = ParseExpression(); } return(retVal); } if (IsKeyword("if")) { CodeConditionStatement retVal = new CodeConditionStatement(); GetNextToken(); retVal.Condition = ParseExpression(); ExpectKeyword("then"); while (TokenType != CDILToken.EOF && !IsKeyword("else") && !IsKeyword("endif")) { retVal.TrueStatements.Add(ParseStatement()); if (TokenType == CDILToken.Semicolon) { GetNextToken(); } } if (IsKeyword("else")) { ExpectKeyword("else"); while (TokenType != CDILToken.EOF && !IsKeyword("endif")) { retVal.FalseStatements.Add(ParseStatement()); if (TokenType == CDILToken.Semicolon) { GetNextToken(); } } } ExpectKeyword("endif"); return(retVal); } if (IsKeyword("let")) { CodeAssignStatement retVal = new CodeAssignStatement(); GetNextToken(); retVal.Left = ParseExpression(); Expect(CDILToken.Assign); retVal.Right = ParseExpression(); return(retVal); } if (IsKeyword("comment")) { GetNextToken(); string s = TokenValue.ToString(); GetNextToken(); return(new CodeCommentStatement(s)); } throw BuildException("Invalid token: '" + TokenType + "': " + TokenValue); }
public void HandleTokenParam() { var p1 = new TokenValue("NOK", "http://somewhere.nl/codes"); Assert.AreEqual("http://somewhere.nl/codes|NOK", p1.ToString()); var p2 = new TokenValue("y|n", "http://some|where.nl/codes"); Assert.AreEqual(@"http://some\|where.nl/codes|y\|n", p2.ToString()); var p3 = new TokenValue("NOK", matchAnyNamespace: true); Assert.AreEqual("NOK", p3.ToString()); var p4 = new TokenValue("NOK", matchAnyNamespace: false); Assert.AreEqual("|NOK", p4.ToString()); var p5 = TokenValue.Parse("http://somewhere.nl/codes|NOK"); Assert.AreEqual("http://somewhere.nl/codes", p5.Namespace); Assert.AreEqual("NOK", p5.Value); Assert.IsFalse(p4.AnyNamespace); var p6 = TokenValue.Parse(@"http://some\|where.nl/codes|y\|n"); Assert.AreEqual(@"http://some|where.nl/codes", p6.Namespace); Assert.AreEqual("y|n", p6.Value); Assert.IsFalse(p6.AnyNamespace); var p7 = TokenValue.Parse("|NOK"); Assert.AreEqual(null, p7.Namespace); Assert.AreEqual("NOK", p7.Value); Assert.IsFalse(p7.AnyNamespace); var p8 = TokenValue.Parse("NOK"); Assert.AreEqual(null, p8.Namespace); Assert.AreEqual("NOK", p8.Value); Assert.IsTrue(p8.AnyNamespace); var crit = Criterium.Parse("paramX=|NOK"); var p9 = ((UntypedValue)crit.Operand).AsTokenValue(); Assert.AreEqual("NOK", p9.Value); Assert.IsFalse(p9.AnyNamespace); }