private GridDefinition GetGridModel(int blogCategory)
        {
            return(new GridDefinition {
                ModuleGuid = Module.ModuleGuid,
                SettingsModuleGuid = Module.PermanentGuid,
                RecordType = typeof(BrowseItem),
                AjaxUrl = GetActionUrl(nameof(EntriesBrowse_GridData)),
                ExtraData = new BrowseItem.ExtraData {
                    BlogCategory = blogCategory
                },
                DirectDataAsync = async(int skip, int take, List <DataProviderSortInfo> sort, List <DataProviderFilterInfo> filters) => {
                    // filter by category
                    if (blogCategory != 0)
                    {
                        filters = DataProviderFilterInfo.Join(filters, new DataProviderFilterInfo {
                            Field = nameof(BlogEntry.CategoryIdentity), Operator = "==", Value = blogCategory,
                        });
                    }
                    using (BlogEntryDataProvider entryDP = new BlogEntryDataProvider()) {
                        using (BlogCategoryDataProvider categoryDP = new BlogCategoryDataProvider()) {
                            DataProviderGetRecords <BlogEntry> browseItems = await entryDP.GetItemsAsync(skip, take, sort, filters);

                            return new DataSourceResult {
                                Data = (from s in browseItems.Data select new BrowseItem(Module, categoryDP, s)).ToList <object>(),
                                Total = browseItems.Total
                            };
                        }
                    }
                },
            });
        }
Exemple #2
0
        public async Task <ActionResult> Summary()
        {
            //int category;
            //Manager.TryGetUrlArg<int>("BlogCategory", out category);
            BlogConfigData config = await BlogConfigDataProvider.GetConfigAsync();

            using (BlogEntryDataProvider dataProvider = new BlogEntryDataProvider()) {
                List <DataProviderSortInfo> sort = new List <DataProviderSortInfo> {
                    new DataProviderSortInfo {
                        Field = nameof(BlogEntry.DatePublished), Order = DataProviderSortInfo.SortDirection.Descending
                    },
                };
                List <DataProviderFilterInfo> filters = new List <DataProviderFilterInfo> {
                    new DataProviderFilterInfo {
                        Field = nameof(BlogEntry.Published), Operator = "==", Value = true
                    },
                };
                //if (category != 0)
                //    filters = DataProviderFilterInfo.Join(filters, new DataProviderFilterInfo { Field = nameof(BlogEntry.CategoryIdentity), Operator = "==", Value = category });
                DataProviderGetRecords <BlogEntry> data = await dataProvider.GetItemsAsync(0, Module.Entries, sort, filters);

                if (data.Data.Count == 0)
                {
                    return(new EmptyResult());
                }

                EntryDisplayModule dispMod = new EntryDisplayModule();
                List <Entry>       list    = new List <Entry>();
                foreach (BlogEntry d in data.Data)
                {
                    ModuleAction viewAction = await dispMod.GetAction_DisplayAsync(d.Identity);

                    list.Add(new Entry(d, dispMod, viewAction));
                }
                DisplayModel model = new DisplayModel()
                {
                    BlogEntries = list,
                };
                return(View(model));
            }
        }
Exemple #3
0
        public async Task <ActionResult> Archive(int?blogCategory)
        {
            int category = (int)(blogCategory ?? 0);

            BlogModule   blogMod = new BlogModule();
            DisplayModel model   = new DisplayModel()
            {
            };

            using (BlogEntryDataProvider entryDP = new BlogEntryDataProvider()) {
                List <DataProviderSortInfo> sort = new List <DataProviderSortInfo> {
                    new DataProviderSortInfo {
                        Field = nameof(BlogEntry.DatePublished), Order = DataProviderSortInfo.SortDirection.Descending
                    },
                };
                List <DataProviderFilterInfo> filters = new List <DataProviderFilterInfo> {
                    new DataProviderFilterInfo {
                        Field = nameof(BlogEntry.Published), Operator = "==", Value = true
                    },
                };
                if (category != 0)
                {
                    filters = DataProviderFilterInfo.Join(filters, new DataProviderFilterInfo {
                        Field = nameof(BlogEntry.CategoryIdentity), Operator = "==", Value = category
                    });
                }

                int year = 0, month = 0, count = 0;

                int totalRecs = 0, start = 0, incr = 100;
                for ( ; ;)
                {
                    DataProviderGetRecords <BlogEntry> data = await entryDP.GetItemsAsync(start, incr, sort, filters);

                    if (data.Data.Count == 0)
                    {
                        return(new EmptyResult());
                    }

                    foreach (BlogEntry entry in data.Data)
                    {
                        if (entry.DatePublished.Month != month || entry.DatePublished.Year != year)
                        {
                            if (count > 0)
                            {
                                DateTime d = new DateTime(year, month, 1).AddMonths(1).AddSeconds(-1);
                                model.Actions.New(await blogMod.GetAction_BlogAsync(null, category, StartDate: d, Count: count));
                                count = 0;
                            }
                            month = entry.DatePublished.Month;
                            year  = entry.DatePublished.Year;
                        }
                        ++count;
                    }
                    start += incr;
                    if (start >= totalRecs)
                    {
                        if (count > 0)
                        {
                            DateTime d = new DateTime(year, month, 1).AddMonths(1).AddSeconds(-1);
                            model.Actions.New(await blogMod.GetAction_BlogAsync(null, category, StartDate: d, Count: count));
                        }
                        break;
                    }
                }
                return(View(model));
            }
        }
Exemple #4
0
        // Windows RSS Publisher's Guide http://blogs.msdn.com/b/rssteam/archive/2005/08/02/publishersguide.aspx

        public async Task <ActionResult> RssFeed(int?blogCategory)
        {
            BlogConfigData config = await BlogConfigDataProvider.GetConfigAsync();

            if (!config.Feed)
            {
                throw new Error(this.__ResStr("noFeed", "The feed is no longer available"));
            }

            int          categoryIdentity = blogCategory ?? 0;
            BlogCategory category         = null;

            if (categoryIdentity != 0)
            {
                using (BlogCategoryDataProvider categoryDP = new BlogCategoryDataProvider()) {
                    category = await categoryDP.GetItemAsync(categoryIdentity);

                    if (!category.Syndicated)
                    {
                        throw new Error(this.__ResStr("noFeed", "The feed is no longer available"));
                    }
                }
            }

            using (BlogEntryDataProvider dataProvider = new BlogEntryDataProvider()) {
                List <DataProviderSortInfo> sort = new List <DataProviderSortInfo> {
                    new DataProviderSortInfo {
                        Field = nameof(BlogEntry.DatePublished), Order = DataProviderSortInfo.SortDirection.Descending
                    },
                };
                List <DataProviderFilterInfo> filters = new List <DataProviderFilterInfo> {
                    new DataProviderFilterInfo {
                        Field = nameof(BlogEntry.Published), Operator = "==", Value = true
                    },
                };
                if (categoryIdentity != 0)
                {
                    filters = DataProviderFilterInfo.Join(filters, new DataProviderFilterInfo {
                        Field = nameof(BlogEntry.CategoryIdentity), Operator = "==", Value = categoryIdentity
                    });
                }
                DataProviderGetRecords <BlogEntry> data = await dataProvider.GetItemsAsync(0, 0, sort, filters);

                string url = string.IsNullOrWhiteSpace(config.FeedMainUrl) ? Manager.CurrentSite.HomePageUrl : config.FeedMainUrl;

                List <SyndicationItem> items   = new List <SyndicationItem>();
                EntryDisplayModule     dispMod = new EntryDisplayModule();

                DateTime lastUpdated = DateTime.MinValue;
                foreach (BlogEntry blogEntry in data.Data)
                {
                    if (categoryIdentity == 0)
                    {
                        using (BlogCategoryDataProvider categoryDP = new BlogCategoryDataProvider()) {
                            category = await categoryDP.GetItemAsync(blogEntry.CategoryIdentity);

                            if (!category.Syndicated)
                            {
                                continue;
                            }
                        }
                    }
                    ModuleAction viewAction = await dispMod.GetAction_DisplayAsync(blogEntry.Identity);

                    if (viewAction == null)
                    {
                        continue;
                    }
                    SyndicationItem sItem   = new SyndicationItem(blogEntry.Title.ToString(), blogEntry.Text, new Uri(viewAction.GetCompleteUrl()));
                    DateTime        updDate = blogEntry.DateUpdated ?? blogEntry.DateCreated;
                    sItem.LastUpdatedTime = updDate;
                    if (!string.IsNullOrEmpty(category.SyndicationEmail))
                    {
                        sItem.Authors.Add(new SyndicationPerson(category.SyndicationEmail));
                    }
                    sItem.Categories.Add(new SyndicationCategory(category.Category.ToString()));
                    if (!string.IsNullOrEmpty(category.SyndicationCopyright.ToString()))
                    {
                        sItem.Copyright = new TextSyndicationContent(category.SyndicationCopyright.ToString());
                    }
                    sItem.PublishDate = blogEntry.DatePublished;
                    if (!string.IsNullOrEmpty(blogEntry.DisplayableSummary))
                    {
                        sItem.Summary = new TextSyndicationContent(blogEntry.DisplayableSummary);
                    }
                    lastUpdated = updDate > lastUpdated ? updDate : lastUpdated;

                    items.Add(sItem);
                }

                SyndicationFeed feed;
                if (categoryIdentity != 0)
                {
                    feed = new SyndicationFeed(category.Category.ToString(), category.Description.ToString(), new Uri(Manager.CurrentSite.MakeUrl(url)), items);
                }
                else
                {
                    feed = new SyndicationFeed(config.FeedTitle, config.FeedSummary, new Uri(Manager.CurrentSite.MakeUrl(url)), items);
                }
                if (config.FeedImage != null)
                {
                    feed.ImageUrl = new Uri(Manager.CurrentSite.MakeUrl(ImageHTML.FormatUrl(BlogConfigData.ImageType, null, config.FeedImage))); //$$$ caching issue
                }
                if (lastUpdated != DateTime.MinValue)
                {
                    feed.LastUpdatedTime = lastUpdated;
                }
                return(new RssResult(feed));
            }
        }
Exemple #5
0
        public async Task <ActionResult> Blog(DateTime?StartDate = null)
        {
            int category;

            Manager.TryGetUrlArg <int>("BlogCategory", out category);
            BlogConfigData config = await BlogConfigDataProvider.GetConfigAsync();

            using (BlogEntryDataProvider dataProvider = new BlogEntryDataProvider()) {
                List <DataProviderSortInfo> sort = new List <DataProviderSortInfo> {
                    new DataProviderSortInfo {
                        Field = nameof(BlogEntry.DatePublished), Order = DataProviderSortInfo.SortDirection.Descending
                    },
                };
                List <DataProviderFilterInfo> filters = new List <DataProviderFilterInfo> {
                    new DataProviderFilterInfo {
                        Field = nameof(BlogEntry.Published), Operator = "==", Value = true
                    },
                };
                if (category != 0)
                {
                    filters = DataProviderFilterInfo.Join(filters, new DataProviderFilterInfo {
                        Field = nameof(BlogEntry.CategoryIdentity), Operator = "==", Value = category
                    });
                }
                DateTime sdShown = DateTime.MaxValue;
                if (StartDate != null)
                {
                    sdShown = ((DateTime)StartDate).Date;
                    if (sdShown < DateTime.UtcNow)
                    {
                        filters = DataProviderFilterInfo.Join(filters, new DataProviderFilterInfo {
                            Field = nameof(BlogEntry.DatePublished), Operator = "<=", Value = sdShown
                        });
                    }
                    else
                    {
                        sdShown = DateTime.MaxValue;
                    }
                }
                DataProviderGetRecords <BlogEntry> data = await dataProvider.GetItemsAsync(0, config.Entries, sort, filters);

                if (data.Data.Count == 0)
                {
                    return(new EmptyResult());
                }

                string rssUrl = string.IsNullOrWhiteSpace(config.FeedMainUrl) ? Manager.CurrentSite.HomePageUrl : config.FeedMainUrl;
                Manager.LinkAltManager.AddLinkAltTag(AreaRegistration.CurrentPackage.AreaName, "application/rss+xml", config.FeedTitle, rssUrl);

                EntryEditModule    editMod = new EntryEditModule();
                EntryDisplayModule dispMod = new EntryDisplayModule();

                List <Entry> list = new List <Entry>();
                foreach (BlogEntry d in data.Data)
                {
                    ModuleAction viewAction = await dispMod.GetAction_DisplayAsync(d.Identity, ReadMore : d.Summary != d.Text);

                    ModuleAction editAction = await editMod.GetAction_EditAsync(null, d.Identity);

                    list.Add(new Entry(d, editMod, dispMod, editAction, viewAction));
                }
                DisplayModel model = new DisplayModel()
                {
                    BlogEntries      = list,
                    CategoryIdentity = category,
                    StartDate        = sdShown == DateTime.MaxValue ? null : (DateTime?)sdShown,
                };
                return(View(model));
            }
        }