コード例 #1
0
        public LoginWindow(IdSettings idSettings, ExpressClient expressClient)
        {
            InitializeComponent();

            _expressClient = expressClient;
            _idSettings    = idSettings;

            this.Title += $"Login required for {_expressClient.UriString}";
        }
コード例 #2
0
        private async void Window_Loaded(object sender, RoutedEventArgs e)
        {
            var loggedIn = false;

            try
            {
                _idSettings  = IdSettings.ReadOrNew();
                _appSettings = AppSettings.ReadOrNew();

                ShowLoginInTitle("");

                if (_appSettings.PluginWindowWidth > 150 && _appSettings.PluginWindowHeight > 50) // not first time, not too small
                {
                    this.Top    = _appSettings.PluginWindowTop;
                    this.Left   = _appSettings.PluginWindowLeft;
                    this.Width  = _appSettings.PluginWindowWidth;
                    this.Height = _appSettings.PluginWindowHeight;
                }

                if (string.IsNullOrEmpty(_orderDir))
                {
                    ShowMessage($"You must select a single order", Visual.Severities.Error); // DentalManager passes empty if multiple
                    ButtonUpload.IsEnabled       = false;
                    CheckboxAutoUpload.IsEnabled = false;
                    return;
                }

                _orderHandler = OrderHandler.MakeIfValid(_orderDir);
                if (_orderHandler == null)
                {
                    ShowMessage($"{_orderDir} is not a valid order directory", Visual.Severities.Error);
                    ButtonUpload.IsEnabled       = false;
                    CheckboxAutoUpload.IsEnabled = false;
                    return;
                }

                TextBlockOrder.Text = _orderHandler.OrderId; // Label would not show first underscore
                this.CheckboxAutoUpload.IsChecked = _appSettings.AutoUpload;
                RefresAutoUploadDependentControls();
                // now that checkbox is set, wire up events
                this.CheckboxAutoUpload.Checked   += CheckboxAutoUpload_CheckedChanged;
                this.CheckboxAutoUpload.Unchecked += CheckboxAutoUpload_CheckedChanged;

                var uri = _appSettings.GetUri(true); // can change only for debug

                _expressClient = new ExpressClient(uri);

                // detect if valid previous login
                loggedIn = await _expressClient.CheckIfStillLoggedIn(_idSettings.AuthCookie);

                if (!loggedIn)
                {
                    var loginWindow = new LoginWindow(_idSettings, _expressClient);

                    loginWindow.Closed += async(s, args) =>
                    {
                        if (loginWindow.LoginSuccessful)
                        {
                            RefreshLoginDependentControls(true, loginWindow.LoginRemembered);
                            await HandleSingleOrder(); // status, qualifiy, possibly upload
                        }
                        else
                        {
                            RefreshLoginDependentControls(false, false);
                        }
                    };

                    loginWindow.Owner = this;
                    loginWindow.ShowDialog();
                }
                else
                {
                    RefreshLoginDependentControls(true, true);
                    await HandleSingleOrder(); // status, qualifiy, possibly upload
                }
            }
            catch (Exception exception)
            {
                ShowMessage(exception.Message, Visual.Severities.Error);
                RefreshLoginDependentControls(false, false);
                return;
            }
        }