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)); }
/// <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); }
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)); }
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)); }
/// <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); } }
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); }
/// <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?"); } } }
/// <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?"); } } }
/// <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); }
/// <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); }
/// <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)); }
public void Exec(ParamDelegate func, object param, int timeMS) { listParamFunc.Add(new ParamTimeParam(timeMS, param, func)); }
public ParamTimeParam(int time, object param, ParamDelegate func) : base(time, param) { function = func; }
/// <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)); }
/// <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)); }
/// <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()); }
/// <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); }
public void PopFunc(ParamDelegate func) { if(!dictParamFunc.ContainsKey(func)) return; dictParamFunc.Remove(func); }
public static void Subscribe(string key, ParamDelegate callback) { SubscribeInternal(key, callback); }
/// <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()); }
/// <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()); }
/// <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?"); } } }
/// <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)); }
public static Task Subscribe(string key, ParamDelegate callback) => SubscribeInternal(key, callback);
/// <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);
/// <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(); }
/// <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);
/// <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); }
/// <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; }
/// <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); }
/// <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);