public LoginWindowViewModel(UserControl view)
        {
            this.view = view as LoginView;

            UseSession = Settings.UserSettings.ContainsKey("UseSessionID") ? bool.Parse(Settings.UserSettings["UseSessionID"]) : false;

            Email = Settings.UserSettings["AccountLogin"];
            this.formChanged = string.IsNullOrEmpty(Settings.UserSettings["AccountPassword"]);

            if (!this.formChanged)
                this.view.txtPassword.Password = string.Empty.PadLeft(8); //For the visuals

            this.view.txtPassword.PasswordChanged += new System.Windows.RoutedEventHandler(txtPassword_PasswordChanged);

            statusController = new StatusController(this.view.StatusBox);

            ApplicationState.Model.Authenticating += model_Authenticating;
            ApplicationState.Model.Throttled += model_Throttled;
            ApplicationState.InitializeFont(Properties.Resources.fontin_regular_webfont);
            ApplicationState.InitializeFont(Properties.Resources.fontin_smallcaps_webfont);

            statusController.DisplayMessage(ApplicationState.Version + " Initialized.\r");

            VersionChecker.CheckForUpdates();
        }
Esempio n. 2
0
        public LoginWindowViewModel(UserControl view)
        {
            _view = view as LoginView;

            ForceRefresh = Settings.UserSettings.ContainsKey("ForceRefresh") ?
                           bool.Parse(Settings.UserSettings["ForceRefresh"]) : true;

            Email = Settings.UserSettings["AccountLogin"];

            if (!string.IsNullOrEmpty(Settings.UserSettings["AccountPassword"]))
            {
                _view.txtPassword.Password = string.Empty.PadLeft(8); //For the visuals
            }
            _view.txtPassword.PasswordChanged += new RoutedEventHandler(TxtPassword_PasswordChanged);
            PropertyChanged += LoginWindow_PropertyChanged;

            _characterInjector = new CharacterTabInjector();

            _statusController = new StatusController(_view.StatusBox);

            ApplicationState.Model.Authenticating += Model_Authenticating;
            ApplicationState.Model.Throttled      += Model_Throttled;
            ApplicationState.InitializeFont(Properties.Resources.fontin_regular_webfont);
            ApplicationState.InitializeFont(Properties.Resources.fontin_smallcaps_webfont);

            _statusController.DisplayMessage(ApplicationState.Version + " Initialized.\r");

            VersionChecker.CheckForUpdates();

            //Todo: Feed this in from a setting so that console players will have their preference remembered
            SelectedRealm = AvailableRealms.First();
        }
        public LoginWindowViewModel(UserControl view)
        {
            this.view = view as LoginView;

            UseSession = Settings.UserSettings.ContainsKey("UseSessionID") ? bool.Parse(Settings.UserSettings["UseSessionID"]) : false;

            Email            = Settings.UserSettings["AccountLogin"];
            this.formChanged = string.IsNullOrEmpty(Settings.UserSettings["AccountPassword"]);

            if (!this.formChanged)
            {
                this.view.txtPassword.Password = string.Empty.PadLeft(8); //For the visuals
            }
            this.view.txtPassword.PasswordChanged += new System.Windows.RoutedEventHandler(txtPassword_PasswordChanged);

            statusController = new StatusController(this.view.StatusBox);

            ApplicationState.Model.Authenticating += model_Authenticating;
            ApplicationState.Model.Throttled      += model_Throttled;
            ApplicationState.InitializeFont(Properties.Resources.fontin_regular_webfont);
            ApplicationState.InitializeFont(Properties.Resources.fontin_smallcaps_webfont);

            statusController.DisplayMessage(ApplicationState.Version + " Initialized.\r");

            VersionChecker.CheckForUpdates();
        }
Esempio n. 4
0
        public LoginWindowViewModel(UserControl view)
        {
            this.view = view as LoginView;

            UseSession = Settings.UserSettings.ContainsKey("UseSessionID") ?
                         bool.Parse(Settings.UserSettings["UseSessionID"]) : false;
            ForceRefresh = Settings.UserSettings.ContainsKey("ForceRefresh") ?
                           bool.Parse(Settings.UserSettings["ForceRefresh"]) : true;

            Email = Settings.UserSettings["AccountLogin"];

            if (!string.IsNullOrEmpty(Settings.UserSettings["AccountPassword"]))
            {
                this.view.txtPassword.Password = string.Empty.PadLeft(8); //For the visuals
            }
            this.view.txtPassword.PasswordChanged += new RoutedEventHandler(txtPassword_PasswordChanged);
            PropertyChanged += loginWindow_PropertyChanged;

            characterInjector = new CharacterTabInjector();

            statusController = new StatusController(this.view.StatusBox);

            ApplicationState.Model.Authenticating += model_Authenticating;
            ApplicationState.Model.Throttled      += model_Throttled;
            ApplicationState.InitializeFont(Properties.Resources.fontin_regular_webfont);
            ApplicationState.InitializeFont(Properties.Resources.fontin_smallcaps_webfont);

            statusController.DisplayMessage($"WTF is {ApplicationState.Version} Initialized. RIP TotalBiscuit.\r");

            VersionChecker.CheckForUpdates();
        }
        public void Login(bool offline)
        {
            toggleControls();

            if (string.IsNullOrEmpty(Email))
            {
                MessageBox.Show(string.Format("{0} is required!", useSession ? "Alias" : "Email"), "Error logging in", MessageBoxButton.OK, MessageBoxImage.Stop);
                toggleControls();
                return;
            }

            if (!offline)
            {
                ApplicationState.Model.StashLoading += model_StashLoading;
                ApplicationState.Model.ImageLoading += model_ImageLoading;
            }


            Task.Factory.StartNew(() =>
            {
                SecureString password = formChanged ? this.view.txtPassword.SecurePassword : Settings.UserSettings["AccountPassword"].Decrypt();
                ApplicationState.Model.Authenticate(Email, password, offline, useSession);

                if (formChanged)
                {
                    saveSettings(password);
                }

                if (!offline)
                {
                    ApplicationState.Model.ForceRefresh();
                    statusController.DisplayMessage("Loading characters...");
                }
                else
                {
                    statusController.DisplayMessage("Loading Procurement in offline mode...");
                }

                List <Character> chars;
                try
                {
                    chars = ApplicationState.Model.GetCharacters();
                }
                catch (WebException wex)
                {
                    Logger.Log(wex);
                    statusController.NotOK();
                    throw new Exception("Failed to load characters", wex.InnerException);
                }
                statusController.Ok();

                updateCharactersByLeague(chars);

                var items = LoadItems(offline, chars).ToList();

                ApplicationState.Model.GetImages(items);

                ApplicationState.SetDefaults();

                if (!offline)
                {
                    statusController.DisplayMessage("\nDone!");
                }

                ApplicationState.Model.Authenticating -= model_Authenticating;
                ApplicationState.Model.StashLoading   -= model_StashLoading;
                ApplicationState.Model.ImageLoading   -= model_ImageLoading;
                ApplicationState.Model.Throttled      -= model_Throttled;
                OnLoginCompleted();
            }).ContinueWith(t => { Logger.Log(t.Exception.InnerException.ToString()); statusController.HandleError(t.Exception.InnerException.Message, toggleControls); }, TaskContinuationOptions.OnlyOnFaulted);
        }
Esempio n. 6
0
        public void Login(bool offline)
        {
            ToggleControls();

            if (string.IsNullOrEmpty(Email))
            {
                MessageBox.Show(string.Format("{0} is required!", _useSession ? "Alias" : "Email"), "Error logging in",
                                MessageBoxButton.OK, MessageBoxImage.Stop);
                ToggleControls();
                return;
            }

            if (!offline)
            {
                // Prevents the event from being registered doubly if the login fails prematurely.
                ApplicationState.Model.StashLoading -= Model_StashLoading;
                ApplicationState.Model.ImageLoading -= Model_ImageLoading;

                ApplicationState.Model.StashLoading += Model_StashLoading;
                ApplicationState.Model.ImageLoading += Model_ImageLoading;
            }


            Task.Factory.StartNew(() =>
            {
                // If offline == true, the password is never checked to know if it is correct, but if
                // passwordChanged == true, the new value is saved to the settings file.  This might not be the
                // behavior the user expects.
                SecureString password = _passwordChanged ? this._view.txtPassword.SecurePassword :
                                        Settings.UserSettings["AccountPassword"].Decrypt();
                ApplicationState.CurrentRealm = SelectedRealm;
                ApplicationState.Model.Authenticate(Email, password, offline, ApplicationState.CurrentRealm);

                if (_formChanged)
                {
                    SaveSettings(password);
                }

                if (!offline)
                {
                    _statusController.DisplayMessage("Fetching account name...");
                    ApplicationState.AccountName = ApplicationState.Model.GetAccountName(ApplicationState.CurrentRealm);
                    _statusController.Ok();
                    if (ForceRefresh)
                    {
                        ApplicationState.Model.ForceRefresh();
                    }
                    _statusController.DisplayMessage("Loading characters...");
                }
                else
                {
                    _statusController.DisplayMessage("Loading Procurement in offline mode...");
                }

                List <Character> chars;
                try
                {
                    chars = ApplicationState.Model.GetCharacters(ApplicationState.CurrentRealm);
                }
                catch (WebException wex)
                {
                    Logger.Log(wex);
                    _statusController.NotOK();
                    throw new Exception("Failed to load characters", wex.InnerException);
                }
                _statusController.Ok();

                UpdateCharactersByLeague(chars);

                var items = LoadItems(offline, chars).ToList();

                ApplicationState.Model.GetImages(items);

                ApplicationState.SetDefaults();

                if (!offline)
                {
                    _statusController.DisplayMessage("\nDone!");
                    PoeTradeOnlineHelper.Instance.Start();
                }

                ApplicationState.Model.Authenticating -= Model_Authenticating;
                ApplicationState.Model.StashLoading   -= Model_StashLoading;
                ApplicationState.Model.ImageLoading   -= Model_ImageLoading;
                ApplicationState.Model.Throttled      -= Model_Throttled;
                OnLoginCompleted();
            }).ContinueWith(t =>
            {
                Logger.Log(t.Exception.InnerException.ToString());
                _statusController.HandleError(t.Exception.InnerException.Message, ToggleControls);
            }, TaskContinuationOptions.OnlyOnFaulted);
        }
        public LoginWindowViewModel(UserControl view)
        {
            this.view = view as LoginView;

            UseSession = Settings.UserSettings.ContainsKey("UseSessionID") ? bool.Parse(Settings.UserSettings["UseSessionID"]) : false;

            Email            = Settings.UserSettings["AccountLogin"];
            this.formChanged = string.IsNullOrEmpty(Settings.UserSettings["AccountPassword"]);

            if (!this.formChanged)
            {
                this.view.txtPassword.Password = string.Empty.PadLeft(8); //For the visuals
            }
            this.view.txtPassword.PasswordChanged += new System.Windows.RoutedEventHandler(txtPassword_PasswordChanged);



            statusController = new StatusController(this.view.StatusBox);
            statusController.DisplayMessage(ApplicationState.Version + " - checking for updates...\r");
            int        latestversion;
            WebRequest LatestVesionRequest;

            LatestVesionRequest = WebRequest.Create("http://raw.github.com/Anubioz/procurement/master/VERSION");

            Stream objStream;

            objStream = LatestVesionRequest.GetResponse().GetResponseStream();

            StreamReader objReader = new StreamReader(objStream);

            string LatestVersionString = "";
            int    i = 0;
            bool   updateAvailable = false;

            while (LatestVersionString != null)
            {
                i++;
                LatestVersionString = objReader.ReadLine();

                if (LatestVersionString != null)
                {
                    latestversion = Convert.ToInt32(LatestVersionString);
                    if (latestversion > 13002)
                    {
                        updateAvailable = true;
                    }
                }
            }

            if (updateAvailable)
            {
                statusController.DisplayMessage("Updated version is available!\r");

                WebRequest ChangeLogRequest;
                ChangeLogRequest = WebRequest.Create("http://raw.github.com/Anubioz/procurement/master/LATEST");

                objStream = ChangeLogRequest.GetResponse().GetResponseStream();
                objReader = new StreamReader(objStream);
                string ChangeLogString = "";
                i = 0;

                while (ChangeLogString != null)
                {
                    i++;
                    ChangeLogString = objReader.ReadLine();

                    if (ChangeLogString != null)
                    {
                        statusController.DisplayMessage(ChangeLogString);
                    }
                }
            }
            else
            {
                statusController.DisplayMessage("Your version is up to date!\r");

                WebRequest ChangeLogRequest;
                ChangeLogRequest = WebRequest.Create("http://raw.github.com/Anubioz/procurement/master/UPTODATE");

                objStream = ChangeLogRequest.GetResponse().GetResponseStream();
                objReader = new StreamReader(objStream);
                string ChangeLogString = "";
                i = 0;

                while (ChangeLogString != null)
                {
                    i++;
                    ChangeLogString = objReader.ReadLine();

                    if (ChangeLogString != null)
                    {
                        statusController.DisplayMessage(ChangeLogString);
                    }
                }
            }
            ApplicationState.Model.Authenticating += new POEModel.AuthenticateEventHandler(model_Authenticating);
            ApplicationState.Model.StashLoading   += new POEModel.StashLoadEventHandler(model_StashLoading);
            ApplicationState.Model.ImageLoading   += new POEModel.ImageLoadEventHandler(model_ImageLoading);
            ApplicationState.Model.Throttled      += new ThottledEventHandler(model_Throttled);
            ApplicationState.InitializeFont(Properties.Resources.fontin_regular_webfont);
            ApplicationState.InitializeFont(Properties.Resources.fontin_smallcaps_webfont);
        }
        public void Login(bool offline)
        {
            authOffLine = offline;
            toggleControls();

            Task.Factory.StartNew(() =>
            {
                if (useSession)
                {
                    ApplicationState.Model.Authenticate(Email, this.view.txtPassword.SecurePassword, authOffLine, useSession, this.view.txtPassword.Password);
                }
                else
                {
                    SecureString password = formChanged ? this.view.txtPassword.SecurePassword : Settings.UserSettings["AccountPassword"].Decrypt();
                    ApplicationState.Model.Authenticate(Email, password, authOffLine, useSession);
                    saveSettings(password);
                }


                if (!authOffLine)
                {
                    ApplicationState.Model.ForceRefresh();
                }

                statusController.DisplayMessage("Loading characters...");
                List <Character> chars;
                try
                {
                    chars = ApplicationState.Model.GetCharacters();
                }
                catch (WebException wex)
                {
                    Logger.Log(wex);
                    statusController.NotOK();
                    throw new Exception("Failed to load characters", wex.InnerException);
                }
                statusController.Ok();

                bool downloadOnlyMyLeagues = false;
                downloadOnlyMyLeagues      = (Settings.UserSettings.ContainsKey("DownloadOnlyMyLeagues") &&
                                              bool.TryParse(Settings.UserSettings["DownloadOnlyMyLeagues"], out downloadOnlyMyLeagues) &&
                                              downloadOnlyMyLeagues &&
                                              Settings.Lists.ContainsKey("MyLeagues") &&
                                              Settings.Lists["MyLeagues"].Count > 0
                                              );

                foreach (var character in chars)
                {
                    if (character.League == "Void")
                    {
                        continue;
                    }

                    if (downloadOnlyMyLeagues && !Settings.Lists["MyLeagues"].Contains(character.League))
                    {
                        continue;
                    }

                    ApplicationState.Characters.Add(character);
                    loadCharacterInventory(character);
                    loadStash(character);
                }

                if (downloadOnlyMyLeagues && ApplicationState.Characters.Count == 0)
                {
                    throw new Exception("No characters found in the leagues specified. Check spelling or try setting DownloadOnlyMyLeagues to false in settings");
                }

                ApplicationState.SetDefaults();

                statusController.DisplayMessage("\nDone!");
                OnLoginCompleted();
            }).ContinueWith((t) => { Logger.Log(t.Exception.InnerException.ToString()); statusController.HandleError(t.Exception.InnerException.Message, toggleControls); }, TaskContinuationOptions.OnlyOnFaulted);
        }