Пример #1
0
        public static void ChooseMethods(IEnumerable <TestMethodExt> mtds, TestingWindow w)
        {
            w.Start();
            var methods = mtds.ToArray();

again:
            w.WriteLine();
            w.RememberState();
            w.WriteLine("Choose method:");
            for (int i = 0; i < methods.Length; i++)
            {
                w.WriteLine($"{i + 1}: {methods[i].Name}");
            }
            w.Write(">");
            var answ = w.ReadLine();

            if (int.TryParse(answ, out var ch) && ch <= methods.Length && ch > 0)
            {
                methods[ch - 1].InvokeWithConsole();
            }
            else
            {
                w.RestoreState();
                w.WriteLine($"\"{answ}\" is really bad choice! Try again");
                goto again;
            }
        }
Пример #2
0
        static void parse2(ParameterInfo p, out object res, out ParseResult o, TestingWindow Window)
        {
            if (p.HasDefaultValue)
            {
                Window.WriteLine($"(default: {p.DefaultValue})");
            }
            Window.Write($"{p.Name}=");
            string answ = Window.ReadLine();

            res = answ;
            if (string.IsNullOrWhiteSpace(answ) && p.HasDefaultValue)
            {
                o = ParseResult.DEFAULT; res = p.DefaultValue; return;
            }
            else if (answ == "$back")
            {
                o = ParseResult.CANCEL; res = null; return;
            }

            o = ParseResult.OK;
            var type = p.ParameterType;

            if (type == typeof(string))
            {
                res = answ; return;
            }
            else if (type == typeof(int))
            {
                if (int.TryParse(answ, out var ire))
                {
                    res = ire; return;
                }
            }
            else if (type == typeof(double))
            {
                if (double.TryParse(answ, out var dre))
                {
                    res = dre; return;
                }
            }
            else if (type == typeof(bool))
            {
                if (bool.TryParse(answ, out var bre))
                {
                    res = bre; return;
                }
            }
            else
            {
                throw new NotImplementedException();
            }

            o = ParseResult.BAD;
        }
Пример #3
0
        static void runall(MethodInfo Target, object[] obj, object parentInstance, TestingWindow Window)
        {
            IAsyncTesting at = null;

            if (parentInstance != null && parentInstance is IAsyncTesting)
            {
                at = (IAsyncTesting)parentInstance;
                Window.WriteLine("Method supports async commands. You can write");
            }

            var th = new Thread(asyncRun);

            th.Start();
            var wth = new Thread(asyncWriting);

            wth.Start();

            if (th != null && th.IsAlive)
            {
                th.Join();
            }
            try { wth.Abort(); } catch { }
            Window.EndRead();

            void asyncRun()
            {
                Window.WriteLine($"\nInvoking \"{Target.Name}\" with params: \n\t{string.Join("\n\t", obj)}\n\t");
                Target.Invoke(parentInstance, obj);
                Window.WriteLine($"\nEnd of \"{Target.Name}\" invoke.");
            }

            void asyncWriting()
            {
                while (th != null && th.IsAlive)
                {
                    try { parseComm(Window.ReadLine(), Window, th, at); }
                    catch (ThreadAbortException) { }
                    catch (Exception ex) { Window.WriteLine($"Error during execution command: {ex.Message}"); }
                }
            }
        }