Ejemplo n.º 1
0
        public void ConvertToPostFixedTest()
        {
            ShuntingYard target = new ShuntingYard();
            Tokens tokens = new Tokens("3*4 - 5*(4-3*3)");
            ReturnMessage actual = target.ConvertToPostFixed(tokens.AsList());

            ReturnMessage expected = new ReturnMessage(true,
                    new List<Token>() {
                    new Token("3", TokenType.numberLiteral),
                    new Token("4", TokenType.numberLiteral),
                    new Token("*", TokenType.operatorOrPunctuation),
                    new Token("-5", TokenType.numberLiteral),
                    new Token("4", TokenType.numberLiteral),
                    new Token("-3", TokenType.numberLiteral),
                    new Token("3", TokenType.numberLiteral),
                    new Token("*", TokenType.operatorOrPunctuation),
                    new Token("+", TokenType.operatorOrPunctuation),
                    new Token("*", TokenType.operatorOrPunctuation),
                    new Token("+", TokenType.operatorOrPunctuation),
                    });
            List<Token> returnedTokens = (List<Token>)actual.ReturnValue;
            List<Token> expectedTokens = (List<Token>)expected.ReturnValue;
            for(int i=0;i < returnedTokens.Count;i++){
                Assert.AreEqual<string>(returnedTokens[i].TokenString, expectedTokens[i].TokenString);
                Assert.AreEqual(returnedTokens[i].TokenType, expectedTokens[i].TokenType);
            }
        }
Ejemplo n.º 2
0
 public Expression(string textOfCurrentLine)
 {
     this.input = textOfCurrentLine;
     Tokens = new Tokens(input);
     ReturnMessage = new ShuntingYard().ConvertToPostFixed(Tokens.AsList());
     if (ReturnMessage.Success == false) {
         failureMessage = ReturnMessage.Message;
     } else {
         PostFixedTokens = (List<Token>)ReturnMessage.ReturnValue;
         //Put postfixed Tokens into the tree
         foreach (Token t in PostFixedTokens) {
             ReturnMessage = ParseTree.AddToken(t);
             if (ReturnMessage.Success == false) {
                 failureMessage = ReturnMessage.Message;
             }
         }
     }
     //Set the outputString
     if (ReturnMessage.Success) {
         NumericalEvaluation = ParseTree.SetRoot().Evaluate();
         SystemLog.Add(NumericalEvaluation, LogObjectType.value);
         OutputString = NumericalEvaluation.ToString();
     } else {
         NumericalEvaluation = null;
         SystemLog.Add(failureMessage, LogObjectType.failureMessage);
         OutputString = failureMessage;
     }
 }
Ejemplo n.º 3
0
 /// <summary>For adding a list of post fixed tokens</summary>
 public ReturnMessage AddListOfTokens(List<Token> tokensToAdd)
 {
     foreach (Token t in tokensToAdd) {
         message = AddToken(t);
         if (message.Success == false)
             return message;
     }
     SetRoot();
     return new ReturnMessage(true, this);
 }
Ejemplo n.º 4
0
        public override IMessage Invoke(IMessage msg)
        {
            //方法启动时间
            DateTime startTime = DateTime.Now;
            //记录方法返回结果
            string returnvalue = "null";
            Log    log         = new Log();

            //log.Uri = msg.Properties["__Uri"].ToString();
            log.IP              = "";
            log.Mac             = "";
            log.MethodName      = msg.Properties["__MethodName"].ToString();
            log.MethodSignature = msg.Properties["__MethodSignature"].ToString();
            log.TypeName        = msg.Properties["__TypeName"].ToString();
            log.CallContext     = msg.Properties["__CallContext"].ToString();
            log.Project         = "AOPTestClient";
            object returnIMessage = null;

            if (msg is IConstructionCallMessage)
            {
                //构造函数调用
                IConstructionCallMessage   constructCallMsg          = msg as IConstructionCallMessage;
                IConstructionReturnMessage constructionReturnMessage = this.InitializeServerObject((IConstructionCallMessage)msg);
                RealProxy.SetStubData(this, constructionReturnMessage.ReturnValue);
                //记录方法输入参数
                object[] args = constructCallMsg.Args;
                for (int i = 0; i < args.Length; i++)
                {
                    log.Args += args[i].ToString() + ",";
                }
                returnIMessage = constructionReturnMessage;
            }
            else
            {
                //非构造函数调用

                IMethodCallMessage callMsg = msg as IMethodCallMessage;
                IMessage           message;
                try
                {
                    object[] args = callMsg.Args;
                    object   o    = callMsg.MethodBase.Invoke(GetUnwrappedServer(), args);
                    message = new ReturnMessage(o, args, args.Length, callMsg.LogicalCallContext, callMsg);
                    //记录方法输入参数
                    for (int i = 0; i < args.Length; i++)
                    {
                        log.Args += args[i].ToString() + ",";
                    }
                }
                catch (Exception e)
                {
                    message     = new ReturnMessage(e, callMsg);
                    returnvalue = e.InnerException.ToString();
                }
                if (message.Properties["__Return"] != null)
                {
                    returnvalue = message.Properties["__Return"].ToString();
                }
                log.ReturnValue = returnvalue;
                Console.WriteLine(returnvalue);
                returnIMessage = message;
            }
            //方法结束时间
            DateTime endTime = DateTime.Now;

            log.UseTime = (endTime - startTime).ToString();
            //写入日志到数据库
            SysLogService.GetInstance().InsertAccessLog(log);
            return(returnIMessage as IMessage);
        }