示例#1
0
        static void DoIt2()
        {
            string counterName  = null;
            var    counterValue = 1L;
            string valueName    = null;
            double valueValue   = 0;

            Console.WriteLine("[q]: Quit, [c]: Count [v]: Value");
            ConsoleKeyInfo keyInfo;

            while ((keyInfo = Console.ReadKey(true)).Key != ConsoleKey.Q)
            {
                switch (keyInfo.Key)
                {
                case ConsoleKey.C:
                    do
                    {
                        Console.Write($"Counter Name [{counterName}]: ");
                        var cni = Console.ReadLine();
                        counterName = cni.IsNullOrWhiteSpace() ? counterName : cni;
                    } while (counterName.IsNullOrWhiteSpace());
                    Console.Write($"Counter Value [{counterValue}]: ");
                    var ci = Console.ReadLine();
                    if (!ci.IsNullOrWhiteSpace() && long.TryParse(ci, out var counterInput))
                    {
                        counterValue = counterInput;
                    }
                    StatHat.Count(counterName, counterValue);
                    break;

                case ConsoleKey.V:
                    do
                    {
                        Console.Write($"Value Name [{valueName}]: ");
                        var vni = Console.ReadLine();
                        valueName = vni.IsNullOrWhiteSpace() ? valueName : vni;
                    } while (valueName.IsNullOrWhiteSpace());
                    Console.Write($"Value Value [{valueValue}]: ");
                    var civ = Console.ReadLine();
                    if (!civ.IsNullOrWhiteSpace() && double.TryParse(civ, out var valueInput))
                    {
                        valueValue = valueInput;
                    }
                    StatHat.Value(valueName, valueValue);
                    break;
                }
            }
        }
示例#2
0
 private void ReportCount(string name, long count = 1, DateTimeOffset?timestamp = null)
 {
     StatHat.Count(StatName(name), count, timestamp ?? DateTimeOffset.UtcNow);
 }