Ejemplo n.º 1
0
 private async void signInButton_Click(object sender, EventArgs e)
 {
     if (!authenticatable.IsAuthenticated)
     {
         var authenticatableAsync = service.AsAuthenticatableAsync();
         if (authenticatableAsync == null)
         {
             var dlg = new CredentialsForm(service);
             dlg.ShowDialog();
             servicePlugin.SettingsFile.Save();
         }
         else
         {
             await authenticatableAsync.AuthenticateAsync();
         }
         signInStatusLabel.Text = String.Format(sspSignInStatus.Get(authenticatable.IsAuthenticated),
                                                LocalisableAccountNameFormat.GetFormattedName(authenticatable.Account));
         sspSignInButton.Update(authenticatable.IsAuthenticated);
     }
     else
     {
         authenticatable.Reset();
         sspSignInStatus.Update(false);
         sspSignInButton.Update(false);
     }
 }
Ejemplo n.º 2
0
        public ServiceSettingsView(PluginInstance servicePlugin)
        {
            this.servicePlugin = servicePlugin;
            service            = servicePlugin.Service;
            authenticatable    = service.AsAuthenticatable();
            if (authenticatable == null)
            {
                throw new ArgumentException("Service instance passed must implement IAuthenticatable", nameof(service));
            }
            InitializeComponent();
            sspSignInStatus = new SplitStringParser(signInStatusLabel);
            sspSignInButton = new SplitStringParser(signInButton);
            if (authenticatable.IsAuthenticated)
            {
                signInStatusLabel.Text = String.Format(sspSignInStatus.Get(authenticatable.IsAuthenticated),
                                                       LocalisableAccountNameFormat.GetFormattedName(authenticatable.Account));
            }
            else
            {
                sspSignInStatus.Update(false);
            }
            sspSignInButton.Update(authenticatable.IsAuthenticated);
            var control = service.GetSettingsControl();

            control.Dock = DockStyle.Fill;
            servicePanel.Controls.Add(control);
        }
Ejemplo n.º 3
0
 private void SetSignedInState()
 {
     restoreButton.Visible  = false;
     signInStatusLabel.Text = "Signed in as " +
                              LocalisableAccountNameFormat.GetFormattedName(authenticatable.Account);
     signInButton.Text = "Sign out";
 }
Ejemplo n.º 4
0
        private void AddServiceListViewItem(MusicService service)
        {
            var lvItem = new ListViewItem
            {
                Text = "Please wait..."
            };

            lvItem.SubItems.Add(service.Info.Name);
            lvItem.SubItems.Add(LocalisableAccountNameFormat.GetFormattedName(service.AsAuthenticatable().Account));
            serviceLvItems.Add(service, lvItem);
            animator.Add(lvItem);
            servicesListView.Items.Add(lvItem);
        }
        private void RestoreServices()
        {
            var am       = Program.DefaultAuthenticationManager;
            var taskList = Program.DefaultPluginManager.ServicesEnumerable()
                           .Where(am.CanRestore).Select(service => am.Restore(service));
            var td     = TaskDialogHelper.CreateWaitDialog(null, Handle);
            var openCt = new CancellationTokenSource();

            td.Opened += async(o, args) =>
            {
                await Task.Factory.StartNew(async() =>
                {
                    foreach (var service in Program.DefaultPluginManager.ServicesEnumerable())
                    {
                        var restorable = service.AsAuthenticatable();
                        if (restorable == null || !restorable.HasSavedSession)
                        {
                            continue;
                        }

                        var result         = false;
                        td.InstructionText = $"Signing into {service.Info.Name}...";
                        td.Text            = $"Signing in as {LocalisableAccountNameFormat.GetFormattedName(restorable.Account)}";
                        openCt.Token.ThrowIfCancellationRequested();
                        result = await restorable.RestoreAsync();
                        if (!result)
                        {
                            Log.Error(Tag, $"Failed to sign into {service.Info.Name}");
                            TaskDialogHelper.ShowMessage(owner: Handle, caption: $"Failed to sign in to {service.Info.Name}",
                                                         message: null, icon: TaskDialogStandardIcon.Error, buttons: TaskDialogStandardButtons.Ok);
                        }
                    }
                    td.Close();
                }, openCt.Token);
            };
            if (td.Show() == TaskDialogResult.Cancel)
            {
                openCt.Cancel(true);
            }
        }
Ejemplo n.º 6
0
        private void ShowStartupTaskDialog()
        {
            var td     = CommonTaskDialogs.Wait(owner: this);
            var openCt = new CancellationTokenSource();

            td.Opened += async(o, args) =>
            {
                await Task.Factory.StartNew(async() =>
                {
                    foreach (var service in Program.DefaultPluginManager.ServicesEnumerable())
                    {
                        var restorable = service.AsAuthenticatable();
                        if (restorable == null || !restorable.HasSavedSession)
                        {
                            continue;
                        }

                        var result         = false;
                        td.InstructionText = $"Signing into {service.Info.Name}...";
                        td.Text            = $"Signing in as {LocalisableAccountNameFormat.GetFormattedName(restorable.Account)}";
                        openCt.Token.ThrowIfCancellationRequested();
                        result = await restorable.RestoreAsync();
                        if (!result)
                        {
                            Log.Error(Tag, $"Failed to sign into {service.Info.Name}");
                            CommonTaskDialogs.Message(owner: this, caption: $"Failed to sign in to {service.Info.Name}",
                                                      message: null, icon: TaskDialogStandardIcon.Error).Show();
                        }
                    }
                    td.Close();
                }, openCt.Token);
            };
            if (td.Show() == TaskDialogResult.Cancel)
            {
                openCt.Cancel(true);
            }
        }