public override void Process(ImportEntityPipelineArgs args, BaseLog logger) { Assert.IsNotNull(args.Item, "The item is null."); Assert.IsNotNull(args.Language, "The language is null."); using (new SecurityDisabler()) { using (new LanguageSwitcher(args.Language)) { try { args.Item.Editing.BeginEdit(); foreach (var item in from i in args.EntityMappingItem.Children where i.TemplateID == Constants.LinkFieldMappingTypeId select i) { var cmpLinkLabelFieldName = item[Constants.LinkFieldMappingCmpLinkLabelFieldNameFieldId]; var cmpLinkFieldName = item[Constants.LinkFieldMappingCmpLinkFieldNameFieldId]; var sitecoreFieldName = item[Constants.LinkFieldMappingSitecoreFieldNameFieldId]; try { var linkLabel = args.Entity.GetPropertyValue <string>(cmpLinkLabelFieldName); var link = args.Entity.GetPropertyValue <string>(cmpLinkFieldName); if (!string.IsNullOrEmpty(link)) { LinkType linkType; if (link.ToLowerInvariant().StartsWith("http") || link.ToLowerInvariant().StartsWith("www")) { linkType = LinkType.External; } else { linkType = LinkType.Internal; } args.Item[sitecoreFieldName] = GetLinkElement(link, linkLabel, linkType); } } catch (Exception ex) { this.Logger.Error(Helper.GetLogMessageText( $"An error occurred during converting '{(object) cmpLinkLabelFieldName}' field to '{(object) sitecoreFieldName}' field. Image Field mapping ID: '{(object) item.ID}'."), ex, (object)this); } } } finally { args.Item.Editing.EndEdit(); } } } }
public override void Process(ImportEntityPipelineArgs args, BaseLog logger) { var source = args.Item.Database; var target = Factory.GetDatabase("web"); PublishOptions publishOptions = new PublishOptions(source, target, PublishMode.SingleItem, args.Item.Language, DateTime.Now) { RootItem = args.Item, Deep = true, PublishRelatedItems = true }; var publisher = new Publisher(publishOptions); publisher.PublishAsync(); Log.Info("DEMO CUSTOMIZATION : Published item " + args.Item.Name + " with id: " + args.Item.ID, this); }
public override void Process(ImportEntityPipelineArgs args, BaseLog logger) { Assert.IsNotNull(args.Item, "The item is null."); Assert.IsNotNull(args.Language, "The language is null."); Args = args; var contentHubHost = args.ConfigItem[Sitecore.Connector.CMP.Constants.MUriFieldId]; using (new SecurityDisabler()) { using (new LanguageSwitcher(args.Language)) { try { int assetIndexField = 1; args.Item.Editing.BeginEdit(); foreach (Item item in from i in args.EntityMappingItem.Children where i.TemplateID == Constants.ImageFieldMappingTypeID select i) { var cmpFieldName = item[Sitecore.Connector.CMP.Constants.FieldMappingCmpFieldNameFieldId]; var sitecoreFieldName = item[Sitecore.Connector.CMP.Constants.FieldMappingSitecoreFieldNameFieldId]; if (!int.TryParse(item[Constants.FieldMappingSitecoreAssetIndexFieldID], out assetIndexField)) { assetIndexField = 1; } var renditionField = item[Constants.FieldMappingSitecoreRenditionFieldID]; var publicLink = GetPublicLinkData(contentHubHost, args.Entity, cmpFieldName, renditionField, assetIndexField).GetAwaiter().GetResult(); if (publicLink != null && !string.IsNullOrEmpty(publicLink.URL)) { var imgElement = GetContentHubDamImageElement(contentHubHost, publicLink); args.Item[item[Sitecore.Connector.CMP.Constants.FieldMappingSitecoreFieldNameFieldId]] = imgElement; } } } finally { args.Item.Editing.EndEdit(); } } } }
public override void Process(ImportEntityPipelineArgs args, BaseLog logger) { Assert.IsNotNull((object)args.Item, "The item is null."); Assert.IsNotNull((object)args.Language, "The language is null."); using (new SecurityDisabler()) { using (new LanguageSwitcher(args.Language)) { bool flag = false; try { Log.Debug("DEMO CUSTOMIZATION: Processing Item: " + args.Item.Name, this); args.Item.Editing.BeginEdit(); args.Item[Connector.CMP.Constants.EntityIdentifierFieldId] = args.EntityIdentifier; flag = this.TryMapConfiguredFields(args); } catch { flag = false; throw; } finally { if (flag) { args.Item.Editing.EndEdit(); } else { args.Item.Editing.CancelEdit(); args.Item.Editing.BeginEdit(); args.Item[Connector.CMP.Constants.EntityIdentifierFieldId] = args.EntityIdentifier; args.Item.Editing.EndEdit(); } } } } }
internal virtual bool TryMapConfiguredFields(ImportEntityPipelineArgs args) { if (args.EntityMappingItem == null) { args.EntityMappingItem = this._cmpHelper.GetEntityMappingItem(args); } Assert.IsNotNull((object)args.EntityMappingItem, "Could not find any Entity Mapping item for the Entity Type (Schema): " + args.ContentTypeIdentifier); bool flag = false; foreach (Item obj in args.EntityMappingItem.Children.Where <Item>((Func <Item, bool>)(i => i.TemplateID == Sitecore.Connector.CMP.Constants.RelationFieldMappingTemplateId))) { string fieldName = obj[Sitecore.Connector.CMP.Constants.FieldMappingSitecoreFieldNameFieldId]; string str = obj[Sitecore.Connector.CMP.Constants.FieldMappingCmpFieldNameFieldId]; if (!string.IsNullOrEmpty(fieldName)) { if (!string.IsNullOrEmpty(str)) { try { if (obj.TemplateID == Sitecore.Connector.CMP.Constants.RelationFieldMappingTemplateId) { string cmpRelationName = obj[ Sitecore.Connector.CMP.Constants .RelationFieldMappingCmpRelationFieldNameFieldId]; if (string.IsNullOrEmpty(cmpRelationName)) { this.Logger.Error( BaseHelper.GetLogMessageText( DemoCmpFieldMapping._settings.LogMessageTitle, string.Format( "Configuration of the field mapping '{0}' is incorrect. Required fields are not specified.", (object)obj.ID)), (object)this); flag = true; continue; } if (args.Item.Fields[fieldName].Type == "CmpMultiList") { Log.Debug("DEMO CUSTOMIZATION: CmpMultiList field '" + args.Item.Fields[fieldName].Name + "' initial value: " + args.Item[fieldName], this); args.Item[fieldName] = GetListfieldValue(args.Item[fieldName], args.Item.Fields[fieldName].Source, args.Item.Database); Log.Debug("DEMO CUSTOMIZATION: CmpMultiList field '" + args.Item.Fields[fieldName].Name + "' edited with: " + args.Item[fieldName], this); } else { List <string> stringList = this._cmpHelper.TryMapRelationPropertyValues(args, cmpRelationName, str); args.Item[fieldName] = stringList.Count != 0 ? string.Join( DemoCmpFieldMapping._settings.RelationFieldMappingSeparator, (IEnumerable <string>)stringList) : string.Empty; } continue; } args.Item[fieldName] = this._mapper.Convert(args.EntityDefinition, str, args.Entity.GetPropertyValue(str)); continue; } catch (Exception ex) { this.Logger.Error(BaseHelper.GetLogMessageText( DemoCmpFieldMapping._settings.LogMessageTitle, $"An error occurred during converting '{(object)str}' field to '{(object)fieldName}' field. Field mapping ID: '{(object)obj.ID}'."), ex, (object)this); flag = true; args.Exception = ex; continue; } } } this.Logger.Error( BaseHelper.GetLogMessageText(DemoCmpFieldMapping._settings.LogMessageTitle, $"Configuration of the field mapping '{(object)obj.ID}' is incorrect. Required fields are not specified."), (object)this); flag = true; } return(!flag); }