示例#1
0
        /// <summary>
        /// throws exception
        /// </summary>
        /// <param name="page"></param>
        /// <param name="notes"></param>
        /// <returns></returns>
        private async Task ProcessFetchedDataAsync(List <Octokit.Notification> notes)
        {
            if (notificationStore == null)
            {
                notificationStore = new NotificationStorage();
            }
            if (repositoryStore == null)
            {
                repositoryStore = new RepositoryStorage();
            }
            if (userStore == null)
            {
                userStore = new UserStorage();
            }

            var dict = new UpdatableDictionary <int, DenormalizedNotification>();

            if (_notes != null)
            {
                foreach (var item in _notes)
                {
                    var _item = item as DenormalizedNotification;
                    dict.UpdateOrInsert(_item.Id, _item);
                }
            }

            foreach (var note in notes)
            {
                try
                {
                    string responseBuffer = await GetDetailsResponse(note.Subject.LatestCommentUrl);

                    Response details = Serializer.DeserializeToResponse(responseBuffer);

                    int id;
                    if (!Int32.TryParse(note.Id, out id))
                    {
                        throw new ArgumentException();
                    }
                    string userimagepath = await GetImagePath(details.User.Id.ToString(), Constants.AvatarSize);

                    var newNote = new DenormalizedNotification(id,
                                                               details.HtmlUrl,
                                                               details.User.Login,
                                                               note.Repository.FullName,
                                                               note.Subject.Title,
                                                               userimagepath,
                                                               DateTimeHelper.ParsedOrDefaultDateTime(note.UpdatedAt),
                                                               details.Body);

                    dict.UpdateOrInsert(newNote.Id, newNote);

                    notificationStore.UpdateOrInsert(id, note, details);
                    repositoryStore.UpdateOrInsert(id, note, details);
                    userStore.UpdateOrInsert(id, note, details);
                }
                catch
                {
                    // ignore
#if DEBUG
                    throw;
#endif
                }
            }
            _notes = new ObservableCollection <IDataItem>();
            var list = dict.Values.OrderByDescending(i => i.UpdatedAt).Take(Constants.NotificationStorageMaxSize);
            foreach (var value in list)
            {
                _notes.Add(value);
            }
        }
示例#2
0
        public static async Task LoadDenormalizeNotificationsAsync()
        {
            if (notificationStore == null)
            {
                notificationStore = new NotificationStorage();
            }
            if (repositoryStore == null)
            {
                repositoryStore = new RepositoryStorage();
            }
            if (userStore == null)
            {
                userStore = new UserStorage();
            }

            //await GetStorageFileAsync("Repositories");
            //await GetStorageFileAsync("Users");
            await GetStorageFileAsync("Notifications");

            if (notificationStore == null)
            {
                notificationStore = new NotificationStorage();
                return;
            }

            if (notificationStore.Count == 0)
            {
                return;
            }

            var dict = new UpdatableDictionary <int, DenormalizedNotification>();

            if (_notes.Count > 0)
            {
                foreach (var item in _notes)
                {
                    var _item = item as DenormalizedNotification;
                    dict.UpdateOrInsert(_item.Id, _item);
                }
            }

            foreach (var note in notificationStore.Values)
            {
                string imagePath = await GetImagePath(note.UserId.ToString(), Constants.AvatarSize);

                try
                {
                    var denormalizedNote = new DenormalizedNotification(note.Id,
                                                                        note.HtmlUrl,
                                                                        note.UserLogin,
                                                                        note.RepoFullName,
                                                                        note.SubjectTitle,
                                                                        imagePath,
                                                                        DateTimeHelper.ParsedOrDefaultDateTime(note.TimeStamp),
                                                                        note.Body);
                    dict.UpdateOrInsert(denormalizedNote.Id, denormalizedNote);
                }
                catch
                {
                    //ignore
                }
            }

            _notes = new ObservableCollection <IDataItem>();
            var list = dict.Values.OrderByDescending(i => i.UpdatedAt).Take(Constants.NotificationStorageMaxSize);

            foreach (var value in list)
            {
                _notes.Add(value);
            }
        }