コード例 #1
0
        public UpdaterWorkbench(string[] args)
        {
            InitializeComponent();
            if (args == null || args.Length <= 0)
            {
                _packageDropDownButton.Visible = true;
            }
            else
            {
                _packageDropDownButton.Visible = false;
            }
            _updateService = new UpdateService();
//            var a = "--u xknife-erian --p nknife.win.updaterFromGitHub --t NKnife.Win.UpdaterFromGitHub.Example.exe --v 1.2";
//            var cmdHelper = new CommandLineArgsHelper(a.Split(' '));
            var cmdHelper = new CommandLineArgsHelper(args);

            foreach (var item in cmdHelper.Parameters)
            {
                InitializeUpdateInfo(item.Key, item.Value);
            }

            _updateService.UpdateStatusChanged += OnUpdateStatusChanged;
            _versionLabel.Text = $"{Assembly.GetEntryAssembly()?.GetName().Version}";
            if (IsAdministrator())
            {
                AddShieldToButton(_updateButton);
            }
            else
            {
                DeleteShieldFromButton(_updateButton);
            }
            //在Form_Load里会调用一个访问,返回更新到界面
        }
コード例 #2
0
        private static void ParseCommandLineArguments(string[] args)
        {
            CommandLineArgs parsedArgs = CommandLineArgs.Parse(args);

            if (parsedArgs != null)
            {
                try
                {
                    CommandLineArgsHelper.ApplyCommandLineArgs(parsedArgs, ApplicationSettings);
                }
                catch (Exception ex)
                {
                    MessageBoxHelper.ShowError("Failed to process command line arguments: " + ex.Message);
                }
            }
        }
コード例 #3
0
        //BBernard
        //Command Line Args can be defined in the Debug Tab of the Console App Properties...
        static void Main(string[] args)
        {
            var commandLineArgHelper = new CommandLineArgsHelper(args);

            if (commandLineArgHelper.Parameters.Count > 0)
            {
                //First load and output the command args Dynamically (Loosely Coupled)...
                Console.WriteLine("Dynamically processing the Command Line Args...");
                Console.WriteLine($"Command Line Arguments [{commandLineArgHelper.Parameters.Count} found]:");
                var x = 0;
                foreach (var kv in commandLineArgHelper.Parameters)
                {
                    Console.WriteLine($"   {++x}) [{kv.Key}] == [{kv.Value}]");
                }

                Console.WriteLine();
                Console.WriteLine("Press Enter to see Strongly Typed Command Class sample (rendered as Serialized Json)...");
                Console.ReadLine();

                //Now Load and render out the Strongly Typed Command Arg (Static/Tightly Coupled)...
                Console.WriteLine();
                Console.WriteLine($"Statically processing the Command Line Args (Serialized as Json)...");

                var myCommandArgs     = new MyCommandArgs(commandLineArgHelper);
                var myCommandArgsJson = JsonConvert.SerializeObject(myCommandArgs, Formatting.Indented);

                Console.WriteLine($"{nameof(MyCommandArgs)}:");
                Console.WriteLine(myCommandArgsJson);

                Console.WriteLine();
                Console.WriteLine("Finished.");
            }
            else
            {
                Console.Write("No command line arguments were specified, please try again.");
            }

            Console.ReadLine();
        }
コード例 #4
0
 public MyCommandArgs(CommandLineArgsHelper args)
 {
     this.args = args ?? throw new ArgumentNullException(nameof(args), "Command Line Parameters collection must be specified.");
 }