コード例 #1
0
        public void IntinaizedNewsConfigTable()
        {
            var config = new NewsConfig()
            {
                Id             = 1,
                Name           = "newssource",
                Version        = 0,
                Status         = 1,
                CreateDateTime = DateTime.Now
            };
            var config2 = new NewsConfig()
            {
                Id             = 2,
                Name           = "newscategory",
                Version        = 0,
                Status         = 1,
                CreateDateTime = DateTime.Now
            };
            var config3 = new NewsConfig()
            {
                Id             = 3,
                Name           = "newsextraapp",
                Version        = 0,
                Status         = 1,
                CreateDateTime = DateTime.Now
            };
            var configlist = new List <NewsConfig>()
            {
                config, config2, config3
            };

            dbContextService.Add <NewsConfig>(configlist);
        }
コード例 #2
0
        // TODO: Pass parameters via specific node, remove it after processing?
        public List <MenuNode> ManipulateNodes(List <MenuNode> nodes, PortalSettings portalSettings)
        {
            try {
                var config     = NewsConfig.GetInstance(portalSettings.PortalId).NodeManipulator;
                var parentNode = FindNodeByTabId(nodes, config.ParentNodeTabId);
                if (parentNode != null)
                {
                    var streamModule = ModuleController.Instance.GetModule(config.StreamModuleId, config.StreamModuleTabId, false);
                    if (streamModule != null)
                    {
                        var settingsRepository = new StreamSettingsRepository();
                        var settings           = settingsRepository.GetSettings(streamModule);
                        var newsEntries        = GetNewsEntries(settings, settings.PageSize, portalSettings.PortalId);
                        foreach (var newsEntry in newsEntries)
                        {
                            parentNode.Children.Add(CreateMenuNode(newsEntry, parentNode, streamModule));
                        }
                    }
                    else
                    {
                        LogAdminAlert($"Could not find Stream module with ModuleID={config.StreamModuleId} on page with TabID={config.StreamModuleTabId}.", portalSettings.PortalId);
                    }
                }
                else
                {
                    LogAdminAlert($"Could not find parent node with TabID={config.ParentNodeTabId}.", portalSettings.PortalId);
                }
            } catch (Exception ex) {
                Exceptions.LogException(ex);
            }

            return(nodes);
        }
コード例 #3
0
        public async Task <IActionResult> OnPost()
        {
            if (String.IsNullOrEmpty(NewArticle.Summary) && String.IsNullOrEmpty(NewArticle.ArticleContent))
            {
                ModelState.AddModelError(nameof(NewArticle.ArticleContent), "Zusammenfassung und/oder Artikeltext eingeben.");
            }
            if (!String.IsNullOrEmpty(NewArticle.FlickrLink) && String.IsNullOrEmpty(NewArticle.FlickrLinkImage))
            {
                ModelState.AddModelError(nameof(NewArticle.FlickrLinkImage), "Wenn ein Flick-Link angegeben wird, muss auch ein Image-Link angegeben werden.");
            }
            if (ModelState.IsValid)
            {
                this.NewArticle.Author = this.User.Identity.Name;
                NewsConfig newsConfig = configuration.GetSection("NewsConfig:" + NewArticle.ListName).Get <NewsConfig>();
                if (!User.IsInAnyRole(newsConfig.WriteAccess.Split(',')))
                {
                    return(new UnauthorizedResult());
                }
                await this.repository.UpsertDocument(NewArticle);

                if (!String.IsNullOrEmpty(this.NewArticle.Tags))
                {
                    UpdateTags(NewArticle.Tags, NewArticle.ListName);
                }
                await this.LogActivity($"Article in {NewArticle.ListName} posted.");

                return(RedirectToPage(CallingPage));
            }
            else
            {
                ViewData["Message"] = "Da stimmt was nicht.";
                return(Page());
            }
        }
コード例 #4
0
ファイル: NewsRepository.cs プロジェクト: jimeneza14/R7.News
        public IEnumerable <NewsEntryInfo> GetNewsEntriesByAgent(int moduleId, int portalId)
        {
            var cacheKey = NewsCacheKeyPrefix + "AgentModuleId=" + moduleId;

            return(DataCache.GetCachedData <IEnumerable <NewsEntryInfo> > (
                       new CacheItemArgs(cacheKey, NewsConfig.GetInstance(portalId).DataCacheTime, CacheItemPriority.Normal),
                       c => GetNewsEntriesByAgentInternal(moduleId)
                       ));
        }
コード例 #5
0
        protected IEnumerable <INewsEntry> GetNewsEntries_Cached(int moduleId, int portalId, StreamSettings settings)
        {
            // TODO: Reuse cached data from StreamViewModel or (better) move caching to repository
            var cacheKey = "//" + Const.Prefix + "/NodeManipulator?ModuleId=" + moduleId;

            return(DataCache.GetCachedData <IEnumerable <INewsEntry> > (
                       new CacheItemArgs(cacheKey, NewsConfig.GetInstance(portalId).DataCacheTime, CacheItemPriority.Normal),
                       c => GetNewsEntries(portalId, settings)
                       ));
        }
コード例 #6
0
        public ActionResult ConfigEdit(NewsConfig model)
        {
            var config = dbContextService.Single <NewsConfig>(model.Id);

            config.Name           = model.Name;
            config.NameLowCase    = model.NameLowCase;
            config.Status         = model.Status;
            config.CreateDateTime = DateTime.Now;

            dbContextService.Update <NewsConfig>(config);

            return(RedirectToAction("ConfigList"));
        }
コード例 #7
0
        public ActionResult ConfigAdd(NewsConfig model)
        {
            var exist = dbContextService.Exists <NewsConfig>(x => x.Name == model.Name);

            if (exist)
            {
                TempData["errorMsg"] = "该配置项已存在!";
                return(View());
            }
            var ret = dbContextService.Add <NewsConfig>(model);

            return(RedirectToAction("ConfigList"));
        }
コード例 #8
0
ファイル: NewsRepository.cs プロジェクト: jimeneza14/R7.News
        public IEnumerable <NewsEntryInfo> GetAllNewsEntries(int moduleId,
                                                             int portalId,
                                                             WeightRange thematicWeights,
                                                             WeightRange structuralWeights)
        {
            var cacheKey = NewsCacheKeyPrefix + "ModuleId=" + moduleId;

            return(DataCache.GetCachedData <IEnumerable <NewsEntryInfo> > (
                       new CacheItemArgs(cacheKey, NewsConfig.GetInstance(portalId).DataCacheTime, CacheItemPriority.Normal),
                       c => GetAllNewsEntriesInternal(portalId,
                                                      thematicWeights, structuralWeights)
                       ));
        }
コード例 #9
0
 public NewsCommand(ILogger <NewsCommand> log,
                    IClientWrapper client,
                    NewsConfig config,
                    NewsProviderManager newsProvider,
                    ContractManager contractManager,
                    HistoricalNewsManager newsManager)
 {
     this.log             = log ?? throw new ArgumentNullException(nameof(log));
     this.client          = client ?? throw new ArgumentNullException(nameof(client));
     this.config          = config ?? throw new ArgumentNullException(nameof(config));
     this.newsProvider    = newsProvider ?? throw new ArgumentNullException(nameof(newsProvider));
     this.contractManager = contractManager ?? throw new ArgumentNullException(nameof(contractManager));
     this.newsManager     = newsManager ?? throw new ArgumentNullException(nameof(newsManager));
 }
コード例 #10
0
        public async Task <IActionResult> OnGet(string callingPage, string listName, string logicalKey)
        {
            if (String.IsNullOrEmpty(listName) || String.IsNullOrEmpty(callingPage))
            {
                return(new NotFoundResult());
            }
            NewsConfig newsConfig = configuration.GetSection("NewsConfig:" + listName).Get <NewsConfig>();

            if (!User.IsInAnyRole(newsConfig.WriteAccess.Split(',')))
            {
                return(new UnauthorizedResult());
            }
            await this.PrepareArticle(callingPage, listName, logicalKey, null);

            return(Page());
        }
コード例 #11
0
        public IList <NewsConfigView> GetConfigViewList(MobileParam mobileParams)
        {
            #region instance
            var config = new NewsConfig()
            {
                Id             = 1,
                Name           = "提供商",
                NameLowCase    = "newssource",
                Version        = 1,
                Status         = 1,
                CreateDateTime = DateTime.Now
            };

            var config2 = new NewsConfig()
            {
                Id             = 2,
                Name           = "分类",
                NameLowCase    = "newscategory",
                Version        = 2,
                Status         = 1,
                CreateDateTime = DateTime.Now
            };

            var config3 = new NewsConfig()
            {
                Id             = 3,
                Name           = "外推应用",
                NameLowCase    = "newsextraapp",
                Version        = 1,
                Status         = 1,
                CreateDateTime = DateTime.Now
            };
            #endregion

            var configlist = new List <NewsConfig>()
            {
                config, config2, config3
            };

            var result = configlist.To <IList <NewsConfigView> >();

            return(result);
        }
コード例 #12
0
        /// <summary>
        /// Imports news from AnnoView modules to R7.News
        /// </summary>
        /// <param name="sleepTimeout">Sleep timeout.</param>
        protected int Import(int sleepTimeout)
        {
            var itemsImported      = 0;
            var itemsImportedDiv10 = 0;

            var announcements = NewsDataProvider.Instance.GetObjects <AnnouncementInfo> ();

            if (announcements != null)
            {
                var moduleController = new ModuleController();
                var tabController    = new TabController();
                var termController   = new TermController();

                using (var dc = DataContext.Instance()) {
                    var repository = dc.GetRepository <NewsEntryInfo> ();

                    foreach (var announcement in announcements)
                    {
                        var module = moduleController.GetModule(announcement.ModuleId);
                        if (module != null)
                        {
                            try {
                                // fill news entry
                                var newsEntry = new NewsEntryInfo {
                                    Title            = announcement.Title,
                                    Description      = announcement.Description,
                                    StartDate        = announcement.PublishDate,
                                    EndDate          = announcement.ExpireDate,
                                    Url              = announcement.Url,
                                    PortalId         = module.PortalID,
                                    ThematicWeight   = (announcement.Export) ? NewsConfig.GetInstance(module.PortalID).NewsEntry.MaxWeight : 0,
                                    StructuralWeight = (announcement.Export) ? NewsConfig.GetInstance(module.PortalID).NewsEntry.MaxWeight : 0
                                };

                                // add news entry
                                NewsRepository.Instance.AddNewsEntry_Internal(
                                    repository,
                                    newsEntry,
                                    GetTerms(announcement, module, tabController, termController),
                                    GetImages(announcement),
                                    module.ModuleID,
                                    module.TabID
                                    );

                                // count number of items imported,
                                // invoke Progressing method each 10 items
                                itemsImported++;
                                if (itemsImported / 10 > itemsImportedDiv10)
                                {
                                    itemsImportedDiv10++;
                                    Progressing();
                                }

                                Thread.Sleep(sleepTimeout);
                            }
                            catch (Exception ex) {
                                // log error on importing current announcement
                                ScheduleHistoryItem.AddLogNote("Announcement.ItemId:" + announcement.ItemId + "; Exception:" + ex);
                                Exceptions.LogException(ex);
                            }
                        }
                    }
                }
            }

            return(itemsImported);
        }
コード例 #13
0
        public async Task <IActionResult> OnGetCustomized(string callingPage, string listName, string logicalKey, string documentId,
                                                          int?timeToLive,
                                                          bool?titleLink,
                                                          bool?summary,
                                                          bool?link,
                                                          bool?tags,
                                                          bool?image,
                                                          bool?featuredEnabled,
                                                          bool?nickname)
        {
            if (String.IsNullOrEmpty(listName) || String.IsNullOrEmpty(callingPage))
            {
                return(new NotFoundResult());
            }
            NewsConfig newsConfig = configuration.GetSection("NewsConfig:" + listName).Get <NewsConfig>();

            if (!User.IsInAnyRole(newsConfig.WriteAccess.Split(',')))
            {
                return(new UnauthorizedResult());
            }
            await this.PrepareArticle(callingPage, listName, logicalKey, documentId);

            if (null != timeToLive && 0 < timeToLive)
            {
                NewArticle.TimeToLive = timeToLive;
            }
            if (null != featuredEnabled && featuredEnabled == true)
            {
                FeaturedEnabled = true;
            }

            /* rbrands: nickname not used
             * if (null != nickname && nickname == true)
             * {
             *  NicknameEnabled = true;
             * }
             */
            if (null != titleLink && titleLink == true)
            {
                TitleLinkEnabled = true;
            }
            if (null != summary && summary == true)
            {
                SummaryEnabled = true;
            }
            if (null != link && link == true)
            {
                LinkEnabled = true;
            }
            if (null != tags && tags == true)
            {
                TagsEnabled = true;
            }
            if (null != image && image == true)
            {
                ImageEnabled = true;
            }
            if (null != image && image == true)
            {
                ImageEnabled = true;
            }
            return(Page());
        }