Ejemplo n.º 1
0
        public void NameIsCaseInsensitive()
        {
            var dict = new ArgumentDictionary(new[] { "-" }, "-flag", "-name1", "value1");

            Assert.True(dict.HasFlag("Flag"));
            Assert.Equal("value1", dict["Name1"]);
        }
Ejemplo n.º 2
0
        public void ClearTest()
        {
            ArgumentDictionary target = new ArgumentDictionary(); // TODO: Initialize to an appropriate value

            target.Clear();
            Assert.Inconclusive("A method that does not return a value cannot be verified.");
        }
Ejemplo n.º 3
0
        public override void Command(ArgumentDictionary args)
        {
            var inputLine = "";

            System.Console.WriteLine("Going into command mode.  This mode allows you to interpret all of your \n" +
                                     "command arguments in the program without having to restart it.\n" +
                                     "Enter Q to quit.\n");

            while ((inputLine = System.Console.ReadLine()).ToLower() != "q" && inputLine.ToLower() != "quit")
            {
                var intputLineArgs = ConsoleMethods.SplitArgs(inputLine);
                var lst            = ConsoleMethods.GetArguments();
                var parser         = new Parser(lst);
                try
                {
                    var rtn = parser.Parse(intputLineArgs);
                    if (rtn.UnknownArguments.Length > 0)
                    {
                        System.Console.WriteLine($"Unknown argument(s) received: {String.Join(",", rtn.UnknownArguments)}");
                    }
                    else
                    {
                        rtn.CommandArgument?.ProcessCommand(rtn);
                    }
                }
                catch (DefaultArgumentException ex)
                {
                    System.Console.WriteLine("Pardon?\n");
                }
            }
        }
Ejemplo n.º 4
0
        public void CreateWithDefaultNameCharsAndArray()
        {
            var args = new[] { "--flag", "-name1", "value1", "-name2", "/value2" };
            var dict = new ArgumentDictionary(args);

            Assert.True(dict.HasFlag("flag"));
        }
Ejemplo n.º 5
0
        protected override void OnStartup(StartupEventArgs e)
        {
            _argumentDictionary = new ArgumentDictionary(e.Args);

            Directory.CreateDirectory(Globals.AppDataFolder);

            var config = new LoggingConfiguration();

            config.AddTarget(new ColoredConsoleTarget("ConsoleTarget")
            {
                Layout = @"${date:format=HH\:mm\:ss} ${level} ${message} ${exception}",
                DetectConsoleAvailable = true
            });
            config.AddTarget(new FileTarget("FileTarget")
            {
                ArchiveNumbering        = ArchiveNumberingMode.DateAndSequence,
                ArchiveOldFileOnStartup = true,
                MaxArchiveFiles         = 10,
                FileName     = Path.Combine(Globals.AppDataFolder, "Micser.App.log"),
                FileNameKind = FilePathKind.Absolute
            });
            config.AddTarget(new DebuggerTarget("DebuggerTarget"));

            config.AddRuleForAllLevels("ConsoleTarget");
            config.AddRuleForAllLevels("FileTarget");
            config.AddRuleForAllLevels("DebuggerTarget");

            LogManager.Configuration = config;
            Logger.Info("Starting...");

            base.OnStartup(e);
        }
Ejemplo n.º 6
0
        public void ArgumentDictionaryConstructorTest()
        {
            IEnumerable <Argument> arguments = null; // TODO: Initialize to an appropriate value
            ArgumentDictionary     target    = new ArgumentDictionary(arguments);

            Assert.Inconclusive("TODO: Implement code to verify target");
        }
Ejemplo n.º 7
0
        public void AddRangeTest()
        {
            ArgumentDictionary     target    = new ArgumentDictionary(); // TODO: Initialize to an appropriate value
            IEnumerable <Argument> arguments = null;                     // TODO: Initialize to an appropriate value

            target.AddRange(arguments);
            Assert.Inconclusive("A method that does not return a value cannot be verified.");
        }
Ejemplo n.º 8
0
        public void CountTest()
        {
            ArgumentDictionary target = new ArgumentDictionary(); // TODO: Initialize to an appropriate value
            int actual;

            actual = target.Count;
            Assert.Inconclusive("Verify the correctness of this test method.");
        }
Ejemplo n.º 9
0
        public void RemoveAtTest()
        {
            ArgumentDictionary target = new ArgumentDictionary(); // TODO: Initialize to an appropriate value
            int index = 0;                                        // TODO: Initialize to an appropriate value

            target.RemoveAt(index);
            Assert.Inconclusive("A method that does not return a value cannot be verified.");
        }
Ejemplo n.º 10
0
 public override void Command(ArgumentDictionary args)
 {
     Console.WriteLine("Press any key to test.  Press 'Q' to quit.");
     while (Console.ReadKey().Key != ConsoleKey.Q)
     {
         Console.WriteLine("Didn't hit Q!");
     }
 }
Ejemplo n.º 11
0
        public void GetEnumeratorTest()
        {
            ArgumentDictionary     target   = new ArgumentDictionary(); // TODO: Initialize to an appropriate value
            IEnumerator <Argument> expected = null;                     // TODO: Initialize to an appropriate value
            IEnumerator <Argument> actual   = null;

            //actual = target.GetEnumerator();
            Assert.AreEqual(expected, actual);
            Assert.Inconclusive("Verify the correctness of this test method.");
        }
Ejemplo n.º 12
0
        public void GetInvalidArgumentsTest()
        {
            ArgumentDictionary target   = new ArgumentDictionary(); // TODO: Initialize to an appropriate value
            ArgumentDictionary expected = null;                     // TODO: Initialize to an appropriate value
            ArgumentDictionary actual;

            actual = target.GetInvalidArguments();
            Assert.AreEqual(expected, actual);
            Assert.Inconclusive("Verify the correctness of this test method.");
        }
Ejemplo n.º 13
0
        public void CreateWithMultipleNameChars()
        {
            var dict = new ArgumentDictionary(new[] { "-", "/", "--" }, "--flag", "-name1", "value1", "-name2", "/value2");

            Assert.True(dict.HasFlag("flag"));
            Assert.Equal("value1", dict["name1"]);
            Assert.Null(dict["name2"]);
            Assert.True(dict.HasFlag("name2"));
            Assert.True(dict.HasFlag("value2"));
        }
Ejemplo n.º 14
0
        public void CreateWithSingleNameChar()
        {
            var dict = new ArgumentDictionary(new[] { "-" }, "-flag", "-name1", "value1", "-name2", "/value2");

            Assert.True(dict.HasFlag("flag"));
            Assert.False(dict.HasFlag("name2"));
            Assert.False(dict.HasFlag("value2"));
            Assert.Equal("value1", dict["name1"]);
            Assert.Equal("/value2", dict["name2"]);
        }
Ejemplo n.º 15
0
        public void ParametersAreNotFlags()
        {
            var dict = new ArgumentDictionary("-flag", "-key", "value", "-key2", "value2");

            Assert.True(dict.HasFlag("flag"));
            Assert.Null(dict["flag"]);
            Assert.False(dict.HasFlag("key"));
            Assert.False(dict.HasFlag("value"));
            Assert.False(dict.HasFlag("key2"));
            Assert.False(dict.HasFlag("value2"));
        }
Ejemplo n.º 16
0
        public void IndexOfTest1()
        {
            ArgumentDictionary target   = new ArgumentDictionary(); // TODO: Initialize to an appropriate value
            Argument           argument = null;                     // TODO: Initialize to an appropriate value
            int expected = 0;                                       // TODO: Initialize to an appropriate value
            int actual;

            actual = target.IndexOf(argument);
            Assert.AreEqual(expected, actual);
            Assert.Inconclusive("Verify the correctness of this test method.");
        }
Ejemplo n.º 17
0
        public void ContainsTest()
        {
            ArgumentDictionary target       = new ArgumentDictionary(); // TODO: Initialize to an appropriate value
            string             argumentName = string.Empty;             // TODO: Initialize to an appropriate value
            bool expected = false;                                      // TODO: Initialize to an appropriate value
            bool actual;

            actual = target.Contains(argumentName);
            Assert.AreEqual(expected, actual);
            Assert.Inconclusive("Verify the correctness of this test method.");
        }
Ejemplo n.º 18
0
        public void ProcessArgument_StatusFailed()
        {
            FailedTestCommand tc = new FailedTestCommand();
            var args             = new ArgumentDictionary();

            args.Add("test", tc);

            Assert.AreEqual(CommandStatus.NotRun, tc.Status);

            tc.ProcessCommand(args);

            Assert.AreEqual(CommandStatus.Failed, tc.Status);
        }
Ejemplo n.º 19
0
        public void ProcessArgument_StatusSuccess()
        {
            SuccessfulTestCommand sc = new SuccessfulTestCommand();
            var args = new ArgumentDictionary();

            args.Add("test", sc);

            Assert.AreEqual(CommandStatus.NotRun, sc.Status);

            sc.ProcessCommand(args);

            Assert.AreEqual(CommandStatus.Successful, sc.Status);
        }
Ejemplo n.º 20
0
        public void TryGetValueTest()
        {
            ArgumentDictionary target        = new ArgumentDictionary(); // TODO: Initialize to an appropriate value
            string             argumentName  = string.Empty;             // TODO: Initialize to an appropriate value
            Argument           value         = null;                     // TODO: Initialize to an appropriate value
            Argument           valueExpected = null;                     // TODO: Initialize to an appropriate value
            bool expected = false;                                       // TODO: Initialize to an appropriate value
            bool actual;

            actual = target.TryGetValue(argumentName, out value);
            Assert.AreEqual(valueExpected, value);
            Assert.AreEqual(expected, actual);
            Assert.Inconclusive("Verify the correctness of this test method.");
        }
Ejemplo n.º 21
0
        internal static Options ParseArguments(string[] args)
        {
            Mode    mode    = Mode.NotSpecified;
            Options options = null;

            if (args.Length > 0)
            {
                ArgumentDictionary arguments = CommandParser.ParseCommand(args, switches);

                if (arguments.ContainsArgument(Cmd.Install))
                {
                    mode = Mode.Install;
                }

                if (arguments.ContainsArgument(Cmd.Uninstall))
                {
                    if (mode != Mode.NotSpecified)
                    {
                        throw Tool.CreateException(SR.GetString(SR.MultipleModeArguments), null);
                    }

                    mode = Mode.Uninstall;
                }

                if (arguments.ContainsArgument(Cmd.List))
                {
                    if (mode != Mode.NotSpecified)
                    {
                        throw Tool.CreateException(SR.GetString(SR.MultipleModeArguments), null);
                    }

                    mode = Mode.List;
                }
                options = new Options(mode, arguments);
            }
            else
            {
                return(new Options(mode, null));
            }

            if (!options.Help && (mode == Mode.NotSpecified))
            {
                throw Tool.CreateException(SR.GetString(SR.ModeArgumentMissing), null);
            }

            return(options);
        }
Ejemplo n.º 22
0
        static void Main(string[] args)
        {
            AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);
            Application.ThreadException += Application_ThreadException;

            ArgumentParser argumentParser = new ArgumentParser(new[] { "/", "-" }, true, new[] { new Argument("c", ArgumentValue.Optional, true), new Argument("d", ArgumentValue.None, true), new Argument("p", ArgumentValue.Required, true), new Argument("s", ArgumentValue.None, true) });

            argumentParser.Parse(args);
            ArgumentDictionary validArguments = argumentParser.ParsedArguments.GetValidArguments();

            if (validArguments.Contains("d"))
            {
                Debugger.Launch();
                Settings.IsDebug = true;
            }

            if (validArguments.Contains("c"))
            {
                Application.Run(new FormOptions());
            }
            else
            {
                IntPtr previewHandle = IntPtr.Zero;

                if (validArguments.Contains("p"))
                {
                    long tempLong;
                    if (long.TryParse(validArguments["p"].Value, out tempLong))
                    {
                        previewHandle = new IntPtr(tempLong);
                        Logging.LogMessage("Preview Handle: " + previewHandle);
                    }
                }

                Application.Run(new FormMain(previewHandle));
            }
        }
        public bool TryInvokeRemoteMethod <TContract>(MethodInfo contractMethod, KeyValuePair <string, object>[] args, out object result)
            where TContract : class
        {
            MemoryStream requestStream = new MemoryStream();

            ArgumentDictionary arguments = new ArgumentDictionary(args.ToDictionary(x => x.Key, x => x.Value));

            invocationSerializer.Serialize(requestStream, arguments);
            requestStream.Position = 0;

            StreamContent requestContent = new StreamContent(requestStream);

            requestContent.Headers.ContentType = new MediaTypeHeaderValue(invocationSerializer.MediaType);

            HttpRequestMessage requestMessage = new HttpRequestMessage(HttpMethod.Post, CreateRequestPath(typeof(TContract), contractMethod))
            {
                Content = requestContent
            };

            requestMessage.Headers.Accept.Clear();
            requestMessage.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue(invocationSerializer.MediaType));

            Type returnType;

            if (contractMethod.ReturnType == typeof(Task))
            {
                result = GetResultNoReturnTypeAsync(typeof(TContract), requestMessage);
            }
            else
            {
                returnType = contractMethod.ReturnType.GetGenericArguments()[0];
                result     = GetType().GetMethod(nameof(GetResultAsync), BindingFlags.Instance | BindingFlags.NonPublic)
                             .MakeGenericMethod(returnType)
                             .Invoke(this, new object[] { typeof(TContract), requestMessage });
            }

            return(true);
        }
Ejemplo n.º 24
0
        public override void Command(ArgumentDictionary args)
        {
            IArgument showHelpFor;

            if (args.ContainsKey("name"))
            {
                showHelpFor = args.AllArguments[((IArgumentWithValue)args["name"]).Value];
            }
            else
            {
                showHelpFor = this;
            }

            Console.WriteLine(showHelpFor.Summary);

            if (args.ContainsKey("full"))
            {
                Console.WriteLine(showHelpFor.HelpDetail);
            }
            if (args.ContainsKey("example"))
            {
                Console.WriteLine(showHelpFor.HelpExample);
            }
        }
Ejemplo n.º 25
0
 public override void Command(ArgumentDictionary args)
 {
 }
Ejemplo n.º 26
0
        private static int MainInternal(string[] args)
        {
            var arguments = new ArgumentDictionary(Globals.DriverUtility.ArgumentNameChars, args);
            var silent    = arguments.HasFlag(Globals.DriverUtility.Arguments.Silent);

            InitLogging(silent);

            if (silent)
            {
                // In silent mode the console log is deactivated; only show the following:
                Console.WriteLine("Configuring virtual audio cable...");
            }

            var logger = LogManager.GetCurrentClassLogger();

            // TODO the check doesn't work during msi installation..
            if (!silent && !UacHelper.IsProcessElevated)
            {
                logger.Error("The process must have elevated privileges to manage driver installation.");
                return(Globals.DriverUtility.ReturnCodes.RequiresAdminAccess);
            }

            logger.Info("Starting...");

            try
            {
                logger.Info("Arguments: " + arguments);

                var sDeviceCount = arguments[Globals.DriverUtility.Arguments.DeviceCount];

                if (string.IsNullOrEmpty(sDeviceCount) || !int.TryParse(sDeviceCount, out var deviceCount))
                {
                    logger.Error($"Invalid or missing device count argument '{Globals.DriverUtility.ArgumentNameChars[0]}{Globals.DriverUtility.Arguments.DeviceCount}' provided: '{sDeviceCount}'.");
                    return(Globals.DriverUtility.ReturnCodes.InvalidParameter);
                }

                var controller = new DriverController();
                var result     = controller.SetDeviceSettingsAndReload(deviceCount);

                if (result != Globals.DriverUtility.ReturnCodes.Success)
                {
                    logger.Error($"{nameof(DriverController.SetDeviceSettingsAndReload)} returned {result}");
                    return(result);
                }

                using (var deviceService = new DeviceService())
                {
                    var renameResult = deviceService.RenameDevices(deviceCount).GetAwaiter().GetResult();
                    if (!renameResult)
                    {
                        logger.Error("Renaming failed.");
                    }
                }
            }
            catch (Exception ex)
            {
                logger.Error(ex);
                return(Globals.DriverUtility.ReturnCodes.UnknownError);
            }

            logger.Info("Success");
            return(Globals.DriverUtility.ReturnCodes.Success);
        }
Ejemplo n.º 27
0
        public void GetString()
        {
            var dict = new ArgumentDictionary("--flag1", "/Flag2", "-name1", "value1", "-name2", "value2");

            Assert.Equal("Flags: flag1, flag2 | Parameters: [name1=value1], [name2=value2]", dict.ToString());
        }
Ejemplo n.º 28
0
        public void CreateWithDefaultNameCharsAndParams()
        {
            var dict = new ArgumentDictionary("--flag", "-name1", "value1", "-name2", "/value2");

            Assert.True(dict.HasFlag("flag"));
        }
Ejemplo n.º 29
0
 public override void Command(ArgumentDictionary args)
 {
     Status = CommandStatus.Failed;
 }
Ejemplo n.º 30
0
        public override void Command(ArgumentDictionary args)
        {
            var name = ((NamedArgument)args["name"]).Value;

            Console.WriteLine($"Created a new item called {name}.");
        }