コード例 #1
0
            public async Task <MenuList> __GetCommandsAsync()
            {
                MenuList actions = new MenuList()
                {
                    RenderMode = ModuleAction.RenderModeEnum.IconsOnly
                };
                EntryDisplayModule dispMod = new EntryDisplayModule();

                actions.New(await dispMod.GetAction_DisplayAsync(Identity), ModuleAction.ActionLocationEnum.GridLinks);
                EntryEditModule editMod = new EntryEditModule();

                actions.New(await editMod.GetAction_EditAsync(Module.EditUrl, Identity), ModuleAction.ActionLocationEnum.GridLinks);
                actions.New(Module.GetAction_Remove(Identity), ModuleAction.ActionLocationEnum.GridLinks);
                return(actions);
            }
コード例 #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));
            }
        }
コード例 #3
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));
            }
        }
コード例 #4
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));
            }
        }