protected async override void OnStartup(object sender, System.Windows.StartupEventArgs e) { _logger.Info("OnStartup"); var shell = IoC.Get <MainWindowViewModel>(); if (Environment.GetCommandLineArgs().Count() > 1) { CommandLineArgs cmdLineArgs = null; try { if (Environment.CommandLine.ToUpper().Contains("/HELP")) { throw new Exception(); } _logger.Info("Commandline Args=" + Environment.CommandLine); IWindowManager wm = IoC.Get <IWindowManager>(); cmdLineArgs = Args.Configuration.Configure <HockeyApp.AppLoader.Model.CommandLineArgs>().CreateAndBind(Environment.GetCommandLineArgs()); string errMsg = ""; if (!cmdLineArgs.IsValid(out errMsg)) { _logger.Warn("Command line args invalid: " + errMsg); throw new Exception(); } }catch { StringBuilder sb = new StringBuilder(); StringWriter tw = new StringWriter(sb); CommandLineArgs.WriteHelp(tw, "HockeyUpload"); MessageBox.Show(sb.ToString(), "Usage"); Application.Shutdown(); } this.container.ComposeExportedValue <CommandLineArgs>(cmdLineArgs); AppInfoMatcher matcher = new AppInfoMatcher(); List <AppInfo> list = await matcher.GetMatchingApps(cmdLineArgs); if (list.Count == 0) { MessageBox.Show("No matching application found. Please check the configuration information!", "Error", MessageBoxButton.OK, MessageBoxImage.Error); Application.Shutdown(-1); } UploadDialogViewModel vm = new UploadDialogViewModel(list, matcher.ActiveUserConfiguration); vm.Closed += delegate(object s, EventArgs args) { Application.Shutdown(0); }; try { shell.Init(vm); shell.IsDialog = true; } catch (Exception ex) { _logger.Error(ex.Message); MessageBox.Show("Error while loading applications!\n" + ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error); } } else { Configuration config = IoC.Get <Configuration>(); if (config.UserConfigurations.Count == 0) { InitialConfigurationViewModel initialVM = new InitialConfigurationViewModel(); shell.Init(initialVM); shell.IsDialog = false; initialVM.Closed += (a, b) => { if (config.UserConfigurations.Count > 0) { this.container.ComposeExportedValue <ConfigurationViewModel>(new ConfigurationViewModel()); this.container.ComposeExportedValue <FeedbackViewModel>(new FeedbackViewModel()); this.container.ComposeExportedValue <ApplicationsViewModel>(new ApplicationsViewModel()); shell.Init(new ConfigurationContentViewModel()); } else { Application.Shutdown(); } }; } else { this.container.ComposeExportedValue <ConfigurationViewModel>(new ConfigurationViewModel()); this.container.ComposeExportedValue <FeedbackViewModel>(new FeedbackViewModel()); this.container.ComposeExportedValue <ApplicationsViewModel>(new ApplicationsViewModel()); shell.Init(new ConfigurationContentViewModel()); shell.IsDialog = false; } } base.OnStartup(sender, e); }
static void Main(string[] args) { new CrashHandler(); string exeFile = System.Reflection.Assembly.GetEntryAssembly().Location; string exePath = Path.GetDirectoryName(exeFile); var tmp = System.Configuration.ConfigurationManager.OpenExeConfiguration(exePath + @"\HockeyUpload.exe"); System.Configuration.KeyValueConfigurationCollection col = tmp.AppSettings.Settings; HockeyApp.AppLoader.Model.Configuration c = HockeyApp.AppLoader.Model.Configuration.Instance; if (Environment.CommandLine.ToUpper().Contains("/HELP")) { HockeyApp.AppLoader.Model.CommandLineArgs.WriteHelp(Console.Out, "HOCH"); } else if (Environment.GetCommandLineArgs().Count() > 1) { try { _args = Args.Configuration.Configure <HockeyApp.AppLoader.Model.CommandLineArgs>().CreateAndBind(Environment.GetCommandLineArgs()); } catch { HockeyApp.AppLoader.Model.CommandLineArgs.WriteHelp(Console.Out, "HOCH"); return; } string errMsg = ""; if (!_args.IsValid(out errMsg)) { LogToConsole("Wrong parameter: " + errMsg); return; } try { AppInfoMatcher matcher = new AppInfoMatcher(); Task <List <AppInfo> > t = matcher.GetMatchingApps(_args); t.Wait(); List <AppInfo> list = t.Result; if (list.Count == 0) { LogToConsole("No matching application found. Please check the configuration information!"); return; } else if (list.Count > 1) { LogToConsole("More than one apps are matching. Please change parameter!"); LogToConsole("Matching apps: " + list.Select(p => p.Title).Aggregate((a, b) => a + "," + b)); return; } UploadStrategy uploader = UploadStrategy.GetStrategy(list.First()); LogToConsole(""); DateTime start = DateTime.Now; Task task = uploader.Upload(_args.Package, matcher.ActiveUserConfiguration, ProgressHandler, CancellationToken.None); task.Wait(); DateTime end = DateTime.Now; TimeSpan sp = end.Subtract(start); FileInfo fi = new FileInfo(_args.Package); long length = fi.Length; length = length / 8; LogToConsole(""); LogToConsole(string.Format("Uploaded {0}KB in {1}sec", length.ToString("###,###,###"), sp.Seconds.ToString("d"))); } catch (Exception ex) { LogToConsole("Error: " + ex.Message); } } else { HockeyApp.AppLoader.Model.CommandLineArgs.WriteHelp(Console.Out, "HOCH"); } }