public KontentPublishingModule() : base(MODULE_NAME) { _settings = new SyncSettings(); _settings.LoadFromConfig(); if (_settings.IsValid()) { _assetSync = new AssetSync(_settings); _languageSync = new LanguageSync(_settings); _contentTypeSync = new ContentTypeSync(_settings); _pageSync = new PageSync(_settings, _assetSync, _contentTypeSync); _taxonomySync = new TaxonomySync(_settings); } }
private async Task <object> GetElementValue(TreeNode node, FormFieldInfo field) { var value = node.GetValue(field.Name); switch (field.DataType) { case FieldDataType.Boolean: if (value == null) { return(new object[0]); } return((bool)value ? new[] { new { codename = "true" } } : new[] { new { codename = "false" } }); case FieldDataType.Date: case FieldDataType.DateTime: if (value == null) { return(null); } return(((DateTime)value).ToUniversalTime()); case FieldDataType.Decimal: case FieldDataType.Double: case FieldDataType.Integer: case FieldDataType.LongInteger: return(Convert.ToString(Convert.ToDecimal(value))); case FieldDataType.File: if (value == null) { return(Array.Empty <object>()); } else { return(new[] { new { external_id = AssetSync.GetAttachmentExternalId((Guid)value) } }); } case FieldDataType.DocAttachments: return(GetAttachmentGuids(node, field).Select(guid => new { external_id = AssetSync.GetAttachmentExternalId(guid) })); case FieldDataType.DocRelationships: return(GetRelatedNodeGuids(node, field).Select(guid => new { external_id = GetPageExternalId(guid) })); case FieldDataType.LongText: return(await _linkTranslator.TranslateLinks(Convert.ToString(value))); case FieldDataType.Binary: throw new NotSupportedException("Binary field type is not supported"); case FieldDataType.Guid: case FieldDataType.Text: case FieldDataType.Xml: case FieldDataType.TimeSpan: default: return(Convert.ToString(value)); } }
public PageSync(SyncSettings settings, AssetSync assetSync, ContentTypeSync contentTypeSync) : base(settings) { _assetSync = assetSync; _contentTypeSync = contentTypeSync; _linkTranslator = new LinkTranslator(settings, assetSync); }
private async Task UpsertVariant(TreeNode node) { if (node == null) { throw new ArgumentNullException(nameof(node)); } var externalId = GetPageExternalId(node.NodeGUID); var endpoint = GetVariantEndpoint(node); var contentType = DataClassInfoProvider.GetDataClassInfo(node.NodeClassName); if (contentType == null) { throw new InvalidOperationException($"Content type {node.NodeClassName} not found."); } var formInfo = FormHelper.GetFormInfo(node.ClassName, false); if (formInfo == null) { throw new InvalidOperationException($"Form info for {node.NodeClassName} not found."); } var fieldsToSync = ContentTypeSync.GetItemsToSync(node.NodeClassName).OfType <FormFieldInfo>(); var fieldElements = await Task.WhenAll( fieldsToSync.Select(async(field) => new { element = new { external_id = ContentTypeSync.GetFieldExternalId(contentType.ClassGUID, field.Guid) }, value = await GetElementValue(node, field) }) ); var unsortedAttachmentsElement = new { element = new { external_id = ContentTypeSync.GetFieldExternalId(contentType.ClassGUID, ContentTypeSync.UNSORTED_ATTACHMENTS_GUID) }, value = (object)GetAttachmentGuids(node, null).Select(guid => new { external_id = AssetSync.GetAttachmentExternalId(guid) }) }; var categoriesElement = new { element = new { external_id = ContentTypeSync.GetFieldExternalId(contentType.ClassGUID, TaxonomySync.CATEGORIES_GUID) }, value = (object)GetCategoryGuids(node).Select(guid => new { external_id = TaxonomySync.GetCategoryTermExternalId(guid) }).ToList() }; var relationshipElements = GetRelationshipElements(node); var payload = new { elements = fieldElements .Concat(new[] { unsortedAttachmentsElement, categoriesElement, }) .Concat(relationshipElements) .ToList() }; await ExecuteWithoutResponse(endpoint, HttpMethod.Put, payload, true); }
public LinkTranslator(SyncSettings settings, AssetSync assetSync) { _settings = settings; _assetSync = assetSync; }