コード例 #1
0
        public async Task <IFeedGroup> AddFeedGroup(string label)
        {
            var folder = await GetFeedGroupFolder();

            var feedStreamDataFolder = await GetFeedStreamDataFolder();

            var feedGroup    = new FeedGroup2(label);
            var fileAccessor = new FileAccessor <FeedGroup2>(folder, label + ".json");

            feedGroup.HohoemaApp  = this.HohoemaApp;
            feedGroup.FeedManager = this;
            FeedGroupDict.Add(feedGroup, fileAccessor);

            var itemId             = feedGroup.Id.ToString();
            var streamFileAccessor = new FileAccessor <List <FeedItem> >(feedStreamDataFolder, $"{itemId}.json");

            FeedStreamFileAccessors.Add(feedGroup.Id, streamFileAccessor);

            _FeedGroupUpdaters.Add(feedGroup,
                                   HohoemaApp.BackgroundUpdater.RegistrationBackgroundUpdateScheduleHandler(
                                       feedGroup, feedGroup.Label, nameof(FeedGroup), label: $"FeedGroup:{feedGroup.Label}")
                                   );

            await SaveOne(feedGroup);

            return(feedGroup);
        }
コード例 #2
0
        public async Task Load(IReadOnlyList <StorageFile> files)
        {
            var feedGroupFolder = await GetFeedGroupFolder();

            var feedStreamDataFolder = await GetFeedStreamDataFolder();

            var legacyFeedSettingsFolder = await HohoemaApp.GetFeedSettingsFolder();


            foreach (var file in files)
            {
                if (file.FileType == ".json")
                {
                    var fileName     = file.Name;
                    var fileAccessor = new FileAccessor <FeedGroup2>(feedGroupFolder, fileName);

                    try
                    {
                        var item = await fileAccessor.Load(FeedGroupSerializerSettings);

                        bool isLoadFromLegacyFile = false;
                        if (item == null)
                        {
                            var legacyFeedGroupFileAccessor = new FileAccessor <FeedGroup>(legacyFeedSettingsFolder, fileName);
                            var item_legacy = await legacyFeedGroupFileAccessor.Load(FeedGroupSerializerSettings);

                            if (item_legacy != null)
                            {
                                item = new FeedGroup2(item_legacy);

                                isLoadFromLegacyFile = true;
                            }
                        }

                        if (item != null)
                        {
                            item.HohoemaApp  = this.HohoemaApp;
                            item.FeedManager = this;
                            FeedGroupDict.Add(item, fileAccessor);
                            var itemId = item.Id.ToString();

                            var streamFileAccessor = new FileAccessor <List <FeedItem> >(feedStreamDataFolder, $"{itemId}.json");
                            FeedStreamFileAccessors.Add(item.Id, streamFileAccessor);

                            await item.LoadFeedStream(streamFileAccessor);

                            // 古いファイルは新しいフォーマットで上書きして消しておく
                            if (isLoadFromLegacyFile)
                            {
                                await SaveOne(item, isSkipSyncRoaming : true);
                            }

                            // FeedGroupの更新処理情報を構築
                            _FeedGroupUpdaters.Add(item,
                                                   HohoemaApp.BackgroundUpdater.RegistrationBackgroundUpdateScheduleHandler(
                                                       item, item.Label, nameof(FeedGroup), label: $"FeedGroup:{item.Label}")
                                                   );

                            Debug.WriteLine($"FeedManager: [Sucesss] load {item.Label}");
                        }
                        else
                        {
                            Debug.WriteLine($"FeedManager: [?] .json but not FeedGroup file < {fileName}");
                        }
                    }
                    catch
                    {
                        Debug.WriteLine($"FeedManager: [Failed] load {file.Path}");
                    }
                }
            }
        }