Пример #1
0
        public Task <string> TextQueryAsync(byte[] node, string key, BlockParameter blockParameter = null)
        {
            var textFunction = new TextFunction();

            textFunction.Node = node;
            textFunction.Key  = key;

            return(ContractHandler.QueryAsync <TextFunction, string>(textFunction, blockParameter));
        }
Пример #2
0
        public Task <string> TextQueryAsync(byte[] Node, string Key, BlockParameter BlockParameter = null)
        {
            var TextFunction = new TextFunction
            {
                Node = Node,
                Key  = Key
            };

            return(ContractHandler.QueryAsync <TextFunction, string>(TextFunction, BlockParameter));
        }
Пример #3
0
        public async Task <string> GetTxtRecord()
        {
            var TextFunction = new TextFunction()
            {
                Node = EnsUtil.GetNameHash($"{Domain}.eth").HexToByteArray(),
                Key  = "MyKey"
            };

            return(await PublicResolverService.TextQueryAsync(TextFunction));
        }
        public void AddText(string title, Color color, TextFunction textFunc)
        {
            graphs.Add(new TextPrototype(title, color));

            void function(GraphDataPacket ds)
            {
                ds.AddTextData(textFunc());
            }

            updatingFunctions.AddFunction(function);
        }
Пример #5
0
        void InitFunction()
        {
            if (_fns == null)
            {
                _fns = new Dictionary <string, FunctionDefinition>(StringComparer.InvariantCultureIgnoreCase);

                LogicalFunction.Register(this);
                MathFunction.Register(this);
                TextFunction.Register(this);
                StatisticalFunction.Register(this);

                (new CollectionFunction(this)).Register();
            }
        }
Пример #6
0
        public void AddText(string title, Color color, TextFunction textFunc)
        {
            var text = new UpdatingText()
            {
                Title = title,
                Color = color
            };

            void function(DataSource ds)
            {
                ds.AddTextData(textFunc());
            }

            updatingCollection.AddContainer(new UpdatingContainer(text, function));
            updatingFunctions.AddFunction(function);
            Graphs.AddGraph(text);
        }
Пример #7
0
 public Task <string> TextQueryAsync(TextFunction TextFunction, BlockParameter BlockParameter = null)
 {
     return(ContractHandler.QueryAsync <TextFunction, string>(TextFunction, BlockParameter));
 }
Пример #8
0
        /// <summary>
        /// Registers a function <paramref name="handler"/> with the specified <paramref name="name"/>.
        /// </summary>
        /// <param name="name">Name of the function.</param>
        /// <param name="handler">The function that provides the result value.</param>
        public static void RegisterFunction(string name, TextFunction handler)
        {
            Contract.Requires<ArgumentNullException>(!string.IsNullOrWhiteSpace(name));
            Contract.Requires<ArgumentNullException>(handler != null);

            string functionName = name.ToLower();
            if (functions.ContainsKey(functionName))
            {
                if (functions[functionName] == handler)
                    return;

                log.WarnFormat("Replacing existing handler '{0}' for function '{1}' with new handler '{2}'",
                    Util.GetMethodSignature(functions[functionName].Method),
                    functionName,
                    Util.GetMethodSignature(handler.Method));
            }

            functions[functionName] = handler;
        }
Пример #9
0
        public override ValueEval Evaluate(int srcRowIndex, int srcColumnIndex, ValueEval arg0, ValueEval arg1)
        {
            double s0;
            String s1;

            try
            {
                s0 = TextFunction.EvaluateDoubleArg(arg0, srcRowIndex, srcColumnIndex);
                s1 = TextFunction.EvaluateStringArg(arg1, srcRowIndex, srcColumnIndex);
            }
            catch (EvaluationException e)
            {
                return(e.GetErrorEval());
            }
            if (Regex.Match(s1, @"[\d,\#,\.,\$,\,]+").Success)
            {
                FormatBase formatter = new DecimalFormat(s1);
                return(new StringEval(formatter.Format(s0)));
            }
            else if (s1.IndexOf("/") == s1.LastIndexOf("/") && s1.IndexOf("/") >= 0 && !s1.Contains("-"))
            {
                double wholePart = Math.Floor(s0);
                double decPart   = s0 - wholePart;
                if (wholePart * decPart == 0)
                {
                    return(new StringEval("0"));
                }
                String[] parts = s1.Split(' ');
                String[] fractParts;
                if (parts.Length == 2)
                {
                    fractParts = parts[1].Split('/');
                }
                else
                {
                    fractParts = s1.Split('/');
                }

                if (fractParts.Length == 2)
                {
                    double minVal    = 1.0;
                    double currDenom = Math.Pow(10, fractParts[1].Length) - 1d;
                    double currNeum  = 0;
                    for (int i = (int)(Math.Pow(10, fractParts[1].Length) - 1d); i > 0; i--)
                    {
                        for (int i2 = (int)(Math.Pow(10, fractParts[1].Length) - 1d); i2 > 0; i2--)
                        {
                            if (minVal >= Math.Abs((double)i2 / (double)i - decPart))
                            {
                                currDenom = i;
                                currNeum  = i2;
                                minVal    = Math.Abs((double)i2 / (double)i - decPart);
                            }
                        }
                    }
                    FormatBase neumFormatter  = new DecimalFormat(fractParts[0]);
                    FormatBase denomFormatter = new DecimalFormat(fractParts[1]);
                    if (parts.Length == 2)
                    {
                        FormatBase wholeFormatter = new DecimalFormat(parts[0]);
                        String     result         = wholeFormatter.Format(wholePart) + " " + neumFormatter.Format(currNeum) + "/" + denomFormatter.Format(currDenom);
                        return(new StringEval(result));
                    }
                    else
                    {
                        String result = neumFormatter.Format(currNeum + (currDenom * wholePart)) + "/" + denomFormatter.Format(currDenom);
                        return(new StringEval(result));
                    }
                }
                else
                {
                    return(ErrorEval.VALUE_INVALID);
                }
            }
            else
            {
                try
                {
                    FormatBase dateFormatter = new SimpleDateFormat(s1);
                    DateTime   dt            = new DateTime(1899, 11, 30, 0, 0, 0);
                    dt.AddDays((int)Math.Floor(s0));
                    double dayFraction = s0 - Math.Floor(s0);
                    dt.AddMilliseconds((int)Math.Round(dayFraction * 24 * 60 * 60 * 1000));
                    return(new StringEval(dateFormatter.Format(dt)));
                }
                catch (Exception)
                {
                    return(ErrorEval.VALUE_INVALID);
                }
            }
        }