예제 #1
0
 public static void StartupStage(StartStage StagetoRun)
 {
     switch (StagetoRun)
     {
         case StartStage.PreUI:
             SettingsData.Instance.RestartTriggered = false;
             CommonCommands.ChangeTheme((SharedResourceDictionary)null);
             App.StartupStage(StartStage.MainWindow);
             break;
         case StartStage.MainWindow:
             new MainWindow().Show();
             break;
         case StartStage.UIRendered:
             if (SettingsData.Instance.SettingsRecreated)
             {
                 Messenger.Default.Send<DialogMessage>(new DialogMessage(string.Empty, (Action<MessageBoxResult>)(o => { })), (object)DialogType.ConfigError);
                 SettingsData.Instance.SettingsRecreated = false;
             }
             App.StartupStage(StartStage.OOBE);
             break;
         case StartStage.OOBE:
             if (!SettingsData.Instance.OOBEScreenDisplayed && Enumerable.Count<Decimal>((IEnumerable<Decimal>)CommonCommands.GetAvailableUserAccounts()) > 0)
             {
                 SettingsData.Instance.OOBEScreenDisplayed = true;
                 SettingsData.Save();
             }
             if (!SettingsData.Instance.OOBEScreenDisplayed)
             {
                 WelcomeView content = new WelcomeView();
                 AccountManagementViewModel model = new AccountManagementViewModel(0M)
                 {
                     IsOOBE = true
                 };
                 content.DataContext = model;
                 Messenger.Default.Send<GenericMessage<UserControl>>(new GenericMessage<UserControl>(content), ViewModelMessages.ShowCenterModalWindowHost);
             }
             App.StartupStage(StartStage.ProfileUpdate);
             break;
         case StartStage.ProfileUpdate:
             foreach (Decimal num in CommonCommands.GetAvailableUserAccounts())
             {
                 if (num > new Decimal(0))
                 {
                     UserAccountViewModel accountViewModel = new UserAccountViewModel(num);
                     if (accountViewModel.Settings.TwitterAccountID > new Decimal(0) && !string.IsNullOrEmpty(accountViewModel.Settings.TwitterAccountName))
                     {
                         App.AppState.Accounts.Add(accountViewModel);
                         (System.Windows.Application.Current as App).LoadExtensions(num);
                     }
                     else
                         CommonCommands.DeleteAccountData(num);
                 }
                 else
                 {
                     try
                     {
                         Directory.Delete(ApplicationPaths.AppConfigPath + "\\0", true);
                     }
                     catch
                     {
                     }
                 }
             }
             App.AppState.Accounts.Sort<int>((Func<UserAccountViewModel, int>)(x => x.Settings.Index), ListSortDirection.Ascending);
             if (App.AppState.Accounts.Count > 0)
                 LoginView.Show(System.Windows.Application.Current.MainWindow);
             else if (SettingsData.Instance.OOBEScreenDisplayed)
             {
                 Messenger.Default.Send<GenericMessage<object>>(new GenericMessage<object>((object)null), (object)ViewModelMessages.CloseCenterModalWindowHost);
                 AccountManagementViewModel managementViewModel = new AccountManagementViewModel(new Decimal(0));
                 ManageAccountView manageAccountView = new ManageAccountView();
                 manageAccountView.DataContext = (object)managementViewModel;
                 Messenger.Default.Send<GenericMessage<System.Windows.Controls.UserControl>>(new GenericMessage<System.Windows.Controls.UserControl>((System.Windows.Controls.UserControl)manageAccountView), (object)ViewModelMessages.ShowCenterModalWindowHost);
                 managementViewModel.AddUserAccountCommand.Execute((object)null);
             }
             foreach (UserAccountViewModel accountViewModel in (Collection<UserAccountViewModel>)App.AppState.Accounts)
                 accountViewModel.UpdateProfile(true);
             App.StartupStage(StartStage.LoadTwitViews);
             break;
         case StartStage.LoadTwitViews:
             ((System.Windows.Application.Current.MainWindow as MainWindow).DataContext as MainViewModel).PostLoad();
             break;
     }
 }
 private async void SignIn()
 {
     if (this.requestToken != null)
     {
         this.requestToken.VerificationString = AccountManagementViewModel.ParseQuerystringParameter("oauth_verifier", this.URL);
         try
         {
             OAuthTokenResponse response = await OAuth.AccessTokenAsync(SettingsData.Instance.TwitterConsumerKey, SettingsData.Instance.TwitterConsumerSecret, this.requestToken.Token, this.requestToken.VerificationString);
             if (!string.IsNullOrEmpty(response.TokenSecret))
             {
                 this.TwitterAccountID = (Decimal)response.UserId;
                 UserAccountViewModel accountViewModel = new UserAccountViewModel(this.TwitterAccountID);
                 App.AppState.Accounts.Add(accountViewModel);
                 App.AppState.SwitchToAccount(this.TwitterAccountID);
                 Messenger.Default.Send<GenericMessage<TwitViewModel>>(new GenericMessage<TwitViewModel>(accountViewModel.TwitViewModel), (object)ViewModelMessages.AddTwitView);
                 App.AppState.Accounts[this.TwitterAccountID].Settings.TwitterAccountID = (Decimal)response.UserId;
                 App.AppState.Accounts[this.TwitterAccountID].Settings.TwitterAccountName = response.ScreenName;
                 App.AppState.Accounts[this.TwitterAccountID].Settings.UserAuthToken = response.Token;
                 App.AppState.Accounts[this.TwitterAccountID].Settings.UserAuthSecret = response.TokenSecret;
                 App.AppState.Accounts[this.TwitterAccountID].Settings.Save(this.TwitterAccountID);
                 if (!SettingsData.Instance.OOBEScreenDisplayed)
                     SettingsData.Instance.OOBEScreenDisplayed = true;
                 this.requestToken = (OAuthTokenResponse)null;
                 this.CheckifFollowing();
             }
             else
             {
                 Messenger.Default.Send<DialogMessage>(new DialogMessage(string.Empty, (Action<MessageBoxResult>)(r => { })), (object)DialogType.SignInAuthError);
                 return;
             }
         }
         catch (Exception ex)
         {
             Messenger.Default.Send<DialogMessage>(new DialogMessage(ex.Message, (Action<MessageBoxResult>)(r => { })), (object)DialogType.SignInTwitterizerAuthError);
             return;
         }
     }
     Messenger.Default.Send<GenericMessage<object>>(new GenericMessage<object>((object)null), (object)ViewModelMessages.CloseCenterModalWindowHost);
     if (this.IsOOBE)
     {
         FollowUsView content = new FollowUsView
         {
             DataContext = this
         };
         Messenger.Default.Send<GenericMessage<UserControl>>(new GenericMessage<UserControl>(content), ViewModelMessages.ShowCenterModalWindowHost);
     }
     else
     {
         App.AppState.Accounts[this.TwitterAccountID].UpdateProfile(true);
         Messenger.Default.Send<GenericMessage<bool>>(new GenericMessage<bool>(true), (object)this.MultiAccountifyToken((Enum)ViewModelMessages.ReloadTweetViews));
     }
 }