/// <summary>
            /// Starts a new task for an <see cref="IExample"/> implementation.
            /// </summary>
            /// <param name="example">The example to run.</param>
            /// <param name="args">An array of arguments. Depending on what is necessary for an example,
            /// it may contain multiple variables, such as serverUrl, topic paths etc. Check the example class
            /// for the description of what is required for this array.</param>
            public void Start(IExample example, params string[] args)
            {
                var task = Task.Run(async() => {
                    var run = example?.Run(cancellationTokenSource.Token, args);
                    if (run != null)
                    {
                        await run;
                    }
                });

                runningExamples.Add(task);
            }
Example #2
0
        public static void Main()
#endif
        {
            try
            {
#if LOG4NET
                XmlConfigurator.Configure();
#else
                Logging.LogProvider.SetCurrentLogProvider(new ConsoleLogProvider());
#endif

                //Assembly asm = typeof(Program).GetTypeInfo().Assembly;
                //Type[] types = asm.GetTypes();

                //IDictionary<int, Type> typeMap = new Dictionary<int, Type>();
                //int counter = 1;

                //Console.WriteLine("Select example to run: ");
                //List<Type> typeList = new List<Type>();
                //foreach (Type t in types)
                //{
                //    if (new List<Type>(t.GetInterfaces()).Contains(typeof(IExample)))
                //    {
                //        typeList.Add(t);
                //    }
                //}

                //// sort for easier readability
                //typeList.Sort(new TypeNameComparer());

                //foreach (Type t in typeList)
                //{
                //    string counterString = $"[{counter}]".PadRight(4);
                //    Console.WriteLine("{0} {1} {2}", counterString, t.Namespace.Substring(t.Namespace.LastIndexOf(".") + 1), t.Name);
                //    typeMap.Add(counter++, t);
                //}

                //Console.WriteLine();
                //Console.Write("> ");
                //int num = Convert.ToInt32(Console.ReadLine());
                //Type eType = typeMap[num];
                IExample example = ObjectUtils.InstantiateType <IExample>(typeof(Example15.XmlConfigurationExample));

                example.Run().Wait();
                Console.WriteLine("Example run successfully.");
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error running example: " + ex.Message);
                Console.WriteLine(ex.ToString());
            }
            Console.Read();
        }
Example #3
0
        public static async Task Main()
        {
            try
            {
                var logRepository = log4net.LogManager.GetRepository(Assembly.GetEntryAssembly());
                log4net.Config.XmlConfigurator.Configure(logRepository, new System.IO.FileInfo("log4net.config"));

                Assembly asm   = typeof(Program).GetTypeInfo().Assembly;
                Type[]   types = asm.GetTypes();

                IDictionary <int, Type> typeMap = new Dictionary <int, Type>();
                int counter = 1;

                Console.WriteLine("Select example to run: ");
                List <Type> typeList = new List <Type>();
                foreach (Type t in types)
                {
                    if (new List <Type>(t.GetInterfaces()).Contains(typeof(IExample)))
                    {
                        typeList.Add(t);
                    }
                }

                // sort for easier readability
                typeList.Sort(new TypeNameComparer());

                foreach (Type t in typeList)
                {
                    string counterString = $"[{counter}]".PadRight(4);
                    Console.WriteLine("{0} {1} {2}", counterString, t.Namespace.Substring(t.Namespace.LastIndexOf(".") + 1), t.Name);
                    typeMap.Add(counter++, t);
                }

                Console.WriteLine();
                Console.Write("> ");
                int      num     = Convert.ToInt32(Console.ReadLine());
                Type     eType   = typeMap[num];
                IExample example = ObjectUtils.InstantiateType <IExample>(eType);
                await example.Run().ConfigureAwait(false);

                Console.WriteLine("Example run successfully.");
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error running example: " + ex.Message);
                Console.WriteLine(ex.ToString());
            }
            Console.Read();
        }
        public static void Main()
        {
            try
            {
                Assembly asm   = Assembly.GetExecutingAssembly();
                Type[]   types = asm.GetTypes();

                IDictionary <int, Type> typeMap = new Dictionary <int, Type>();
                int counter = 1;

                Console.WriteLine("Select example to run: ");
                List <Type> typeList = new List <Type>();
                foreach (Type t in types)
                {
                    if (new List <Type>(t.GetInterfaces()).Contains(typeof(IExample)))
                    {
                        typeList.Add(t);
                    }
                }

                // sort for easier readability
                typeList.Sort(new TypeNameComparer());

                foreach (Type t in typeList)
                {
                    string counterString = string.Format("[{0}]", counter).PadRight(4);
                    Console.WriteLine("{0} {1} {2}", counterString, t.Namespace.Substring(t.Namespace.LastIndexOf(".") + 1), t.Name);
                    typeMap.Add(counter++, t);
                }

                Console.WriteLine();
                Console.Write("> ");
                int      num     = Convert.ToInt32(Console.ReadLine());
                Type     eType   = typeMap[num];
                IExample example = ObjectUtils.InstantiateType <IExample>(eType);
                example.Run();
                Console.WriteLine("Example run successfully.");
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error running example: " + ex.Message);
                Console.WriteLine(ex.ToString());
            }
            Console.Read();
        }
        private static void RunExamples(IExample example)
        {
            int finished = 0;
            var errors   = new List <string>();
            var success  = new List <string>();

            var sw = new Stopwatch();

            //Console.WriteLine($"{DateTime.UtcNow} Starting {example.Config.Name}", Color.White);

            try
            {
                sw.Restart();
                bool isSuccess = example.Run();
                sw.Stop();

                if (isSuccess)
                {
                    success.Add($"Example: {example.Config.Name} in {sw.Elapsed.TotalSeconds}s");
                }
                else
                {
                    errors.Add($"Example: {example.Config.Name} in {sw.Elapsed.TotalSeconds}s");
                }
            }
            catch (Exception ex)
            {
                errors.Add($"Example: {example.Config.Name}");
                Console.WriteLine(ex);
            }

            finished++;
            Console.WriteLine($"{DateTime.UtcNow} Completed {example.Config.Name}", Color.White);


            success.ForEach(x => Console.WriteLine($"{x} is OK!", Color.Green));
            errors.ForEach(x => Console.WriteLine($"{x} is Failed!", Color.Red));

            //Console.WriteLine($"{finished} of {examples.Length} example(s) are completed.");
            Console.Write("Press [Enter] to continue...");
            Console.ReadLine();
        }
Example #6
0
        public static void Main(string[] args)
        {
            Utils.SetEnvVarsFromAppConfig();

            while (true)
            {
                NameValueCollection examples = Utils.LoadExamples();
                int selected_index           = Utils.ShowMenu(examples);

                string currentNamespace = typeof(MainClass).Namespace;

                examples       = Utils.LoadExamplesFromNamespace(examples.GetKey(selected_index));
                selected_index = Utils.ShowMenu(examples);

                Type type = Type.GetType(examples.GetKey(selected_index));

                IExample instance = (IExample)Activator.CreateInstance(type);
                instance.Run();
            }
        }
Example #7
0
 private static void RunExample(IExample example)
 {
     example.Run().Wait();
 }
Example #8
0
        /// <summary>
        /// Starts a new task for an <see cref="IExample"/> implemetation.
        /// </summary>
        /// <param name="example">The example to run.</param>
        /// <param name="args">An array of arguments. Depending on what is necesarry for an example,
        /// it may contain multiple variables, such as serverUrl, topic paths etc. Check the example class
        /// for the description of what is required for this array.</param>
        public void StartExample(IExample example, params string[] args)
        {
            var task = Task.Run(() => example.Run(cancellationTokenSource.Token, args));

            runningExamples.Add(task);
        }
 /// <summary>
 /// Starts a new task for an <see cref="IExample"/> implemetation.
 /// </summary>
 /// <param name="example">The example to run.</param>
 /// <param name="args">An array of arguments. Depending on what is necesarry for an example,
 /// it may contain multiple variables, such as serverUrl, topic paths etc. Check the example class
 /// for the description of what is required for this array.</param>
 public void StartExample( IExample example, params string[] args )
 {
     var task = Task.Run( () => example.Run( cancellationTokenSource.Token, args ) );
     runningExamples.Add( task );
 }