protected override void OnStartup(StartupEventArgs e) { base.OnStartup(e); bool showLogin = false; _settings = Settings.Load(); if (_settings == null) { _settings = new Settings { PrimaryQuery = "for: me #Open", SecondaryQuery = "for: me #Resolved", }; showLogin = true; } ServiceProvider.Initialize(_settings); MainWindow = new StatusWindow(); if (!showLogin) { // Verify that the userlogin matches our cookie's credentials try { // Mostly just care that we don't get a 400 something from this call. YouTrackService.User currentUser = ServiceProvider.YouTrackService.GetCurrentUser(); if (_settings.UserLogin != currentUser.Login) { showLogin = true; } } catch (WebException) { } } if (showLogin) { var loginWindow = new LoginWindow(); if (!(loginWindow.ShowDialog() ?? false)) { Application.Current.Shutdown(0); return; } _settings.UserLogin = ServiceProvider.YouTrackService.GetCurrentUser().Login; _settings.Save(); } ServiceProvider.OnLoggedIn(); MainWindow.Show(); SingleInstance.SingleInstanceActivated += _SignalExternalCommandLineArgs; }
public static Settings Load() { Utility.EnsureDirectory(_SettingsDirectory); try { dynamic json = null; using (var settingsStream = new StreamReader(_Path)) { json = JsonConvert.DeserializeObject<dynamic>(settingsStream.ReadToEnd()); } if ((int)json["version"] != 1) { // Don't know how to deserialize this. return null; } CookieContainer jar = null; try { var serializedJar = System.Convert.FromBase64String(json["cookie_jar"].ToString()); jar = (CookieContainer)_formatter.Deserialize(new MemoryStream(serializedJar)); } catch { } var maybeSettings = new Settings { UserLogin = json["login"], PrimaryQuery = json["primary_query"], PrimaryQueryScope = json["primary_scope"], SecondaryQuery = json["secondary_query"], SecondaryQueryScope = json["secondary_scope"], CookieContainer = jar ?? new CookieContainer(), }; return maybeSettings; } catch { } return null; }