private void OnLogin(object o, EventArgs args) { LoginDialog dlg = new LoginDialog(MainWindow); switch ((ResponseType)dlg.Run()) { case ResponseType.Ok: ThreadPool.QueueUserWorkItem(new WaitCallback(LoginThread), new string [] { dlg.Username, dlg.Password }); break; default: break; } dlg.Destroy(); }
private void OnGetTagFromFingerprint(object sender, EventArgs args) { active = true; Source source = ServiceManager.SourceManager.ActiveSource; UserJob job = new UserJob(AddinManager.CurrentLocalizer.GetString("Getting sound fingerprint")); job.SetResources(Resource.Cpu, Resource.Disk, Resource.Database); job.PriorityHints = PriorityHints.SpeedSensitive; job.Status = AddinManager.CurrentLocalizer.GetString("Scanning..."); job.IconNames = new string [] { "system-search", "gtk-find" }; job.CanCancel = true; job.CancelRequested += HandleJobCancelRequested; job.Register(); if (account == null) { account = new LastfmAccount(); LoginDialog dialog = new LoginDialog(account, true); dialog.Run(); dialog.Destroy(); } //comment the timeout system for TOS because still have issue and not seems to be linked... //System.DateTime start = System.DateTime.MinValue; ThreadPool.QueueUserWorkItem(delegate { try { var selection = ((ITrackModelSource)source).TrackModel.Selection; int total = selection.Count; int count = 0; foreach (TrackInfo track in ((ITrackModelSource)source).TrackModel.SelectedItems) { if (!active) { break; } if (String.IsNullOrEmpty(track.Uri.AbsolutePath)) { continue; } ad = new AudioDecoder((int)track.Duration.TotalSeconds); //respect last fm term of service : //You will not make more than 5 requests per originating IP address per second, averaged over a 5 minute period // 2 requests are done on each loop ==> time allowed by loop : 400ms /*if (start != System.DateTime.MinValue) { * TimeSpan span = System.DateTime.Now - start; * if (lastFmTOSMinTimeout > span) * Thread.Sleep (lastFmTOSMinTimeout - span); * } * start = DateTime.Now; */ byte[] fingerprint = ad.Decode(track.Uri.AbsolutePath); FingerprintRequest request = new FingerprintRequest(); request.Send(track, fingerprint, account); int fpid = request.GetFpId(); //force GC to dispose ad = null; Log.DebugFormat("Last.fm fingerprint id for {0} is {1}", track.TrackTitle, fpid); if (fpid > 0) { FetchMetadata(track, fpid); } else { Log.WarningFormat("Could not find fingerprint id for the track {0} !", track.TrackTitle); } job.Progress = (double)++count / (double)total; } } catch (Exception e) { account = null; Log.Exception(e); } finally { job.Finish(); } }); }
public void Login() { LoginDialog login = new LoginDialog (); var saved = GetSavedCredentials(); try { if (saved != null) { login.Username = saved.AutoLoginUser; var savedCreds = saved.Credentials.Where(x => x.UserName == saved.AutoLoginUser).FirstOrDefault(); if (savedCreds != null) { login.Password = savedCreds.Password; login.RememberCredentials = true; } } while (true) { int response = login.Run (); if (response == (int)Gtk.ResponseType.Ok) { var auth = new MinecraftAuthentication (); string message = "Invalid login!"; try { Session = auth.Login (login.Username, login.Password); } catch (Exception e) { Session = null; message = e.Message; } if (Session == null || Session.AccessToken == null) { DedicatedLauncher.MessageBox (message); continue; } break; } else if (response == (int)Gtk.ResponseType.Cancel) { throw new CancelException(); } } saved = new SavedCredentials() { AutoLoginUser = login.Username, Credentials = new List<SavedCredential>() }; if (login.RememberCredentials) { saved.Credentials = new List<SavedCredential>() { new SavedCredential() { UserName = login.Username, Password = login.Password } }; } Directory.CreateDirectory(System.IO.Path.GetDirectoryName(SavedCredentialsFile)); using (StreamWriter sw = new StreamWriter(SavedCredentialsFile)) sw.Write(saved.ToJson()); login.Hide (); login.Destroy(); usernameLabel.Markup = string.Format ("Playing as <b>{0}</b>", Session.Username); } finally { login.Destroy(); } }
private void OnLogin( object o, EventArgs args ) { LoginDialog dlg = new LoginDialog( MainWindow ); switch( (ResponseType)dlg.Run() ) { case ResponseType.Ok: ThreadPool.QueueUserWorkItem( new WaitCallback(LoginThread), new string [] { dlg.Username, dlg.Password } ); break; default: break; } dlg.Destroy(); }