protected virtual async void GetNextFriendsAsync (LoginOptions options, Page<IEnumerable<ServiceUser>> previous = null) { Page<IEnumerable<ServiceUser>> friendsPage; try { friendsPage = await Service.GetFriendsAsync (previous: previous, options: options); } catch { Console.WriteLine ("Failed to retrieve friends for {0}. (Maybe we're logged out?)", Service); return; } var friends = friendsPage.Value; if (TableView.Source == null) { TableView.Source = new ServiceUserSource (friends); } else { ((ServiceUserSource) TableView.Source).Add (friends); } TableView.ReloadData (); if (friendsPage.HasNextPage) { NSTimer.CreateScheduledTimer (1, () => { GetNextFriendsAsync (options, friendsPage); }); } }
async void GetRootFolder (LoginOptions options) { tableView.Source = null; tableView.ReloadData (); try { var profile = await Services.Dropbox.GetProfileAsync (options: options); new UIAlertView ("Profile", profile.ToString (), null, "OK").Show (); } catch (UriFormatException) { new UIAlertView ("Specify your API keys", "Open Services.cs and specify your API keys for each provider.", null, "OK").Show (); return; } catch { Console.WriteLine ("Failed to retrieve Dropbox profile. (Maybe we're logged out?)"); return; } DropboxManager.Metadata metadata; try { metadata = await Services.Dropbox.GetMetadataAsync ("/", includeContent: true, hash: null, options: options); } catch { Console.WriteLine ("Failed to retrieve Dropbox metadata"); return; } if (tableView.Source == null) { var source = new MetadataSource (metadata.Contents) { Controller = new WeakReference (this) }; tableView.Source = source; } else { ((MetadataSource)tableView.Source).Add (metadata.Contents); } tableView.ReloadData (); }
public override Task<ServiceUser> GetProfileAsync (CancellationToken token = default (CancellationToken), LoginOptions options = default (LoginOptions)) { return this.WithSession ( () => this.GetProfile (token), options, token ); }
public Task<Metadata> GetMetadataAsync (string path, bool includeContent, string hash, CancellationToken token = default (CancellationToken), LoginOptions options = default (LoginOptions)) { return this.WithSession ( () => this.GetMetadata (path, includeContent, hash, token), options, token ); }
public Task<Metadata> LoadThumbnailAsync (string path, string size, string destPath, CancellationToken token = default (CancellationToken), LoginOptions options = default (LoginOptions)) { return this.WithSession ( () => this.LoadThumbnail (path, size, destPath, token), options, token ); }
public Task<Metadata> LoadFileAsync (string path, string destPath, Action<float> progress, CancellationToken token = default (CancellationToken), LoginOptions options = default (LoginOptions)) { return this.WithSession ( () => this.LoadFile (path, destPath, progress, token), options, token ); }
protected virtual async void GetProfileAndFriendsAsync (LoginOptions options) { TableView.Source = null; TableView.ReloadData (); try { var profile = await Service.GetProfileAsync (options: options); new UIAlertView ("Profile", profile.ToString (), null, "OK").Show (); } catch (UriFormatException) { new UIAlertView ("Specify your API keys", "Open Services.cs and specify your API keys for each provider.", null, "OK").Show (); return; } catch { Console.WriteLine ("Couldn't retrieve profile for {0}. (Maybe we're logged out?)", Service); return; } GetNextFriendsAsync (options); }
public virtual Task <IDictionary <string, string> > GetTokenDataAsync(CancellationToken token = default(CancellationToken), LoginOptions options = default(LoginOptions)) { return(this.WithSession( () => this.GetTokenData(token), options, token )); }
public Task<Session> GetSessionAsync (LoginOptions options, string [] scope = null) { return GetSessionAsync (token => _provider.Login (options, scope, token) ); }
public abstract Task ShareAsync(Item item, CancellationToken token = default(CancellationToken), LoginOptions options = default(LoginOptions));
public abstract Task <Page <IEnumerable <ServiceUser> > > GetFriendsAsync(Page <IEnumerable <ServiceUser> > previous = null, CancellationToken token = default(CancellationToken), LoginOptions options = default(LoginOptions));
public override Task<Page<IEnumerable<ServiceUser>>> GetFriendsAsync (Page<IEnumerable<ServiceUser>> previous = null, CancellationToken token = default (CancellationToken), LoginOptions options = default (LoginOptions)) { throw new NotImplementedException (); }
public abstract Task <ServiceUser> GetProfileAsync(CancellationToken token = default(CancellationToken), LoginOptions options = default(LoginOptions));
internal static Task WithSession(this ServiceManager manager, Func <Task> call, LoginOptions options, CancellationToken token, string [] scope = null) { return(WithSession(manager, async() => { await call(); return true; }, scope, options, token)); }
public Task <Metadata> LoadThumbnailAsync(string path, string size, string destPath, CancellationToken token = default(CancellationToken), LoginOptions options = default(LoginOptions)) { return(this.WithSession( () => this.LoadThumbnail(path, size, destPath, token), options, token )); }
public Task <Session> GetSessionAsync(LoginOptions options, string [] scope = null) { return(GetSessionAsync(token => _provider.Login(options, scope, token) )); }
public Task <Metadata> LoadFileAsync(string path, string destPath, Action <float> progress, CancellationToken token = default(CancellationToken), LoginOptions options = default(LoginOptions)) { return(this.WithSession( () => this.LoadFile(path, destPath, progress, token), options, token )); }
public override Task <ServiceUser> GetProfileAsync(CancellationToken token = default(CancellationToken), LoginOptions options = default(LoginOptions)) { return(this.WithSession( () => this.GetProfile(token), options, token )); }
public override Task <Page <IEnumerable <ServiceUser> > > GetFriendsAsync(Page <IEnumerable <ServiceUser> > previous = null, CancellationToken token = default(CancellationToken), LoginOptions options = default(LoginOptions)) { throw new NotImplementedException(); }
public override Task ShareAsync(Item item, CancellationToken token = default(CancellationToken), LoginOptions options = default(LoginOptions)) { throw new NotImplementedException(); }
static async Task <T> WithSession <T> (ServiceManager manager, Func <Task <T> > call, string [] scope, LoginOptions options, CancellationToken token, bool allowReauthorizeOrLogout = true) { if (!SessionManager.NetworkMonitor.IsNetworkAvailable) { throw new OfflineException(); } var session = await manager.GetSessionAsync(options, scope); ApiException ex = null; try { return(await call()); } catch (ApiException aex) { if (!allowReauthorizeOrLogout) { throw; } ex = aex; } catch (Exception) { throw; } bool tryReauthorize = (ex.Kind == ApiExceptionKind.Unauthorized); if (tryReauthorize) { token.ThrowIfCancellationRequested(); if (await Reauthorize(manager, session)) { token.ThrowIfCancellationRequested(); return(await call()); } } token.ThrowIfCancellationRequested(); bool tryLogout = (ex.Kind == ApiExceptionKind.Unauthorized || ex.Kind == ApiExceptionKind.Forbidden); if (tryLogout) { token.ThrowIfCancellationRequested(); manager.CloseSession(); return(await WithSession(manager, call, scope, options, token, false)); } throw ex; }
public override Task ShareAsync (Item item, CancellationToken token = default(CancellationToken), LoginOptions options = default (LoginOptions)) { throw new NotImplementedException (); }
internal static Task <T> WithSession <T> (this ServiceManager manager, Func <Task <T> > call, LoginOptions options, CancellationToken token, string [] scope = null) { return(WithSession(manager, call, scope, options, token)); }
public Task <Metadata> GetMetadataAsync(string path, bool includeContent, string hash, CancellationToken token = default(CancellationToken), LoginOptions options = default(LoginOptions)) { return(this.WithSession( () => this.GetMetadata(path, includeContent, hash, token), options, token )); }