private List <BlendedListItem> GetNewsBlendedForUrl(List <Type> dynamicContent, string url) { List <BlendedListItem> newsBlend = new List <BlendedListItem>(); if (dynamicContent.Any()) { var dynamicModuleManager = DynamicModuleManager.GetManager(); var taxonomyManager = TaxonomyManager.GetManager(); log.Info("contYpe:{0}".Fmt(dynamicContent.Count)); foreach (Type contentType in dynamicContent) { log.Info("type of:{0} with url{1}".Fmt(contentType, url)); DynamicContent content = dynamicModuleManager.GetDataItems(contentType).FirstOrDefault(bp => bp.UrlName == url); if (content != null) { log.Info("dyn content url is:{0} from {1}".Fmt(content.UrlName, url)); DynamicContent liveContent = dynamicModuleManager.Lifecycle.GetLive(content) as DynamicContent; if (liveContent != null) { List <Guid> categories = liveContent.GetValue <IList <Guid> >("Category").ToList(); Guid[] contentCategories = new Guid[0]; int hitCount = 0; contentCategories = categories.Where(c => taxonomyManager.GetTaxon <HierarchicalTaxon>(c) != null) .Select(m => m) .ToArray(); //var resultContent = BlendedNewsHelper.GetNewsItems(Providers, _searchIndex, out hitCount, contentCategories, null, 0, this.NumberOfPosts + 10); var resultContent = BlendedNewsHelper.GetNewsDocs(Providers, _searchIndex, out hitCount, contentCategories, null, 0, this.NumberOfPosts + 10); List <BlendedListItem> newsResult = SetBlendedListItems(resultContent); return(newsResult); } } } } return(newsBlend); }
private List <NewsResult> GetBlenedResult(out int hitCount, string term, int skip, int take) { //hitCount = 1; /*return new List<NewsResult>() * { * new NewsResult() * { * Content = "test", * DateField = DateTime.UtcNow, * DisplayDate = DateTime.UtcNow.ToLongDateString(), * Featured = false, * Image = null, * ImageCaption = "imgCap", * ImageId = string.Empty, * Link = "link url", * PublicationDate = DateTime.UtcNow, * Title = "Test Title", Summary = "test Summary" * } * };*/ List <NewsResult> resultSet = new List <NewsResult>(); //log.Info("content, title, Id \r\n"); var results = BlendedNewsHelper.GetNewsDocs(Providers, SearchIndex, out hitCount, Categories, term, skip, take); foreach (var result in results) { //newsResult.DisplayDate = result.GetValue("DisplayDate").ToString(); // try { var ctnType = result.GetValue("ContentType")?.ToString() ?? string.Empty; var featured = result.Fields.Any(c => c.Name == "FeaturedRank") ? result.GetValue("FeaturedRank")?.ToString() ?? string.Empty: string.Empty; NewsResult newsResult = new NewsResult() { ImageId = result.Fields.Any(c => c.Name == "FeaturedRank")? result.GetValue("ImageId")?.ToString() ?? string.Empty: string.Empty, Title = result.GetValue("Title")?.ToString() ?? string.Empty, Summary = result.GetValue("Summary")?.ToString() ?? string.Empty, Featured = !string.IsNullOrEmpty(featured) && (featured == "1" ? true : false), Content = result.GetValue("Content")?.ToString() ?? string.Empty, Link = result.Fields.Any(c => c.Name == "FeaturedRank") ? result.GetValue("Link")?.ToString() ?? string.Empty: string.Empty }; var dynaManager = DynamicModuleManager.GetManager(); string txtId = result.GetValue("Id")?.ToString() ?? String.Empty; log.InfoFormat("try to get from iD:{0} ofType:{1}-title:{2}", txtId, ctnType, newsResult.Title); try { if (!string.IsNullOrEmpty(ctnType) && !string.IsNullOrEmpty(txtId) && txtId.IsGuid()) { Guid itemId = new Guid(txtId); if (ctnType.IndexOf("BlogPost") > 0) { var manager = BlogsManager.GetManager(); var bp = manager.GetBlogPosts() //.Where(c => c.Status == Telerik.Sitefinity.GenericContent.Model.ContentLifecycleStatus.Live) .FirstOrDefault(b => b.Id == itemId); if (bp != null) { bp = manager.Lifecycle.GetLive(bp) as BlogPost; log.InfoFormat("has item:{0}-date:{1}", bp?.GetType()?.FullName, bp?.GetValue("DisplayDate")?.ToString() ?? string.Empty); newsResult.DisplayDate = bp?.GetValue("DisplayDate")?.ToString() ?? string.Empty; } } else { var item = dynaManager.GetDataItems(TypeResolutionService.ResolveType(ctnType)) .Where(c => c.Status == Telerik.Sitefinity.GenericContent.Model.ContentLifecycleStatus.Live) .FirstOrDefault(c => c.Id == itemId); log.InfoFormat("has item:{0}-date:{1}", item?.GetType()?.FullName, item?.GetValue("DisplayDate")?.ToString() ?? string.Empty); newsResult.DisplayDate = item?.GetValue("DisplayDate")?.ToString() ?? string.Empty; } /*if (result.Fields.Any(x => x.Name == "DisplayDate") && item?.GetValue("DisplayDate") != null) * { * newsResult.DisplayDate = item.GetValue("DisplayDate").ToString() ?? string.Empty; * }*/ } } catch (Exception ex) { log.InfoFormat("failedToGetDateItemType:{0}-id:{1}, msg:{2}", ctnType, txtId, ex.Message); } string formatString = "yyyyMMddHHmmssfff"; // seem like there are already assing below if (!String.IsNullOrEmpty(result.GetValue("PublicationDate")?.ToString())) { DateTime pubd = DateTime.MinValue; //DateTime dt = DateTime.ParseExact(result.GetValue("PublicationDate").ToString(), formatString, null); //newsResult.PublicationDate = dt.ToLocalTime(); DateTime.TryParseExact(result.GetValue("PublicationDate").ToString(), formatString, new CultureInfo("en-US"), DateTimeStyles.None, out pubd); newsResult.PublicationDate = pubd; //log.InfoFormat("pubd:{0}", pubd.ToString("MMMM d, yyyy")); //sb.Append("PubDate:").Append(pubd).Append("\r"); } if (result.Fields.Any(x => x.Name == "DateField")) { try { /*DateTime dt2 = DateTime.ParseExact(result.GetValue("DateField").ToString(), "MM/dd/yyyy HH:mm:ss", CultureInfo.InvariantCulture); * newsResult.DateField = dt2.ToLocalTime();*/ if (!String.IsNullOrEmpty(result.GetValue("DateField")?.ToString())) { DateTime eDateTime = DateTime.MinValue; DateTime.TryParseExact(result.GetValue("DateField").ToString(), "MM/dd/yyyy HH:mm:ss", new CultureInfo("en-US"), DateTimeStyles.None, out eDateTime); newsResult.DateField = eDateTime; //log.InfoFormat("datef:{0}", eDateTime.ToString("MMMM d, yyyy")); } } catch (Exception ex) { log.ErrorFormat("GetBlendedResult-DateField:{0}, inner:{1}, stack:{2}", ex.Message, ex.InnerException?.Message, ex.StackTrace); } } if (string.IsNullOrWhiteSpace(newsResult.Summary) && !string.IsNullOrWhiteSpace(newsResult.Content)) { newsResult.Summary = SummaryParser.GetSummary(newsResult.Content, new SummarySettings(SummaryMode.Words, 40, true)); } resultSet.Add(newsResult); } catch (Exception ex) { log.InfoFormat("bled-createNewsResult:{0}", ex.Message); } } return(resultSet); }
protected override void HandleUnknownAction(string actionName = "") { try { log.Info("Begin HandleUnknownAction. view:{0}", _viewTemplate); var dynamicModuleManager = DynamicModuleManager.GetManager(); /*if (string.IsNullOrEmpty(_viewTemplate)) * { * this.View(new EmptyResult()).ExecuteResult(ControllerContext); * * }*/ var dynamicTypes = new List <Type>(); var dynamicTypeNames = AppSettingsUtility.GetValue <string>("RelatedItems.DynamicType.List").Split('|').ToList(); foreach (var dynamicTypeName in dynamicTypeNames) { if (!string.IsNullOrWhiteSpace(dynamicTypeName)) { dynamicTypes.Add(TypeResolutionService.ResolveType("Telerik.Sitefinity.DynamicTypes.Model." + dynamicTypeName)); } } // set default if (dynamicTypes.Count == 0) { dynamicTypes.Add(TypeResolutionService.ResolveType("Telerik.Sitefinity.DynamicTypes.Model.OnSceneArticles.OnSceneArticle")); } var taxonomyManager = TaxonomyManager.GetManager(); var currentContext = System.Web.HttpContext.Current; var postUrl = currentContext.Request.Url.AbsolutePath; if (postUrl.Contains('?')) { postUrl = postUrl.Split('?').First(); log.Trace("postUrl: {0}", SitefinityExtensions.IsNullOrEmpty(postUrl) ? "There is no url available" : postUrl); } postUrl = currentContext.Request.Url.AbsolutePath.Split('/').Last(); log.Debug("postUrl: {0}", SitefinityExtensions.IsNullOrEmpty(postUrl) ? "There is no url available" : postUrl); foreach (var dynamicType in dynamicTypes) { var item = dynamicModuleManager.GetDataItems(dynamicType) .FirstOrDefault(bp => bp.UrlName == postUrl && bp.Status == Telerik.Sitefinity.GenericContent.Model.ContentLifecycleStatus.Live); if (item != null) { //log.Debug("item: {0}", SitefinityExtensions.IsNullOrEmpty(item.GetValue<Lstring>("Title").Value) ? "There is no title set" : item.GetValue<Lstring>("Title").Value); //---item = dynamicModuleManager.Lifecycle.GetLive(item) as DynamicContent; //log.Trace("Got the live version of the Blog Post."); try { //var allCategories = Enumerable.ToArray(item.GetValue<IList<Guid>>("Category")); var allCategories = item.GetValue <IList <Guid> >("Category")?.ToArray(); //log.Debug("Got a list of category ids for the post, {0}.", allCategories.Count()); List <Guid> categories = new List <Guid>(); //log.Trace("Set the list for Blended List Query."); int hitCount = 0; //log.Trace("Set the hitcount variable required for Sitefinity Search."); if (allCategories != null && allCategories.Any()) { foreach (var currGuid in allCategories) { var currTaxon = taxonomyManager.GetTaxon <HierarchicalTaxon>(currGuid); if (currTaxon != null) { //log.Debug("Got taxonomy, {0}, for the id, {1}", SitefinityExtensions.IsNullOrEmpty(currTaxon.Title.Value) ? "There is no title set" : currTaxon.Title.Value); categories.Add(currGuid); //log.Trace("Taxon added to the list for the search."); } } } IEnumerable <IDocument> resultListItems = BlendedNewsHelper.GetNewsDocs(Providers, _searchIndex, out hitCount, categories?.ToArray(), null, 0, this.NumberOfPosts + 10); List <BlendedListItem> blendedListItems = new List <BlendedListItem>(); if (resultListItems != null) { var rs = SetBlendedListItems(resultListItems); if (rs != null) { blendedListItems = rs .Where(bli => !bli.Link.Contains(item.UrlName) && !bli.Featured).Take(this.NumberOfPosts).ToList(); } } //string template = _viewTemplate; //log.Info("Finishing HandleUnknownAction"); this.View(_viewTemplate, blendedListItems).ExecuteResult(ControllerContext); } catch (Exception ex) { log.Error("Source: {0}", ex.Source); log.Error("Stack Trace: {0}", ex.StackTrace); log.Error("HandleUnknownAction-relatedContentForDyn: {0}", ex.Message); } } else { log.Debug("There was no item for the given url, ({0}).", SitefinityExtensions.IsNullOrEmpty(postUrl) ? "There is no url available" : postUrl); } } } catch (Exception ex) { log.Info("exceptionRelatedContent:{0}, inner:{1}", ex.Message, ex.InnerException?.Message); } }