Exemplo n.º 1
0
        private static async Task SubscribeInternal(string key, ParamDelegate callback)
        {
            string      mappedKey = Names.Resolve(key);
            XmlRpcValue parm      = new XmlRpcValue();

            parm.Set(0, ThisNode.Name);
            parm.Set(1, XmlRpcManager.Instance.Uri);
            parm.Set(2, mappedKey);

            var  result  = new XmlRpcValue();
            var  payload = new XmlRpcValue();
            bool success = await Master.ExecuteAsync("subscribeParam", parm, result, payload, false).ConfigureAwait(false);

            lock (gate)
            {
                if (success)
                {
                    if (!subscriptions.TryGetValue(key, out var list))
                    {
                        list = new List <ParamDelegate>();
                        subscriptions.Add(key, list);
                    }
                    list.Add(callback);
                }
            }

            Update(key, GetParam(key, true));
        }
Exemplo n.º 2
0
        /// <summary>
        /// Initializes the Param tag
        /// </summary>
        /// <param name="tagName">Name of the parsed tag</param>
        /// <param name="markup">Markup of the parsed tag</param>
        /// <param name="tokens">Tokens of the parsed tag</param>
        /// <exception cref="SyntaxException">If parameter format is invalid.</exception>
        public override void Initialize(string tagName, string markup, List <string> tokens)
        {
            var syntaxMatch = Syntax.Match(markup);

            if (!syntaxMatch.Success)
            {
                throw new SyntaxException("Invalid markup format for tag Param: " + markup);
            }

            // Ensure the markup refers to a valid param (discard underscore to support both Ruby and C# naming)
            var paramName = syntaxMatch.Groups[1].Value.Replace("_", "").ToLower();

            if (!Params.ContainsKey(paramName))
            {
                throw new SyntaxException(
                          message: "ParamTagSyntaxException",
                          args: new string[] { syntaxMatch.Groups[1].Value, Params.Keys.ToString() });
            }

            // Save the Param and the Value (which could be a variable or literal).
            this.param      = Params[paramName];
            this.paramValue = syntaxMatch.Groups[2].Value;

            base.Initialize(tagName: tagName, markup: markup, tokens: tokens);
        }
Exemplo n.º 3
0
 public static void Subscribe(string key, ParamDelegate del)
 {
     if (!Callbacks.ContainsKey(key))
     {
         Callbacks.Add(key, new List <ParamDelegate>());
     }
     Callbacks[key].Add(del);
     update(key, getParam(key, true));
 }
Exemplo n.º 4
0
    public void PushFunc(ParamDelegate func, object param, int timeMS)
    {
        if(dictParamFunc.ContainsKey(func))
        {
            Debug.LogWarning("param func is already exist...");
            return;
        }

        dictParamFunc.Add(func, new FuncParam(timeMS, param));
    }
Exemplo n.º 5
0
 /// <summary>
 /// Get a result from the equation
 /// </summary>
 /// <param name="paramCallback">This is a callback function to get the value of params to pass to this equation</param>
 public double Solve(ParamDelegate paramCallback)
 {
     if (null != RootNode)
     {
         return(RootNode.Solve(paramCallback));
     }
     else
     {
         //There is no equation parsed into this equationator
         return(0.0);
     }
 }
Exemplo n.º 6
0
        public static void Complete(IAsyncResult result)
        {
            UserInfo    userInfoRes = null;
            AsyncResult asyncResult = (AsyncResult)result;

            //获取在其上调用异步调用的委托对象
            ParamDelegate myDelegate = (ParamDelegate)asyncResult.AsyncDelegate;

            //结束在其上调用的异步委托,并获取返回值
            userInfoRes = myDelegate.EndInvoke(result);

            Console.WriteLine("My name is " + userInfoRes.Name);
            Console.WriteLine("I'm " + userInfoRes.Age + " years old this year");
            Console.WriteLine("Thread ID is:" + userInfoRes.ThreadId);
        }
Exemplo n.º 7
0
        /// <summary>
        /// Solve the equation!
        /// This method recurses into the whole tree and returns a result from the equation.
        /// </summary>
        /// <param name="paramCallback">Parameter callback that will be used to get teh values of parameter nodes.</param>
        /// <returns>The solution of this node and all its subnodes!</returns>
        public override float Solve(ParamDelegate paramCallback)
        {
            //make sure this node is set up correctly
            Debug.Assert(null != Prev);
            Debug.Assert(null != Next);

            //Solve the sub nodes!
            float prevResult = Prev.Solve(paramCallback);
            float nextResult = Next.Solve(paramCallback);

            //what kind of operator do we got?
            switch (OrderOfOperationsValue)
            {
            case PemdasValue.Exponent:
            {
                return((float)Math.Pow(prevResult, nextResult));
            }

            case PemdasValue.Multiplication:
            {
                return(prevResult * nextResult);
            }

            case PemdasValue.Division:
            {
                //TODO: can hit divide by zero exception here
                return(prevResult / nextResult);
            }

            case PemdasValue.Addition:
            {
                return(prevResult + nextResult);
            }

            case PemdasValue.Subtraction:
            {
                return(prevResult - nextResult);
            }

            default:
            {
                throw new NotSupportedException("found a weirdo thing in an equation node?");
            }
            }
        }
Exemplo n.º 8
0
        /// <summary>
        /// Solve the equation!
        /// This method recurses into the whole tree and returns a result from the equation.
        /// </summary>
        /// <param name="paramCallback">Parameter callback that will be used to get teh values of parameter nodes.</param>
        /// <returns>The solution of this node and all its subnodes!</returns>
        public override float Solve(ParamDelegate paramCallback)
        {
            //make sure this node is set up correctly
            Debug.Assert(null != Prev);
            Debug.Assert(null != Next);

            //Solve the sub nodes!
            float prevResult = Prev.Solve(paramCallback);
            float nextResult = Next.Solve(paramCallback);

            //what kind of operator do we got?
            switch (OrderOfOperationsValue)
            {
                case PemdasValue.Exponent:
                {
                    return (float)Math.Pow(prevResult, nextResult);
                }
                case PemdasValue.Multiplication:
                {
                    return prevResult * nextResult;
                }
                case PemdasValue.Division:
                {
                    //TODO: can hit divide by zero exception here
                    return prevResult / nextResult;
                }
                case PemdasValue.Addition:
                {
                    return prevResult + nextResult;
                }
                case PemdasValue.Subtraction:
                {
                    return prevResult - nextResult;
                }
                default:
                {
                    throw new NotSupportedException("found a weirdo thing in an equation node?");
                }
            }
        }
Exemplo n.º 9
0
 /// <summary>
 /// Solve the equation!
 /// This method recurses into the whole tree and returns a result from the equation.
 /// </summary>
 /// <param name="paramCallback">Parameter callback that will be used to get teh values of parameter nodes.</param>
 /// <returns>The solution of this node and all its subnodes!</returns>
 public override float Solve(ParamDelegate paramCallback)
 {
     //get the parameter value.
     Debug.Assert(null != paramCallback);
     return paramCallback(ParamIndex);
 }
Exemplo n.º 10
0
 /// <summary>
 /// Solve the equation!
 /// This method recurses into the whole tree and returns a result from the equation.
 /// </summary>
 /// <param name="paramCallback">Parameter callback that will be used to get teh values of parameter nodes.</param>
 /// <returns>The solution of this node and all its subnodes!</returns>
 public override double Solve(ParamDelegate paramCallback)
 {
     //Return our number
     return(NumberValue);
 }
Exemplo n.º 11
0
 /// <summary>
 /// Solve the equation!
 /// This method recurses into the whole tree and returns a result from the equation.
 /// </summary>
 /// <param name="paramCallback">Parameter callback that will be used to get teh values of parameter nodes.</param>
 /// <returns>The solution of this node and all its subnodes!</returns>
 public override float Solve(ParamDelegate paramCallback)
 {
     //get the parameter value.
     Debug.Assert(null != paramCallback);
     return(paramCallback(ParamIndex));
 }
Exemplo n.º 12
0
 public void Exec(ParamDelegate func, object param, int timeMS)
 {
     listParamFunc.Add(new ParamTimeParam(timeMS, param, func));
 }
Exemplo n.º 13
0
 public ParamTimeParam(int time, object param, ParamDelegate func)
     : base(time, param)
 {
     function = func;
 }
Exemplo n.º 14
0
 /// <summary>
 /// Solve the equation!
 /// This method recurses into the whole tree and returns a result from the equation.
 /// </summary>
 /// <param name="paramCallback">Parameter callback that will be used to get teh values of parameter nodes.</param>
 /// <returns>The solution of this node and all its subnodes!</returns>
 public override double Solve(ParamDelegate paramCallback)
 {
     //Return the sub equation solver
     Debug.Assert(null != SubEquation); //TODO: throw exceptions
     return(SubEquation.Solve(paramCallback));
 }
Exemplo n.º 15
0
 /// <summary>
 /// Get a result from the equation
 /// </summary>
 /// <param name="paramCallback">This is a callback function to get the value of params to pass to this equation</param>
 public float Solve(ParamDelegate paramCallback)
 {
     Debug.Assert(null != RootNode);
     return(RootNode.Solve(paramCallback));
 }
Exemplo n.º 16
0
 /// <summary>
 /// Solve the equation!
 /// This method recurses into the whole tree and returns a result from the equation.
 /// </summary>
 /// <param name="paramCallback">Parameter callback that will be used to get teh values of parameter nodes.</param>
 /// <returns>The solution of this node and all its subnodes!</returns>
 public override double Solve(ParamDelegate paramCallback)
 {
     //return a random float between 0.0 and 1.0
     return(_rand.NextDouble());
 }
Exemplo n.º 17
0
 /// <summary>
 /// Solve the equation!
 /// This method recurses into the whole tree and returns a result from the equation.
 /// </summary>
 /// <param name="paramCallback">Parameter callback that will be used to get teh values of parameter nodes.</param>
 /// <returns>The solution of this node and all its subnodes!</returns>
 public override float Solve(ParamDelegate paramCallback)
 {
     //Return the sub equation solver
     Debug.Assert(null != SubEquation);
     return SubEquation.Solve(paramCallback);
 }
Exemplo n.º 18
0
    public void PopFunc(ParamDelegate func)
    {
        if(!dictParamFunc.ContainsKey(func)) return;

        dictParamFunc.Remove(func);
    }
Exemplo n.º 19
0
 public static void Subscribe(string key, ParamDelegate callback)
 {
     SubscribeInternal(key, callback);
 }
Exemplo n.º 20
0
 /// <summary>
 /// Solve the equation!
 /// This method recurses into the whole tree and returns a result from the equation.
 /// </summary>
 /// <param name="paramCallback">Parameter callback that will be used to get teh values of parameter nodes.</param>
 /// <returns>The solution of this node and all its subnodes!</returns>
 public override float Solve(ParamDelegate paramCallback)
 {
     //Return the function we found in the parser
     Debug.Assert(null != MyFunction);
     return(MyFunction());
 }
Exemplo n.º 21
0
 /// <summary>
 /// Solve the equation!
 /// This method recurses into the whole tree and returns a result from the equation.
 /// </summary>
 /// <param name="paramCallback">Parameter callback that will be used to get teh values of parameter nodes.</param>
 /// <returns>The solution of this node and all its subnodes!</returns>
 public override double Solve(ParamDelegate paramCallback)
 {
     //Return the function we found in the parser
     Debug.Assert(null != MyFunction); //TODO: throw exceptions
     return(MyFunction());
 }
Exemplo n.º 22
0
        /// <summary>
        /// Solve the equation!
        /// This method recurses into the whole tree and returns a result from the equation.
        /// </summary>
        /// <param name="paramCallback">Parameter callback that will be used to get teh values of parameter nodes.</param>
        /// <returns>The solution of this node and all its subnodes!</returns>
        public override double Solve(ParamDelegate paramCallback)
        {
            //make sure this node is set up correctly

            //check arguments
            if (null == Prev)
            {
                throw new ArgumentNullException("Prev");
            }
            if (null == Next)
            {
                throw new ArgumentNullException("Next");
            }

            //Solve the sub nodes!
            double prevResult = Prev.Solve(paramCallback);
            double nextResult = Next.Solve(paramCallback);

            //what kind of operator do we got?
            switch (OrderOfOperationsValue)
            {
            case PemdasValue.Exponent:
            {
                return(Math.Pow(prevResult, nextResult));
            }

            case PemdasValue.Multiplication:
            {
                return(prevResult * nextResult);
            }

            case PemdasValue.Division:
            {
                //guard against divide by zero exception
                if (0.0 == nextResult)
                {
                    return(0.0);
                }
                else
                {
                    return(prevResult / nextResult);
                }
            }

            case PemdasValue.Modulo:
            {
                //guard against divide by zero exception
                if (0.0 == nextResult)
                {
                    return(0.0);
                }
                else
                {
                    return(prevResult % nextResult);
                }
            }

            case PemdasValue.Addition:
            {
                return(prevResult + nextResult);
            }

            case PemdasValue.Subtraction:
            {
                return(prevResult - nextResult);
            }

            default:
            {
                throw new NotSupportedException("found a weirdo thing in an equation node?");
            }
            }
        }
Exemplo n.º 23
0
 /// <summary>
 /// Solve the equation!
 /// This method recurses into the whole tree and returns a result from the equation.
 /// </summary>
 /// <param name="paramCallback">Parameter callback that will be used to get teh values of parameter nodes.</param>
 /// <returns>The solution of this node and all its subnodes!</returns>
 public override float Solve(ParamDelegate paramCallback)
 {
     //Return the sub equation solver
     Debug.Assert(null != SubEquation);
     return(SubEquation.Solve(paramCallback));
 }
Exemplo n.º 24
0
 public static Task Subscribe(string key, ParamDelegate callback) =>
 SubscribeInternal(key, callback);
Exemplo n.º 25
0
 /// <summary>
 /// Solve the equation!
 /// This method recurses into the whole tree and returns a result from the equation.
 /// </summary>
 /// <param name="paramCallback">Parameter callback that will be used to get teh values of parameter nodes.</param>
 /// <returns>The solution of this node and all its subnodes!</returns>
 public abstract float Solve(ParamDelegate paramCallback);
Exemplo n.º 26
0
 /// <summary>
 /// Solve the equation!
 /// This method recurses into the whole tree and returns a result from the equation.
 /// </summary>
 /// <param name="paramCallback">Parameter callback that will be used to get teh values of parameter nodes.</param>
 /// <returns>The solution of this node and all its subnodes!</returns>
 public override float Solve(ParamDelegate paramCallback)
 {
     //Return the function we found in the parser
     Debug.Assert(null != MyFunction);
     return MyFunction();
 }
Exemplo n.º 27
0
 /// <summary>
 /// Solve the equation!
 /// This method recurses into the whole tree and returns a result from the equation.
 /// </summary>
 /// <param name="paramCallback">Parameter callback that will be used to get teh values of parameter nodes.</param>
 /// <returns>The solution of this node and all its subnodes!</returns>
 public abstract float Solve(ParamDelegate paramCallback);
Exemplo n.º 28
0
 /// <summary>
 /// Solve the equation!
 /// This method recurses into the whole tree and returns a result from the equation.
 /// </summary>
 /// <param name="paramCallback">Parameter callback that will be used to get teh values of parameter nodes.</param>
 /// <returns>The solution of this node and all its subnodes!</returns>
 public override double Solve(ParamDelegate paramCallback)
 {
     //get the parameter value.
     return((null != paramCallback) ? paramCallback(ParamIndex) : 0.0);
 }
Exemplo n.º 29
0
 /// <summary>
 /// Solve the equation!
 /// This method recurses into the whole tree and returns a result from the equation.
 /// </summary>
 /// <param name="paramCallback">Parameter callback that will be used to get teh values of parameter nodes.</param>
 /// <returns>The solution of this node and all its subnodes!</returns>
 public override float Solve(ParamDelegate paramCallback)
 {
     //Return our number
     return NumberValue;
 }
Exemplo n.º 30
0
 /// <summary>
 /// Get a result from the equation
 /// </summary>
 /// <param name="paramCallback">This is a callback function to get the value of params to pass to this equation</param>
 public float Solve(ParamDelegate paramCallback)
 {
     Debug.Assert(null != RootNode);
     return RootNode.Solve(paramCallback);
 }
Exemplo n.º 31
0
 /// <summary>
 /// Solve the equation!
 /// This method recurses into the whole tree and returns a result from the equation.
 /// </summary>
 /// <param name="paramCallback">Parameter callback that will be used to get teh values of parameter nodes.</param>
 /// <returns>The solution of this node and all its subnodes!</returns>
 public abstract double Solve(ParamDelegate paramCallback);