private async Task GetFriends(string url) { try { Debug.WriteLine(url); SetProgressBar("Getting the people you follow on Instagram..."); var response = await App.HttpClient.GetAsync(url); if (response.StatusCode == HttpStatusCode.OK) { var responseString = await response.Content.ReadAsStringAsync(); var friendsResponse = await JsonConvert.DeserializeObjectAsync <InstagramFollowsResponse>(responseString); if (!friendsResponse.Users.IsNullOrEmpty()) { if (_users == null) { _users = new List <InstagramUser>(); } _users.AddRange(friendsResponse.Users); if (friendsResponse.Pagination != null && !string.IsNullOrEmpty(friendsResponse.Pagination.NextUrl)) { await GetFriends(friendsResponse.Pagination.NextUrl); } else { var messageBox = new MessageBoxService(); var result = await messageBox.ShowAsync(string.Format("We have found {0} user(s), would you like to add them now?", _users.Count), "Add users", new List <string> { "yes", "no" }); if (result == 0) { await ContactService.Current.CheckAndUpdateUsers(_users.Cast <IContact>().ToList()); MessageBox.Show("Done"); } } } } } catch (Exception ex) { Log.ErrorException("GetContactsCommand", ex); } SetProgressBar(); }
private async Task GetFriends(int offset) { var url = string.Format(FriendsUrl, offset, App.AuthenticationService.FourSquareAccessToken); Debug.WriteLine(url); var response = await App.HttpClient.GetAsync(url); Debug.WriteLine(response.StatusCode); if (response.StatusCode == HttpStatusCode.OK) { var responseString = await response.Content.ReadAsStringAsync(); if (!string.IsNullOrEmpty(responseString)) { var friendResponse = await JsonConvert.DeserializeObjectAsync <FourSquareResponse <FourSquareUserResponse> >(responseString); if (friendResponse.Response.Friends.Count > 0) { if (_friends == null) { _friends = new List <FourSquareFriend>(); } _friends.AddRange(friendResponse.Response.Friends.Items); if (friendResponse.Response.Friends.Count > _friends.Count) { await GetFriends(_friends.Count); } else { var messageBox = new MessageBoxService(); var result = await messageBox.ShowAsync(string.Format("We have found {0} user(s), would you like to add them now?", _friends.Count), "Add users", new List <string> { "yes", "no" }); if (result == 0) { await ContactService.Current.CheckAndUpdateUsers(_friends.Cast <IContact>().ToList()); MessageBox.Show("Done"); } } } } } }
private async Task BootstrapFrame(LaunchActivatedEventArgs launchActivatedEventArgs, IActivatedEventArgs activatedEventArgs, string addTaskTitle = null) { Frame rootFrame = Window.Current.Content as Frame; // Do not repeat app initialization when the Window already has content, // just ensure that the window is active if (rootFrame == null) { // Create a Frame to act as the navigation context and navigate to the first page rootFrame = new Frame(); try { ApplicationView appView = ApplicationView.GetForCurrentView(); this.mainview = appView; SetupTitleBar(appView); SetupStatusBar(appColor); appView.SetPreferredMinSize(new Size(Constants.AppMinWidth, Constants.AppMinHeight)); this.bootstraper = new Bootstraper(ApplicationVersion.GetAppVersion()); InitializeViewLocator(); await this.bootstraper.ConfigureAsync(rootFrame); this.navigationService = Ioc.Resolve <INavigationService>(); this.platformService = Ioc.Resolve <IPlatformService>(); this.suspensionManager = new SuspensionManager(Ioc.Resolve <IPersistenceLayer>(), Ioc.Resolve <ISynchronizationManager>(), Ioc.Resolve <ITileManager>()); rootFrame.Navigated += this.OnNavigated; rootFrame.NavigationFailed += this.OnNavigationFailed; // Place the frame in the current Window Window.Current.Content = rootFrame; if (rootFrame.Content == null) { Type startupPage = typeof(MainPage); object navigationParameter = launchActivatedEventArgs?.Arguments; var startupManager = Ioc.Resolve <IStartupManager>(); if (startupManager.IsFirstLaunch) { startupPage = typeof(WelcomePage); } else if (!String.IsNullOrWhiteSpace(addTaskTitle)) { startupPage = typeof(WelcomePage); navigationParameter = new TaskCreationParameters { Title = addTaskTitle }; } SystemNavigationManager.GetForCurrentView().BackRequested += this.OnBackRequested; SystemNavigationManager.GetForCurrentView().AppViewBackButtonVisibility = rootFrame.CanGoBack ? AppViewBackButtonVisibility.Visible : AppViewBackButtonVisibility.Collapsed; Window.Current.VisibilityChanged += this.OnVisibilityChanged; // When the navigation stack isn't restored navigate to the first page, // configuring the new page by passing required information as a navigation parameter rootFrame.Navigate(startupPage, navigationParameter); } if (launchActivatedEventArgs != null) { LauncherHelper.TryHandleArgs(launchActivatedEventArgs.Arguments); } else if (activatedEventArgs != null) { LauncherHelper.TryHandleArgs(activatedEventArgs); } // Ensure the current window is active Window.Current.Activate(); } catch (Exception ex) { var messageBoxService = new MessageBoxService(new NavigationService(rootFrame)); await messageBoxService.ShowAsync("Error", "2Day was unable to start please send a screenshot of this page to the development team. Details: " + ex); DeviceFamily deviceFamily = DeviceFamily.Unkown; if (this.platformService != null) { deviceFamily = this.platformService.DeviceFamily; } var trackingManager = new TrackingManager(true, deviceFamily); trackingManager.Exception(ex, "Bootstrap", true); } } else { if (launchActivatedEventArgs != null) { LauncherHelper.TryHandleArgs(launchActivatedEventArgs.Arguments); } else if (activatedEventArgs != null) { LauncherHelper.TryHandleArgs(activatedEventArgs); } } }