Exemplo n.º 1
0
        async Task ExecuteLoadSocialCommandAsync()
        {
            if (LoadingSocial)
            {
                return;
            }

            LoadingSocial = true;
            try
            {
                SocialError = false;
                Tweets.Clear();

                var tweetService = DependencyService.Get <ITweetsService>();

                Tweets.ReplaceRange(await tweetService.GetTweets());
                // todo: implement this
            }
            catch (Exception ex)
            {
                SocialError       = true;
                ex.Data["method"] = "ExecuteLoadSocialCommandAsync";
                Logger.Report(ex);
            }
            finally
            {
                LoadingSocial = false;
                NoSocial      = Tweets.Count == 0;
            }
        }
Exemplo n.º 2
0
        public async Task ExecuteLoadCommand(bool forceRefresh)
        {
            if (IsBusy)
            {
                return;
            }

            IsBusy = true;
            try
            {
#if DEBUG
                await Task.Delay(1000);
#endif
                var items = await DataService.GetTweetsAsync(_screenName);

                if (items == null)
                {
                    await DisplayAlert("Error", "Unable to load tweets.", "OK");
                }
                else
                {
                    Tweets.ReplaceRange(items);
                }
            }
            catch
            {
                await DisplayAlert("Error", "Unable to load tweets.", "OK");
            }
            finally
            {
                IsBusy = false;
            }

            LoadCommand.ChangeCanExecute();
        }
Exemplo n.º 3
0
        async Task ExecuteLoadSocialCommandAsync()
        {
            if (LoadingSocial)
            {
                return;
            }

            LoadingSocial = true;
            try
            {
                SocialError = false;
                Tweets.Clear();

                using (var client = new HttpClient())
                {
                    #if ENABLE_TEST_CLOUD
                    var json = ResourceLoader.GetEmbeddedResourceString(Assembly.Load(new AssemblyName("UtahOpenSource.Clients.Portable")), "sampletweets.txt");
                    Tweets.ReplaceRange(JsonConvert.DeserializeObject <List <Tweet> >(json));
                    #else
                    var manager = DependencyService.Get <IStoreManager>() as UtahOpenSource.DataStore.Azure.StoreManager;
                    if (manager == null)
                    {
                        return;
                    }

                    await manager.InitializeAsync();

                    var mobileClient = UtahOpenSource.DataStore.Azure.StoreManager.MobileService;
                    if (mobileClient == null)
                    {
                        return;
                    }

                    var json = await mobileClient.InvokeApiAsync <string> ("Tweet", System.Net.Http.HttpMethod.Get, null);

                    if (string.IsNullOrWhiteSpace(json))
                    {
                        SocialError = true;
                        return;
                    }


                    Tweets.ReplaceRange(JsonConvert.DeserializeObject <List <Tweet> >(json));
                    #endif
                }
            }
            catch (Exception ex)
            {
                SocialError       = true;
                ex.Data["method"] = "ExecuteLoadSocialCommandAsync";
                Logger.Report(ex);
            }
            finally
            {
                LoadingSocial = false;
            }
        }
Exemplo n.º 4
0
        private async Task ExecuteLoadSocialCommandAsync()
        {
            if (LoadingSocial)
            {
                return;
            }

            LoadingSocial = true;
            try
            {
                SocialError = false;
                Tweets.Clear();

                using (var client = new HttpClient())
                {
                    await StoreManager.InitializeAsync();

                    if (StoreManager is open.conference.app.DataStore.Azure.StoreManager)
                    {
                        var mobileClient = open.conference.app.DataStore.Azure.StoreManager.MobileService;
                        if (mobileClient == null)
                        {
                            return;
                        }

                        var json = await mobileClient.InvokeApiAsync <string>("Tweet", HttpMethod.Get, null);

                        if (string.IsNullOrWhiteSpace(json))
                        {
                            SocialError = true;
                            return;
                        }

                        Tweets.ReplaceRange(JsonConvert.DeserializeObject <List <Tweet> >(json));
                    }
                }
            }
            catch (Exception ex)
            {
                SocialError       = true;
                ex.Data["method"] = "ExecuteLoadSocialCommandAsync";
                Logger.Log(ex.Message, Prism.Logging.Category.Exception, Priority.High);
            }
            finally
            {
                LoadingSocial = false;
            }
        }
        public async Task ExecuteLoadTweetsCommand()
        {
            if (IsBusy)
            {
                return;
            }

            IsBusy = true;
            LoadTweetsCommand.ChangeCanExecute();

            try
            {
                var tweetsRaw = await GetTweets();


                var tweets = tweetsRaw.Select(t => new Tweet
                {
                    StatusID           = (ulong)t.Id,
                    ScreenName         = t.User.ScreenName,
                    Text               = t.Text,
                    CurrentUserRetweet = (ulong)t.RetweetCount,
                    CreatedAt          = GetDate(t.CreatedAt, DateTime.MinValue),
                    Image              = t.RetweetedStatus != null && t.RetweetedStatus.User != null ?
                                         t.RetweetedStatus.User.ProfileImageUrlHttps.ToString() : (t.User.ScreenName == "shanselman" ? "scott159.png" : t.User.ProfileImageUrlHttps.ToString())
                });

                if (Device.RuntimePlatform == Device.iOS)
                {
                    // only does anything on iOS, for the Watch
                    DependencyService.Get <ITweetStore>().Save(tweets.ToList());
                }

                Tweets.ReplaceRange(tweets);
            }
            catch
            {
                await Application.Current.MainPage.DisplayAlert("Error", "Unable to load tweets.", "OK");
            }

            IsBusy = false;
            LoadTweetsCommand.ChangeCanExecute();
        }
Exemplo n.º 6
0
        private async Task SelectedFeedChanged()
        {
            if (SelectedFeed == null)
            {
                return;
            }

            IsBusy = true;
            var items = await DataService.GetTweetsAsync(SelectedFeed.UserName, IncludeRetweets);

            if (items == null)
            {
                //await DisplayAlert("Error", "Unable to load tweets.", "OK");
            }
            else
            {
                Tweets.ReplaceRange(items);
            }
            IsBusy = false;
        }