protected override SyncAttempt <XElement> SerializeCore(IMedia item) { var node = InitializeNode(item, item.ContentType.Alias); var info = SerializeInfo(item); var properties = SerializeProperties(item); node.Add(info); node.Add(properties); return(SyncAttempt <XElement> .Succeed( item.Name, node, typeof(IMedia), ChangeType.Export)); }
public virtual SyncAttempt <XElement> SerializeEmpty(TObject item, SyncActionType change, string alias) { logger.Debug <TObject>("Base: Serializing Empty Element (Delete or rename) {0}", alias); if (string.IsNullOrEmpty(alias)) { alias = ItemAlias(item); } var node = new XElement(uSyncConstants.Serialization.Empty, new XAttribute("Key", item.Key), new XAttribute("Alias", alias), new XAttribute("Change", change)); return(SyncAttempt <XElement> .Succeed("Empty", node, ChangeType.Removed)); }
protected override SyncAttempt <XElement> SerializeCore(FormDataSource item, SyncSerializerOptions options) { var node = this.InitializeBaseNode(item, item.Name); var info = new XElement("Info"); info.Add(new XElement("Name", item.Name)); info.Add(new XElement("FormDataSourceTypeId", item.FormDataSourceTypeId)); node.Add(info); var settingsJson = JsonConvert.SerializeObject(item.Settings, Formatting.Indented); node.Add(new XElement("Settings", new XCData(settingsJson))); return(SyncAttempt <XElement> .Succeed(item.Name, node, ChangeType.Export)); }
protected override SyncAttempt <XElement> SerializeCore(IContentType item) { var node = SerializeBase(item); var info = SerializeInfo(item); var parent = item.ContentTypeComposition.FirstOrDefault(x => x.Id == item.ParentId); if (parent != null) { info.Add(new XElement("Parent", parent.Alias, new XAttribute("Key", parent.Key))); } else if (item.Level != 1) { var folderNode = this.GetFolderNode(contentTypeService.GetContainers(item)); if (folderNode != null) { info.Add(folderNode); } } // compositions ? info.Add(SerializeCompostions((ContentTypeCompositionBase)item)); // templates var templateAlias = (item.DefaultTemplate != null && item.DefaultTemplate.Id != 0) ? item.DefaultTemplate.Alias : ""; info.Add(new XElement("DefaultTemplate", templateAlias)); var templates = SerailizeTemplates(item); if (templates != null) { info.Add(templates); } node.Add(info); node.Add(SerializeStructure(item)); node.Add(SerializeProperties(item)); node.Add(SerializeTabs(item)); return(SyncAttempt <XElement> .Succeed(item.Name, node, typeof(IContentType), ChangeType.Export)); }
protected override SyncAttempt <IDictionaryItem> DeserializeCore(XElement node) { var item = FindItem(node); var info = node.Element("Info"); var alias = node.GetAlias(); Guid?parentKey = null; var parentItemKey = info.Element("Parent").ValueOrDefault(string.Empty); if (parentItemKey != string.Empty) { var parent = localizationService.GetDictionaryItemByKey(parentItemKey); if (parent != null) { parentKey = parent.Key; } } var key = node.GetKey(); if (item == null) { item = new DictionaryItem(parentKey, alias); item.Key = key; } else { item.ParentId = parentKey; } if (item.ItemKey != alias) { item.ItemKey = alias; } if (item.Key != key) { item.Key = key; } DeserializeTranslations(item, node); return(SyncAttempt <IDictionaryItem> .Succeed(item.ItemKey, item, ChangeType.Import)); }
public override SyncAttempt <IContent> DesearlizeSecondPass(IContent item, XElement node) { base.DeserializeMappedIds(item, node); int sortOrder = node.Attribute("sortOrder").ValueOrDefault(-1); if (sortOrder >= 0) { item.SortOrder = sortOrder; } var published = node.Attribute("published").ValueOrDefault(false); PublishOrSave(item, published, true); return(SyncAttempt <IContent> .Succeed(item.Name, ChangeType.Import)); }
protected override SyncAttempt <IMemberType> DeserializeCore(XElement node) { var item = FindOrCreate(node); DeserializeBase(item, node); DeserializeTabs(item, node); DeserializeProperties(item, node); CleanTabs(item, node); // memberTypeService.Save(item); return(SyncAttempt <IMemberType> .Succeed( item.Name, item, ChangeType.Import, "")); }
public override SyncAttempt <IContentType> DeserializeSecondPass(IContentType item, XElement node, SyncSerializerOptions options) { logger.Debug <ContentTypeSerializer>("Deserialize Second Pass {0}", item.Alias); var details = new List <uSyncChange>(); details.AddRange(DeserializeCompositions(item, node)); details.AddRange(DeserializeStructure(item, node)); if (!options.Flags.HasFlag(SerializerFlags.DoNotSave) && item.IsDirty()) { contentTypeService.Save(item); } CleanFolder(item, node); return(SyncAttempt <IContentType> .Succeed(item.Name, item, ChangeType.Import, details)); }
protected override SyncAttempt <XElement> SerializeCore(IDictionaryItem item, SyncSerializerOptions options) { var node = InitializeBaseNode(item, item.ItemKey, GetLevel(item)); // if we are serializing by culture, then add the culture attribute here. var cultures = options.GetSetting(uSyncConstants.CultureKey, string.Empty); if (!string.IsNullOrWhiteSpace(cultures)) { node.Add(new XAttribute(uSyncConstants.CultureKey, cultures)); } var info = new XElement("Info"); if (item.ParentId.HasValue) { var parent = FindItem(item.ParentId.Value); if (parent != null) { info.Add(new XElement("Parent", parent.ItemKey)); } } var activeCultures = options.GetCultures(); var translationsNode = new XElement("Translations"); foreach (var translation in item.Translations .SafeDistinctBy(x => x.Language.IsoCode) .OrderBy(x => x.Language.IsoCode)) { if (activeCultures.IsValid(translation.Language.IsoCode)) { translationsNode.Add(new XElement("Translation", translation.Value, new XAttribute("Language", translation.Language.IsoCode))); } } node.Add(info); node.Add(translationsNode); return(SyncAttempt <XElement> .Succeed( item.ItemKey, node, typeof(IDictionaryItem), ChangeType.Export)); }
/// <summary> /// second pass we set the default language again (because you can't just set it) /// </summary> public override SyncAttempt <ILanguage> DeserializeSecondPass(ILanguage item, XElement node, SerializerFlags flags) { logger.Debug <LanguageSerializer>("Language Second Pass {IsoCode}", item.IsoCode); item.IsDefault = node.Element("IsDefault").ValueOrDefault(false); var fallbackId = GetFallbackLanguageId(item, node); if (fallbackId > 0) { item.FallbackLanguageId = fallbackId; } if (!flags.HasFlag(SerializerFlags.DoNotSave) && item.IsDirty()) { localizationService.Save(item); } return(SyncAttempt <ILanguage> .Succeed(item.CultureName, item, ChangeType.Import)); }
protected override SyncAttempt <XElement> SerializeCore(FieldPreValueSource item, SyncSerializerOptions options) { var node = new XElement(ItemType, new XAttribute("Key", ItemKey(item)), new XAttribute("Alias", ItemAlias(item))); var info = new XElement("Info"); info.Add(new XElement("Name", item.Name)); info.Add(new XElement("FieldPreValueSourceTypeId", item.FieldPreValueSourceTypeId)); node.Add(info); var settingsJson = JsonConvert.SerializeObject(item.Settings, Formatting.Indented); node.Add(new XElement("Settings", settingsJson)); return(SyncAttempt <XElement> .Succeed(item.Name, node, ChangeType.Export)); }
protected override SyncAttempt <IContent> DeserializeCore(XElement node, SyncSerializerOptions options) { var attempt = FindOrCreate(node); if (!attempt.Success) { throw attempt.Exception; } var item = attempt.Result; var details = new List <uSyncChange>(); details.AddRange(DeserializeBase(item, node, options)); details.AddNotNull(DeserializeTemplate(item, node)); details.AddRange(DeserializeSchedules(item, node, options)); return(SyncAttempt <IContent> .Succeed(item.Name, item, ChangeType.Import, details)); }
protected override SyncAttempt <IContent> DeserializeCore(XElement node) { var item = FindOrCreate(node); if (item.Trashed) { // TODO: Where has changed trashed state gone? } DeserializeBase(item, node); // contentService.Save(item); return(SyncAttempt <IContent> .Succeed( item.Name, item, ChangeType.Import, "")); }
protected override SyncAttempt <IDataType> DeserializeCore(XElement node) { var info = node.Element("Info"); var name = info.Element("Name").ValueOrDefault(string.Empty); var key = node.GetKey(); var item = FindOrCreate(node); if (item == null) { throw new ArgumentException($"Cannot find underling datatype for {name}"); } // basic item.Name = name; item.Key = key; var editorAlias = info.Element("EditorAlias").ValueOrDefault(string.Empty); if (editorAlias != item.EditorAlias) { // change the editor type..... var newEditor = Current.DataEditors.FirstOrDefault(x => x.Alias.InvariantEquals(editorAlias)); if (newEditor != null) { item.Editor = newEditor; } } item.SortOrder = info.Element("SortOrder").ValueOrDefault(0); item.DatabaseType = info.Element("DatabaseType").ValueOrDefault(ValueStorageType.Nvarchar); // config DeserializeConfiguration(item, node); SetFolderFromElement(item, info.Element("Folder")); // dataTypeService.Save(item); return(SyncAttempt <IDataType> .Succeed(item.Name, item, ChangeType.Import)); }
protected override SyncAttempt <ILanguage> DeserializeCore(XElement node) { var isoCode = node.Element("IsoCode").ValueOrDefault(string.Empty); logger.Debug <LanguageSerializer>("Derserializing {0}", isoCode); var item = localizationService.GetLanguageByIsoCode(isoCode); if (item == null) { logger.Debug <LanguageSerializer>("Creating New Language: {0}", isoCode); item = new Language(isoCode); } item.IsoCode = isoCode; try { var culture = CultureInfo.GetCultureInfo(isoCode); item.CultureName = culture.DisplayName; } catch { logger.Warn <LanguageSerializer>("Can't set culture name based on IsoCode"); } item.IsDefault = node.Element("IsDefault").ValueOrDefault(false); item.IsMandatory = node.Element("IsMandatory").ValueOrDefault(false); var fallbackId = GetFallbackLanguageId(item, node); if (fallbackId > 0) { item.FallbackLanguageId = fallbackId; } // logger.Debug<ILanguage>("Saving Language"); //localizationService.Save(item); return(SyncAttempt <ILanguage> .Succeed(item.CultureName, item, ChangeType.Import)); }
public override SyncAttempt <IContent> DeserializeSecondPass(IContent item, XElement node, SyncSerializerOptions options) { var attempt = DeserializeProperties(item, node, options); if (!attempt.Success) { return(SyncAttempt <IContent> .Fail(item.Name, ChangeType.ImportFail, attempt.Exception)); } var changes = attempt.Result; // sort order var sortOrder = node.Element("Info").Element("SortOrder").ValueOrDefault(-1); changes.AddNotNull(HandleSortOrder(item, sortOrder)); var trashed = node.Element("Info").Element("Trashed").ValueOrDefault(false); changes.AddNotNull(HandleTrashedState(item, trashed)); var publishTimer = Stopwatch.StartNew(); // published status // this does the last save and publish var saveAttempt = DoSaveOrPublish(item, node, options); if (saveAttempt.Success) { var message = attempt.Status; if (publishTimer.ElapsedMilliseconds > 10000) { message += $" (Slow publish {publishTimer.ElapsedMilliseconds}ms)"; } // we say no change back, this stops the core second pass function from saving // this item (which we have just done with DoSaveOrPublish) return(SyncAttempt <IContent> .Succeed(item.Name, item, ChangeType.NoChange, message, true, changes)); } return(SyncAttempt <IContent> .Fail(item.Name, item, ChangeType.ImportFail, $"{saveAttempt.Result} {attempt.Status}")); }
protected override SyncAttempt <XElement> SerializeCore(Form item, SyncSerializerOptions options) { var node = new XElement(ItemType, new XAttribute("Key", ItemKey(item)), new XAttribute("Alias", ItemAlias(item))); var info = new XElement("Info"); info.Add(new XElement("Name", item.Name)); // info.Add(new XElement("Created", item.Created)); info.Add(new XElement("FieldIndicationType", item.FieldIndicationType)); info.Add(new XElement("Indicator", item.Indicator)); info.Add(new XElement("ShowValidationSummary", item.ShowValidationSummary)); info.Add(new XElement("HideFieldValidation", item.HideFieldValidation)); info.Add(new XElement("RequireErrorMessage", item.RequiredErrorMessage)); info.Add(new XElement("InvalidErrorMessage", item.InvalidErrorMessage)); info.Add(new XElement("MessageOnSubmit", item.MessageOnSubmit)); info.Add(new XElement("GoToPageOnSubmit", GetContentKey(item.GoToPageOnSubmit))); info.Add(new XElement("XPathOnSubmit", item.XPathOnSubmit ?? string.Empty)); info.Add(new XElement("ManualApproval", item.ManualApproval)); info.Add(new XElement("StoreRecordsLocally", item.StoreRecordsLocally)); info.Add(new XElement("CssClass", item.CssClass ?? string.Empty)); info.Add(new XElement("DisabledDefaultStylesheet", item.DisableDefaultStylesheet)); info.Add(new XElement("UseClientDependency", item.UseClientDependency)); info.Add(SerializeWorkflows(item)); info.Add(SerializeDataSource(item.DataSource)); info.Add(new XElement("SubmitLabel", item.SubmitLabel)); info.Add(new XElement("NextLabel", item.NextLabel)); info.Add(new XElement("PreVLabel", item.PrevLabel)); node.Add(info); node.Add(SerializePages(item.Pages)); return(SyncAttempt <XElement> .Succeed(item.Name, node, ChangeType.Export)); }
internal override SyncAttempt <XElement> SerializeCore(IDataTypeDefinition item) { try { var node = new XElement(Constants.Packaging.DataTypeNodeName, new XAttribute("Name", item.Name), new XAttribute("Key", item.Key), new XAttribute("Id", item.PropertyEditorAlias), new XAttribute("DatabaseType", item.DatabaseType.ToString()) ); node.Add(SerializePreValues(item, node)); return(SyncAttempt <XElement> .Succeed(item.Name, node, typeof(IDataTypeDefinition), ChangeType.Export)); } catch (Exception ex) { LogHelper.Warn <DataTypeSerializer>("Error Serializing {0}", () => ex.ToString()); return(SyncAttempt <XElement> .Fail(item.Name, typeof(IDataTypeDefinition), ChangeType.Export, "Failed to export", ex)); } }
public override SyncAttempt <IMediaType> DeserializeSecondPass(IMediaType item, XElement node, SyncSerializerOptions options) { var details = new List <uSyncChange>(); details.AddRange(DeserializeCompositions(item, node)); details.AddRange(DeserializeStructure(item, node)); SetSafeAliasValue(item, node, false); CleanTabAliases(item); CleanTabs(item, node, options); bool saveInSerializer = !options.Flags.HasFlag(SerializerFlags.DoNotSave); if (saveInSerializer && item.IsDirty()) { mediaTypeService.Save(item); } return(SyncAttempt <IMediaType> .Succeed(item.Name, item, ChangeType.Import, "", saveInSerializer, details)); }
internal override SyncAttempt <XElement> SerializeCore(IMemberType item) { if (item == null) { throw new ArgumentNullException("item"); } // most of the things are ContentTypeBase var info = SerializeInfo(item); var tabs = SerializeTabs(item); var properties = SerializeProperties(item); var structure = SerializeStructure(item); var node = new XElement("MemberType", info, structure, properties, tabs); return(SyncAttempt <XElement> .Succeed(item.Name, node, typeof(IMemberType), ChangeType.Export)); }
public override SyncAttempt <IDictionaryItem> Import(string filePath, HandlerSettings config, SerializerFlags flags) { if (IsOneWay(config)) { // only sync dictionary items if they are new // so if it already exists we don't do the sync // // <Handler Alias="dictionaryHandler" Enabled="true"> // <Add Key="OneWay" Value="true" /> // </Handler> // var item = GetExistingItem(filePath); if (item != null) { return(SyncAttempt <IDictionaryItem> .Succeed(item.ItemKey, ChangeType.NoChange)); } } return(base.Import(filePath, config, flags)); }
public override SyncAttempt <IContentType> DeserializeSecondPass(IContentType item, XElement node, SyncSerializerOptions options) { logger.LogDebug("Deserialize Second Pass {0}", item.Alias); var details = new List <uSyncChange>(); SetSafeAliasValue(item, node, false); details.AddRange(DeserializeCompositions(item, node)); details.AddRange(DeserializeStructure(item, node)); // When doing this reflectiony - it doesn't set is dirty. var historyChanges = DeserializeCleanupHistory(item, node); var historyUpdated = historyChanges.Any(x => x.Change > ChangeDetailType.NoChange); details.AddRange(historyChanges); CleanTabAliases(item); // clean tabs details.AddRange(CleanTabs(item, node, options)); bool saveInSerializer = !options.Flags.HasFlag(SerializerFlags.DoNotSave); if (saveInSerializer && (item.IsDirty() || historyUpdated)) { var dirty = string.Join(", ", item.GetDirtyProperties()); dirty += string.Join(", ", item.PropertyGroups.Where(x => x.IsDirty()).Select(x => $"Group:{x.Name}")); dirty += string.Join(", ", item.PropertyTypes.Where(x => x.IsDirty()).Select(x => $"Property:{x.Name}")); dirty += historyUpdated ? " CleanupHistory" : ""; logger.LogDebug("Saving in Serializer because item is dirty [{properties}]", dirty); contentTypeService.Save(item); } CleanFolder(item, node); return(SyncAttempt <IContentType> .Succeed(item.Name, item, ChangeType.Import, "", saveInSerializer, details)); }
public override SyncAttempt <IMedia> DeserializeSecondPass(IMedia item, XElement node, SerializerFlags flags) { DeserializeProperties(item, node); var info = node.Element("Info"); var sortOrder = info.Element("SortOrder").ValueOrDefault(-1); if (sortOrder != -1) { item.SortOrder = sortOrder; } var trashed = info.Element("Trashed").ValueOrDefault(false); if (trashed) { if (!item.Trashed) { mediaService.MoveToRecycleBin(item); } return(SyncAttempt <IMedia> .Succeed(item.Name, ChangeType.Import)); } if (item.Trashed) { // remove from bin. // ? } var attempt = mediaService.Save(item); if (attempt.Success) { return(SyncAttempt <IMedia> .Succeed(item.Name, ChangeType.Import)); } return(SyncAttempt <IMedia> .Fail(item.Name, ChangeType.Fail, "")); }
protected virtual SyncAttempt <TObject> ProcessDelete(Guid key, string alias, SerializerFlags flags) { var item = this.FindItem(key); if (item == null && !string.IsNullOrWhiteSpace(alias)) { // we need to build in some awareness of alias matching in the folder // because if someone deletes something in one place and creates it // somewhere else the alias will exist, so we don't want to delete // it from over there - this needs to be done at save time // (bascially if a create happens) - turn any delete files into renames item = this.FindItem(alias); } if (item != null) { DeleteItem(item); return(SyncAttempt <TObject> .Succeed(alias, ChangeType.Delete)); } return(SyncAttempt <TObject> .Succeed(alias, ChangeType.NoChange)); }
protected override SyncAttempt <XElement> SerializeCore(ILanguage item) { var node = InitializeBaseNode(item, item.IsoCode); node.Add(new XElement("Id", item.Id)); node.Add(new XElement("IsoCode", item.IsoCode)); node.Add(new XElement("CultureName", item.CultureName)); node.Add(new XElement("IsMandatory", item.IsMandatory)); node.Add(new XElement("IsDefault", item.IsDefault)); if (item.FallbackLanguageId != null) { node.Add(new XElement("Fallback", item.FallbackLanguageId.Value)); } return(SyncAttempt <XElement> .SucceedIf( node != null, item.CultureName, node, typeof(ILanguage), ChangeType.Export)); }
protected override SyncAttempt <XElement> SerializeCore(IRelationType item, SyncSerializerOptions options) { var node = this.InitializeBaseNode(item, item.Alias); node.Add(new XElement("Info", new XElement("Name", item.Name), new XElement("ParentType", item.ParentObjectType), new XElement("ChildType", item.ChildObjectType), new XElement("Bidirectional", item.IsBidirectional))); if (options.GetSetting <bool>("IncludeRelations", true)) { node.Add(SerializeRelations(item)); } return(SyncAttempt <XElement> .SucceedIf( node != null, item.Name, node, typeof(IRelationType), ChangeType.Export)); }
public override SyncAttempt <ITemplate> DeserializeSecondPass(ITemplate item, XElement node, SerializerFlags flags) { var master = node.Element("Parent").ValueOrDefault(string.Empty); if (master != string.Empty && item.MasterTemplateAlias != master) { logger.Debug <TemplateSerializer>("Looking for master {0}", master); var masterItem = fileService.GetTemplate(master); if (masterItem != null) { logger.Debug <TemplateSerializer>("Setting Master {0}", masterItem.Alias); item.SetMasterTemplate(masterItem); if (!flags.HasFlag(SerializerFlags.DoNotSave)) { SaveItem(item); } } } return(SyncAttempt <ITemplate> .Succeed(item.Name, item, ChangeType.Import)); }
virtual public SyncAttempt <TObject> Import(string filePath, HandlerSettings config, SerializerFlags flags) { try { syncFileService.EnsureFileExists(filePath); using (var stream = syncFileService.OpenRead(filePath)) { var node = XElement.Load(stream); var attempt = serializer.Deserialize(node, flags); return(attempt); } } catch (FileNotFoundException notFoundException) { return(SyncAttempt <TObject> .Fail(Path.GetFileName(filePath), ChangeType.Fail, $"File not found {notFoundException.Message}")); } catch (Exception ex) { return(SyncAttempt <TObject> .Fail(Path.GetFileName(filePath), ChangeType.Fail, $"Import Fail: {ex.Message}")); } }
protected override SyncAttempt <XElement> SerializeCore(IMacro item, SyncSerializerOptions options) { var node = this.InitializeBaseNode(item, item.Alias); node.Add(new XElement("Name", item.Name)); node.Add(new XElement("MacroSource", item.MacroSource)); node.Add(new XElement("MacroType", item.MacroType)); node.Add(new XElement("UseInEditor", item.UseInEditor)); node.Add(new XElement("DontRender", item.DontRender)); node.Add(new XElement("CachedByMember", item.CacheByMember)); node.Add(new XElement("CachedByPage", item.CacheByPage)); node.Add(new XElement("CachedDuration", item.CacheDuration)); var properties = new XElement("Properties"); foreach (var propertyKey in item.Properties.Keys.OrderBy(x => x)) { var property = item.Properties[propertyKey]; if (property != null) { properties.Add(new XElement("Property", new XElement("Name", property.Name), new XElement("Alias", property.Alias), new XElement("SortOrder", property.SortOrder), new XElement("EditorAlias", property.EditorAlias))); } } node.Add(properties); return(SyncAttempt <XElement> .SucceedIf( node != null, item.Name, node, typeof(IMacro), ChangeType.Export)); }
internal override SyncAttempt <ILanguage> DeserializeCore(XElement node) { var culture = node.Attribute("CultureAlias"); var fName = node.Attribute("FriendlyName"); if (culture == null || fName == null) { return(SyncAttempt <ILanguage> .Fail(node.NameFromNode(), ChangeType.Import, "missing Alias or Name")); } // by name ILanguage item = _localizationService.GetLanguageByCultureCode(fName.Value); // by iso code if (item == null) { item = _localizationService.GetLanguageByIsoCode(culture.Value); } // create a new one if (item == null) { item = new Language(culture.Value); } // all that failed if (item == null) { return(SyncAttempt <ILanguage> .Fail(node.NameFromNode(), ChangeType.Import, "Unable to import language")); } // it worked update stuff.. item.IsoCode = culture.Value; item.CultureName = fName.Value; _localizationService.Save(item); return(SyncAttempt <ILanguage> .Succeed(item.CultureName, item, ChangeType.Import)); }