Esempio n. 1
0
        public Task <TransactionReceipt> PushRequestAndWaitForReceiptAsync(string dst, BigInteger wad, CancellationTokenSource cancellationToken = null)
        {
            var pushFunction = new PushFunction();

            pushFunction.Dst = dst;
            pushFunction.Wad = wad;

            return(ContractHandler.SendRequestAndWaitForReceiptAsync(pushFunction, cancellationToken));
        }
Esempio n. 2
0
        public Task <string> PushRequestAsync(string dst, BigInteger wad)
        {
            var pushFunction = new PushFunction();

            pushFunction.Dst = dst;
            pushFunction.Wad = wad;

            return(ContractHandler.SendRequestAsync(pushFunction));
        }
        public static PushFunction PushMsg(PushMode pushMode, MsgType msgType)
        {
            PushFunction pt = null;

            switch (msgType)
            {
            case MsgType.Text:
                pt = new TextPush();                        //文本推送
                break;

            case MsgType.Img:
                pt = new ImagePush();                       //图片推送
                break;

            case MsgType.SingleTextAndImg:
                pt = new SingleTextAndImgPush();            //图文推送
                break;

            case MsgType.Exercise:
                pt = new ExercisePush();                    //习题推送
                break;

            case MsgType.Trained:
                pt = new SingleTextAndImgPush();            //培训推送
                break;

            case MsgType.KnowledgeBase:                     //知识库推送
                pt = new KnowledgeBasePush();
                break;

            case MsgType.Revenue:                           //营收推送
                pt = new RevenuePush();
                break;

            case MsgType.Agreement:
                pt = new AgreementPush();                   //协议推送
                break;

            case MsgType.RedPacket:                         //红包推送
                pt = new RedPacketPush();
                break;

            case MsgType.Payment:                           //企业付款推送
                pt = new PaymentPush();
                break;

            case MsgType.Salary:
                pt = new SalaryPush();                    //工资条推送
                break;

            case MsgType.Question:
                pt = new QuestionPush();
                break;
            }
            return(pt);
        }
Esempio n. 4
0
 public static Function ValueToFunction(Object o)
 {
     if (o is Int32)
     {
         return new PushInt((int)o);
     }
     else if (o is Double)
     {
         return new PushValue<double>((double)o);
     }
     else if (o is String)
     {
         return new PushValue<string>((string)o);
     }
     else if (o is Boolean)
     {
         bool b = (bool)o;
         if (b)
             return new Primitives.True();
         else
             return new Primitives.False();
     }
     else if (o is CatList)
     {
         return new PushValue<CatList>(o as CatList);
     }
     else if (o is QuotedFunction)
     {
         QuotedFunction qf = o as QuotedFunction;
         CatExpr fxns = qf.GetSubFxns();
         PushFunction q = new PushFunction(fxns);
         return q;
     }
     else
     {
         throw new Exception("Partial evaluator does not yet handle objects of type " + o);
     }
 }
        public static PushFunction PushMsg(PushMode pushMode, MsgType msgType)
        {
            PushFunction pt = null;

            switch (msgType)
            {
            case MsgType.NoticeSMS:
                pt = new NoticeSMS();                       //通知短信
                break;

            case MsgType.RevenueSMS:
                pt = new RevenueSMS();                      //营收短信
                break;

            case MsgType.VerificationCodeSMS:
                pt = new VerificationCodeSMS();             //验证码短信
                break;

            case MsgType.ValidVerificationCodeSMS:
                pt = new ValidVerificationCodeSMS();        //验证验证码短信
                break;
            }
            return(pt);
        }
Esempio n. 6
0
        private static void ApplyMacrosInner(INameLookup names, CatExpr fxns)
        {            
            // Recursively apply macros for all quotations.
            for (int i=0; i < fxns.Count; ++i)
            {
                if (fxns[i] is PushFunction)
                {
                    PushFunction qf = fxns[i] as PushFunction;
                    CatExpr tmp = new CatExpr(qf.GetChildren());
                    ApplyMacros(names, tmp);
                    fxns[i] = new PushFunction(tmp);
                }
            }

            // This could be done multiple time
            List<MacroMatch> matches = new List<MacroMatch>();
            
            // The peephole is the maximum size of the range of functions that we will consider
            // for rewriting. This helps to reduces the overall complexity of the algorithm.
            //int nPeephole = 20;

            // This is the maximum size of the sub-expression that will be considered for matching.
            int nMaxSubExpr = 10;

            // Find matches
            int nLastMatchPos = -1;
            for (int nPos = 0; nPos < fxns.Count; ++nPos)
            {
                string s = fxns[nPos].msName;

                if (mMacros.ContainsKey(s))
                {
                    foreach (AstMacro m in mMacros[s])
                    {
                        MacroMatch match = MacroMatch.Create(m, fxns, nLastMatchPos, nPos, nMaxSubExpr);
                        if (match != null)
                        {
                            nLastMatchPos = nPos;
                            matches.Add(match);
                        }
                    }
                }
            }

            // Replace matches
            for (int i = matches.Count - 1; i >= 0; --i)
            {
                MacroMatch m = matches[i];
                List<AstMacroTerm> pattern = m.mMacro.mDest.mPattern;
                m.Replace(names, fxns, pattern);      
            }
        }
Esempio n. 7
0
            public CatExpr PatternToFxns(INameLookup names, List<AstMacroTerm> pattern)
            {
                CatExpr ret = new CatExpr();
                foreach (AstMacroTerm t in pattern)
                {
                    if (t is AstMacroTypeVar)
                    {
                        string s = t.ToString();
                        if (!mCapturedVars.ContainsKey(s))
                            throw new Exception("macro variable " + s + " was not captured");
                        CatExpr expr = mCapturedVars[s];
                        ret.AddRange(expr);
                    }
                    else if (t is AstMacroStackVar)
                    {
                        string s = (t as AstMacroStackVar).msName;
                        if (!mCapturedVars.ContainsKey(s))
                            throw new Exception("macro variable " + s + " was not captured");
                        CatExpr expr = mCapturedVars[s];
                        ret.AddRange(expr);
                    }
                    else if (t is AstMacroName)
                    {
                        string s = t.ToString();
                        if (s.Length < 1) 
                            throw new Exception("internal error: macro name is empty string");

                        Function f = names.ThrowingLookup(s);
                        
                        if (f == null)
                        {
                            if (Char.IsDigit(s[0]))
                            {
                                f = new PushInt(int.Parse(s));
                            }
                            else
                            {
                                throw new Exception("Could not find function " + s);
                            }
                        }
                        ret.Add(f);
                    }
                    else if (t is AstMacroQuote)
                    {
                        // TODO: handle typed terms within a quotation.
                        AstMacroQuote macroQuote = t as AstMacroQuote;
                        List<AstMacroTerm> localPattern = macroQuote.mTerms;
                        PushFunction q = new PushFunction(PatternToFxns(names, localPattern));
                        ret.Add(q);
                    }
                    else
                    {
                        throw new Exception("unrecognized macro term " + t.ToString());
                    }
                }
                return ret;
            }
Esempio n. 8
0
 public Task <TransactionReceipt> PushRequestAndWaitForReceiptAsync(PushFunction pushFunction, CancellationTokenSource cancellationToken = null)
 {
     return(ContractHandler.SendRequestAndWaitForReceiptAsync(pushFunction, cancellationToken));
 }
Esempio n. 9
0
 public Task <string> PushRequestAsync(PushFunction pushFunction)
 {
     return(ContractHandler.SendRequestAsync(pushFunction));
 }
Esempio n. 10
0
        /// <summary>
        /// We attempt to execute an expression (list of functions) on an empty stack. 
        /// When no exception is raised we know that the subexpression can be replaced with anything 
        /// that generates the values. 
        /// </summary>
        static CatExpr PartialEval(Executor exec, CatExpr fxns)
        {
            // Recursively partially evaluate all quotations
            for (int i = 0; i < fxns.Count; ++i)
            {
                Function f = fxns[i];
                if (f is PushFunction)
                {
                    PushFunction q = f as PushFunction;
                    CatExpr tmp = PartialEval(new Executor(), q.GetSubFxns());
                    fxns[i] = new PushFunction(tmp);
                }
            }

            CatExpr ret = new CatExpr();
            object[] values = null;

            int j = 0;
            while (j < fxns.Count)
            {
                try
                {
                    Function f = fxns[j];

                    if (f is DefinedFunction)
                    {
                        f.Eval(exec);
                    }
                    else
                    {
                        if (f.GetFxnType() == null)
                            throw new Exception("no type availables");

                        if (f.GetFxnType().HasSideEffects())
                            throw new Exception("can't perform partial execution when an expression has side-effects");

                        f.Eval(exec);
                    }

                    // at each step, we have to get the values stored so far
                    // since they could keep changing and any exception
                    // will obliterate the old values.
                    values = exec.GetStackAsArray();
                }
                catch
                {
                    if (values != null)
                    {
                        // Copy all of the values from the previous good execution 
                        for (int k = values.Length - 1; k >= 0; --k)
                            ret.Add(ValueToFunction(values[k]));
                    }
                    ret.Add(fxns[j]);
                    exec.Clear();
                    values = null;
                }
                j++;
            }

            if (values != null)
                for (int l = values.Length - 1; l >= 0; --l)
                    ret.Add(ValueToFunction(values[l]));

            return ret;
        }
Esempio n. 11
0
 static void ExpandInline(CatExpr fxns, PushFunction q, int nMaxDepth)
 {
     CatExpr tmp = new CatExpr();
     foreach (Function f in q.GetChildren())
         ExpandInline(tmp, f, nMaxDepth - 1);
     fxns.Add(new PushFunction(tmp));
 }