private IEnumerable <WYDContentItem> GetWYDRelatedItems(DynamicContent childItem, List <Guid> parentItemLinks, DynamicModuleManager dynamicModuleManager, string parentName) { var relatedContentItems = new List <WYDContentItem>(); var parentType = TypeResolutionService.ResolveType(ParentType); foreach (var contentId in parentItemLinks) { var parentItem = dynamicModuleManager.GetDataItem(parentType, contentId); if ((parentItem.ApprovalWorkflowState == Constants.WorkflowStatusPublished || parentItem.ApprovalWorkflowState == Constants.WorkflowStatusDraft) && !parentItem.IsDeleted) { relatedContentItems.Add(new WYDContentItem { JobProfileId = dynamicContentExtensions.GetFieldValue <Guid>(parentItem, nameof(WYDContentItem.Id)), JobProfileTitle = dynamicContentExtensions.GetFieldValue <Lstring>(parentItem, nameof(WYDContentItem.Title)), Id = dynamicContentExtensions.GetFieldValue <Guid>(childItem, nameof(WYDContentItem.Id)), Title = dynamicContentExtensions.GetFieldValue <Lstring>(childItem, nameof(WYDContentItem.Title)), Description = dynamicContentExtensions.GetFieldValue <Lstring>(childItem, nameof(WYDContentItem.Description)), IsNegative = dynamicContentExtensions.GetFieldValue <bool>(childItem, nameof(WYDContentItem.IsNegative)), Url = dynamicContentExtensions.GetFieldValue <Lstring>(childItem, Constants.Url) }); } } return(relatedContentItems); }
public void CreateItem(string title, string[] relatedColors) { var providerName = string.Empty; if (ServerOperations.MultiSite().CheckIsMultisiteMode()) { providerName = "dynamicContentProvider"; } DynamicModuleManager dynamicModuleManager = DynamicModuleManager.GetManager(providerName); Type itemType = TypeResolutionService.ResolveType("Telerik.Sitefinity.DynamicTypes.Model.Module2.Item"); DynamicContent itemItem = dynamicModuleManager.CreateDataItem(itemType); itemItem.SetValue("Title", title); DynamicModuleManager relatedColorManager = DynamicModuleManager.GetManager(providerName); var relatedColorType = TypeResolutionService.ResolveType("Telerik.Sitefinity.DynamicTypes.Model.Module1.Color"); foreach (var relatedColor in relatedColors) { var relatedColorItem = relatedColorManager.GetDataItems(relatedColorType).Where("Status = Master AND Title = \"" + relatedColor + "\"").First(); itemItem.CreateRelation(relatedColorItem, "RelatedColor"); dynamicModuleManager.SaveChanges(); } itemItem.SetString("UrlName", Regex.Replace(title.ToLower(), urlNameCharsToReplace, urlNameReplaceString)); itemItem.SetValue("Owner", SecurityManager.GetCurrentUserId()); itemItem.SetValue("PublicationDate", DateTime.Now); itemItem.SetWorkflowStatus(dynamicModuleManager.Provider.ApplicationName, "Published"); dynamicModuleManager.Lifecycle.Publish(itemItem); dynamicModuleManager.SaveChanges(); }
/// <summary> /// Called by the client to retrieve the settings. /// </summary> /// <param name="itemType"></param> /// <param name="siteId"></param> /// <returns></returns> public SettingsItemContext GetSettings(string itemType, string siteId) { ServiceUtility.RequestBackendUserAuthentication(); if (itemType == null) { throw new ArgumentNullException("itemType"); } Type type = TypeResolutionService.ResolveType(itemType); if (!typeof(IGigyaDSSettingsDataContract).IsAssignableFrom(type)) { throw new Exception("The settings type specified by 'itemType' parameter must implement 'IGigyaDSSettingsDataContract' interface"); } Guid id = Guid.Empty; if (SystemManager.CurrentContext.IsMultisiteMode && !string.IsNullOrEmpty(siteId)) { id = Guid.Parse(siteId); } var settingsDataContract = (IGigyaDSSettingsDataContract)Activator.CreateInstance(type); settingsDataContract.Load(id); var inherit = settingsDataContract.SiteId == Guid.Empty; return(new SettingsItemContext(settingsDataContract, inherit)); }
private PageNode CreateBootstrapPageWithDynamicWidget() { Guid templateId = Telerik.Sitefinity.TestUtilities.CommonOperations.ServerOperations.Templates().GetTemplateIdByTitle(PageTemplateName); var pageId = ServerOperations.Pages().CreatePage("TestPage1", templateId); var pageNodeId = ServerOperations.Pages().GetPageNodeId(pageId); var pageManager = Telerik.Sitefinity.Modules.Pages.PageManager.GetManager(); var pageNode = pageManager.GetPageNode(pageNodeId); var pageDraft = pageManager.EditPage(pageNode.PageId, CultureInfo.CurrentUICulture); var mvcProxy = new MvcWidgetProxy(); mvcProxy.ControllerName = typeof(DynamicContentController).FullName; var dynamicController = new DynamicContentController(); dynamicController.Model.ContentType = TypeResolutionService.ResolveType(ResolveType); dynamicController.Model.SelectionMode = SelectionMode.AllItems; dynamicController.Model.ProviderName = FeatherWidgets.TestUtilities.CommonOperations.DynamicModulesOperations.ProviderName; mvcProxy.Settings = new ControllerSettings(dynamicController); mvcProxy.WidgetName = WidgetName; var placeHoler = "Contentplaceholder1"; var draftControlDefault = pageManager.CreateControl <PageDraftControl>(mvcProxy, placeHoler); draftControlDefault.Caption = string.Empty; pageManager.SetControlDefaultPermissions(draftControlDefault); pageDraft.Controls.Add(draftControlDefault); pageManager.PublishPageDraft(pageDraft, CultureInfo.CurrentUICulture); pageManager.SaveChanges(); return(pageNode); }
protected IQueryable SetExpression(string filterExpression, string sortExpr, int?itemsToSkip, int?itemsToTake, ref int?totalCount) { IQueryable query = null; var profileType = TypeResolutionService.ResolveType(this.ProfileTypeFullName); var skip = itemsToSkip.HasValue ? itemsToSkip.Value : 0; var take = itemsToTake.HasValue ? itemsToTake.Value : 0; try { query = this.Manager.Provider.GetItems( profileType, filterExpression, sortExpr, skip, take, ref totalCount).AsQueryable(); } catch (MemberAccessException) { this.SortExpression = DefaultSortExpression; query = this.Manager.Provider.GetItems( profileType, filterExpression, null, skip, take, ref totalCount).AsQueryable(); } return(query); }
/// <summary> /// Gets the type of the content item for specified controller. /// </summary> /// <param name="controller">The controller.</param> private Type GetItemType(ControllerBase controller) { var controllerType = controller.GetType(); Type contentType = null; var detailsAction = new ReflectedControllerDescriptor(controllerType).FindAction(controller.ControllerContext, DetailActionParamsMapper.DefaultActionName); if (detailsAction != null) { var contentParam = detailsAction.GetParameters().FirstOrDefault(); if (contentParam != null && contentParam.ParameterType.ImplementsInterface(typeof(IDataItem))) { if (typeof(DynamicContent) == contentParam.ParameterType) { var controllerName = this.GetControllerName(controller); var dynamicContentType = controller.GetDynamicContentType(controllerName); contentType = dynamicContentType != null?TypeResolutionService.ResolveType(dynamicContentType.GetFullTypeName(), throwOnError : false) : null; } else { contentType = contentParam.ParameterType; } } } return(contentType); }
public void DynamicWidgets_ContentLocationService_VerifyDynamicItemLocationOnMoreThanOnePage() { int expectedLocationsCount; var page2Name = PageName + "2"; try { var countryId = ServerOperationsFeather.DynamicModuleBooking().CreateCountry(CountryName); Type countryType = TypeResolutionService.ResolveType(ResolveTypeCountry); DynamicModuleManager dynamicModuleManager = DynamicModuleManager.GetManager(); var page1Id = ServerOperations.Pages().CreatePage(PageName); var page2Id = ServerOperations.Pages().CreatePage(page2Name); var countriesWidget = this.CreateMvcWidget(ResolveTypeCountry, WidgetNameCountries); var controls = new List <System.Web.UI.Control>(); controls.Add(countriesWidget); PageContentGenerator.AddControlsToPage(page1Id, controls); PageContentGenerator.AddControlsToPage(page2Id, controls); var locationsService = SystemManager.GetContentLocationService(); var dynamicItemLocations = locationsService.GetItemLocations(countryType, dynamicModuleManager.Provider.Name, countryId); expectedLocationsCount = 2; Assert.AreEqual(expectedLocationsCount, dynamicItemLocations.Count(), "Unexpected locations count"); } finally { ServerOperations.Pages().DeleteAllPages(); ServerOperationsFeather.DynamicModuleBooking().DeleteCountry(CountryName); } }
private static string GetProviderName(string type) { string providerName = null; if (type != null) { var itemType = TypeResolutionService.ResolveType(type); if (itemType != null) { Type managerType; ManagerBase.TryGetMappedManagerType(itemType, out managerType); if (managerType != null) { var currentSite = SystemManager.CurrentContext.CurrentSite; var provider = currentSite.GetDefaultProvider(managerType.FullName); if (provider != null) { providerName = provider.ProviderName; } } } } return(providerName); }
public static List <DynamicContent> GetCurrentSiteItems(string dynamicType, string dataSource) { Type itemType = TypeResolutionService.ResolveType(dynamicType); var managerArticle = TaxonomyManager.GetManager(); MultisiteContext multisiteContext = SystemManager.CurrentContext as MultisiteContext; var providerName = multisiteContext.CurrentSite.GetProviders(dataSource).Select(p => p.ProviderName); // Set a transaction name var transactionName = Guid.NewGuid(); // I often using Guid.NewGuid() // Set the culture name for the multilingual fields var cultureName = ""; Thread.CurrentThread.CurrentUICulture = new CultureInfo(cultureName); DynamicModuleManager dynamicModuleManager = DynamicModuleManager.GetManager(providerName.FirstOrDefault(), transactionName.ToString()); Type type = TypeResolutionService.ResolveType(dynamicType); // This is how we get the consultant items through filtering var myFilteredCollection = dynamicModuleManager.GetDataItems(type).Where(c => c.Status == ContentLifecycleStatus.Live & c.Visible); return(myFilteredCollection.ToList()); }
/// <summary> /// Creates a new hotel item. /// </summary> /// <param name="parentId">The id of the city.</param> /// <param name="title">The title of the hotel.</param> public void CreateHotel(Guid parentId, string title) { var providerName = string.Empty; if (ServerOperations.MultiSite().CheckIsMultisiteMode()) { providerName = "dynamicContentProvider"; } DynamicModuleManager dynamicModuleManager = DynamicModuleManager.GetManager(providerName); Type hotelType = TypeResolutionService.ResolveType("Telerik.Sitefinity.DynamicTypes.Model.Booking.Hotel"); DynamicContent hotelItem = dynamicModuleManager.CreateDataItem(hotelType); hotelItem.SetValue("Title", title); hotelItem.SetString("UrlName", Regex.Replace(title.ToLower(), urlNameCharsToReplace, urlNameReplaceString)); hotelItem.SetValue("Owner", SecurityManager.GetCurrentUserId()); hotelItem.SetValue("PublicationDate", DateTime.Now); hotelItem.SetWorkflowStatus(dynamicModuleManager.Provider.ApplicationName, "Published"); Type cityType = TypeResolutionService.ResolveType("Telerik.Sitefinity.DynamicTypes.Model.Booking.City"); DynamicContent parent = dynamicModuleManager.GetDataItems(cityType) .First(i => i.Id == parentId && i.Status == Telerik.Sitefinity.GenericContent.Model.ContentLifecycleStatus.Master); hotelItem.SetParent(parent.Id, cityType.FullName); dynamicModuleManager.Lifecycle.Publish(hotelItem); dynamicModuleManager.SaveChanges(); }
private static List <DynamicContent> GetQueryableContent(string type) { try { var dynamicModuleManager = DynamicModuleManager.GetManager(); var objectType = TypeResolutionService.ResolveType(type); // Fetch a collection of "live" and "visible" content items. var content = dynamicModuleManager.GetDataItems(objectType) .Where(i => i.Status == ContentLifecycleStatus.Live && i.Visible); var res = new List <DynamicContent>(); foreach (var status in content) { if (status.GetUIStatus(CultureInfo.CurrentCulture).Equals(ContentUIStatus.Published)) { res.Add(status); } } return(res); } catch (Exception ex) { return(null); } }
/// <summary> /// Creates a new country item. /// </summary> /// <param name="title">The title of the country.</param> public Guid CreateCountry(string title) { var providerName = string.Empty; if (ServerOperations.MultiSite().CheckIsMultisiteMode()) { providerName = "dynamicContentProvider"; } DynamicModuleManager dynamicModuleManager = DynamicModuleManager.GetManager(providerName); Type countryType = TypeResolutionService.ResolveType("Telerik.Sitefinity.DynamicTypes.Model.Booking.Country"); DynamicContent countryItem = dynamicModuleManager.CreateDataItem(countryType); countryItem.SetValue("Title", title); countryItem.SetString("UrlName", Regex.Replace(title.ToLower(), urlNameCharsToReplace, urlNameReplaceString)); countryItem.SetValue("Owner", SecurityManager.GetCurrentUserId()); countryItem.SetValue("PublicationDate", DateTime.Now); countryItem.SetWorkflowStatus(dynamicModuleManager.Provider.ApplicationName, "Published"); dynamicModuleManager.Lifecycle.Publish(countryItem); dynamicModuleManager.SaveChanges(); return(countryItem.Id); }
public void CreateFieldWithTitle(string title, string dynamicurl) { // Set the provider name for the DynamicModuleManager here. All available providers are listed in // Administration -> Settings -> Advanced -> DynamicModules -> Providers var providerName = string.Empty; if (ServerOperations.MultiSite().CheckIsMultisiteMode()) { providerName = "dynamicContentProvider"; } DynamicModuleManager dynamicModuleManager = DynamicModuleManager.GetManager(providerName); Type allTypes = TypeResolutionService.ResolveType("Telerik.Sitefinity.DynamicTypes.Model.AllTypesModule.Alltypes"); Telerik.Sitefinity.DynamicModules.Model.DynamicContent allTypesItem = dynamicModuleManager.CreateDataItem(allTypes); // This is how values for the properties are set allTypesItem.SetValue("Title", title); Address address = new Address(); allTypesItem.SetValue("Address", address); allTypesItem.SetString("UrlName", dynamicurl); allTypesItem.SetValue("Owner", SecurityManager.GetCurrentUserId()); allTypesItem.SetValue("PublicationDate", DateTime.Now); allTypesItem.SetWorkflowStatus(dynamicModuleManager.Provider.ApplicationName, "Published"); dynamicModuleManager.Lifecycle.Publish(allTypesItem); // You need to call SaveChanges() in order for the items to be actually persisted to data store dynamicModuleManager.SaveChanges(); }
/// <summary> /// A DynamicContent extension method that gets the parent of this item. /// Since Sitefinity broke SystemParentItem. /// </summary> /// <param name="dataItem">The data item.</param> /// <returns> /// The parent. /// </returns> public static DynamicContent GetParent(this DynamicContent dataItem) { return(dataItem.SystemParentId != Guid.Empty && !string.IsNullOrEmpty(dataItem.SystemParentType) ? DynamicModuleManager.GetManager().GetDataItem( TypeResolutionService.ResolveType(dataItem.SystemParentType), dataItem.SystemParentId) : null); }
public void DynamicWidgetDesignerContent_VerifyInvalidSortingOptionAsSetInAdvancedMode() { string sortExpession = "InvalidSortingExpression"; var itemsCount = 5; string[] publishers = { "Ivan", "George", "Steve", "Ana", "Tom" }; string[] expectedSortedItemsTitles = { "Title4", "Title3", "Title2", "Title1", "Title0" }; try { var dynamicController = new DynamicContentController(); dynamicController.Model.ContentType = TypeResolutionService.ResolveType(ResolveType); dynamicController.Model.SortExpression = sortExpession; dynamicController.Model.ProviderName = FeatherWidgets.TestUtilities.CommonOperations.DynamicModulesOperations.ProviderName; for (int i = 0; i < itemsCount; i++) { ServerOperationsFeather.DynamicModulePressArticle().CreatePressArticle("Title" + i, "Title" + i + "Url", publishers[i]); } var items = dynamicController.Model.CreateListViewModel(null, 1).Items.ToArray(); for (int i = 0; i < itemsCount; i++) { Assert.AreEqual(expectedSortedItemsTitles[i], items[i].Identifier.ToString(), "The dynamic item with this title was not found!"); } } finally { ServerOperationsFeather.DynamicModulePressArticle().DeleteDynamicItems(ServerOperationsFeather.DynamicModulePressArticle().RetrieveCollectionOfPressArticles()); } }
/// <summary> /// Gets Form controls that implement IFormPageBreak interface from "Body" placeholder /// </summary> private static IList <FormDraftControl> GetPageBreakControls(FormDraft form) { var behaviorResolver = ObjectFactory.Resolve <IControlBehaviorResolver>(); IList <FormDraftControl> orderedControls = new List <FormDraftControl>(); var bodyControls = form.Controls.Where(c => c.PlaceHolder == "Body").ToList(); var siblingId = Guid.Empty; while (bodyControls.Count > 0) { var currentControl = bodyControls.FirstOrDefault(c => c.SiblingId == siblingId); if (currentControl == null) { break; } bodyControls.Remove(currentControl); siblingId = currentControl.Id; orderedControls.Add(currentControl); } IList <FormDraftControl> pageBreakControls = new List <FormDraftControl>(); foreach (var control in orderedControls.Where(c => c.IsLayoutControl == false)) { var controlType = TypeResolutionService.ResolveType(behaviorResolver.GetBehaviorObjectType(control), false); if (controlType != null && controlType.ImplementsInterface(typeof(IFormPageBreak))) { pageBreakControls.Add(control); } } return(pageBreakControls); }
public void CreatePressArticleWithCustomTaxonomy(string title, string url, string taxonomyName, IEnumerable <string> taxonNames, bool isHierarchicalTaxonomy = false) { // Set the provider name for the DynamicModuleManager here. All available providers are listed in // Administration -> Settings -> Advanced -> DynamicModules -> Providers var providerName = string.Empty; if (ServerOperations.MultiSite().CheckIsMultisiteMode()) { providerName = "dynamicContentProvider"; } DynamicModuleManager dynamicModuleManager = DynamicModuleManager.GetManager(providerName); Type pressArticleType = TypeResolutionService.ResolveType("Telerik.Sitefinity.DynamicTypes.Model.PressRelease.PressArticle"); Telerik.Sitefinity.DynamicModules.Model.DynamicContent pressArticleItem = dynamicModuleManager.CreateDataItem(pressArticleType); // This is how values for the properties are set pressArticleItem.SetValue("Title", title); pressArticleItem.SetValue("PublishedBy", "Some PublishedBy"); pressArticleItem.SetValue("Guid", Guid.NewGuid()); this.AddCustomTaxonomy(taxonNames, taxonomyName, pressArticleItem, isHierarchicalTaxonomy); pressArticleItem.SetString("UrlName", url); pressArticleItem.SetValue("Owner", SecurityManager.GetCurrentUserId()); pressArticleItem.SetValue("PublicationDate", DateTime.Now); pressArticleItem.SetWorkflowStatus(dynamicModuleManager.Provider.ApplicationName, "Published"); dynamicModuleManager.Lifecycle.Publish(pressArticleItem); // You need to call SaveChanges() in order for the items to be actually persisted to data store dynamicModuleManager.SaveChanges(); }
public IEnumerable <Type> GetParentTypes() { var parentContentTypes = new List <Type>(); if (this.Model.ParentFilterMode == ParentFilterMode.CurrentlyOpen && !this.Model.CurrentlyOpenParentType.IsNullOrEmpty()) { if (this.Model.CurrentlyOpenParentType != DynamicContentController.AnyParentValue) { var parentType = TypeResolutionService.ResolveType(this.Model.CurrentlyOpenParentType, throwOnError: false); if (parentType != null) { parentContentTypes.Add(parentType); } } else { var dynamicContentType = this.GetDynamicContentType(); var currentParentType = dynamicContentType != null ? dynamicContentType.ParentModuleType : null; while (currentParentType != null) { var contentType = TypeResolutionService.ResolveType(currentParentType.GetFullTypeName(), throwOnError: false); if (contentType != null) { parentContentTypes.Add(contentType); } currentParentType = currentParentType.ParentModuleType; } } } return(parentContentTypes); }
private MvcWidgetProxy CreateMvcWidget(string resolveType, string widgetName, string[] selectedItemsIds = null) { var mvcProxy = new MvcWidgetProxy(); mvcProxy.ControllerName = typeof(DynamicContentController).FullName; var dynamicController = new DynamicContentController(); dynamicController.Model.ContentType = TypeResolutionService.ResolveType(resolveType); if (selectedItemsIds != null) { StringBuilder sb = new StringBuilder(); foreach (var id in selectedItemsIds) { sb.Append("\""); sb.Append(id); sb.Append("\""); if (Array.IndexOf(selectedItemsIds, id) < selectedItemsIds.Length - 1) { sb.Append(","); } } dynamicController.Model.SerializedSelectedParentsIds = "[" + sb.ToString() + "]"; } mvcProxy.Settings = new ControllerSettings(dynamicController); mvcProxy.WidgetName = widgetName; return(mvcProxy); }
private void CreateItems() { var child1Type = TypeResolutionService.ResolveType(DynamicWidgetsHierarchicalContentTests.Child1TypeName); var rootContentType = TypeResolutionService.ResolveType(DynamicWidgetsHierarchicalContentTests.RootContentTypeName); var dynamicModuleManager = DynamicModuleManager.GetManager(); var child1 = dynamicModuleManager.CreateDataItem(child1Type); child1.SetValue("Title", "Child1 title"); child1.UrlName = "Child1-title"; var child2 = dynamicModuleManager.CreateDataItem(child1Type); child2.SetValue("Title", "Child2 title"); child2.UrlName = "Child2-title"; var rootContentItem = dynamicModuleManager.CreateDataItem(rootContentType); rootContentItem.SetValue("Title", "Some Title"); rootContentItem.UrlName = "SomeUrlName"; rootContentItem.AddChildItem(child1); rootContentItem.AddChildItem(child2); dynamicModuleManager.SaveChanges(); }
/// <summary> /// Builds the related data field template. /// </summary> /// <param name="childTypeName">Name of the child type.</param> /// <param name="isMasterView">if set to <c>true</c> is master view.</param> /// <returns></returns> protected string FindRelatedDataFieldTemplatePath(string childTypeName, bool isMasterView) { var childType = TypeResolutionService.ResolveType(childTypeName, false); var templateMarkup = this.GetInlineFieldTemplatePath(isMasterView, childType); return(templateMarkup); }
/// <summary> /// Adapts item T into a DynamicContent item containing fields/values found in item T. This will also create /// any relational data found in the item. /// </summary> /// <typeparam name="T">A subclass of SitefinityContent.</typeparam> /// <param name="item">The item being adapted into a DynamicContent data item.</param> /// <param name="properties">The property info of item T.</param> /// <param name="providerName">The provider name used when retrieving the DynamicModuleManager.</param> /// <returns></returns> public static DynamicContent SetDataItemProperties <T>(this T item, PropertyInfo[] properties, string providerName) where T : SitefinityContent { SitefinityMetadataAttribute metadataAttribute = (SitefinityMetadataAttribute)item.GetType().GetCustomAttribute(typeof(SitefinityMetadataAttribute)); if (metadataAttribute == null) { throw new Exception($"Could not cast attribute to {nameof(SitefinityMetadataAttribute)}"); } var dynamicContentType = metadataAttribute.DynamicContentType; if (dynamicContentType == null) { return(null); } var resolvedDynamicContentType = TypeResolutionService.ResolveType(dynamicContentType); var dynamicModuleManager = DynamicModuleManager.GetManager(providerName); var dataItem = dynamicModuleManager.CreateDataItem(resolvedDynamicContentType); properties.ToList().ForEach(property => SetPropertyInDataItem( item, metadataAttribute, ref dataItem, property, providerName )); return(dataItem); }
public static DynamicContent GetFeaturedArticleNavigation() { var taxonomyManager = TaxonomyManager.GetManager(); var tagsTaxonomy = taxonomyManager.GetTaxonomies <FlatTaxonomy>().FirstOrDefault(s => s.Name == "Tags"); var taxa = tagsTaxonomy.Taxa.Where(c => c.Title == "Featured").FirstOrDefault(); if (taxa != null) { var itemType = TypeResolutionService.ResolveType("Telerik.Sitefinity.DynamicTypes.Model.Articles.Article"); var multisiteContext = SystemManager.CurrentContext as MultisiteContext; var providerName = multisiteContext.CurrentSite.GetProviders("Articles").Select(p => p.ProviderName).FirstOrDefault(); var transactionName = Guid.NewGuid(); var dynamicModuleManager = DynamicModuleManager.GetManager(providerName, transactionName.ToString()); var offices = dynamicModuleManager.GetDataItems(itemType).Where(o => o.Status == ContentLifecycleStatus.Live && o.Visible && o.GetValue <TrackedList <Guid> >("Tags").Contains(taxa.Id)); var cultureInfo = Thread.CurrentThread.CurrentUICulture; if (!cultureInfo.IsNeutralCulture) { offices.Where(o => o.PublishedTranslations.Contains(cultureInfo.Name)); } return(offices.OrderByDescending(a => a.GetValue <DateTime>("PublicationDate")).FirstOrDefault()); } return(null); }
/// <summary> /// Adds an antiforgery markup and scripts to the view. /// </summary> /// <param name="htmlHelper">The HTML helper which this method is extending.</param> /// <param name="retrievalScriptPath">The path to the token retrieval script.</param> /// <returns></returns> public static MvcHtmlString AddSitefinityAntiforgeryToken(this HtmlHelper htmlHelper, string retrievalScriptPath = null) { var antiForgery = ObjectFactory.IsTypeRegistered <IAntiCsrf>() ? ObjectFactory.Resolve <IAntiCsrf>() : null; var antiForgeryEnabled = antiForgery != null && antiForgery.Enabled; if (antiForgeryEnabled) { if (retrievalScriptPath == null) { var page = htmlHelper.ViewContext.HttpContext.Handler.GetPageHandler() ?? new PageProxy(null); retrievalScriptPath = page.ClientScript.GetWebResourceUrl(TypeResolutionService.ResolveType("Telerik.Sitefinity.WebSecurity.WebSecurityModule"), "Telerik.Sitefinity.WebSecurity.CSRF.TokenRetrieval.js"); } htmlHelper.Script(retrievalScriptPath, "bottom", false); var result = $@"<input type=""hidden"" value="""" name=""{antiForgery.HiddenFieldName}"" /> <input type=""hidden"" value='{antiForgery.ServicePath}' name='antiCsrfService' /> <input type=""hidden"" value='{antiForgery.CustomHeaderName}' name='antiCsrfCustomHeaderName' />"; return(MvcHtmlString.Create(result)); } else { return(MvcHtmlString.Empty); } }
public void DynamicWidgetsDesignerSingleItemSettingsTests_SetDetailTemplate() { string detailTemplate = "PressArticleNew"; string paragraphText = "Detail template"; this.pageOperations = new PagesOperations(); string testName = System.Reflection.MethodInfo.GetCurrentMethod().Name; string pageNamePrefix = testName + "DynamicPage"; string pageTitlePrefix = testName + "Dynamic Page"; string urlNamePrefix = testName + "dynamic-page"; int index = 1; string url = UrlPath.ResolveAbsoluteUrl("~/" + urlNamePrefix + index); string fileDeatil = null; string fileList = null; var dynamicCollection = ServerOperationsFeather.DynamicModulePressArticle().RetrieveCollectionOfPressArticles(); try { fileDeatil = this.CopyFile(DynamicFileName, DynamicFileFileResource); fileList = this.CopyFile(DynamicFileListName, DynamicFileListFileResource); for (int i = 0; i < this.dynamicTitles.Length; i++) { ServerOperationsFeather.DynamicModulePressArticle().CreatePressArticleItem(this.dynamicTitles[i], this.dynamicUrls[i]); } dynamicCollection = ServerOperationsFeather.DynamicModulePressArticle().RetrieveCollectionOfPressArticles(); var mvcProxy = new MvcWidgetProxy(); mvcProxy.ControllerName = typeof(DynamicContentController).FullName; var dynamicController = new DynamicContentController(); dynamicController.Model.ContentType = TypeResolutionService.ResolveType(ResolveType); dynamicController.Model.ProviderName = ((Telerik.Sitefinity.Data.DataProviderBase)dynamicCollection.First().Provider).Name; dynamicController.ListTemplateName = detailTemplate; dynamicController.DetailTemplateName = detailTemplate; mvcProxy.Settings = new ControllerSettings(dynamicController); mvcProxy.WidgetName = WidgetName; this.pageOperations.CreatePageWithControl(mvcProxy, pageNamePrefix, pageTitlePrefix, urlNamePrefix, index); string detailNewsUrl = url + dynamicCollection[0].ItemDefaultUrl; string responseContent = PageInvoker.ExecuteWebRequest(detailNewsUrl); Assert.IsTrue(responseContent.Contains(paragraphText), "The paragraph text was not found!"); Assert.IsTrue(responseContent.Contains(this.dynamicTitles[0]), "The dynamic item with this title was not found!"); Assert.IsFalse(responseContent.Contains(this.dynamicTitles[1]), "The dynamic item with this title was found!"); Assert.IsFalse(responseContent.Contains(this.dynamicTitles[2]), "The dynamic item with this title was found!"); } finally { File.Delete(fileDeatil); File.Delete(fileList); Directory.Delete(this.folderPath); this.pageOperations.DeletePages(); ServerOperationsFeather.DynamicModulePressArticle().DeleteDynamicItems(dynamicCollection); } }
public void DynamicWidgets_VerifySelectedItemsFunctionalityWithUseLimit() { this.pageOperations = new PagesOperations(); string testName = System.Reflection.MethodInfo.GetCurrentMethod().Name; string pageNamePrefix = testName + "DynamicPage"; string pageTitlePrefix = testName + "Dynamic Page"; string urlNamePrefix = testName + "dynamic-page"; int index = 1; string url = UrlPath.ResolveAbsoluteUrl("~/" + urlNamePrefix + index); try { for (int i = 0; i < 20; i++) { ServerOperationsFeather.DynamicModulePressArticle().CreatePressArticleItem("Title" + i, "Title" + i + "Url"); } var dynamicCollection = ServerOperationsFeather.DynamicModulePressArticle().RetrieveCollectionOfPressArticles(); var dynamicController = new DynamicContentController(); dynamicController.Model.ContentType = TypeResolutionService.ResolveType(ResolveType); dynamicController.Model.SelectionMode = SelectionMode.SelectedItems; dynamicController.Model.DisplayMode = ListDisplayMode.Limit; dynamicController.Model.LimitCount = 5; dynamicController.Model.SortExpression = AsSetManuallySortingOption; dynamicController.Model.ProviderName = FeatherWidgets.TestUtilities.CommonOperations.DynamicModulesOperations.ProviderName; var mvcProxy = new MvcWidgetProxy(); mvcProxy.ControllerName = typeof(DynamicContentController).FullName; mvcProxy.Settings = new ControllerSettings(dynamicController); mvcProxy.WidgetName = WidgetName; string[] selectedDynamicTitles = { "Title7", "Title15", "Title11", "Title3", "Title5", "Title8", "Title2", "Title16", "Title6" }; var selectedDynamicItems = new DynamicContent[9]; for (int i = 0; i < selectedDynamicTitles.Count(); i++) { selectedDynamicItems[i] = dynamicCollection.FirstOrDefault <DynamicContent>(n => n.UrlName == (selectedDynamicTitles[i] + "Url")); } //// SerializedSelectedItemsIds string should appear in the following format: "[\"ca782d6b-9e3d-6f9e-ae78-ff00006062c4\",\"66782d6b-9e3d-6f9e-ae78-ff00006062c4\"]" dynamicController.Model.SerializedSelectedItemsIds = "[\"" + selectedDynamicItems[0].Id.ToString() + "\"," + "\"" + selectedDynamicItems[1].Id.ToString() + "\"," + "\"" + selectedDynamicItems[2].Id.ToString() + "\"," + "\"" + selectedDynamicItems[3].Id.ToString() + "\"," + "\"" + selectedDynamicItems[4].Id.ToString() + "\"," + "\"" + selectedDynamicItems[5].Id.ToString() + "\"," + "\"" + selectedDynamicItems[6].Id.ToString() + "\"," + "\"" + selectedDynamicItems[7].Id.ToString() + "\"," + "\"" + selectedDynamicItems[8].Id.ToString() + "\"]"; this.VerifyCorrectItemsOnPageWithUseLimitsOption(mvcProxy, pageNamePrefix, pageTitlePrefix, urlNamePrefix, index, url, selectedDynamicTitles); } finally { this.pageOperations.DeletePages(); ServerOperationsFeather.DynamicModulePressArticle().DeleteDynamicItems(ServerOperationsFeather.DynamicModulePressArticle().RetrieveCollectionOfPressArticles()); } }
internal static string GetDefaultLayoutControlsHtml(TemplateDraftControl ctrlData, string layout) { // this is for getting default layout controls html if (layout.StartsWith("~/")) { using (Stream templateStream = SitefinityFile.Open(layout)) using (StreamReader reader = new StreamReader(templateStream)) { layout = reader.ReadToEnd(); } } else if (layout.EndsWith(".ascx", StringComparison.OrdinalIgnoreCase)) { Type assInfo; var assProb = ctrlData.PropertiesLang.SingleOrDefault(p => p.Name == "AssemblyInfo"); if (assProb != null && !String.IsNullOrEmpty(assProb.Value)) { assInfo = TypeResolutionService.ResolveType(assProb.Value, true); } else { assInfo = Config.Get <ControlsConfig>().ResourcesAssemblyInfo; } layout = ControlUtilities.GetTextResource(layout, assInfo); } return(layout); }
public void DynamicWidgetsDesignerContent_VerifyDynamicItemsByTagFunctionality() { try { TaxonomyManager taxonomyManager = TaxonomyManager.GetManager(); var taxonId = this.CreatePressArticleAndReturnTagId(this.tagTitles); var dynamicController = new DynamicContentController(); dynamicController.Model.ContentType = TypeResolutionService.ResolveType(ResolveType); dynamicController.Model.ProviderName = FeatherWidgets.TestUtilities.CommonOperations.DynamicModulesOperations.ProviderName; for (int i = 0; i < taxonId.Length; i++) { var tag = taxonomyManager.GetTaxa <FlatTaxon>().Where(t => t.Id == taxonId[i]).FirstOrDefault(); var modelItems = dynamicController.Model.CreateListViewModel(taxonFilter: tag, page: 1); var dynamicItems = modelItems.Items.ToList(); int itemsCount = dynamicItems.Count; Assert.AreEqual(1, itemsCount, "The count of the dynamic item is not as expected"); string title = dynamicItems[0].Fields.Title; Assert.IsTrue(title.Equals(this.dynamicTitles[i]), "The dynamic item with this title was not found!"); } } finally { ServerOperationsFeather.DynamicModulePressArticle().DeleteDynamicItems(ServerOperationsFeather.DynamicModulePressArticle().RetrieveCollectionOfPressArticles()); Telerik.Sitefinity.TestUtilities.CommonOperations.ServerOperations.Taxonomies().DeleteTags(this.tagTitles); } }
private IUrlParamsMapper GetInferredDetailActionParamsMapper(ControllerBase controller) { var controllerType = controller.GetType(); IUrlParamsMapper result = null; var detailsAction = new ReflectedControllerDescriptor(controllerType).FindAction(controller.ControllerContext, DetailActionParamsMapper.DefaultActionName); if (detailsAction != null) { var contentParam = detailsAction.GetParameters().FirstOrDefault(); if (contentParam != null && contentParam.ParameterType.ImplementsInterface(typeof(IDataItem))) { Type contentType; if (typeof(DynamicContent) == contentParam.ParameterType) { var dynamicContentType = controller.GetDynamicContentType(); contentType = dynamicContentType != null?TypeResolutionService.ResolveType(dynamicContentType.GetFullTypeName(), throwOnError : false) : null; } else { contentType = contentParam.ParameterType; } if (contentType != null) { var providerNames = this.GetModelProperty(controller, "ProviderName") as string; result = result.SetLast(new DetailActionParamsMapper(controller, contentType, () => providerNames)); } } } return(result); }
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); }