// Insert or Update imported data into the content manager. // Call content item handlers. public void Import(XElement element, ImportContentSession importContentSession) { var elementId = element.Attribute("Id"); if (elementId == null) { return; } var identity = elementId.Value; if (String.IsNullOrWhiteSpace(identity)) { return; } var status = element.Attribute("Status"); var item = importContentSession.Get(identity, VersionOptions.Latest, XmlConvert.DecodeName(element.Name.LocalName)); if (item == null) { item = New(XmlConvert.DecodeName(element.Name.LocalName)); if (status != null && status.Value == "Draft") { Create(item, VersionOptions.Draft); } else { Create(item); } } // create a version record if import handlers need it if (item.VersionRecord == null) { item.VersionRecord = new ContentItemVersionRecord { ContentItemRecord = new ContentItemRecord { ContentType = AcquireContentTypeRecord(item.ContentType) }, Number = 1, Latest = true, Published = true }; } var context = new ImportContentContext(item, element, importContentSession); foreach (var contentHandler in Handlers) { contentHandler.Importing(context); } foreach (var contentHandler in Handlers) { contentHandler.Imported(context); } var savedItem = Get(item.Id, VersionOptions.Latest); // the item has been pre-created in the first pass of the import, create it in db if (savedItem == null) { if (status != null && status.Value == "Draft") { Create(item, VersionOptions.Draft); } else { Create(item); } } if (status == null || status.Value == Published) { Publish(item); } }
public virtual void Imported(ImportContentContext context) { }
protected override void Importing(ContentPart part, DateTimeField field, ImportContentContext context) { context.ImportAttribute(GetPrefix(field, part), "Value", v => field.Storage.Set(null, XmlConvert.ToDateTime(v, XmlDateTimeSerializationMode.Utc))); }
protected virtual void Imported(ImportContentContext context, TPart instance) { }
protected override void Importing(TagCloudPart part, ImportContentContext context) { part.Slug = context.Attribute(part.PartDefinition.Name, "Slug"); part.Buckets = Convert.ToInt32(context.Attribute(part.PartDefinition.Name, "Buckets")); }
protected override void Importing(WidgetExPart part, ImportContentContext context) { context.ImportAttribute(part.PartDefinition.Name, "HostId", s => part.Host = context.GetItemFromSession(s)); }
public void Imported(ImportContentContext context) { }
protected override void Importing(DiscountPart part, ImportContentContext context) { var name = context.Attribute(part.PartDefinition.Name, "Name"); if (!String.IsNullOrWhiteSpace(name)) { part.Name = name; } var discountString = context.Attribute(part.PartDefinition.Name, "Discount"); if (!String.IsNullOrWhiteSpace(discountString)) { part.Record.Discount = discountString; } var startDateString = context.Attribute(part.PartDefinition.Name, "StartDate"); if (String.IsNullOrWhiteSpace(startDateString)) { part.StartDate = null; } else { DateTime startDate; if (DateTime.TryParse(startDateString, out startDate)) { part.StartDate = startDate; } } var endDateString = context.Attribute(part.PartDefinition.Name, "EndDate"); if (String.IsNullOrWhiteSpace(endDateString)) { part.EndDate = null; } else { DateTime endDate; if (DateTime.TryParse(endDateString, out endDate)) { part.EndDate = endDate; } } var startQuantityString = context.Attribute(part.PartDefinition.Name, "StartQuantity"); if (String.IsNullOrWhiteSpace(startQuantityString)) { part.StartQuantity = null; } else { int startQuantity; if (int.TryParse(startQuantityString, out startQuantity)) { part.StartQuantity = startQuantity; } } var endQuantityString = context.Attribute(part.PartDefinition.Name, "EndQuantity"); if (String.IsNullOrWhiteSpace(endQuantityString)) { part.EndQuantity = null; } else { int endQuantity; if (int.TryParse(endQuantityString, out endQuantity)) { part.EndQuantity = endQuantity; } } part.Record.Roles = context.Attribute(part.PartDefinition.Name, "Roles"); part.Pattern = context.Attribute(part.PartDefinition.Name, "Pattern") ?? ""; part.Comment = context.Attribute(part.PartDefinition.Name, "Comment") ?? ""; }
protected override void Importing(SeoPart part, ImportContentContext context) { var importedTitleOverride = context.Attribute(part.PartDefinition.Name, "TitleOverride"); if (importedTitleOverride != null) { part.TitleOverride = importedTitleOverride; } var importedCanonicalUrl = context.Attribute(part.PartDefinition.Name, "CanonicalUrl"); if (importedCanonicalUrl != null) { part.CanonicalUrl = importedCanonicalUrl; } var importedKeywords = context.Attribute(part.PartDefinition.Name, "Keywords"); if (importedKeywords != null) { part.Keywords = importedKeywords; } var importedDescription = context.Attribute(part.PartDefinition.Name, "Description"); if (importedDescription != null) { part.Description = importedDescription; } var importedRobotsNoIndex = context.Attribute(part.PartDefinition.Name, "RobotsNoIndex"); if (importedRobotsNoIndex != null) { part.RobotsNoIndex = Convert.ToBoolean(importedRobotsNoIndex); } var importedRobotsNoFollow = context.Attribute(part.PartDefinition.Name, "RobotsNoFollow"); if (importedRobotsNoFollow != null) { part.RobotsNoFollow = Convert.ToBoolean(importedRobotsNoFollow); } var importedRobotsNoSnippet = context.Attribute(part.PartDefinition.Name, "RobotsNoSnippet"); if (importedRobotsNoSnippet != null) { part.RobotsNoSnippet = Convert.ToBoolean(importedRobotsNoSnippet); } var importedRobotsNoOdp = context.Attribute(part.PartDefinition.Name, "RobotsNoOdp"); if (importedRobotsNoOdp != null) { part.RobotsNoOdp = Convert.ToBoolean(importedRobotsNoOdp); } var importedRobotsNoArchive = context.Attribute(part.PartDefinition.Name, "RobotsNoArchive"); if (importedRobotsNoArchive != null) { part.RobotsNoArchive = Convert.ToBoolean(importedRobotsNoArchive); } var importedRobotsUnavailableAfter = context.Attribute(part.PartDefinition.Name, "RobotsUnavailableAfter"); if (importedRobotsUnavailableAfter != null) { part.RobotsUnavailableAfter = Convert.ToBoolean(importedRobotsUnavailableAfter); } var importedRobotsUnavailableAfterDate = context.Attribute(part.PartDefinition.Name, "RobotsUnavailableAfterDate"); if (importedRobotsUnavailableAfterDate != null) { part.RobotsUnavailableAfterDate = DateTime.Parse(importedRobotsUnavailableAfterDate); } var importedRobotsNoImageIndex = context.Attribute(part.PartDefinition.Name, "RobotsNoImageIndex"); if (importedRobotsNoImageIndex != null) { part.RobotsNoImageIndex = Convert.ToBoolean(importedRobotsNoImageIndex); } var importedGoogleNoSiteLinkSearchBox = context.Attribute(part.PartDefinition.Name, "GoogleNoSiteLinkSearchBox"); if (importedGoogleNoSiteLinkSearchBox != null) { part.GoogleNoSiteLinkSearchBox = Convert.ToBoolean(importedGoogleNoSiteLinkSearchBox); } var importedGoogleNoTranslate = context.Attribute(part.PartDefinition.Name, "GoogleNoTranslate"); if (importedGoogleNoTranslate != null) { part.GoogleNoTranslate = Convert.ToBoolean(importedGoogleNoTranslate); } var importedHideDetailMicrodata = context.Attribute(part.PartDefinition.Name, "HideDetailMicrodata"); if (importedHideDetailMicrodata != null) { part.HideDetailMicrodata = Convert.ToBoolean(importedHideDetailMicrodata); } var importedHideAggregatedMicrodata = context.Attribute(part.PartDefinition.Name, "HideAggregatedMicrodata"); if (importedHideDetailMicrodata != null) { part.HideAggregatedMicrodata = Convert.ToBoolean(importedHideAggregatedMicrodata); } }
protected override void Importing(ContentPart part, Fields.ContentPickerField field, ImportContentContext context) { var contentItemIds = context.Attribute(field.FieldDefinition.Name + "." + field.Name, "ContentItems"); if (contentItemIds != null) { field.Ids = contentItemIds.Split(',') .Select(context.GetItemFromSession) .Select(contentItem => contentItem.Id).ToArray(); } else { field.Ids = new int[0]; } }
protected override void Importing(ContentPart part, Fields.MediaPickerField field, ImportContentContext context) { context.ImportAttribute(field.FieldDefinition.Name + "." + field.Name, "Url", value => field.Url = value); context.ImportAttribute(field.FieldDefinition.Name + "." + field.Name, "AlternateText", value => field.AlternateText = value); context.ImportAttribute(field.FieldDefinition.Name + "." + field.Name, "Class", value => field.Class = value); context.ImportAttribute(field.FieldDefinition.Name + "." + field.Name, "Style", value => field.Style = value); context.ImportAttribute(field.FieldDefinition.Name + "." + field.Name, "Alignment", value => field.Alignment = value); context.ImportAttribute(field.FieldDefinition.Name + "." + field.Name, "Width", value => field.Width = Int32.Parse(value)); context.ImportAttribute(field.FieldDefinition.Name + "." + field.Name, "Height", value => field.Height = Int32.Parse(value)); }
protected override void Importing(ContentPart part, LinkField field, ImportContentContext context) { context.ImportAttribute(field.FieldDefinition.Name + "." + field.Name, "Text", v => field.Text = v); context.ImportAttribute(field.FieldDefinition.Name + "." + field.Name, "Url", v => field.Value = v); context.ImportAttribute(field.FieldDefinition.Name + "." + field.Name, "Target", v => field.Target = v); }
protected override void Importing(AvatarProfilePart part, ImportContentContext context) { context.ImportAttribute(part.PartDefinition.Name, "FileExtension", value => part.FileExtension = value); }
public async Task ImportAsync(IEnumerable <ContentItem> contentItems) { var skip = 0; var take = ImportBatchSize; var batchedContentItems = contentItems.Take(take); while (batchedContentItems.Any()) { // Preload all the versions for this batch from the database. var versionIds = batchedContentItems .Where(x => !String.IsNullOrEmpty(x.ContentItemVersionId)) .Select(x => x.ContentItemVersionId); var itemIds = batchedContentItems .Where(x => !String.IsNullOrEmpty(x.ContentItemId)) .Select(x => x.ContentItemId); var existingContentItems = await _session .Query <ContentItem, ContentItemIndex>(x => x.ContentItemId.IsIn(itemIds) && (x.Latest || x.Published || x.ContentItemVersionId.IsIn(versionIds))) .ListAsync(); var versionsToUpdate = existingContentItems.Where(c => versionIds.Any(v => String.Equals(v, c.ContentItemVersionId, StringComparison.OrdinalIgnoreCase))); var versionsThatMaybeEvicted = existingContentItems.Except(versionsToUpdate); foreach (var version in existingContentItems) { await LoadAsync(version); } foreach (var importingItem in batchedContentItems) { ContentItem originalVersion = null; if (!String.IsNullOrEmpty(importingItem.ContentItemVersionId)) { originalVersion = versionsToUpdate.FirstOrDefault(x => String.Equals(x.ContentItemVersionId, importingItem.ContentItemVersionId, StringComparison.OrdinalIgnoreCase)); } if (originalVersion == null) { // The version does not exist in the current database. var context = new ImportContentContext(importingItem); await Handlers.InvokeAsync((handler, context) => handler.ImportingAsync(context), context, _logger); var evictionVersions = versionsThatMaybeEvicted.Where(x => String.Equals(x.ContentItemId, importingItem.ContentItemId, StringComparison.OrdinalIgnoreCase)); var result = await CreateContentItemVersionAsync(importingItem, evictionVersions); if (!result.Succeeded) { if (_logger.IsEnabled(LogLevel.Error)) { _logger.LogError("Error importing content item version id '{ContentItemVersionId}' : '{Errors}'", importingItem?.ContentItemVersionId, string.Join(", ", result.Errors)); } throw new ValidationException(string.Join(", ", result.Errors)); } // Imported handlers will only be fired if the validation has been successful. // Consumers should implement validated handlers to alter the success of that operation. await ReversedHandlers.InvokeAsync((handler, context) => handler.ImportedAsync(context), context, _logger); // Re-enlist content item here in case of session queries. _session.Save(importingItem); } else { // The version exists in the database. // It is important to only import changed items. // We compare the two versions and skip importing it if they are the same. // We do this to prevent unnecessary sql updates, and because UpdateContentItemVersionAsync // may remove drafts of updated items. // This is necesary because an imported item maybe set to latest, and published. // In this case, the draft item in the system, must be removed, or there will be two drafts. // The draft item should be removed, because it would now be orphaned, as the imported published item // would be further ahead, on a timeline, between the two. var jImporting = JObject.FromObject(importingItem); // Removed Published and Latest from consideration when evaluating. // Otherwise an import of an unchanged (but published) version would overwrite a newer published version. jImporting.Remove(nameof(ContentItem.Published)); jImporting.Remove(nameof(ContentItem.Latest)); var jOriginal = JObject.FromObject(originalVersion); jOriginal.Remove(nameof(ContentItem.Published)); jOriginal.Remove(nameof(ContentItem.Latest)); if (JToken.DeepEquals(jImporting, jOriginal)) { _logger.LogInformation("Importing '{ContentItemVersionId}' skipped as it is unchanged", importingItem.ContentItemVersionId); continue; } // Handlers are only fired if the import is going ahead. var context = new ImportContentContext(importingItem, originalVersion); await Handlers.InvokeAsync((handler, context) => handler.ImportingAsync(context), context, _logger); var evictionVersions = versionsThatMaybeEvicted.Where(x => String.Equals(x.ContentItemId, importingItem.ContentItemId, StringComparison.OrdinalIgnoreCase)); var result = await UpdateContentItemVersionAsync(originalVersion, importingItem, evictionVersions); if (!result.Succeeded) { if (_logger.IsEnabled(LogLevel.Error)) { _logger.LogError("Error importing content item version id '{ContentItemVersionId}' : '{Errors}'", importingItem.ContentItemVersionId, string.Join(", ", result.Errors)); } throw new ValidationException(string.Join(", ", result.Errors)); } // Imported handlers will only be fired if the validation has been successful. // Consumers should implement validated handlers to alter the success of that operation. await ReversedHandlers.InvokeAsync((handler, context) => handler.ImportedAsync(context), context, _logger); // Re-enlist content item here in case of session queries. _session.Save(originalVersion); } } skip += ImportBatchSize; take += ImportBatchSize; batchedContentItems = contentItems.Skip(skip).Take(take); } }
/// <summary> /// /// </summary> /// <param name="part"></param> /// <param name="context"></param> protected override void Importing(EmailContactPart part, ImportContentContext context) { var emailRecord = context.Data.Element(part.PartDefinition.Name).Elements("EmailRecord"); if (emailRecord != null) { if (part.EmailRecord == null) { part.EmailRecord = new List <CommunicationEmailRecord>(); } foreach (var rec in emailRecord) { string locEmail = ""; var Email = rec.Attribute("Email"); if (Email != null) { locEmail = Email.Value; } CommunicationEmailRecord recMail = part.Record.EmailRecord.FirstOrDefault(x => x.Email == locEmail); if (recMail == null) { recMail = new CommunicationEmailRecord(); recMail.EmailContactPartRecord_Id = part.Id; recMail.Email = locEmail; recMail.DataInserimento = DateTime.Now; //valore iniziale temporaneo per poter creare il record recMail.DataModifica = DateTime.Now; //valore iniziale temporaneo per poter creare il record _repoEmail.Create(recMail); part.EmailRecord.Add(recMail); } var Language = rec.Attribute("Language"); if (Language != null) { recMail.Language = Language.Value; } var Validated = rec.Attribute("Validated"); if (Validated != null) { recMail.Validated = Convert.ToBoolean(Validated.Value); } var DataInserimento = rec.Attribute("DataInserimento"); if (DataInserimento != null) { recMail.DataInserimento = Convert.ToDateTime(DataInserimento.Value, CultureInfo.InvariantCulture); } var DataModifica = rec.Attribute("DataModifica"); if (DataModifica != null) { recMail.DataModifica = Convert.ToDateTime(DataModifica.Value, CultureInfo.InvariantCulture); } var Produzione = rec.Attribute("Produzione"); if (Produzione != null) { recMail.Produzione = Convert.ToBoolean(Produzione.Value); } var AccettatoUsoCommerciale = rec.Attribute("AccettatoUsoCommerciale"); if (AccettatoUsoCommerciale != null) { recMail.AccettatoUsoCommerciale = Convert.ToBoolean(AccettatoUsoCommerciale.Value); } var AutorizzatoTerzeParti = rec.Attribute("AutorizzatoTerzeParti"); if (AutorizzatoTerzeParti != null) { recMail.AutorizzatoTerzeParti = Convert.ToBoolean(AutorizzatoTerzeParti.Value); } var KeyUnsubscribe = rec.Attribute("KeyUnsubscribe"); if (KeyUnsubscribe != null) { recMail.KeyUnsubscribe = KeyUnsubscribe.Value; } var DataUnsubscribe = rec.Attribute("DataUnsubscribe"); if (DataUnsubscribe != null) { recMail.DataUnsubscribe = Convert.ToDateTime(DataUnsubscribe.Value, CultureInfo.InvariantCulture); } } _repoEmail.Flush(); } }
protected override void Importing(ContentPart part, YouTubeEmbedField field, ImportContentContext context) { context.ImportAttribute(field.FieldDefinition.Name + "." + field.Name, "VideoId", v => field.VideoId = v); }
protected override void Importing(ContentPart part, EnumerationField field, ImportContentContext context) { context.ImportAttribute(field.FieldDefinition.Name + "." + field.Name, "Value", v => field.Value = v); }
protected override void Importing(PipelineSettingsPart part, ImportContentContext context) { part.Record.EditorTheme = context.Attribute(part.PartDefinition.Name, "EditorTheme"); }
public void Importing(ImportContentContext context) { }
protected override void Importing(ContentWidgetsPart part, ImportContentContext context) { context.ImportAttribute(part.PartDefinition.Name, "ExcludedWidgetIdsDefinition", value => part.ExcludedWidgetIdsDefinition = value); }
public void ImportCompleted(ImportContentContext importContentContext) { }
protected override void Importing(ShapeMenuItemPart part, ImportContentContext context) { IfNotNull(context.Attribute(part.PartDefinition.Name, "ShapeType"), x => part.ShapeType = x); }
protected override void Importing(EndpointPart part, ImportContentContext context) { ImportInfoset(part, context); }
protected override void Importing(QueryPart part, ImportContentContext context) { // Don't do anything if the tag is not specified. if (context.Data.Element(part.PartDefinition.Name) == null) { return; } var queryElement = context.Data.Element(part.PartDefinition.Name); part.Record.FilterGroups.Clear(); foreach (var item in queryElement.Element("FilterGroups").Elements("FilterGroup").Select(filterGroup => new FilterGroupRecord { Filters = filterGroup.Elements("Filter").Select(filter => { var category = filter.Attribute("Category").Value; var type = filter.Attribute("Type").Value; var state = filter.Attribute("State").Value; var descriptor = _projectionManager.GetFilter(category, type); if (descriptor != null) { state = _formManager.Import(descriptor.Form, state, context); } return(new FilterRecord { Category = category, Description = filter.Attribute("Description").Value, Position = Convert.ToInt32(filter.Attribute("Position").Value), State = state, Type = type }); }).ToList() })) { part.Record.FilterGroups.Add(item); } part.Record.SortCriteria.Clear(); foreach (var item in queryElement.Element("SortCriteria").Elements("SortCriterion").Select(sortCriterion => { var category = sortCriterion.Attribute("Category").Value; var type = sortCriterion.Attribute("Type").Value; var state = sortCriterion.Attribute("State").Value; var descriptor = _projectionManager.GetFilter(category, type); if (descriptor != null) { state = _formManager.Import(descriptor.Form, state, context); } return(new SortCriterionRecord { Category = category, Description = sortCriterion.Attribute("Description").Value, Position = Convert.ToInt32(sortCriterion.Attribute("Position").Value), State = state, Type = type }); })) { part.Record.SortCriteria.Add(item); } part.Record.Layouts.Clear(); foreach (var item in queryElement.Element("Layouts").Elements("Layout").Select(layout => { var category = layout.Attribute("Category").Value; var type = layout.Attribute("Type").Value; var state = layout.Attribute("State").Value; var descriptor = _projectionManager.GetFilter(category, type); if (descriptor != null) { state = _formManager.Import(descriptor.Form, state, context); } return(new LayoutRecord { Category = category, Description = layout.Attribute("Description").Value, Display = int.Parse(layout.Attribute("Display").Value), DisplayType = layout.Attribute("DisplayType").Value, State = state, Type = type, Properties = layout.Element("Properties").Elements("Property").Select(GetProperty).ToList(), GroupProperty = GetProperty(layout.Element("Group").Element("Property")) }); })) { part.Record.Layouts.Add(item); } }
protected virtual void Imported(TContent part, ImportContentContext context) { }
protected override void Importing(ContentPart part, BooleanField field, ImportContentContext context) { context.ImportAttribute(field.FieldDefinition.Name + "." + field.Name, "Value", v => field.Value = bool.Parse(v)); }
protected override void Importing(NavigationQueryPart part, ImportContentContext context) { IfNotNull(context.Attribute(part.PartDefinition.Name, "Items"), x => part.Record.Items = Int32.Parse(x)); IfNotNull(context.Attribute(part.PartDefinition.Name, "Offset"), x => part.Record.Skip = Int32.Parse(x)); }
protected override void Importing(ContainablePart part, ImportContentContext context) { context.ImportAttribute(part.PartDefinition.Name, "Position", s => part.Position = XmlConvert.ToInt32(s)); }
protected override void Importing(SslSettingsPart part, ImportContentContext context) { base.Importing(part, context); _signals.Trigger(SslSettingsPart.CacheKey); }
protected override void Importing(AjaxifyPart part, ImportContentContext context) { context.ImportAttribute(part.PartDefinition.Name, "Ajaxify", x => part.Ajaxify = XmlConvert.ToBoolean(x)); }
public virtual void Imported(ImportContentContext context) {}
public virtual void ImportCompleted(ImportContentContext importContentContext) {}