From 122e3eeef9981626c9388c5bf1251ee5b2f0f2d2 Mon Sep 17 00:00:00 2001 From: Kevin Jump Date: Tue, 10 Dec 2019 16:27:41 +0000 Subject: [PATCH] One Way Dictionary Handler --- .../Handlers/DictionaryHandler.cs | 38 ++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/uSync8.ContentEdition/Handlers/DictionaryHandler.cs b/uSync8.ContentEdition/Handlers/DictionaryHandler.cs index b4b6eca9..eb3e8afe 100644 --- a/uSync8.ContentEdition/Handlers/DictionaryHandler.cs +++ b/uSync8.ContentEdition/Handlers/DictionaryHandler.cs @@ -1,7 +1,7 @@ using System; using System.Collections.Generic; using System.Linq; - +using System.Xml.Linq; using Umbraco.Core; using Umbraco.Core.Logging; using Umbraco.Core.Models; @@ -12,7 +12,9 @@ using uSync8.BackOffice.Configuration; using uSync8.BackOffice.Services; using uSync8.BackOffice.SyncHandlers; +using uSync8.Core; using uSync8.Core.Dependency; +using uSync8.Core.Models; using uSync8.Core.Serialization; using uSync8.Core.Tracking; @@ -38,7 +40,41 @@ public DictionaryHandler(IEntityService entityService, : base(entityService, logger, serializer, tracker, checker, syncFileService) { this.localizationService = localizationService; + } + public override SyncAttempt Import(string filePath, HandlerSettings config, SerializerFlags flags) + { + if (config.Settings.ContainsKey("OneWay") + && config.Settings["OneWay"].InvariantEquals("true")) + { + // only sync dictionary items if they are new + // so if it already exists we don't do the sync + + // + // + // + // + // + var item = GetExistingItem(filePath); + if (item != null) + { + return SyncAttempt.Succeed(item.ItemKey, ChangeType.NoChange); + } + } + + return base.Import(filePath, config, flags); + + } + + private IDictionaryItem GetExistingItem(string filePath) + { + syncFileService.EnsureFileExists(filePath); + + using (var stream = syncFileService.OpenRead(filePath)) + { + var node = XElement.Load(stream); + return serializer.FindItem(node); + } } public override IEnumerable ExportAll(string folder, HandlerSettings config, SyncUpdateCallback callback)