Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            MacroProcessor.Register <Foo>();

            double mSecFrequency = (Stopwatch.Frequency / 1000);

            string result = null;

            Stopwatch sw = Stopwatch.StartNew();

            CompiledTemplate compiledTemplate = MacroProcessor.Compile("Hello, my name is [name] and I'm [age] years old");

            Console.WriteLine($"Compilation duration : {sw.ElapsedTicks / mSecFrequency} msecs");

            int iteration = 1000 * 1000;

            sw = Stopwatch.StartNew();

            for (int i = 0; i < 1000 * 1000; i++)
            {
                result = MacroProcessor.Process("I'm [name], I'm [age] years old", new Foo(42, "Josh"));
            }

            Console.WriteLine($"Result: {result}");

            Console.WriteLine($"AVG rendering duration : {sw.ElapsedTicks / iteration / mSecFrequency * 1000} usecs over {iteration} iterations");

            System.Console.ReadKey();
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Преобразует значение с помощью макропроцессора
        /// </summary>
        /// <param name="value">значение, которое нужно преобразовать</param>
        /// <param name="defaultValue">возвращаемое значение по умолчанию</param>
        /// <param name="processor">макропроцессор</param>
        /// <returns>целое значение, полученное после работы макропроцессора</returns>
        private int processInt(string value, int defaultValue, MacroProcessor processor)
        {
            if (value == null || value == string.Empty)
            {
                return(defaultValue);
            }

            string processedValue = processor.Process(value);

            if (processedValue == null || processedValue == string.Empty)
            {
                return(defaultValue);
            }
            return(Convert.ToInt32(processedValue));
        }
Ejemplo n.º 3
0
 public async Task <InputResult> SendInput(InputMessage input)
 {
     try {
         if (input.Type == InputType.Macro)
         {
             _macroProcessor.Process(input);
         }
         else
         {
             _inputProcessor.Process(input);
         }
         return(new InputResult {
             Ok = true
         });
     } catch (Exception e) {
         return(new InputResult {
             Ok = false,
             Message = e.Message,
         });
     }
 }