public Pet(DynamicContent dynamicContent) { this.Id = dynamicContent.Id; this.Name = dynamicContent.GetValue <Lstring>("Name"); this.Age = dynamicContent.GetValue <decimal?>("Age"); this.Breed = dynamicContent.GetValue <Lstring>("Breed"); }
private IEnumerable <SocCodeContentItem> GetSocRelatedItems(DynamicContent childItem, List <Guid> parentItemLinks, DynamicModuleManager dynamicModuleManager, string parentName) { var relatedSocContentItems = new List <SocCodeContentItem>(); var parentType = TypeResolutionService.ResolveType(ParentType); var apprenticeshipStandardsData = childItem.GetValue <TrackedList <Guid> >(Constants.ApprenticeshipStandards.ToLower()); var apprenticeshipFrameworkData = childItem.GetValue <TrackedList <Guid> >(Constants.ApprenticeshipFramework.ToLower()); foreach (var contentId in parentItemLinks) { var parentItem = dynamicModuleManager.GetDataItem(parentType, contentId); if ((parentItem.ApprovalWorkflowState == Constants.WorkflowStatusPublished || parentItem.ApprovalWorkflowState == Constants.WorkflowStatusDraft) && !parentItem.IsDeleted) { relatedSocContentItems.Add(new SocCodeContentItem { Id = childItem.Id, Title = dynamicContentExtensions.GetFieldValue <Lstring>(childItem, nameof(SocCodeContentItem.SOCCode)), SOCCode = dynamicContentExtensions.GetFieldValue <Lstring>(childItem, nameof(SocCodeContentItem.SOCCode)), Description = dynamicContentExtensions.GetFieldValue <Lstring>(childItem, nameof(SocCodeContentItem.Description)), UrlName = dynamicContentExtensions.GetFieldValue <Lstring>(childItem, nameof(SocCodeContentItem.UrlName)), ONetOccupationalCode = dynamicContentExtensions.GetFieldValue <Lstring>(childItem, nameof(SocCodeContentItem.ONetOccupationalCode)), ApprenticeshipFramework = MapClassificationData(apprenticeshipFrameworkData), ApprenticeshipStandards = MapClassificationData(apprenticeshipStandardsData), JobProfileId = dynamicContentExtensions.GetFieldValue <Guid>(parentItem, nameof(SocCodeContentItem.Id)), JobProfileTitle = dynamicContentExtensions.GetFieldValue <Lstring>(parentItem, nameof(SocCodeContentItem.Title)) }); } } return(relatedSocContentItems); }
private void ProductsList_ItemDataBound(object sender, Telerik.Web.UI.RadListViewItemEventArgs e) { if (e.Item is RadListViewDataItem) { HtmlControl heading3 = e.Item.FindControl("ProductTitle") as HtmlControl; DynamicContent productItem = ((RadListViewDataItem)e.Item).DataItem as DynamicContent; string productTitle = String.Empty; if (productItem != null) { productTitle = productItem.GetString("Title"); } if (heading3 != null) { if (productTitle.StartsWith("EU")) { HtmlGenericControl span = new HtmlGenericControl("span"); span.Attributes.Add("class", productNameSpanClass); string firstPart = productTitle.Substring(0, 2); string secondPart = productTitle.Substring(2); Literal literalEU = new Literal(); literalEU.Text = firstPart; heading3.Controls.Add(literalEU); span.InnerText = secondPart; heading3.Controls.Add(span); } else { Literal productTitleLtl = new Literal(); productTitleLtl.Text = productTitle; heading3.Controls.Add(productTitleLtl); } } //Add NavigateUrl to Policy Coverage link HyperLink policyCoverageLink = e.Item.FindControl("PolicyCoverageLink") as HyperLink; PageNode policyCoveragePageNode = productItem.GetValue("PolicyCoverageLandingPage") as PageNode; if (policyCoverageLink != null && policyCoveragePageNode != null) { policyCoverageLink.NavigateUrl = PagesUtilities.GetPageUrlByPageNode(policyCoveragePageNode); } //Add NavigateUrl to Read More link HyperLink readMoreLink = e.Item.FindControl("ReadMoreLink") as HyperLink; PageNode readMorePageNode = productItem.GetValue("ReadMoreLandingPage") as PageNode; if (readMoreLink != null && readMorePageNode != null) { readMoreLink.NavigateUrl = PagesUtilities.GetPageUrlByPageNode(readMorePageNode); } } }
private void ValidatePermission(DynamicDetailContainer container) { DynamicContent[] detailItems = (DynamicContent[])container.DataSource; DynamicContent item = detailItems[0]; var identity = ClaimsManager.GetCurrentIdentity(); var url = Request.Url.OriginalString; var loginUrl = string.Format("~/Mxg/AuthService/SignInByHelix?ReturnUrl={0}", url.UrlDecode()); try { /*var manager = DynamicModuleManager.GetManager(); * Type contentType = TypeResolutionService * .ResolveType("Telerik.Sitefinity.DynamicTypes.Model.ResourcesProtected.ProtectedResource");*/ if (item != null) { //var det = item?.Issec.DataItem as DynamicContent; //var pressitem = manager.GetDataItem(contentType, new Guid(item.GetValue("Id").ToString())); //bool isSecgrand = pressitem.IsSecurityActionTypeGranted(SecurityActionTypes.View); bool isSecgrand = item.IsSecurityActionTypeGranted(SecurityActionTypes.View); log.InfoFormat("title is {0}-:{1}, permission:{2}, userid:{3}, isNullGuid:{4}", item.GetValue("Title"), item.GetValue("Id"), isSecgrand, identity.UserId, identity.UserId.IsNullOrEmptyGuid() ); if (isSecgrand == false) { Response.Redirect(identity.UserId.IsNullOrEmptyGuid() ? loginUrl : "~/account/not-authorized"); } } // not login & not granded } catch (Exception ex) { log.InfoFormat("exception from get dynamic:{0}- inner:{1}", ex.Message, ex.InnerException?.Message); //Response.Redirect("~/account/not-authorized"); Response.Redirect(identity.UserId.IsNullOrEmptyGuid() ? loginUrl : "~/account/not-authorized"); } }
public static T?GetEnumValueOrNull <T>(this DynamicContent source, string fieldName) where T : struct, IConvertible { var sourceValue = source?.GetValue(fieldName); if (sourceValue == null) { return(default);
/// <summary> /// Get a single document from a content link /// ** Sitefinitysteve.com Extension ** /// </summary> /// <returns>Telerik.Sitefinity.Libraries.Model.Image object</returns> public static Document GetDocument(this DynamicContent item, string fieldName) { var contentLinks = (ContentLink[])item.GetValue(fieldName); ContentLink docContentLink = contentLinks.FirstOrDefault(); return((docContentLink == null) ? null : docContentLink.ChildItemId.GetDocument()); }
/// <summary> /// Get a single image from a content link /// ** Sitefinitysteve.com Extension ** /// </summary> /// <returns>Telerik.Sitefinity.Libraries.Model.Image object</returns> public static Image GetImage(this DynamicContent item, string fieldName) { var contentLinks = (ContentLink[])item.GetValue(fieldName); ContentLink imageContentLink = contentLinks.FirstOrDefault(); return((imageContentLink == null) ? null : imageContentLink.ChildItemId.GetImage()); }
public static IQueryable <DynamicContent> GetRelatedContentItems(this DynamicContent dataItem, string fieldName, string type) { var contentLinks = dataItem.GetValue <Guid[]>(fieldName); var items = contentLinks.GetDynamicContentItems(type); return(items); }
public void CreateFestival() { DynamicModuleManager dynamicModuleManager = DynamicModuleManager.GetManager(); Type festivalType = TypeResolutionService.ResolveType(HierarchicalDynamicContentTests.FestivalType); DynamicContent festivalItem = dynamicModuleManager.CreateDataItem(festivalType, HierarchicalDynamicContentTests.FestivalId, dynamicModuleManager.Provider.ApplicationName); festivalItem.SetValue("Name", "Test Name"); festivalItem.SetValue("Description", "Test Description"); festivalItem.SetValue("From", DateTime.Now); festivalItem.SetValue("To", DateTime.Now); LibrariesManager mainPictureManager = LibrariesManager.GetManager(); var mainPictureItem = mainPictureManager.GetImages().FirstOrDefault(i => i.Status == Telerik.Sitefinity.GenericContent.Model.ContentLifecycleStatus.Master); if (mainPictureItem != null) { festivalItem.CreateRelation(mainPictureItem, "MainPicture"); } Address address = new Address(); CountryElement addressCountry = Config.Get <LocationsConfig>().Countries.Values.First(x => x.Name == "United States"); address.CountryCode = addressCountry.IsoCode; address.StateCode = addressCountry.StatesProvinces.Values.First().Abbreviation; address.City = "Test City"; address.Street = "Test Street"; address.Zip = "12345"; address.Latitude = 0.00; address.Longitude = 0.00; address.MapZoomLevel = 8; festivalItem.SetValue("Address", address); festivalItem.SetString("UrlName", "TestUrlName"); festivalItem.SetValue("Owner", SecurityManager.GetCurrentUserId()); festivalItem.SetValue("PublicationDate", DateTime.Now); festivalItem.SetWorkflowStatus(dynamicModuleManager.Provider.ApplicationName, "Draft"); dynamicModuleManager.SaveChanges(); var actualFestival = dynamicModuleManager.GetDataItem(festivalType, festivalItem.Id); Assert.IsNotNull(actualFestival); Assert.AreEqual(festivalItem.GetValue("Name").ToString(), actualFestival.GetValue("Name").ToString()); Assert.AreEqual(festivalItem.GetValue("Description").ToString(), actualFestival.GetValue("Description").ToString()); Assert.AreEqual(festivalItem.GetValue("From"), actualFestival.GetValue("From")); Assert.AreEqual(festivalItem.GetValue("To"), actualFestival.GetValue("To")); Assert.AreEqual(festivalItem.GetValue("MainPicture"), actualFestival.GetValue("MainPicture")); Assert.AreEqual(festivalItem.GetValue("Address"), actualFestival.GetValue("Address")); Assert.AreEqual(festivalItem.GetValue("UrlName").ToString(), actualFestival.GetValue("UrlName").ToString()); Assert.AreEqual(festivalItem.GetValue("Owner"), actualFestival.GetValue("Owner")); Assert.AreEqual(festivalItem.GetValue("PublicationDate"), actualFestival.GetValue("PublicationDate")); }
/// <summary> /// Gets the documents from a content link array /// ** Sitefinitysteve.com Extension ** /// </summary> /// <returns>IQueryable Telerik.Sitefinity.Libraries.Model.Image</returns> public static IQueryable <Document> GetDocuments(this DynamicContent item, string fieldName) { var contentLinks = (ContentLink[])item.GetValue(fieldName); var docs = from i in contentLinks select i.ChildItemId.GetDocument(); return(docs.AsQueryable()); }
/// <summary> /// Gets the images from a content link array /// ** Sitefinitysteve.com Extension ** /// </summary> /// <returns>IQueryable Telerik.Sitefinity.Libraries.Model.Image</returns> public static IQueryable <Image> GetImages(this DynamicContent item, string fieldName) { var contentLinks = (ContentLink[])item.GetValue(fieldName); var images = from i in contentLinks select i.ChildItemId.GetImage(); return(images.AsQueryable()); }
private SocCodeItem GenerateSocData(DynamicContent jobprofileContent, DynamicContent content) { var apprenticeshipStandardsData = content?.GetValue <TrackedList <Guid> >(Constants.ApprenticeshipStandards.ToLower()); var apprenticeshipFrameworkData = content?.GetValue <TrackedList <Guid> >(Constants.ApprenticeshipFramework.ToLower()); var socCodes = new SocCodeItem { Id = dynamicContentExtensions.GetFieldValue <Guid>(content, content.Id.ToString()), SOCCode = dynamicContentExtensions.GetFieldValue <Lstring>(content, nameof(SocCode.SOCCode)), Description = dynamicContentExtensions.GetFieldValue <Lstring>(content, nameof(SocCode.Description)), UrlName = dynamicContentExtensions.GetFieldValue <Lstring>(content, nameof(SocCode.UrlName)), ONetOccupationalCode = dynamicContentExtensions.GetFieldValue <Lstring>(content, nameof(SocCode.ONetOccupationalCode)), ApprenticeshipFramework = MapClassificationData(apprenticeshipFrameworkData), ApprenticeshipStandards = MapClassificationData(apprenticeshipStandardsData) }; return(socCodes); }
public static int GetIntChoiseValueOrDefault(DynamicContent item, string property, int defaultValue = 0) { ChoiceOption propertyValue = item.GetValue(property) as ChoiceOption; if (propertyValue == null) { return defaultValue; } return Convert.ToInt32(propertyValue.PersistedValue); }
public static bool GetBoolValueOrDefault(DynamicContent item, string property, bool defaultValue = false) { object propertyValue = item.GetValue(property); if (propertyValue == null) { return defaultValue; } return Convert.ToBoolean(propertyValue); }
public static DateTime GetDateTimeValueOrDefault(DynamicContent item, string property, DateTime defaultValue = default(DateTime)) { object propertyValue = item.GetValue(property); if (propertyValue == null) { return defaultValue; } return Convert.ToDateTime(propertyValue); }
public static decimal GetDecimalValueOrDefault(DynamicContent item, string property, decimal defaultValue = 0) { object propertyValue = item.GetValue(property); if (propertyValue == null) { return defaultValue; } return Convert.ToDecimal(propertyValue); }
/// <summary> /// Get the linked Tags. /// </summary> /// <param name="item">The item to act on.</param> /// <returns> /// The tags. /// </returns> public static List <Taxon> GetTags(this DynamicContent item) { var tags = item.GetValue <TrackedList <Guid> >("Tags"); TaxonomyManager manager = TaxonomyManager.GetManager(); var taxonomyParent = manager.GetTaxonomy <Taxonomy>(TaxonomyManager.TagsTaxonomyId); var taxons = taxonomyParent.Taxa.Where(x => tags.Contains(x.Id)).ToList(); return(taxons); }
/// <summary> /// Generic Taxon control, use GetCategories or GetTags for the defaults /// </summary> /// <returns>IQueryable<HierarchicalTaxon></returns> public static List <HierarchicalTaxon> GetHierarchicalTaxons(this DynamicContent item, string fieldName, string taxonomyName) { var categories = item.GetValue <TrackedList <Guid> >(fieldName); TaxonomyManager manager = TaxonomyManager.GetManager(); var taxonomyParent = manager.GetTaxonomies <HierarchicalTaxonomy>().SingleOrDefault(x => x.Name == taxonomyName); var taxons = taxonomyParent.Taxa.Where(x => categories.Contains(x.Id)).Select(x => (HierarchicalTaxon)x); return(taxons.ToList()); }
/// <summary> /// Get the linked Categories. /// </summary> /// <param name="item">The item to act on.</param> /// <returns> /// The categories. /// </returns> public static List <HierarchicalTaxon> GetCategories(this DynamicContent item) { var categories = item.GetValue <TrackedList <Guid> >("Category"); TaxonomyManager manager = TaxonomyManager.GetManager(); var taxonomyParent = manager.GetTaxonomy <HierarchicalTaxonomy>(TaxonomyManager.CategoriesTaxonomyId); var taxons = taxonomyParent.Taxa.Where(x => categories.Contains(x.Id)).Select(x => (HierarchicalTaxon)x); return(taxons.ToList()); }
public static List <string> GetAssociatedTagNamesForContentItem(this DynamicContent item, string fieldName, List <FlatTaxon> listOfTaxa) { var taxa = new List <string>(); var contentItemIds = item.GetValue <TrackedList <Guid> >(fieldName); foreach (var tagId in contentItemIds) { var itemTaxa = listOfTaxa.FirstOrDefault(t => t.Id == tagId); if (itemTaxa != null) { taxa.Add(itemTaxa.Title); } } return(taxa); }
private PetModel CreateModel(DynamicContent dynItem) { PetModel model = new PetModel(); model.Name = dynItem.GetValue("Name").ToString(); string imgUrl = ""; Image imageField = dynItem.GetRelatedItems <Image>("Image").FirstOrDefault(); if (imageField != null) { imgUrl = imageField.Url; } model.ImageUrl = imgUrl; model.Id = dynItem.Id; return(model); }
public void CreateCity() { DynamicModuleManager dynamicModuleManager = DynamicModuleManager.GetManager(); Type cityType = TypeResolutionService.ResolveType(HierarchicalDynamicContentTests.CityType); DynamicContent cityItem = dynamicModuleManager.CreateDataItem(cityType, HierarchicalDynamicContentTests.CityId, dynamicModuleManager.Provider.ApplicationName); cityItem.SetValue("Name", "Test Name"); cityItem.SetValue("History", "Test History"); Address location = new Address(); CountryElement locationCountry = Config.Get <LocationsConfig>().Countries.Values.First(x => x.Name == "United States"); location.CountryCode = locationCountry.IsoCode; location.StateCode = locationCountry.StatesProvinces.Values.First().Abbreviation; location.City = "Test City"; location.Street = "Test Street"; location.Zip = "12345"; location.Latitude = 0.00; location.Longitude = 0.00; location.MapZoomLevel = 8; cityItem.SetValue("Location", location); LibrariesManager mainPictureManager = LibrariesManager.GetManager(); var mainPictureItem = mainPictureManager.GetImages().FirstOrDefault(i => i.Status == Telerik.Sitefinity.GenericContent.Model.ContentLifecycleStatus.Master); if (mainPictureItem != null) { cityItem.CreateRelation(mainPictureItem, "MainPicture"); } cityItem.SetString("UrlName", "TestUrlName"); cityItem.SetValue("Owner", SecurityManager.GetCurrentUserId()); cityItem.SetValue("PublicationDate", DateTime.Now); cityItem.SetWorkflowStatus(dynamicModuleManager.Provider.ApplicationName, "Draft"); dynamicModuleManager.SaveChanges(); var actualCity = dynamicModuleManager.GetDataItem(cityType, cityItem.Id); Assert.IsNotNull(actualCity); Assert.AreEqual(cityItem.GetValue("Name").ToString(), actualCity.GetValue("Name").ToString()); Assert.AreEqual(cityItem.GetValue("History").ToString(), actualCity.GetValue("History").ToString()); Assert.AreEqual(cityItem.GetValue("Location"), actualCity.GetValue("Location")); Assert.AreEqual(cityItem.GetValue("MainPicture"), actualCity.GetValue("MainPicture")); Assert.AreEqual(cityItem.GetValue("UrlName").ToString(), actualCity.GetValue("UrlName").ToString()); Assert.AreEqual(cityItem.GetValue("Owner"), actualCity.GetValue("Owner")); Assert.AreEqual(cityItem.GetValue("PublicationDate"), actualCity.GetValue("PublicationDate")); }
public void CreateCountry() { DynamicModuleManager dynamicModuleManager = DynamicModuleManager.GetManager(); Type countryType = TypeResolutionService.ResolveType(HierarchicalDynamicContentTests.CountryType); DynamicContent countryItem = dynamicModuleManager.CreateDataItem(countryType, HierarchicalDynamicContentTests.CountryId, dynamicModuleManager.Provider.ApplicationName); countryItem.SetValue("Name", "Test country"); countryItem.SetValue("Description", "Test Description"); Address location = new Address(); location.Latitude = 0.00; location.Longitude = 0.00; location.MapZoomLevel = 8; countryItem.SetValue("Location", location); LibrariesManager mainPictureManager = LibrariesManager.GetManager(); var mainPictureItem = mainPictureManager.GetImages().FirstOrDefault(i => i.Status == Telerik.Sitefinity.GenericContent.Model.ContentLifecycleStatus.Master); if (mainPictureItem != null) { countryItem.CreateRelation(mainPictureItem, "MainPicture"); } countryItem.SetString("UrlName", "TestUrlName"); countryItem.SetValue("Owner", SecurityManager.GetCurrentUserId()); countryItem.SetValue("PublicationDate", DateTime.Now); countryItem.SetWorkflowStatus(dynamicModuleManager.Provider.ApplicationName, "Draft"); dynamicModuleManager.SaveChanges(); var actualCountry = dynamicModuleManager.GetDataItem(countryType, countryItem.Id); Assert.IsNotNull(actualCountry); Assert.AreEqual(countryItem.GetValue("Name").ToString(), actualCountry.GetValue("Name").ToString()); Assert.AreEqual(countryItem.GetValue("Description").ToString(), actualCountry.GetValue("Description").ToString()); Assert.AreEqual(countryItem.GetValue("Location"), actualCountry.GetValue("Location")); Assert.AreEqual(countryItem.GetValue("MainPicture"), actualCountry.GetValue("MainPicture")); Assert.AreEqual(countryItem.GetValue("UrlName").ToString(), actualCountry.GetValue("UrlName").ToString()); Assert.AreEqual(countryItem.GetValue("Owner"), actualCountry.GetValue("Owner")); Assert.AreEqual(countryItem.GetValue("PublicationDate"), actualCountry.GetValue("PublicationDate")); }
/// <summary> /// Parses string to field tags /// </summary> /// <param name="field">The field</param> /// <param name="currentDynamicItem">DC item</param> /// <returns>string parsed string</returns> private string ParseFieldTags(string field, DynamicContent currentDynamicItem) { var tokens = new List <string>(); //Get fieldnames Regex regex = new Regex(@"\{\{(.+?)\}\}"); foreach (Match match in regex.Matches(field)) { tokens.Add(match.Groups[0].Value); } //Loop given fields string result = field; foreach (string key in tokens) { string fieldName = key; fieldName = fieldName.Replace("{{", string.Empty); fieldName = fieldName.Replace("}}", string.Empty); //Skip if it is a unknown field if (!currentDynamicItem.DoesFieldExist(fieldName)) { continue; } //get value of key string fieldValue = currentDynamicItem.GetValue <Lstring>(fieldName).ToString(); //Append if (!String.IsNullOrEmpty(fieldValue)) { result = result.Replace(key, fieldValue); } } return(removeHtml(result)); }
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); }
public static DynamicContent GetRelatedContentItem(this DynamicContent dataItem, string fieldName, string type) { var contentLink = dataItem.GetValue <Guid>(fieldName); return(contentLink.GetDynamicContent(type)); }
public static string GetStringValueOrDefault(DynamicContent item, string property, string defaultValue = null) { object propertyValue = item.GetValue(property); if (propertyValue == null) { return defaultValue; } return propertyValue.ToString(); }
/// <summary> /// Updates the OG item model. /// </summary> /// <param name="itemsType">Type of the item</param> /// <param name="ogModel">The open graph model</param> /// <param name="pageUrl">The url</param> /// <returns> true or false</returns> private bool GetDataItemByType(Type itemsType, OpengraphModuleConfig ogModel, string pageUrl) { switch (itemsType.FullName) { //Default type case "Telerik.Sitefinity.News.Model.NewsItem": NewsManager newsManager = NewsManager.GetManager(); List <Telerik.Sitefinity.News.Model.NewsItem> items = newsManager.GetNewsItems().Where(i => i.Status == ContentLifecycleStatus.Live && i.Visible == true).ToList(); Telerik.Sitefinity.News.Model.NewsItem item = items.FirstOrDefault(newsItem => newsItem.ItemDefaultUrl == pageUrl); if (item == null) { return(false); } //Default openGraphModel.ogTitle = item.Title.ToString(); //Given property if (item.DoesFieldExist(ogModel.TitlePropertyName)) { if (!String.IsNullOrEmpty(item.GetValue <Lstring>(ogModel.TitlePropertyName).ToString())) { openGraphModel.ogTitle = item.GetValue <Lstring>(ogModel.TitlePropertyName).ToString(); } } //Default OG prop if (item.DoesFieldExist("OpenGraphTitle")) { if (!String.IsNullOrEmpty(item.GetValue <Lstring>("OpenGraphTitle").ToString())) { openGraphModel.ogTitle = item.GetValue <Lstring>("OpenGraphTitle").ToString(); } } //OG prop if (item.DoesFieldExist("LgszOpenGraphTitle")) { if (!String.IsNullOrEmpty(item.GetValue <Lstring>("LgszOpenGraphTitle").ToString())) { openGraphModel.ogTitle = item.GetValue <Lstring>("LgszOpenGraphTitle").ToString(); } } //Default openGraphModel.ogDescription = item.Summary != null?item.Summary.ToString() : openGraphDefaultDescription; //Given property if (item.DoesFieldExist(ogModel.DescriptionPropertyName)) { if (!String.IsNullOrEmpty(item.GetValue <Lstring>(ogModel.DescriptionPropertyName).ToString())) { openGraphModel.ogDescription = item.GetValue <Lstring>(ogModel.DescriptionPropertyName).ToString(); } } //Default OG prop if (item.DoesFieldExist("OpenGraphDescription")) { if (!String.IsNullOrEmpty(item.GetValue <Lstring>("OpenGraphDescription").ToString())) { openGraphModel.ogDescription = item.GetValue <Lstring>("OpenGraphDescription").ToString(); } } //OG prop if (item.DoesFieldExist("LgszOpenGraphDescription")) { if (!String.IsNullOrEmpty(item.GetValue <Lstring>("LgszOpenGraphDescription").ToString())) { openGraphModel.ogDescription = item.GetValue <Lstring>("LgszOpenGraphDescription").ToString(); } } Telerik.Sitefinity.Libraries.Model.Image image = null; IDataItem newsImage = null; openGraphModel.ogImage = openGraphDefaultImage; if (item.DoesFieldExist(ogModel.ImagePropertyName)) { if (item.GetRelatedItems(ogModel.ImagePropertyName).FirstOrDefault() != null) { newsImage = item.GetRelatedItems(ogModel.ImagePropertyName).FirstOrDefault(); } } if (item.DoesFieldExist("OpenGraphImage")) { if (item.GetRelatedItems("OpenGraphImage").FirstOrDefault() != null) { newsImage = item.GetRelatedItems("OpenGraphImage").FirstOrDefault(); } } if (item.DoesFieldExist("LgszOpenGraphImage")) { if (item.GetRelatedItems("LgszOpenGraphImage").FirstOrDefault() != null) { newsImage = item.GetRelatedItems("LgszOpenGraphImage").FirstOrDefault(); } } if (newsImage != null) { image = _liberariesManager.GetImages().FirstOrDefault(ogImg => ogImg.Id == newsImage.Id); } if (image != null) { openGraphModel.ogImage = image.Url; } return(true); default: DynamicModuleManager dynamicModuleManager = DynamicModuleManager.GetManager(); try { string redirectUrl; DynamicContent currentDynamicItem = dynamicModuleManager.Provider.GetItemFromUrl(itemsType, pageUrl, true, out redirectUrl) as DynamicContent; if (currentDynamicItem == null) { return(false); } //Given property openGraphModel.ogTitle = openGraphDefaultTitle; if (!String.IsNullOrEmpty(ogModel.TitlePropertyName)) { openGraphModel.ogTitle = ParseFieldTags(ogModel.TitlePropertyName, currentDynamicItem); } //Default OG prop if (currentDynamicItem.DoesFieldExist("OpenGraphTitle")) { if (!String.IsNullOrEmpty(currentDynamicItem.GetValue <Lstring>("OpenGraphTitle").ToString())) { openGraphModel.ogTitle = currentDynamicItem.GetValue <Lstring>("OpenGraphTitle").ToString(); } } //OG prop if (currentDynamicItem.DoesFieldExist("LgszOpenGraphTitle")) { if (!String.IsNullOrEmpty(currentDynamicItem.GetValue <Lstring>("LgszOpenGraphTitle").ToString())) { openGraphModel.ogTitle = currentDynamicItem.GetValue <Lstring>("LgszOpenGraphTitle").ToString(); } } //Default openGraphModel.ogDescription = openGraphDefaultDescription; if (!String.IsNullOrEmpty(ogModel.DescriptionPropertyName)) { openGraphModel.ogDescription = ParseFieldTags(ogModel.DescriptionPropertyName, currentDynamicItem); } //Default OG prop if (currentDynamicItem.DoesFieldExist("OpenGraphDescription")) { if (!String.IsNullOrEmpty(currentDynamicItem.GetValue <Lstring>("OpenGraphDescription").ToString())) { openGraphModel.ogDescription = currentDynamicItem.GetValue <Lstring>("OpenGraphDescription").ToString(); } } //OG prop if (currentDynamicItem.DoesFieldExist("LgszOpenGraphDescription")) { if (!String.IsNullOrEmpty(currentDynamicItem.GetValue <Lstring>("LgszOpenGraphDescription").ToString())) { openGraphModel.ogDescription = currentDynamicItem.GetValue <Lstring>("LgszOpenGraphDescription").ToString(); } } Telerik.Sitefinity.Libraries.Model.Image img = null; IDataItem dynamicContentImage = null; openGraphModel.ogImage = openGraphDefaultImage; if (currentDynamicItem.DoesFieldExist(ogModel.ImagePropertyName)) { if (currentDynamicItem.GetRelatedItems(ogModel.ImagePropertyName).FirstOrDefault() != null) { dynamicContentImage = currentDynamicItem.GetRelatedItems(ogModel.ImagePropertyName).FirstOrDefault(); } } if (currentDynamicItem.DoesFieldExist("OpenGraphImage")) { if (currentDynamicItem.GetRelatedItems("OpenGraphImage").FirstOrDefault() != null) { dynamicContentImage = currentDynamicItem.GetRelatedItems("OpenGraphImage").FirstOrDefault(); } } if (currentDynamicItem.DoesFieldExist("LgszOpenGraphImage")) { if (currentDynamicItem.GetRelatedItems("LgszOpenGraphImage").FirstOrDefault() != null) { dynamicContentImage = currentDynamicItem.GetRelatedItems("LgszOpenGraphImage").FirstOrDefault(); } } if (dynamicContentImage != null) { img = _liberariesManager.GetImages().FirstOrDefault(ogImg => ogImg.Id == dynamicContentImage.Id); } if (img != null) { openGraphModel.ogImage = img.Url; } return(true); } catch (Exception) { return(false); } } }
private void AddMetaDataTagsFromArticle(DynamicContent dynamicContent) { Page.RemoveExistingPublishedTags(); // add published date tags Page.AddCustomMetaTags("Published", dynamicContent.PublicationDate.ToString("yyyy-MM-dd'T'HH:mm:ss", CultureInfo.InvariantCulture)); TaxonomyManager taxonomyManager = TaxonomyManager.GetManager(); if (dynamicContent.DoesFieldExist("Category")) { TrackedList <Guid> categoryIds = dynamicContent.GetValue("Category") as TrackedList <Guid>; if (categoryIds != null && categoryIds.Any()) { var categoryList = string.Join(",", categoryIds.Select(cid => taxonomyManager.GetTaxon(cid).Title)); Page.AddCustomMetaTags("webcategory", categoryList); } } if (dynamicContent.DoesFieldExist("resourcetypes")) { TrackedList <Guid> resourcetypesIds = dynamicContent.GetValue("resourcetypes") as TrackedList <Guid>; if (resourcetypesIds != null && resourcetypesIds.Any()) { var resourcetypesList = string.Join(",", resourcetypesIds.Select(cid => taxonomyManager.GetTaxon(cid).Title)); Page.AddCustomMetaTags("resourcetypes", resourcetypesList); } } Page.RemoveExistingModuleTags(); string modulePage = dynamicContent.GetType().Name; try { if (!AppSettingsUtility.GetValue <string>("MetaDataTags.Article.Name").IsNullOrWhitespace()) { modulePage = AppSettingsUtility.GetValue <string>("MetaDataTags.Article.Name"); } } catch (Exception) { } Page.AddCustomMetaTags("Module", modulePage); Type type; if (dynamicContent.SystemParentItem != null) { type = dynamicContent.SystemParentItem.GetType(); } else { type = dynamicContent.GetType(); } string articleType = type.FullName.Split('.')[4]; //Could change this to work with On-Scene Articles... if (articleType.ToLower().Contains("healthprogress")) { Page.AddCustomMetaTags("Publication", "Health Progress"); //Health Progress } if (dynamicContent.DoesFieldExist("author")) { var authorname = dynamicContent.Author; if (authorname != null) { Page.AddCustomMetaTags("ContentAuthor", authorname); } } var authorsFieldName = "organizationalauthors"; if (dynamicContent.DoesFieldExist(authorsFieldName)) { TrackedList <Guid> authorIds = dynamicContent.GetValue(authorsFieldName) as TrackedList <Guid>; if (authorIds != null) { var authorList = string.Join(",", authorIds.Select(cid => taxonomyManager.GetTaxon(cid).Title)); Page.AddCustomMetaTags("contentauthor", authorList); } } }
public T GetFieldValue <T>(DynamicContent contentItem, string fieldName) { return(contentItem != null && contentItem.DoesFieldExist(fieldName) ? contentItem.GetValue <T>(fieldName) : default);
protected Guid SaveImageToSitefinity(string Url, DynamicContent syncedVideoItem, string title) { try { string extension; var imageToSave = ReturnImageStreamFromUrl(Url, out extension); LibrariesManager librariesManager = LibrariesManager.GetManager(); librariesManager.Provider.SuppressSecurityChecks = true; //The album post is created as master. The masterImageId is assigned to the master version. Image image = librariesManager.CreateImage(); //Set the parent album. Album album = librariesManager.GetAlbums().Where(i => i.Title == config.ThumbLibName).SingleOrDefault(); if (album == null) { CreateNewAlbum(out album, config.ThumbLibName, librariesManager); } image.Parent = album; //Set the properties of the image. image.Title = title; image.DateCreated = DateTime.UtcNow; image.PublicationDate = DateTime.UtcNow; image.LastModified = DateTime.UtcNow; int intAppend = 0; Image imgToTest; string testName; do // Test url-name to verify doesnt exist { intAppend++; testName = Regex.Replace(title.ToLower(), @"[^\w\-\!\$\'\(\)\=\@\d_]+", "-") + "-" + intAppend; imgToTest = librariesManager.GetImages().Where(i => i.UrlName == testName).FirstOrDefault(); } while (imgToTest != null); image.UrlName = testName; //Upload the image file. librariesManager.Upload(image, imageToSave, extension); image.SetWorkflowStatus(librariesManager.Provider.ApplicationName, "Published"); librariesManager.Lifecycle.Publish(image); librariesManager.SaveChanges(); librariesManager.Provider.SuppressSecurityChecks = false; return image.Id; } catch (Exception e) { Logger.Writer.Write("The WebVideoSync process failed on video id: " + syncedVideoItem.GetValue("YouTubeVidId") + ". The title of the video that failed was: \"" + title + "\". Stack trace below:\n"); Logger.Writer.Write(e.StackTrace); return Guid.Empty; } }
public void CreateHotel() { DynamicModuleManager dynamicModuleManager = DynamicModuleManager.GetManager(); Type hotelType = TypeResolutionService.ResolveType(HierarchicalDynamicContentTests.HotelType); DynamicContent hotelItem = dynamicModuleManager.CreateDataItem(hotelType, HierarchicalDynamicContentTests.HotelId, dynamicModuleManager.Provider.ApplicationName); hotelItem.SetValue("Name", "Test Name"); hotelItem.SetValue("Overview", "Test Overview"); hotelItem.SetValue("Checkin", "Test Checkin"); hotelItem.SetValue("Checkout", "Test Checkout"); hotelItem.SetValue("FoodAndDrink", new string[] { "Option2" }); hotelItem.SetValue("Activities", new string[] { "Option2" }); hotelItem.SetValue("Rating", 25); TaxonomyManager taxonomyManager = TaxonomyManager.GetManager(); var Tag = taxonomyManager.GetTaxa <FlatTaxon>().Where(t => t.Taxonomy.Name == "Tags").FirstOrDefault(); if (Tag != null) { hotelItem.Organizer.AddTaxa("Tags", Tag.Id); } Address location = new Address(); CountryElement locationCountry = Config.Get <LocationsConfig>().Countries.Values.First(x => x.Name == "United States"); location.CountryCode = locationCountry.IsoCode; location.StateCode = locationCountry.StatesProvinces.Values.First().Abbreviation; location.City = "Test City"; location.Street = "Test Street"; location.Zip = "12345"; location.Latitude = 0.00; location.Longitude = 0.00; location.MapZoomLevel = 8; hotelItem.SetValue("Location", location); LibrariesManager mainPictureManager = LibrariesManager.GetManager(); var mainPictureItem = mainPictureManager.GetImages().FirstOrDefault(i => i.Status == Telerik.Sitefinity.GenericContent.Model.ContentLifecycleStatus.Master); if (mainPictureItem != null) { hotelItem.CreateRelation(mainPictureItem, "MainPicture"); } hotelItem.SetString("UrlName", "TestUrlName"); hotelItem.SetValue("Owner", SecurityManager.GetCurrentUserId()); hotelItem.SetValue("PublicationDate", DateTime.Now); hotelItem.SetWorkflowStatus(dynamicModuleManager.Provider.ApplicationName, "Draft"); dynamicModuleManager.SaveChanges(); var actualHotel = dynamicModuleManager.GetDataItem(hotelType, hotelItem.Id); Assert.IsNotNull(actualHotel); Assert.AreEqual(hotelItem.GetValue("Name").ToString(), actualHotel.GetValue("Name").ToString()); Assert.AreEqual(hotelItem.GetValue("Overview").ToString(), actualHotel.GetValue("Overview").ToString()); Assert.AreEqual(hotelItem.GetValue("Checkin").ToString(), actualHotel.GetValue("Checkin").ToString()); Assert.AreEqual(hotelItem.GetValue("Checkout").ToString(), actualHotel.GetValue("Checkout").ToString()); Assert.AreEqual(hotelItem.GetValue("FoodAndDrink").ToString(), actualHotel.GetValue("FoodAndDrink").ToString()); Assert.AreEqual(hotelItem.GetValue("Activities").ToString(), actualHotel.GetValue("Activities").ToString()); Assert.AreEqual(hotelItem.GetValue("Rating"), actualHotel.GetValue("Rating")); Assert.AreEqual(hotelItem.GetValue("MainPicture"), actualHotel.GetValue("MainPicture")); Assert.AreEqual(hotelItem.GetValue("Location"), actualHotel.GetValue("Location")); Assert.AreEqual(hotelItem.GetValue("UrlName").ToString(), actualHotel.GetValue("UrlName").ToString()); Assert.AreEqual(hotelItem.GetValue("Owner"), actualHotel.GetValue("Owner")); Assert.AreEqual(hotelItem.GetValue("PublicationDate"), actualHotel.GetValue("PublicationDate")); }
public JobProfileMessage ConvertFrom(DynamicContent content) { DynamicModuleManager dynamicModuleManager = DynamicModuleManager.GetManager(Constants.DynamicProvider); var jobProfileMessage = new JobProfileMessage { JobProfileId = dynamicContentExtensions.GetFieldValue <Guid>(content, content.GetContentItemIdKey()), Title = dynamicContentExtensions.GetFieldValue <Lstring>(content, nameof(JobProfileMessage.Title)), WidgetContentTitle = dynamicContentExtensions.GetFieldValue <Lstring>(content, nameof(JobProfileMessage.WidgetContentTitle)), AlternativeTitle = dynamicContentExtensions.GetFieldValue <Lstring>(content, nameof(JobProfileMessage.AlternativeTitle)), Overview = dynamicContentExtensions.GetFieldValue <Lstring>(content, nameof(JobProfileMessage.Overview)), SalaryStarter = dynamicContentExtensions.GetFieldValue <decimal?>(content, nameof(JobProfileMessage.SalaryStarter)), SalaryExperienced = dynamicContentExtensions.GetFieldValue <decimal?>(content, nameof(JobProfileMessage.SalaryExperienced)), MinimumHours = dynamicContentExtensions.GetFieldValue <decimal?>(content, nameof(JobProfileMessage.MinimumHours)), MaximumHours = dynamicContentExtensions.GetFieldValue <decimal?>(content, nameof(JobProfileMessage.MaximumHours)), CareerPathAndProgression = dynamicContentExtensions.GetFieldValue <Lstring>(content, nameof(JobProfileMessage.CareerPathAndProgression)), CourseKeywords = dynamicContentExtensions.GetFieldValue <Lstring>(content, nameof(JobProfileMessage.CourseKeywords)), //Need to use a string to get the content cannot use JobProfileMessage.JobProfileCategories as this is already used in the search //index and we will get a clash UrlName = dynamicContentExtensions.GetFieldValue <Lstring>(content, nameof(JobProfileMessage.UrlName)), IsImported = dynamicContentExtensions.GetFieldValue <bool>(content, nameof(JobProfileMessage.IsImported)), // How To Become section HowToBecomeData = htbContentPropertyConverter.ConvertFrom(content), RelatedCareersData = GetRelatedCareersData(content, Constants.RelatedCareerProfiles), Restrictions = GetRestrictions(content, RelatedRestrictionsField), OtherRequirements = dynamicContentExtensions.GetFieldValue <Lstring>(content, OtherRequirementsField), DynamicTitlePrefix = dynamicContentExtensions.GetFieldChoiceLabel(content, nameof(JobProfileMessage.DynamicTitlePrefix)), DigitalSkillsLevel = dynamicContentExtensions.GetFieldChoiceLabel(content, nameof(JobProfileMessage.DigitalSkillsLevel)), }; jobProfileMessage.IncludeInSitemap = content.IncludeInSitemap; //What You will do section jobProfileMessage.WhatYouWillDoData = GetWYDRelatedDataForJobProfiles(content); //Related Skills Data jobProfileMessage.SocSkillsMatrixData = GetSocSkillMatrixItems(content, Constants.RelatedSkills); //Get SOC Code data var socItem = dynamicContentExtensions.GetRelatedItems(content, Constants.SocField, 1).FirstOrDefault(); //SocCode Data jobProfileMessage.SocCodeData = GenerateSocData(content, socItem); //Working Pattern Details jobProfileMessage.WorkingPatternDetails = MapClassificationData(content.GetValue <TrackedList <Guid> >(Constants.WorkingPatternDetail)); //Working Hours Details jobProfileMessage.WorkingHoursDetails = MapClassificationData(content.GetValue <TrackedList <Guid> >(Constants.WorkingHoursDetail)); //Working Pattern jobProfileMessage.WorkingPattern = MapClassificationData(content.GetValue <TrackedList <Guid> >(Constants.WorkingPattern)); //Hidden Alternative Title jobProfileMessage.HiddenAlternativeTitle = MapClassificationData(content.GetValue <TrackedList <Guid> >(Constants.HiddenAlternativeTitle)); //Job Profile Specialism jobProfileMessage.JobProfileSpecialism = MapClassificationData(content.GetValue <TrackedList <Guid> >(Constants.JobProfileSpecialism)); if (socItem != null) { jobProfileMessage.SocLevelTwo = dynamicContentExtensions.GetFieldValue <Lstring>(socItem, Constants.SOCCode).ToString().Substring(0, 2); } jobProfileMessage.LastModified = dynamicContentExtensions.GetFieldValue <DateTime>(content, nameof(JobProfileMessage.LastModified)); jobProfileMessage.CanonicalName = dynamicContentExtensions.GetFieldValue <Lstring>(content, nameof(JobProfileMessage.UrlName)).ToLower(); jobProfileMessage.JobProfileCategories = GetJobCategories(dynamicContentExtensions.GetFieldValue <IList <Guid> >(content, RelatedJobProfileCategoriesField)); return(jobProfileMessage); }
public static int GetIntValueOrDefault(DynamicContent item, string property, int defaultValue = 0) { object propertyValue = item.GetValue(property); if (propertyValue == null) { return defaultValue; } return Convert.ToInt32(propertyValue); }
public override void Write(byte[] buffer, int offset, int count) { bool isDeveloper = LogiszDependencyContainer.Resolve <ILogiszUserManager>().GetLoggedOnUser().IsDeveloper; Encoding encoding = HttpContext.Current.Response.ContentEncoding; string output = encoding.GetString(buffer); var tokens = new List <string>(); string seperatorOpeningTag = config.Modules.Shortcoder.SeperatorOpeningTag; string seperatorCloseTag = config.Modules.Shortcoder.SeperatorCloseTag; //Match paterns to find out with tokens are used Regex regex = new Regex(@"" + seperatorOpeningTag + "(.+?)" + seperatorCloseTag); foreach (Match match in regex.Matches(output)) { tokens.Add(match.Groups[0].Value); } if (tokens.Count > 0) { var modified = false; for (var i = 0; i < tokens.Count; i++) { //Get manager & Type DynamicModuleManager dynamicModuleManager = DynamicModuleManager.GetManager(); Type type = TypeResolutionService.ResolveType("Telerik.Sitefinity.DynamicTypes.Model.Shortcoder.Shortcode"); //Replace brackets string token = tokens[i]; token = token.Replace(seperatorOpeningTag, string.Empty); token = token.Replace(seperatorCloseTag, string.Empty); //Get token based on token key DynamicContent dynamicModuleToken = dynamicModuleManager.GetDataItems(type).FirstOrDefault(t => t.GetValue <string>("key") == token); if (dynamicModuleToken != null) { string value = dynamicModuleToken.GetValue <Lstring>("value"); if (config.Modules.Shortcoder.Debug && isDeveloper) { value = DebugValue(value, token); } output = output.Replace(tokens[i], value); modified = true; } } //Change buffer if (modified) { buffer = Encoding.ASCII.GetBytes(output); } } this.output += output; _stream.Write(buffer, offset, buffer.Length); }