//**************Actions**************// //***********************************// //***********************************// #region HandleUnknownAction protected override void HandleUnknownAction(string actionName) { log.Info("Begin HandleUnknownAction."); var blogsManager = BlogsManager.GetManager(); log.Trace("Got an instance of the BlogsManager."); var taxonomyManager = TaxonomyManager.GetManager(); log.Trace("Got an instance of the TaxonomyManager."); var currentContext = System.Web.HttpContext.Current; log.Trace("Got the Current Context."); var postUrl = currentContext.Request.Url.AbsolutePath; if (postUrl.Contains('?')) { log.Debug("postUrl contains a '?'."); postUrl = postUrl.Split('?').First(); log.Trace("postUrl: {0}", postUrl.IsNullOrEmpty() ? "There is no url available" : postUrl); } postUrl = currentContext.Request.Url.AbsolutePath.Split('/').Last(); log.Debug("postUrl: {0}", postUrl.IsNullOrEmpty() ? "There is no url available" : postUrl); var item = blogsManager.GetBlogPosts().Where(bp => bp.UrlName == postUrl).FirstOrDefault(); if (item != null) { log.Debug("item: {0}", item.Title.Value.IsNullOrEmpty() ? "There is no title set" : item.Title.Value); item = blogsManager.Lifecycle.GetLive(item) as BlogPost; log.Trace("Got the live version of the Blog Post."); try { 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."); foreach (var currGuid in allCategories) { var currTaxon = taxonomyManager.GetTaxon <HierarchicalTaxon>(currGuid); if (currTaxon != null) { log.Debug("Got taxonomy, {0}, for the id, {1}", currTaxon.Title.Value.IsNullOrEmpty() ? "There is no title set" : currTaxon.Title.Value); categories.Add(currGuid); log.Trace("Taxon added to the list for the search."); } } log.Info("Calling BlendedListHelper.GetItems."); var resultListItems = BlendedNewsHelper.GetNewsItems(Providers, _searchIndex, out hitCount, categories.ToArray(), null, 0, this.NumberOfPosts + 10); log.Info("Number of results: {0}", hitCount); log.Info("Calling SetBlendedListItems."); var blendedListItems = SetBlendedListItems(resultListItems); log.Debug("Prune the current Item if it is in the list."); blendedListItems = blendedListItems .Where(bli => !bli.Link.Contains(item.UrlName) && !bli.Featured).Take(this.NumberOfPosts).ToList(); log.Debug("Prep the template for use."); string template = _viewTemplate; log.Info("Finishing HandleUnknownAction"); this.View(template, blendedListItems).ExecuteResult(ControllerContext); } catch (Exception ex) { log.Error("Source: {0}", ex.Source); log.Error("Stack Trace: {0}", ex.StackTrace); log.Error("Message: {0}", ex.Message); } } else { log.Debug("There was no item for the given url, ({0}).", postUrl.IsNullOrEmpty() ? "There is no url available" : postUrl); } }
private List <NewsResult> GetBlenedResult_org(out int hitCount, string term, int skip, int take) { var results = BlendedNewsHelper.GetNewsItems(Providers, SearchIndex, out hitCount, Categories, term, skip, take); log.InfoFormat("There are {0}, results, prov:{1}, idx:{2}, term:{3}, take:{4}", results.HitCount, Providers?.Join(","), SearchIndex, Categories?.Join(","), term, take); List <NewsResult> resultSet = new List <NewsResult>(); //log.Info("content, title, Id \r\n"); StringBuilder sb = new StringBuilder(); foreach (var result in results) { //newsResult.DisplayDate = result.GetValue("DisplayDate").ToString(); // try { var ctnType = result.GetValue("ContentType")?.ToString() ?? string.Empty; var featured = result.GetValue("FeaturedRank")?.ToString() ?? string.Empty; NewsResult newsResult = new NewsResult() { ImageId = result.GetValue("ImageId")?.ToString() ?? 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.GetValue("Link")?.ToString() ?? 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); } //newsResult.ImageCaption = result.GetValue("ImageCaption").ToString(); // testing below /*if (!String.IsNullOrEmpty(result.GetValue("PublicationDate")?.ToString())) * { * //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 eDateTime); * newsResult.DisplayDate = eDateTime.ToLocalTime().ToShortDateString(); * }*/ /// } return(resultSet); }