Exemplo n.º 1
0
        public static MessageBoxResult ShowModalDialog(OsbideLoginViewModel vm)
        {
            OsbideLoginControl window = new OsbideLoginControl();

            window.ViewModel = vm;
            window.ShowDialog();
            return(vm.Result);
        }
Exemplo n.º 2
0
        /// <summary>
        /// </summary>
        private void OpenLoginScreen(object sender, EventArgs e)
        {
            IVsUIShell           uiShell = (IVsUIShell)GetService(typeof(SVsUIShell));
            Guid                 clsid   = Guid.Empty;
            OsbideLoginViewModel vm      = new OsbideLoginViewModel();

            vm.RequestCreateAccount += ShowCreateAccountTool;

            //attempt to store previously cached values if possible
            vm.Password   = _userPassword;
            vm.Email      = _userName;
            vm.IsLoggedIn = _client.IsSendingData;

            MessageBoxResult result = OsbideLoginControl.ShowModalDialog(vm);

            //assume that data was changed and needs to be saved
            if (result == MessageBoxResult.OK)
            {
                try
                {
                    _cache[StringConstants.UserNameCacheKey] = vm.Email;
                    _userName     = vm.Email;
                    _userPassword = vm.Password;
                    _cache[StringConstants.PasswordCacheKey]       = AesEncryption.EncryptStringToBytes_Aes(vm.Password, _encoder.Key, _encoder.IV);
                    _cache[StringConstants.AuthenticationCacheKey] = vm.AuthenticationHash;
                }
                catch (Exception ex)
                {
                    //write to the log file
                    _errorLogger.WriteToLog(string.Format("SaveUser error: {0}", ex.Message), LogPriority.HighPriority);

                    //turn off client sending if we run into an error
                    if (_client != null)
                    {
                        _client.StopSending();
                    }
                }

                //If we got back a valid user, turn on log saving
                if (_userName != null && _userPassword != null)
                {
                    //turn on client sending
                    if (_client != null)
                    {
                        _client.IsCollectingData = true;
                        _client.StartSending();
                    }
                    MessageBox.Show("Welcome to OSBIDE!");
                }
                else
                {
                    //turn off client sending if the user didn't log in.
                    if (_client != null)
                    {
                        _client.StopSending();
                    }
                }
            }
            else if (result == MessageBoxResult.No)
            {
                //In this case, I'm using MessageBoxResult.No to represent a log out request.  We can
                //fake that by just turning off client collection and sending.
                _client.IsCollectingData = false;
                _client.StopSending();
                _cache[StringConstants.AuthenticationCacheKey] = "";
                MessageBox.Show("You have been logged out of OSBIDE.");
            }
        }