예제 #1
0
        public async void SetUserAndPassword()
        {
            var loginDialogSettings = new LoginDialogSettings
            {
                AffirmativeButtonText    = Resources.SettingsView_ButtonSave,
                NegativeButtonText       = Resources.SettingsView_ButtonCancel,
                NegativeButtonVisibility = Visibility.Visible,
                InitialUsername          = DraftSource.UserName,
                InitialPassword          = DraftSource.Password
            };

            // Only allow the previewing of a password when creating a new source
            // not when modifying an existing source
            if (_isNewItem)
            {
                loginDialogSettings.EnablePasswordPreview = true;
            }

            var result = await _dialogCoordinator.ShowLoginAsync(this, Resources.SettingsViewModel_SetSourceUsernameAndPasswordTitle, Resources.SettingsViewModel_SetSourceUsernameAndPasswordMessage, loginDialogSettings);

            if (result != null)
            {
                DraftSource.UserName = result.Username;
                DraftSource.Password = result.Password;
                NotifyOfPropertyChange(nameof(DraftSource));
            }
        }
예제 #2
0
 /// <summary>
 /// Shows a login dialog inside the current window.
 /// </summary>
 /// <returns>The async task with login result</returns>
 public async Task <LoginDialogData> ShowLoginAsync()
 {
     return(await dialogCoordinator.ShowLoginAsync(shell, "Log on", "Please specify your login data", new LoginDialogSettings
     {
         UsernameWatermark = "Email",
         NegativeButtonVisibility = Visibility.Visible
     }));
 }
예제 #3
0
        public async void ShowLoginDialog()
        {
            // note that setting allows much additional functionality
            LoginDialogSettings settings = new LoginDialogSettings()
            {
                NegativeButtonText = "Cancel", NegativeButtonVisibility = System.Windows.Visibility.Visible
            };

            await _dialogCoordinator.ShowLoginAsync(this, "Please Login", "This login dialog was shown from Screen1ViewModel.", MessageDialogStyle.AffirmativeAndNegative, settings).ContinueWith(t => HandleLoginClose(t.Result));
        }
        private async void ExecuteWindowLoaded()
        {
            ClientService.GetInstance().OnUpdateReceived += OnUpdateReceived;
            ClientService.GetInstance().OnCandleStickDataEventHandler          += MainWindowViewModel_OnCandleStickDataEventHandler;
            ClientService.GetInstance().OnConnectionClosedByServerEventHandler += MainWindowViewModel_OnConnectionClosedByServerEventHandler;

            DealerService.GetInstance().OnOfficePositionsUpdateReceived  += OnOfficePositionsUpdateReceived;
            DealerService.GetInstance().OnConnectionsInformationReceived += MainWindowViewModel_OnConnectionsInformationReceived;
            DealerService.GetInstance().OnNotificationReceived           += MainWindowViewModel_OnNotificationReceived;

            AuthService.GetInstance().OnGenericResponseReceived += MainWindow_OnGenericResponseReceived;

            LoginDialogData creds = await _dialogCoord.ShowLoginAsync(this, "Backoffice Login", "Login to continue using your account");

            if (creds != null && !string.IsNullOrEmpty(creds.Username) && !string.IsNullOrEmpty(creds.Password))
            {
                progressController = await _dialogCoord.ShowProgressAsync(this, "Please wait...", "Authenticating with server.");

                progressController.SetIndeterminate();

                if (!AuthService.GetInstance().init(creds.Username, creds.Password)
                    ||
                    !AuthService.GetInstance().ResolveUserEndpoints()
                    )
                {
                    await progressController.CloseAsync();

                    await _dialogCoord.ShowMessageAsync(this, "Authentication", "Incorrect username/password.");

                    App.Current.Shutdown();
                }
                else
                {
                    username = creds.Username;
                    password = creds.Password;
                }
            }
            else
            {
                await _dialogCoord.ShowMessageAsync(this, "Authentication", "Credentials are needed to continue.");

                App.Current.Shutdown();
            }
        }
        public async void OpenRepository()
        {
            if (!string.IsNullOrEmpty(UrlTextBox))
            {
                _isLocal = SetIsLocal();
                try
                {
                    IsLoading = true;
                    if (IsGitRepositoryPicked)
                    {
                        RepositoryCloneType currentRepositoryType = RepositoryCloneType.Public;
                        string username = string.Empty, password = string.Empty;
                        if (!_isLocal && GitCloneService.CheckRepositoryCloneType(UrlTextBox) == RepositoryCloneType.Private)
                        {
                            currentRepositoryType = RepositoryCloneType.Private;
                            var loginResult =
                                await
                                _dialogCoordinator.ShowLoginAsync(ViewModelLocator.Instance.Main,
                                                                  this.GetLocalizedString("LoginInformation"),
                                                                  this.GetLocalizedString("EnterCredentials"));

                            if (loginResult != null)
                            {
                                username = loginResult.Username;
                                password = loginResult.Password;
                            }
                        }

                        await Task.Run(() =>
                        {
                            this.IsOpening = true;
                            switch (currentRepositoryType)
                            {
                            case RepositoryCloneType.Private:
                                _repositoryFilePersister = new GitFilePersister(UrlTextBox,
                                                                                RepositoryCloneType.Private, username, password,
                                                                                ConfigurationService.Instance.Configuration.SavingRepositoryPath,
                                                                                ConfigurationService.Instance.Configuration.CloneAllBranches);
                                break;

                            case RepositoryCloneType.Public:
                                _repositoryFilePersister = new GitFilePersister(this.UrlTextBox, !_isLocal,
                                                                                ConfigurationService.Instance.Configuration.SavingRepositoryPath,
                                                                                ConfigurationService.Instance.Configuration.CloneAllBranches);
                                break;
                            }
                            _repositoryFilePersister.AddRepositoryToDataBase(DbService.Instance.SessionFactory);
                        });
                    }
                    else
                    {
                        await Task.Run(() =>
                        {
                            _repositoryFilePersister = new SvnFilePersister(UrlTextBox);
                            _repositoryFilePersister.AddRepositoryToDataBase(DbService.Instance.SessionFactory);
                        });
                    }

                    this.UrlTextBox = string.Empty;
                    Messenger.Default.Send <RefreshMessageToPresentation>(new RefreshMessageToPresentation(true));
                    ViewModelLocator.Instance.Filtering.ResetInitialization();
                    Messenger.Default.Send <RefreshMessageToFiltering>(new RefreshMessageToFiltering(true));
                    ViewModelLocator.Instance.Main.OnLoad();
                }
                catch (Exception ex)
                {
                    await DialogHelper.Instance.ShowDialog(new CustomDialogEntryData()
                    {
                        MetroWindow     = StaticServiceProvider.MetroWindowInstance,
                        DialogTitle     = this.GetLocalizedString("Error"),
                        DialogMessage   = ex.Message,
                        OkButtonMessage = "Ok",
                        InformationType = InformationType.Error
                    });
                }
                finally
                {
                    this.IsLoading = false;
                }
            }
        }
예제 #6
0
 public async Task <LoginDialogData> ShowLoginAsync(string title, string message,
                                                    LoginDialogSettings settings = null)
 {
     return(await instance.ShowLoginAsync(this, title, message, settings));
 }
예제 #7
0
 public static async Task <LoginDialogData> ShowNtLogin(this IDialogCoordinator source, object context)
 {
     return(await source.ShowLoginAsync(context, "LOGIN", string.Empty));
 }
예제 #8
0
        private async Task <byte[]> GetPasswordFromUser(int nServerGUID, String strServerName, byte[] abyPasswordSalt, bool bFailedBefore, CancellationToken cancelToken)
        {
            LoginDialogData result = null;

            try
            {
                String strText = "Enter the " + (string)Application.Current.FindResource("AppName") + " password for " + strServerName;
                if (bFailedBefore)
                {
                    strText = "Authentication failed. " + strText;
                }

                result = await m_dialogCoordinator.ShowLoginAsync(this, "Authentication", strText
                                                                  , new LoginDialogSettings()
                {
                    ColorScheme                = MetroDialogColorScheme.Theme,
                    ShouldHideUsername         = true,
                    EnablePasswordPreview      = true,
                    RememberCheckBoxVisibility = Visibility.Visible,
                    NegativeButtonText         = "Cancel",
                    NegativeButtonVisibility   = Visibility.Visible,
                    AffirmativeButtonText      = "OK",
                    CancellationToken          = cancelToken
                });
            }
            catch (Exception e)
            {
                Log.w(TAG, "LoginDialog Exception: " + e.Message);
                result = null;
            }
            if (result != null)
            {
                byte[] abyPassword = result.SecurePassword.ToByteArray();
                try
                {
                    byte[] key = await Task.Run(() =>
                    {
                        Pkcs5S1ParametersGenerator gen = new Pkcs5S1ParametersGenerator(new Sha256Digest());
                        gen.Init(abyPassword, abyPasswordSalt, ITERATIONS);
#pragma warning disable CS0618 // Type or member is obsolete
                        return(((KeyParameter)gen.GenerateDerivedParameters(256)).GetKey());

#pragma warning restore CS0618 // Type or member is obsolete
                    }, cancelToken);

                    if (result.ShouldRemember)
                    {
                        AddStoredPassword(nServerGUID, key);
                    }

                    return(key);
                }
                catch (Exception e)
                {
                    if (!(e is OperationCanceledException))
                    {
                        Log.e(TAG, "Error while generating key from password: " + e.Message);
                    }
                }
                finally
                {
                    Arrays.Fill(abyPassword, 0);
                }
            }
            return(null);
        }
예제 #9
0
        public async void Start()
        {
            Log.Information("Starting controller");

            var success = false;

            while (!success)
            {
                Log.Information("Showing login dialog");
                var data = await dialogs.ShowLoginAsync(this, "Login", string.Empty, new LoginDialogSettings { AnimateShow = false, AnimateHide = false, NegativeButtonText = "Exit", NegativeButtonVisibility = Visibility.Visible });

                if (data == null)
                {
                    Log.Information("Login canceled - exiting");
                    Application.Current.Shutdown();
                    return;
                }
                else
                {
                    Log.Information("Got login details");
                    var progress = await dialogs.ShowProgressAsync(this, "Logging in...", "Connecting to Alarm.com", false, new MetroDialogSettings { AnimateShow = false, AnimateHide = false });

                    progress.SetIndeterminate();

                    success = await Task.Run(() => client.Login(data.Username, data.Password));

                    await progress.CloseAsync();

                    if (!success)
                    {
                        await dialogs.ShowMessageAsync(this, "Error", "There was an error logging you in, please try again.", MessageDialogStyle.Affirmative, new MetroDialogSettings { AnimateShow = false, AnimateHide = false });
                    }
                }
            }

            var loadProgress = await dialogs.ShowProgressAsync(this, "Loading...", "Loading temperature sensor data", false, new MetroDialogSettings { AnimateShow = false, AnimateHide = true });

            loadProgress.SetIndeterminate();

            var sensors = await Task.Run(() => getTemperatureSensors());

            sensors.ForEach(sensor =>
            {
                Log.Information("Registering temperature sensor {SensorName}", sensor.Name);
                sensor.WhenTemperatureRecorded.Subscribe(r =>
                {
                    var readings = Sensors.SelectMany(s => s.TemperatureReadings);
                    Max          = (int)readings.Max(reading => reading.Temperature) + GraphSettings.Buffer;
                    Min          = (int)readings.Where(reading => !double.IsNegativeInfinity(reading.Temperature)).Min(reading => reading.Temperature) - GraphSettings.Buffer;
                    StartTime    = readings.Min(reading => reading.Time);
                    EndTime      = readings.Max(reading => reading.Time);
                });

                Sensors.Add(sensor);
            });

            Observable.Timer(TimeSpan.Zero, TimeSpan.FromMinutes(5)).Subscribe(x => updateTemperatures());

            Observable.Interval(TimeSpan.FromMinutes(1)).Subscribe(x =>
            {
                lock (clientLock)
                {
                    client.KeepAlive();
                }
            });

            _ = loadProgress.CloseAsync();

            IsStarted = true;
            Log.Information("Controller started");
        }