public async Task <BlogConfigData> GetItemAsync()
        {
            BlogConfigData config = await DataProvider.GetAsync(KEY);

            if (config == null)
            {
                config = new BlogConfigData();
                await AddConfigAsync(config);
            }
            return(config);
        }
        private async Task AddConfigAsync(BlogConfigData data)
        {
            data.Id = KEY;
            await SaveImagesAsync(ModuleDefinition.GetPermanentGuid(typeof(BlogConfigModule)), data);

            if (!await DataProvider.AddAsync(data))
            {
                throw new InternalError("Unexpected error adding settings");
            }
            await Auditing.AddAuditAsync($"{nameof(BlogConfigDataProvider)}.{nameof(AddConfigAsync)}", "Config", Guid.Empty,
                                         "Add Blog Config",
                                         DataBefore : null,
                                         DataAfter : data,
                                         ExpensiveMultiInstance : true
                                         );
        }
        public static async Task <string> GetEntryCanonicalNameAsync(int blogEntry)
        {
            BlogConfigData config = await BlogConfigDataProvider.GetConfigAsync();

            string canon = string.Format("{0}/?BlogEntry={1}", config.BlogEntryUrl, blogEntry);

            using (BlogEntryDataProvider entryDP = new BlogEntryDataProvider()) {
                BlogEntry data = await entryDP.GetItemAsync(blogEntry);

                if (data != null)
                {
                    canon = string.Format("{0}/Title/{1}/?BlogEntry={2}", config.BlogEntryUrl, Utility.UrlEncodeSegment(data.Title.ToString().Truncate(80)), blogEntry);
                }
                return(canon);
            }
        }
        public async Task UpdateConfigAsync(BlogConfigData data)
        {
            BlogConfigData origConfig = Auditing.Active ? await GetItemAsync() : null;

            data.Id = KEY;
            await SaveImagesAsync(ModuleDefinition.GetPermanentGuid(typeof(BlogConfigModule)), data);

            UpdateStatusEnum status = await DataProvider.UpdateAsync(data.Id, data.Id, data);

            if (status != UpdateStatusEnum.OK)
            {
                throw new InternalError("Unexpected error saving settings {0}", status);
            }
            await Auditing.AddAuditAsync($"{nameof(BlogConfigDataProvider)}.{nameof(UpdateConfigAsync)}", "Config", Guid.Empty,
                                         "Update Blog Config",
                                         DataBefore : origConfig,
                                         DataAfter : data,
                                         ExpensiveMultiInstance : true
                                         );
        }
Example #5
0
        // ISEARCHDYNAMICURLS
        // ISEARCHDYNAMICURLS
        // ISEARCHDYNAMICURLS

        public async Task KeywordsForDynamicUrlsAsync(ISearchWords searchWords)
        {
            using (this) {
                BlogConfigData config = await BlogConfigDataProvider.GetConfigAsync();

                List <DataProviderFilterInfo> filters = DataProviderFilterInfo.Join(null, new DataProviderFilterInfo {
                    Field = nameof(BlogEntry.Published), Operator = "==", Value = true
                });
                DataProviderGetRecords <BlogEntry> entries = await GetItemsAsync(0, 0, null, filters);

                foreach (BlogEntry entry in entries.Data)
                {
                    string url = await BlogConfigData.GetEntryCanonicalNameAsync(entry.Identity);

                    PageDefinition page = await PageDefinition.LoadFromUrlAsync(url);

                    if (page == null)
                    {
                        return;               // there is no such root page
                    }
                    if (!searchWords.WantPage(page))
                    {
                        return;
                    }

                    if (await searchWords.SetUrlAsync(url, page.PageSecurity, entry.Title, entry.DisplayableSummaryText, entry.DateCreated, entry.DateUpdated, page.IsAuthorized_View_Anonymous(), page.IsAuthorized_View_AnyUser()))
                    {
                        searchWords.AddObjectContents(entry);
                        using (BlogCommentDataProvider commentDP = new BlogCommentDataProvider(entry.Identity)) {
                            DataProviderGetRecords <BlogComment> comments = await commentDP.GetItemsAsync(0, 0, null, null);

                            foreach (BlogComment comment in comments.Data)
                            {
                                searchWords.AddObjectContents(comment);
                            }
                        }
                        await searchWords.SaveAsync();
                    }
                }
            }
        }
        private async Task <ImageSupport.GetImageInBytesInfo> RetrieveImageAsync(string name, string location)
        {
            ImageSupport.GetImageInBytesInfo fail = new ImageSupport.GetImageInBytesInfo();
            if (!string.IsNullOrWhiteSpace(location))
            {
                return(fail);
            }
            if (string.IsNullOrWhiteSpace(name))
            {
                return(fail);
            }
            BlogConfigData config = await BlogConfigDataProvider.GetConfigAsync();

            if (config.FeedImage_Data == null || config.FeedImage_Data.Length == 0)
            {
                return(fail);
            }
            return(new ImageSupport.GetImageInBytesInfo {
                Content = config.FeedImage_Data,
                Success = true,
            });
        }
        internal static async Task <string> GetCategoryCanonicalNameAsync(int blogCategory = 0)
        {
            using (BlogCategoryDataProvider categoryDP = new BlogCategoryDataProvider()) {
                BlogConfigData config = await BlogConfigDataProvider.GetConfigAsync();

                string canon = config.BlogUrl;
                if (blogCategory != 0)
                {
                    BlogCategory cat = await categoryDP.GetItemAsync(blogCategory);

                    if (cat != null)
                    {
                        canon = string.Format("{0}/Title/{1}/?BlogCategory={2}", config.BlogUrl, Utility.UrlEncodeSegment(cat.Category.ToString().Truncate(80)), blogCategory);
                    }
                }
                else
                {
                    canon = config.BlogUrl;
                }
                return(canon);
            }
        }
Example #8
0
        // ISITEMAPDYNAMICURLS
        // ISITEMAPDYNAMICURLS
        // ISITEMAPDYNAMICURLS

        public async Task FindDynamicUrlsAsync(AddDynamicUrlAsync addDynamicUrlAsync, Func <PageDefinition, bool> validForSiteMap)
        {
            using (this) {
                List <DataProviderFilterInfo> filters = DataProviderFilterInfo.Join(null, new DataProviderFilterInfo {
                    Field = nameof(BlogEntry.Published), Operator = "==", Value = true
                });
                DataProviderGetRecords <BlogEntry> entries = await GetItemsAsync(0, 0, null, filters);

                foreach (BlogEntry entry in entries.Data)
                {
                    string url = await BlogConfigData.GetEntryCanonicalNameAsync(entry.Identity);

                    PageDefinition page = await PageDefinition.LoadFromUrlAsync(url);

                    if (page == null)
                    {
                        return;               // there is no such root page
                    }
                    await addDynamicUrlAsync(page, url, entry.DateUpdated, page.SiteMapPriority, page.ChangeFrequency, entry);
                }
            }
        }