private async Task <bool> VerifyAuthentication(string plugin, bool nostatus = false) { IDownloadPlugin pp = DownloadPluginHandler.Instance.Plugins[plugin]; Dictionary <string, object> meta = Settings.Instance.AuthorizationsMetadataDictionary[plugin]; ISession session = await pp.Authenticate(meta); if (session.Status == ResponseStatus.Ok) { if (!nostatus) { labStatus.ForeColor = Color.Green; labStatus.Text = "OK"; } if (!Settings.Instance.OpenSessionsDictionary.ContainsKey(plugin)) { Settings.Instance.OpenSessionsDictionary.Add(plugin, session); } else { Settings.Instance.OpenSessionsDictionary[plugin] = session; } return(true); } if (!nostatus) { labStatus.ForeColor = Color.Red; labStatus.Text = session.ErrorMessage; } return(false); }
public object GetAuthSetting(string name) { IDownloadPlugin d = (IDownloadPlugin)this; Dictionary <string, object> meta = Settings.Instance.AuthorizationsMetadataDictionary[d.Information().Name]; if (meta.ContainsKey(name)) { return(meta[name]); } return(null); }
public async Task <T> AuthWrapper <T>(string plugin, Func <IDownloadPlugin, ISession, Task <T> > function) where T : Response, new() { if (!Plugins.ContainsKey(plugin)) { T t = new T(); t.Status = ResponseStatus.MissingPlugin; t.ErrorMessage = "Plugin '" + plugin + "' not found."; DoLogging(t); return(t); } IDownloadPlugin p = Plugins[plugin]; int retry = 0; T r; do { if (!Settings.Instance.OpenSessionsDictionary.ContainsKey(plugin)) { if (!Settings.Instance.AuthorizationsMetadataDictionary.ContainsKey(plugin)) { T t = new T(); t.Status = ResponseStatus.MissingAuthenticationParameters; t.ErrorMessage = "Authentication parameters for Plugin '" + plugin + "' are missing."; DoLogging(t); return(t); } ISession ses = await p.Authenticate(Settings.Instance.AuthorizationsMetadataDictionary[plugin]); if (ses.Status != ResponseStatus.Ok) { T t = new T(); ses.PropagateError(t); DoLogging(t); return(t); } Settings.Instance.OpenSessionsDictionary.Add(plugin, ses); DoChangeSettings(); } ISession s = Settings.Instance.OpenSessionsDictionary[plugin]; r = await function(p, s); if (r.Status != ResponseStatus.Ok) { if (r.Status == ResponseStatus.LoginRequired) { Settings.Instance.OpenSessionsDictionary.Remove(plugin); DoChangeSettings(); } DoLogging(r); } retry++; } while (r.Status == ResponseStatus.LoginRequired && retry <= Settings.Instance.NumberOfRetries); return(r); }