public override IEnumerable <uSyncDependency> GetDependencies(object value, string editorAlias, DependencyFlags flags) { // validate string var stringValue = value?.ToString(); if (string.IsNullOrWhiteSpace(stringValue) || !stringValue.DetectIsJson()) { return(Enumerable.Empty <uSyncDependency>()); } // convert to an array. var images = JsonConvert.DeserializeObject <JArray>(value.ToString()); if (images == null || !images.Any()) { return(Enumerable.Empty <uSyncDependency>()); } var dependencies = new List <uSyncDependency>(); foreach (var image in images.Cast <JObject>()) { var key = GetGuidValue(image, "mediaKey"); if (key != Guid.Empty) { var udi = GuidUdi.Create(UdiEntityType.Media, key); dependencies.Add(CreateDependency(udi as GuidUdi, flags)); } } return(dependencies); }
protected IEnumerable <uSyncDependency> GetItemDependency(JObject itemValue, DependencyFlags flags) { if (itemValue == null) { return(Enumerable.Empty <uSyncDependency>()); } if (itemValue.ContainsKey("contentData")) { // nested content mode. var contentData = itemValue.Value <JObject>("contentData"); var docTypeAlias = contentData.Value <string>(this.docTypeAliasValue); if (contentData == null || docTypeAlias == null) { return(Enumerable.Empty <uSyncDependency>()); } var docType = GetDocType(docTypeAlias); if (docType == null) { return(Enumerable.Empty <uSyncDependency>()); } List <uSyncDependency> dependencies = new List <uSyncDependency>(); var docTypeDependency = CreateDocTypeDependency(docType, flags); dependencies.AddNotNull(docTypeDependency); dependencies.AddRange(GetPropertyDependencies(contentData, docType, flags)); return(dependencies); } else { // linked content mode var key = itemValue.Value <Guid>("key"); if (key != null) { // we need to include the ancestors of any included // bento items, to ensure we get the library structure // of the bento items as part of the sync. var bentoFlags = flags | DependencyFlags.IncludeAncestors; var udi = GuidUdi.Create(Constants.UdiEntityType.Document, key); return(CreateDependency(udi as GuidUdi, bentoFlags).AsEnumerableOfOne()); } } return(Enumerable.Empty <uSyncDependency>()); }
public IEnumerable <UmbracoEntityReference> GetReferences(object value) { var rawJson = value == null ? string.Empty : value is string str ? str : value.ToString(); if (rawJson.IsNullOrWhiteSpace()) { yield break; } var mediaWithCropsDtos = JsonConvert.DeserializeObject <MediaPickerWithCropsValueConverter.MediaWithCropsDto[]>(rawJson); foreach (var mediaWithCropsDto in mediaWithCropsDtos) { yield return(new UmbracoEntityReference(GuidUdi.Create(Constants.UdiEntityType.Media, mediaWithCropsDto.MediaKey))); } }
private void MapOldToNewUdis(Dictionary <Udi, Udi> oldToNew, IEnumerable <BlockItemData> blockData, Func <Guid> createGuid) { foreach (var data in blockData) { // This should never happen since a FormatException will be thrown if one is empty but we'll keep this here if (data.Udi == null) { throw new InvalidOperationException("Block data cannot contain a null UDI"); } // replace the UDIs var newUdi = GuidUdi.Create(Constants.UdiEntityType.Element, createGuid()); oldToNew[data.Udi] = newUdi; data.Udi = newUdi; } }
private string GetBlockListJson( string subFeatures, string contentGuid1 = ContentGuid1, string contentGuid2 = ContentGuid2, string settingsGuid1 = SettingsGuid1) { return(@"{ ""layout"": { ""Umbraco.BlockList"": [ { ""contentUdi"": """ + (contentGuid1.IsNullOrWhiteSpace() ? string.Empty : GuidUdi.Create(Constants.UdiEntityType.Element, Guid.Parse(contentGuid1)).ToString()) + @""" }, { ""contentUdi"": ""umb://element/" + contentGuid2 + @""", ""settingsUdi"": ""umb://element/" + settingsGuid1 + @""" } ] }, ""contentData"": [ { ""contentTypeKey"": ""d6ce4a86-91a2-45b3-a99c-8691fc1fb020"", ""udi"": """ + (contentGuid1.IsNullOrWhiteSpace() ? string.Empty : GuidUdi.Create(Constants.UdiEntityType.Element, Guid.Parse(contentGuid1)).ToString()) + @""", ""featureName"": ""Hello"", ""featureDetails"": ""World"" }, { ""contentTypeKey"": ""d6ce4a86-91a2-45b3-a99c-8691fc1fb020"", ""udi"": ""umb://element/" + contentGuid2 + @""", ""featureName"": ""Another"", ""featureDetails"": ""Feature""" + (subFeatures == null ? string.Empty : (@", ""subFeatures"": " + subFeatures)) + @" } ], ""settingsData"": [ { ""contentTypeKey"": ""d6ce4a86-91a2-45b3-a99c-8691fc1fb020"", ""udi"": ""umb://element/" + settingsGuid1 + @""", ""featureName"": ""Setting 1"", ""featureDetails"": ""Setting 2"" }, ] }"); }