示例#1
0
        protected override void OnStartup(StartupEventArgs e)
        {
            if (e.Args.Length == 2)
            {
                if (e.Args[0] == "command")
                {
                    InterProcessCommunication.SendCommand(e.Args[1]);
                    Shutdown(0);
                }
            }

            CommandLine.Handler.Handle(e.Args);

            Task.Run(() =>
            {
                Thread.CurrentThread.Name = "Avalonia";
                avaloniaApplication       = AppBuilder.Configure <AvaloniaApp>()
                                            .UsePlatformDetect()
                                            .UseReactiveUI()
                                            .LogToDebug()
                                            .SetupWithoutStarting()
                                            .Instance;

                avaloniaApplication.ExitMode = ExitMode.OnExplicitExit;
                avaloniaApplication.Run(applicationClosedTokenSource.Token);
            });

            base.OnStartup(e);
        }
示例#2
0
        private static void AppMain(Avalonia.Application app, string[] args)
        {
            var mainWindow = new MainWindow();

            app.Run(mainWindow);
        }
        // Your application's entry point. Here you can initialize your MVVM framework, DI
        // container, etc.
        private static void AppMain(Avalonia.Application app, string[] args)
        {
            var cla = new CommandLineApplication();

            cla.HelpOption();
            var optionPromptType = cla.Option("-p|--prompt <USERPASS,AUTHCODE>", "The prompt type",
                                              CommandOptionType.SingleValue);
            var optionHostUrl = cla.Option("-h|--host <HOST_URL>", "The URL of the target host, displayed to the user and used to determine host type",
                                           CommandOptionType.SingleValue);
            var optionProxyUrl = cla.Option("--proxy <PROXY_URL>", "The URL of the proxy",
                                            CommandOptionType.SingleValue);
            var optionVerifySsl = cla.Option("--verifyssl <TRUE_FALSE>", "Whether SSL shoudl be verified or not",
                                             CommandOptionType.SingleValue);
            var optionOAuthConsumerKey = cla.Option("--oauthkey <KEY>", "The OAuth Consumer Key to use during OAuth flows",
                                                    CommandOptionType.SingleValue);
            var optionOAuthConsumerSecret = cla.Option("--oauthsecret <SECRET>", "The OAuth Consumer Secret to use during OAuth flows",
                                                       CommandOptionType.SingleValue);
            var optionTrace = cla.Option("--trace <TRUE_FALSE_FILEPATH>", "False for no logging, True to log to console, Filepath to log to file",
                                         CommandOptionType.SingleValue);

            cla.OnExecute(() =>
            {
                var prompt = optionPromptType.HasValue()
                            ? optionPromptType.Value()
                            : "userpass";

                var hostUrl = optionHostUrl.HasValue()
                            ? optionHostUrl.Value()
                            : BitbucketConstants.BitbucketBaseUrl; // default to https://bitbucket.org
                var proxyUrl = optionProxyUrl.HasValue()
                            ? optionProxyUrl.Value()
                            : null; // default to no proxy
                var verifySsl = optionVerifySsl.HasValue()
                            ? optionVerifySsl.Value()
                            : "true"; // default to true
                var oAuthConsumerKey = optionOAuthConsumerKey.HasValue()
                            ? optionOAuthConsumerKey.Value()
                            : null; // default to no key
                var oAuthConsumerSecret = optionOAuthConsumerSecret.HasValue()
                            ? optionOAuthConsumerSecret.Value()
                            : null; // default to no secret
                var traceConfig = optionTrace.HasValue()
                            ? optionTrace.Value()
                            : null; // default to no logging

                var streams = new StandardStreams();

                using (var trace = new Itofinity.Bitbucket.Authentication.Helpers.Microsoft.Git.CredentialManager.Trace())
                    using (var settings = new Settings(hostUrl, proxyUrl, verifySsl, oAuthConsumerKey, oAuthConsumerSecret, traceConfig))
                    {
                        var httpClientFactory = new HttpClientFactory(trace, settings, streams);

                        // Enable tracing
                        ConfigureTrace(trace, settings, streams);

                        var viewModel = GetViewModel(prompt, hostUrl, trace, httpClientFactory, settings);
                        var window    = GetWindow(viewModel);
                        app.Run(window);

                        if (viewModel.Output != null &&
                            viewModel.Output.Any())
                        {
                            streams.Out.WriteDictionary(viewModel.Output);
                        }
                    }

                return(0);
            });

            var result = cla.Execute(args);
        }