コード例 #1
0
        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);
                });
            }
        }
コード例 #2
0
        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 ();
        }
コード例 #3
0
 public override Task<ServiceUser> GetProfileAsync (CancellationToken token = default (CancellationToken), LoginOptions options = default (LoginOptions))
 {
     return this.WithSession (
         () => this.GetProfile (token),
         options,
         token
     );
 }
コード例 #4
0
 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
     );
 }
コード例 #5
0
 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
     );
 }
コード例 #6
0
 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
     );
 }
コード例 #7
0
        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);
        }
コード例 #8
0
 public virtual Task <IDictionary <string, string> > GetTokenDataAsync(CancellationToken token = default(CancellationToken), LoginOptions options = default(LoginOptions))
 {
     return(this.WithSession(
                () => this.GetTokenData(token),
                options,
                token
                ));
 }
コード例 #9
0
 public Task<Session> GetSessionAsync (LoginOptions options, string [] scope = null)
 {
     return GetSessionAsync (token =>
         _provider.Login (options, scope, token)
     );
 }
コード例 #10
0
 public abstract Task ShareAsync(Item item, CancellationToken token         = default(CancellationToken), LoginOptions options = default(LoginOptions));
コード例 #11
0
 public abstract Task <Page <IEnumerable <ServiceUser> > > GetFriendsAsync(Page <IEnumerable <ServiceUser> > previous = null, CancellationToken token = default(CancellationToken), LoginOptions options = default(LoginOptions));
コード例 #12
0
 public override Task<Page<IEnumerable<ServiceUser>>> GetFriendsAsync (Page<IEnumerable<ServiceUser>> previous = null, CancellationToken token = default (CancellationToken), LoginOptions options = default (LoginOptions))
 {
     throw new NotImplementedException ();
 }
コード例 #13
0
 public abstract Task <ServiceUser> GetProfileAsync(CancellationToken token = default(CancellationToken), LoginOptions options = default(LoginOptions));
コード例 #14
0
 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));
 }
コード例 #15
0
 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
                ));
 }
コード例 #16
0
 public Task <Session> GetSessionAsync(LoginOptions options, string [] scope = null)
 {
     return(GetSessionAsync(token =>
                            _provider.Login(options, scope, token)
                            ));
 }
コード例 #17
0
 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
                ));
 }
コード例 #18
0
 public override Task <ServiceUser> GetProfileAsync(CancellationToken token = default(CancellationToken), LoginOptions options = default(LoginOptions))
 {
     return(this.WithSession(
                () => this.GetProfile(token),
                options,
                token
                ));
 }
コード例 #19
0
 public override Task <Page <IEnumerable <ServiceUser> > > GetFriendsAsync(Page <IEnumerable <ServiceUser> > previous = null, CancellationToken token = default(CancellationToken), LoginOptions options = default(LoginOptions))
 {
     throw new NotImplementedException();
 }
コード例 #20
0
 public override Task ShareAsync(Item item, CancellationToken token = default(CancellationToken), LoginOptions options = default(LoginOptions))
 {
     throw new NotImplementedException();
 }
コード例 #21
0
        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;
        }
コード例 #22
0
 public override Task ShareAsync (Item item, CancellationToken token = default(CancellationToken), LoginOptions options = default (LoginOptions))
 {
     throw new NotImplementedException ();
 }
コード例 #23
0
 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));
 }
コード例 #24
0
 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
                ));
 }