public void ToStringRemoveNonExistentMultipleValuesWithSomeNoValue()
        {
            // the arguments
            var args   = new[] { "--a", "b", "--e", "--c", "d" };
            var parser = new CommandlineParser(args);
            var clone  = parser.Clone().Remove("z");

            Assert.AreEqual("--a b --e --c d", clone.ToString());
        }
        public void CloneToStingWithSpacesDoesNotAddExtraQuotes()
        {
            // the arguments
            var args   = new[] { "--a", "b", "--c", "Hello World" };
            var parser = new CommandlineParser(args);
            var clone  = parser.Clone();

            Assert.AreEqual("--a b --c \"Hello World\"", clone.ToString());
        }
        public void ToStringRecoverLeadingValueMultipleValuesWithSomeNoValue()
        {
            // the arguments
            var args   = new[] { "-a", "b", "-e", "-c", "d" };
            var parser = new CommandlineParser(args, null, "-");
            var clone  = parser.Clone();

            Assert.AreEqual("-a b -e -c d", clone.ToString());
        }
        public void ToStringMultipleValues()
        {
            // the arguments
            var args   = new[] { "--a", "b", "--c", "d" };
            var parser = new CommandlineParser(args);
            var clone  = parser.Clone();

            Assert.AreEqual("--a b --c d", clone.ToString());
        }
        public void CloneValue()
        {
            // the arguments
            var args   = new[] { "--a", "b" };
            var parser = new CommandlineParser(args);
            var clone  = parser.Clone();

            Assert.AreEqual("b", clone["a"]); //  direct value.
        }
        public void CloneAndRemoveDoesNotChangeTheOriginal()
        {
            // the arguments
            var args   = new[] { "--a", "b", "--e", "--c", "d" };
            var parser = new CommandlineParser(args);
            var clone  = parser.Clone().Remove("a");

            Assert.AreEqual("--a b --e --c d", parser.ToString()); //  unchanged
            Assert.AreEqual("--e --c d", clone.ToString());
        }
Exemplo n.º 7
0
        /// <summary>
        /// Do the actual install.
        /// </summary>
        private void DoInstall()
        {
            using (var serviceProcessInstaller = new ServiceProcessInstaller {
                Account = ServiceAccount.LocalSystem
            })
            {
                // make sure we do not have the install listed.
                var clone = _commandlineParsers.Clone().Remove("install");

                // figure out the command line based on whether we have a custom service name or not
                var processLaunchCommand = $"\"{Assembly.GetEntryAssembly().Location}\" {clone}";

                // set this up as part of the install params - it won't work of course since the silly
                // installer is going to put quotes around the whole thing thus screwing our -sn ServiceName
                // paramater - we'll fix this after the intall step below with the custom registry fix
                string[] cmdline =
                {
                    $"/assemblypath=\"{processLaunchCommand}\""
                };

                using (
                    var serviceInstaller = new ServiceInstaller
                {
                    Context = new InstallContext(null, cmdline),
                    DisplayName = ServiceName,
                    Description = $"{DesktopSearchServiceName} Service to parse folders/files.",
                    ServiceName = ServiceName,
                    StartType = ServiceStartMode.Automatic,
                    Parent = serviceProcessInstaller
                })
                {
                    serviceInstaller.Install(new ListDictionary());
                }

                // now fix up the command line - the braindead installer puts quotes around everything
                var serviceKeyName = $@"SYSTEM\CurrentControlSet\Services\{ServiceName}";
                using (var key = Registry.LocalMachine.OpenSubKey(serviceKeyName, true))
                {
                    // check if key is null - in weird cases I guess the installer might have failed to populate this
                    if (key == null)
                    {
                        var msg = $"Failed to locate service key {serviceKeyName}";
                        throw new Exception(msg);
                    }
                    key.SetValue("ImagePath", processLaunchCommand);
                }
            }
            Console.WriteLine("The service has been installed!");
        }