/// <summary> /// Initiate an Archive creation and publish an InitiateUploadMessage for /// the UploadManagerViewModel to handle. /// </summary> /// <returns></returns> public async Task Upload() { try { if (!this._deepfreezeClient.IsInternetConnected) { throw new Exception("Can't upload an archive without an active Internet connection."); } HasChosenFiles = false; IsBusy = true; BusyMessageText = Properties.Resources.CreatingArchiveText; _log.Info("Create new archive, size = " + this._archiveSize + " bytes, title = \"" + ArchiveTitle + "\"."); // create a new archive using DF API. var archive = await this._deepfreezeClient.CreateArchiveAsync(this._archiveSize, ArchiveTitle); if (archive != null) { // send a message to refresh user storage stats. this._eventAggregator.PublishOnCurrentThread(IoC.Get <IRefreshUserMessage>()); // publish a message to UploadManager to initiate the upload. var message = IoC.Get <IInitiateUploadMessage>(); message.Archive = archive; message.ArchiveFilesInfo = this._archiveInfo.ToList(); this._eventAggregator.PublishOnBackgroundThread(message); } else { _log.Warn("CreateArchiveAsync returned null."); } // reset the view this.Reset(); } catch (Exception e) { HasChosenFiles = true; _log.Error(Utilities.GetCallerName() + " threw " + e.GetType().ToString() + " with message \"" + e.Message + "\"." + BigStashExceptionHelper.TryGetBigStashExceptionInformation(e), e); this.ErrorCreatingArchive = Properties.Resources.ErrorCreatingArchiveGenericText; } finally { IsBusy = false; } }
/// <summary> /// Fetches Notification objects by requesting the notifications URI. /// If a previous fetch has been completed and a next page result exists, /// then the next fetch will get the next page results etc. /// Optional /// page: The page to fetch. /// </summary> /// <param name="page"></param> /// <returns></returns> private async Task FetchNotificationsAsync(int page = 0) { this.IsBusy = true; this.ErrorMessage = null; string url = String.Empty; // if page 1 is not requested, then try to fetch the next page. if (page != 1) { url = _nextPageUri; } try { var notificationsTuple = await this._deepfreezeClient.GetNotificationsAsync(url, etagToMatch : this._eTagPage1); // if the result is null, then there was nothing to fetch // Update the UI and return. if (notificationsTuple == null) { //this.NoActivityText = Properties.Resources.NoActivityText; return; } // get the response metadata var responseMetadata = notificationsTuple.Item1; // if page == 1 then we need to check for etag change // if the page 1 etag is null then set it, since this is obviously the 1st time you fetched notifications if (page == 1 && String.IsNullOrEmpty(this._eTagPage1)) { this._eTagPage1 = responseMetadata.Etag; } // set the next page results uri this._nextPageUri = responseMetadata.NextPageUri; responseMetadata = null; // get the notifications result var notifications = notificationsTuple.Item2.ToList(); // foreach result, create a new Notification object and try marking it as unread. // finally add it to the Notifications list. foreach (var notification in notifications) { if (this.Notifications.Select(x => x.Id).Contains(notification.Id)) { continue; } this.SetUnreadStatusInNotification(notification); this.Notifications.Add(notification); } notifications.Clear(); notificationsTuple = null; // finally try updating the new notifications flag this.UpdateHasNewNotifications(); } catch (Exception e) { _log.Error(Utilities.GetCallerName() + " threw " + e.GetType().ToString() + " with message \"" + e.Message + "\"." + BigStashExceptionHelper.TryGetBigStashExceptionInformation(e), e); this.ErrorMessage = Properties.Resources.ErrorFetchingActivityGenericText; } finally { this.IsBusy = false; } }