#pragma warning disable 4014
        public ArticleRepository(ISettingsRepository settingsRepository, IProgressService progressService, IStorageService storageService, ISqliteService sqliteService, IThemeRepository themeRepository, IImageDownloadService imageDownloadService, IPermissionsService permissionsService)
        {
            _settingsRepository = settingsRepository;
            _progressService = progressService;
            _storageService = storageService;
            _sqliteService = sqliteService;
            _themeRepository = themeRepository;
            _imageDownloadService = imageDownloadService;
            _permissionsService = permissionsService;

            _articleGenericRepository = new GenericRepository<ArticleModel, ArticleEntity>(_sqliteService);
            _imageContentGenericRepository = new GenericRepository<ImageContentModel, ImageContentEntity>(_sqliteService);
            _textContentGenericRepository = new GenericRepository<TextContentModel, TextContentEntity>(_sqliteService);
            _galleryContentGenericRepository = new GenericRepository<GalleryContentModel, GalleryContentEntity>(_sqliteService);

            Initialize();
        }
Exemple #2
0
#pragma warning disable 4014
        public ArticleRepository(ISettingsRepository settingsRepository, IProgressService progressService, IStorageService storageService, ISqliteService sqliteService, IThemeRepository themeRepository, IImageDownloadService imageDownloadService, IPermissionsService permissionsService)
        {
            _settingsRepository   = settingsRepository;
            _progressService      = progressService;
            _storageService       = storageService;
            _sqliteService        = sqliteService;
            _themeRepository      = themeRepository;
            _imageDownloadService = imageDownloadService;
            _permissionsService   = permissionsService;

            _articleGenericRepository        = new GenericRepository <ArticleModel, ArticleEntity>(_sqliteService);
            _imageContentGenericRepository   = new GenericRepository <ImageContentModel, ImageContentEntity>(_sqliteService);
            _textContentGenericRepository    = new GenericRepository <TextContentModel, TextContentEntity>(_sqliteService);
            _galleryContentGenericRepository = new GenericRepository <GalleryContentModel, GalleryContentEntity>(_sqliteService);

            Initialize();
        }
Exemple #3
0
        public static async Task<ArticleModel> LoadForFeed(int id, FeedModel feed, ISqliteService sqliteService, IImageDownloadService imageDownloadService)
        {
            var arRepo = new GenericRepository<ArticleModel, ArticleEntity>(sqliteService);
            var imgRepo = new GenericRepository<ImageContentModel, ImageContentEntity>(sqliteService);

            var art = await arRepo.GetByIdAsync(id);
            var contents = await sqliteService.GetByCondition<ContentEntity>(s => s.ParentId == id && s.ContentType == (int)ContentType.LeadImage, s => s.Index, false, 1, 0);
            if (contents?.FirstOrDefault() != null)
            {
                var image = await imgRepo.GetByIdAsync(contents.FirstOrDefault().ContentId);
                art.LeadImage = image;

                if (art.LeadImage?.LoadingState < LoadingState.Loaded)
                    imageDownloadService.Download(art);
            }
            art.Feed = feed;
            return art;
        }
Exemple #4
0
        public static async Task <ArticleModel> LoadForFeed(int id, FeedModel feed, ISqliteService sqliteService, IImageDownloadService imageDownloadService)
        {
            var arRepo  = new GenericRepository <ArticleModel, ArticleEntity>(sqliteService);
            var imgRepo = new GenericRepository <ImageContentModel, ImageContentEntity>(sqliteService);

            var art = await arRepo.GetByIdAsync(id);

            var contents = await sqliteService.GetByCondition <ContentEntity>(s => s.ParentId == id && s.ContentType == (int)ContentType.LeadImage, s => s.Index, false, 1, 0);

            if (contents?.FirstOrDefault() != null)
            {
                var image = await imgRepo.GetByIdAsync(contents.FirstOrDefault().ContentId);

                art.LeadImage = image;

                if (art.LeadImage?.LoadingState < LoadingState.Loaded)
                {
                    imageDownloadService.Download(art);
                }
            }
            art.Feed = feed;
            return(art);
        }
Exemple #5
0
 public PostCommand(PigbotDbContext dbContext, IImageDownloadService imageDownloadService, DiscordSocketClient discordClient)
 {
     this.dbContext            = dbContext;
     this.imageDownloadService = imageDownloadService;
     this.discordClient        = discordClient;
 }
Exemple #6
0
        public static async Task SaveFeed(FeedModel model, List<ArticleModel> newArticles, ISqliteService service, IImageDownloadService imageDownloadService)
        {
            var stringGuid = model.Guid.ToString();
            var feedEntries = await service.GetByCondition<FeedArticleRelationEntity>(d => d.FeedGuid == stringGuid, null, false, 0, 0);
            var oldArticles = new List<ArticleModel>(model.AllArticles);


            for (int index = 0; index < newArticles.Count; index++)
            {
                var articleModel = newArticles[index];
                articleModel.Feed = model;

                var oldOne = oldArticles.FirstOrDefault(s => s.PublicUri == articleModel.PublicUri);
                if (oldOne == null)
                {
                    var oldFromDatabase = feedEntries.FirstOrDefault(s => articleModel.PublicUri == s.Url);
                    if (oldFromDatabase != null)
                    {
                        var article = await LoadHelper.LoadForFeed(oldFromDatabase.ArticleId, model, service, imageDownloadService);
                        feedEntries.Remove(oldFromDatabase);
                        oldFromDatabase.Index = index;
                        await service.Update(oldFromDatabase);

                        if (model.AllArticles.Count > index)
                            model.AllArticles[index] = article;
                        else
                            model.AllArticles.Add(article);
                    }
                    else
                    {
                        await SaveArticle(articleModel, service);
                        await SaveArticleLeadImage(articleModel, service, true);
                        await SaveArticleContent(articleModel, service, true);

                        var fe = new FeedArticleRelationEntity()
                        {
                            ArticleId = articleModel.GetId(),
                            Url = articleModel.PublicUri,
                            FeedGuid = model.Guid.ToString(),
                            Index = index
                        };
                        await service.Add(fe);

                        if (model.AllArticles.Count > index)
                            model.AllArticles[index] = articleModel;
                        else
                            model.AllArticles.Add(articleModel);
                    }
                }
                else
                {
                    if (model.AllArticles.Count > index)
                        model.AllArticles[index] = oldOne;
                    else
                        model.AllArticles.Add(oldOne);

                    var oldFromDatabase = feedEntries.FirstOrDefault(s => articleModel.PublicUri == s.Url);
                    if (oldFromDatabase != null)
                    {
                        oldFromDatabase.Index = index;
                        await service.Update(oldFromDatabase);
                    }
                    else
                    {
                        var fe = new FeedArticleRelationEntity()
                        {
                            ArticleId = oldOne.GetId(),
                            Url = oldOne.PublicUri,
                            FeedGuid = model.Guid.ToString(),
                            Index = index
                        };
                        await service.Add(fe);
                    }
                }
            }

            await service.DeleteAllById<FeedArticleRelationEntity>(feedEntries.Select(s => s.Id));
        }
Exemple #7
0
        public static async Task SaveFeed(FeedModel model, List <ArticleModel> newArticles, ISqliteService service, IImageDownloadService imageDownloadService)
        {
            var stringGuid  = model.Guid.ToString();
            var feedEntries = await service.GetByCondition <FeedArticleRelationEntity>(d => d.FeedGuid == stringGuid, null, false, 0, 0);

            var oldArticles = new List <ArticleModel>(model.AllArticles);


            for (int index = 0; index < newArticles.Count; index++)
            {
                var articleModel = newArticles[index];
                articleModel.Feed = model;

                var oldOne = oldArticles.FirstOrDefault(s => s.PublicUri == articleModel.PublicUri);
                if (oldOne == null)
                {
                    var oldFromDatabase = feedEntries.FirstOrDefault(s => articleModel.PublicUri == s.Url);
                    if (oldFromDatabase != null)
                    {
                        var article = await LoadHelper.LoadForFeed(oldFromDatabase.ArticleId, model, service, imageDownloadService);

                        feedEntries.Remove(oldFromDatabase);
                        oldFromDatabase.Index = index;
                        await service.Update(oldFromDatabase);

                        if (model.AllArticles.Count > index)
                        {
                            model.AllArticles[index] = article;
                        }
                        else
                        {
                            model.AllArticles.Add(article);
                        }
                    }
                    else
                    {
                        await SaveArticle(articleModel, service);
                        await SaveArticleLeadImage(articleModel, service, true);
                        await SaveArticleContent(articleModel, service, true);

                        var fe = new FeedArticleRelationEntity()
                        {
                            ArticleId = articleModel.GetId(),
                            Url       = articleModel.PublicUri,
                            FeedGuid  = model.Guid.ToString(),
                            Index     = index
                        };
                        await service.Add(fe);

                        if (model.AllArticles.Count > index)
                        {
                            model.AllArticles[index] = articleModel;
                        }
                        else
                        {
                            model.AllArticles.Add(articleModel);
                        }
                    }
                }
                else
                {
                    if (model.AllArticles.Count > index)
                    {
                        model.AllArticles[index] = oldOne;
                    }
                    else
                    {
                        model.AllArticles.Add(oldOne);
                    }

                    var oldFromDatabase = feedEntries.FirstOrDefault(s => articleModel.PublicUri == s.Url);
                    if (oldFromDatabase != null)
                    {
                        oldFromDatabase.Index = index;
                        await service.Update(oldFromDatabase);
                    }
                    else
                    {
                        var fe = new FeedArticleRelationEntity()
                        {
                            ArticleId = oldOne.GetId(),
                            Url       = oldOne.PublicUri,
                            FeedGuid  = model.Guid.ToString(),
                            Index     = index
                        };
                        await service.Add(fe);
                    }
                }
            }

            await service.DeleteAllById <FeedArticleRelationEntity>(feedEntries.Select(s => s.Id));
        }