private IEnumerable <FrameworkSkillItem> GetRelatedSkillsData(DynamicContent jobProfileContent, DynamicContent content, string relatedField) { var relatedSkillsData = new List <FrameworkSkillItem>(); if (jobProfileContent.ApprovalWorkflowState == Constants.WorkflowStatusDraft && content.GetType().Name == Constants.SOCSkillsMatrix) { DynamicModuleManager dynamicModuleManager = DynamicModuleManager.GetManager(Constants.DynamicProvider); var liveItem = dynamicModuleManager.Lifecycle.GetLive(content); content = dynamicModuleManager.GetDataItem(content.GetType(), liveItem.Id); } var relatedItems = dynamicContentExtensions.GetRelatedItems(content, relatedField); if (relatedItems != null) { foreach (var relatedItem in relatedItems) { relatedSkillsData.Add(new FrameworkSkillItem { Id = dynamicContentExtensions.GetFieldValue <Guid>(relatedItem, relatedItem.GetContentItemIdKey()), Title = dynamicContentExtensions.GetFieldValue <Lstring>(relatedItem, nameof(FrameworkSkillItem.Title)), Description = dynamicContentExtensions.GetFieldValue <Lstring>(relatedItem, nameof(FrameworkSkillItem.Description)), ONetElementId = dynamicContentExtensions.GetFieldValue <Lstring>(relatedItem, nameof(FrameworkSkillItem.ONetElementId)) }); } } return(relatedSkillsData); }
private void GenerateServiceBusMessageForJobProfileUnPublish(DynamicContent item, MessageAction eventAction) { var jobProfileMessage = new JobProfileMessage(); jobProfileMessage.JobProfileId = item.OriginalContentId; jobProfileMessage.Title = dynamicContentExtensions.GetFieldValue <Lstring>(item, nameof(JobProfileMessage.Title)); serviceBusMessageProcessor.SendJobProfileMessage(jobProfileMessage, item.GetType().Name, eventAction.ToString()); }
/// <summary> /// A DynamicContent extension method that gets an original. /// </summary> /// <param name="item">Current Dynamic Content Object.</param> /// <returns> /// The original item. /// </returns> public static DynamicContent GetOriginal(this DynamicContent item) { if (item.OriginalContentId != Guid.Empty) { var manager = item.GetManager(); return(manager.GetItem(item.GetType(), item.OriginalContentId) as DynamicContent); } return(item); }
protected void submit_Click(object sender, EventArgs e) { // Get the fields value of the form var title = this.TitleBox.Text; var name = this.NameBox.Text; var number = this.NumberBox.Text; this.FormPanel.Visible = false; this.TitleBox.Text = ""; this.NameBox.Text = ""; this.NumberBox.Text = ""; this.ApprovalLbl.Text = "The Form has been sent for approval"; // Create new Dynamic Item var providerName = String.Empty; DynamicModuleManager dynamicModuleManager = DynamicModuleManager.GetManager(providerName); Type testType = TypeResolutionService.ResolveType("Telerik.Sitefinity.DynamicTypes.Model.Test.Test"); DynamicContent testItem = dynamicModuleManager.CreateDataItem(testType); // Set the values in the new Dynamic Item fields testItem.SetValue("Title", title); testItem.SetValue("Name", name); testItem.SetValue("TelephoneNumber", number); var urlName = Regex.Replace(title, @"[\\~#%&*{}/:<>?|""@ ]", "-").ToLower(); testItem.SetString("UrlName", urlName); // FIRST Check-out the Item dynamicModuleManager.Lifecycle.CheckOut(testItem); // THEN Save the changes dynamicModuleManager.SaveChanges(); // Send the Item for approval var bag = new Dictionary <string, string>(); bag.Add("ContentType", testItem.GetType().FullName); WorkflowManager.MessageWorkflow(testItem.Id, testItem.GetType(), dynamicModuleManager.Provider.ToString(), "SendForApproval", false, bag); }
private void GenerateServiceBusMessageForWYDTypes(DynamicContent item, MessageAction eventAction) { DynamicModuleManager dynamicModuleManager = DynamicModuleManager.GetManager(Constants.DynamicProvider); var contentLinksManager = ContentLinksManager.GetManager(); var parentItemContentLinks = contentLinksManager.GetContentLinks() .Where(c => c.ParentItemType == ParentType && c.ChildItemId == item.Id) .Select(c => c.ParentItemId).ToList(); var relatedWYDTypes = GetWYDRelatedItems(item, parentItemContentLinks, dynamicModuleManager, ParentType); serviceBusMessageProcessor.SendOtherRelatedTypeMessages(relatedWYDTypes, item.GetType().Name, eventAction.ToString()); }
/// <summary> /// Returns the Child Items of the current DataItems Parent, so like every content item on the same level as THIS item /// ** Sitefinitysteve.com Extension ** /// </summary> public static IQueryable <DynamicContent> GetChildrenFromParent(this DynamicContent dataItem, Type type = null) { if (type == null) { type = TypeResolutionService.ResolveType(dataItem.GetType().FullName); } if (dataItem != null) { return(DynamicContentExtensions.RetrieveDataThroughFiltering(type).Where(x => x.SystemParentItem.SystemParentId == dataItem.SystemParentId)); } else { return(new List <DynamicContent>().AsQueryable()); } }
/// <summary> /// Maps a DynamicContent object to a custom model representing that dynamic content. /// This simplifies the conversion from a Sitefinity DynamicContent object into something /// more easily usable in code. /// </summary> /// <param name="content">The DynamicContent object to be mapped.</param> /// <param name="includes">A comma separated list of related objects to additionally map, /// with each include path separated by a comma and each property in a path separated by a period. /// E.g. "Buyer.Product,Category.ParentCategory"</param> /// <typeparam name="T">The type to which the DynamicContent object should be mapped.</typeparam> /// <returns>An instantiated object of type T, with the appropriate fields mapped from the DynamicContent object.</returns> public static T MapTo <T>(this DynamicContent content, string includes = null) where T : new() { var includePaths = includes?.Split(INCLUDE_PROPS_PATH_SEPARATOR).ToList() ?? new List <string>(); if (content == null) { throw new ArgumentNullException(); } var mappedItem = new T(); var properties = mappedItem.GetType().GetProperties(); var dynamicContentProperties = content.GetType().GetProperties(); foreach (var property in properties) { // Check if this property has a relation attribute, if it does, map by getting the related value. var attributes = property.GetCustomAttributes(false); var relatedIncludePath = includePaths.FirstOrDefault(e => e.Split(INCLUDE_PROPS_ITEM_SEPARATOR).FirstOrDefault(p => p == property.Name) != null); if (relatedIncludePath != null) { // Remove the first item in the include path as we pass it down the chain. var newIncludePath = relatedIncludePath.Split(INCLUDE_PROPS_ITEM_SEPARATOR).Skip(1).Join(INCLUDE_PROPS_PATH_SEPARATOR.ToString()); var relatedContent = GetRelatedContent(content, property, newIncludePath); property.SetValue(mappedItem, relatedContent); continue; } // This property doesn't specify it comes from a relation, so map directly from the // dynamic content property with a matching name and type. var dynamicProperty = dynamicContentProperties.FirstOrDefault(e => e.Name == property.Name); if (dynamicProperty == null || dynamicProperty.PropertyType != property.PropertyType) { continue; } property.SetValue(mappedItem, dynamicProperty.GetValue(content)); } return(mappedItem); }
public void Update(DynamicContent entity, string changeComment) { if (entity == null) { throw new ArgumentNullException(nameof(entity)); } // Set a transaction name and get the version manager var transactionName = $"{entity.GetType().Name}-{DateTime.Now.Ticks}"; applicationLogger.Info($"Updating entity with transaction name {transactionName} for {entity.UrlName}"); var versionManager = VersionManager.GetManager(null, transactionName); CreateVersion(entity, changeComment, versionManager, WorkflowStatus.Draft); // Commit the transaction in order for the items to be actually persisted to data store TransactionManager.CommitTransaction(transactionName); }
private IEnumerable <RelatedSocCodeItem> GetRelatedSocsData(DynamicContent jobprofileContent, DynamicContent content, string relatedField) { var relatedSocsData = new List <RelatedSocCodeItem>(); if (jobprofileContent.ApprovalWorkflowState == Constants.WorkflowStatusDraft && content.GetType().Name == Constants.SOCSkillsMatrix) { DynamicModuleManager dynamicModuleManager = DynamicModuleManager.GetManager(Constants.DynamicProvider); var liveItem = dynamicModuleManager.Lifecycle.GetLive(content); content = dynamicModuleManager.GetDataItem(content.GetType(), liveItem.Id); } var relatedItems = dynamicContentExtensions.GetRelatedItems(content, relatedField); if (relatedItems != null) { foreach (var relatedItem in relatedItems) { relatedSocsData.Add(GetRelatedSocData(jobprofileContent, relatedItem)); } } return(relatedSocsData); }
public MessageAction GetDynamicContentEventAction(DynamicContent item) { if (item == null) { throw new ArgumentNullException("item"); } if (item.GetType().Name.ToString() == Constants.JobProfile && item.ApprovalWorkflowState.Value == Constants.WorkflowStatusPublished && item.Visible && item.Status.ToString() == Constants.ItemStatusLive) { return(MessageAction.Published); } else if (item.GetType().Name.ToString() == Constants.JobProfile && item.ApprovalWorkflowState.Value == Constants.WorkflowStatusDraft && item.Status.ToString() == Constants.ItemStatusMaster) { return(MessageAction.Draft); } else if (item.ApprovalWorkflowState.Value == Constants.WorkflowStatusPublished && !item.Visible && item.Status.ToString() == Constants.ItemStatusLive) { return(MessageAction.Deleted); } else if (item.Status.ToString() == Constants.ItemActionDeleted) { if (item.GetType().Name == Constants.SOCSkillsMatrix || item.GetType().Name == Constants.JobProfile) { return(MessageAction.Ignored); } return(MessageAction.Deleted); } else if (item.GetType().Name.ToString() != Constants.SOCSkillsMatrix && item.GetType().Name.ToString() != Constants.JobProfile && item.ApprovalWorkflowState.Value == Constants.WorkflowStatusUnpublished && item.Status.ToString() == Constants.ItemStatusMaster) { //Unpublished return(MessageAction.Deleted); } else if (item.GetType().Name.ToString() != Constants.JobProfile && item.ApprovalWorkflowState.Value == Constants.WorkflowStatusPublished && item.Status.ToString() == Constants.ItemStatusMaster) { return(MessageAction.Published); } return(MessageAction.Ignored); }
public void Publish(DynamicContent entity, string changeComment) { if (entity == null) { throw new ArgumentNullException(nameof(entity)); } //CodeReview: Consider audit / log transaction name as well, might be an useful instrument for prd troubleshooting. var transactionName = $"{entity.GetType().Name}-{DateTime.Now.Ticks}"; applicationLogger.Info($"Publishing entity with transaction name {transactionName} for {entity.UrlName}"); var versionManager = VersionManager.GetManager(null, transactionName); // You need to set appropriate workflow status // Now the item is published and can be seen in the page CreateVersion(entity, changeComment, versionManager, WorkflowStatus.Published); // We can now call the following to publish the item dynamicModuleManager.Lifecycle.Publish(entity); // Commit the transaction in order for the items to be actually persisted to data store TransactionManager.CommitTransaction(transactionName); }
/// <summary> /// Validates a DynamicContent item has a field defined, thx Stacey Schlenker for the update\testing /// </summary> /// <param name="dataItem"></param> /// <param name="field"></param> /// <returns></returns> public static bool HasValue(this DynamicContent dataItem, string field) { return(App.WorkWith().DynamicData().Type(dataItem.GetType()).Get().Fields.Any(f => f.FieldName == field)); }
public IQueryable <DynamicContent> GetRelatedItems(DynamicContent contentItem, string fieldName, int maximumItemsToReturn = Constants.DefaultMaxRelatedItems) { return((contentItem.ApprovalWorkflowState == Constants.WorkflowStatusDraft && contentItem.GetType().Name == Constants.JobProfile) ? contentItem? .GetRelatedItems <DynamicContent>(fieldName).Where(d => d.Status == ContentLifecycleStatus.Master).Take(maximumItemsToReturn) : contentItem? .GetRelatedItems <DynamicContent>(fieldName) .Where(d => d.Status == ContentLifecycleStatus.Live && d.Visible) .Take(maximumItemsToReturn)); }
public void PublishDynamicContent(DynamicContent item) { if (item == null) { throw new ArgumentNullException("eventInfo"); } DynamicModuleManager dynamicModuleManager = DynamicModuleManager.GetManager(Constants.DynamicProvider); var eventAction = dynamicContentAction.GetDynamicContentEventAction(item); //using (System.IO.StreamWriter file = new System.IO.StreamWriter(@"\logs\logger.txt", true)) //{ // //file.WriteLine($"\n| Dynamic Content Action Type - | {eventActionType.PadRight(10, ' ')}"); // file.WriteLine($" |Item Type -- {item.GetType().Name.PadRight(10, ' ')} |Item ID -- {item.Id.ToString().PadRight(15, ' ')} | Item ApprovalWorkflowState -- {item.ApprovalWorkflowState.Value.PadRight(15, ' ')} | Item Status -- {item.Status.ToString().PadRight(10, ' ')} | Item Triggered action - {eventActionType.PadRight(10, ' ')} |"); // file.WriteLine($"*********************************************************************************************************************************************************\n"); //} applicationLogger.Trace($"Got event - |{item.GetType().Name.PadRight(15, ' ')} -- {item.Id.ToString().PadRight(15, ' ')} |{item.ApprovalWorkflowState.Value.PadRight(15, ' ')} | {item.Status.ToString().PadRight(15, ' ')} | Derived action - {eventAction.ToString().PadRight(15, ' ')}"); try { if (eventAction == MessageAction.Ignored) { return; } switch (item.GetType().Name) { case Constants.JobProfile: if (eventAction == MessageAction.Published || eventAction == MessageAction.Draft) { GenerateServiceBusMessageForJobProfile(item, eventAction); } else { GenerateServiceBusMessageForJobProfileUnPublish(item, eventAction); } break; case Constants.Restriction: case Constants.Registration: case Constants.ApprenticeshipRequirement: case Constants.CollegeRequirement: case Constants.UniversityRequirement: GenerateServiceBusMessageForInfoTypes(item, eventAction); break; case Constants.Uniform: case Constants.Location: case Constants.Environment: GenerateServiceBusMessageForWYDTypes(item, eventAction); break; case Constants.UniversityLink: case Constants.CollegeLink: case Constants.ApprenticeshipLink: GenerateServiceBusMessageForTextFieldTypes(item, eventAction); break; case Constants.Skill: GenerateServiceBusMessageForSkillTypes(item, eventAction); break; case Constants.JobProfileSoc: GenerateServiceBusMessageForSocCodeType(item, eventAction); break; case Constants.SOCSkillsMatrix: //For all the Dynamic content types we are using Jobprofile as Parent Type //and for only Skills we are using SocSkillsMatrix Type as the Parent Type var liveVersionItem = item; if (item.Status.ToString() != Constants.ItemStatusLive) { var liveItem = dynamicModuleManager.Lifecycle.GetLive(item); liveVersionItem = dynamicModuleManager.GetDataItem(item.GetType(), liveItem.Id); } else { var masterItem = dynamicModuleManager.Lifecycle.GetMaster(item); item = dynamicModuleManager.GetDataItem(item.GetType(), masterItem.Id); } SkillsMatrixParentItems = GetParentItemsForSocSkillsMatrix(item); GenerateServiceBusMessageForSocSkillsMatrixType(liveVersionItem, item, eventAction); break; default: break; } } catch (Exception ex) { applicationLogger.ErrorJustLogIt($"Failed to export data for item id {item.Id}", ex); throw; } }
private void GenerateServiceBusMessageForJobProfile(DynamicContent item, MessageAction eventAction) { JobProfileMessage jobprofileData = dynamicContentConverter.ConvertFrom(item); serviceBusMessageProcessor.SendJobProfileMessage(jobprofileData, item.GetType().Name, eventAction.ToString()); }
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); } } }