Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 2 additions & 54 deletions uSync.BackOffice/SyncHandlers/Handlers/DictionaryHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,38 +60,6 @@ public DictionaryHandler(
_dictionaryItemService = dictionaryItemService;
}

/// <inheritdoc/>
public override async Task<IEnumerable<uSyncAction>> ImportAsync(string file, HandlerSettings config, uSyncImportOptions options)
{
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 = await GetExistingItemAsync(file);
if (item != null)
{
return uSyncAction.SetAction(true, item.ItemKey, change: ChangeType.NoChange).AsEnumerableOfOne();
}
}

return await base.ImportAsync(file, config, options);

}

private async Task<IDictionaryItem?> GetExistingItemAsync(string filePath)
{
syncFileService.EnsureFileExists(filePath);

var node = await syncFileService.LoadXElementAsync(filePath);
return await serializer.FindItemAsync(node);
}

/// <inheritdoc/>
protected override async Task<IEnumerable<IEntity>> GetFoldersAsync(Guid key)
=> await GetChildItemsAsync(key);
Expand Down Expand Up @@ -122,26 +90,6 @@ protected override string GetItemName(IDictionaryItem item)
/// <inheritdoc/>
protected override string GetItemPath(IDictionaryItem item, bool useGuid, bool isFlat)
=> item.ItemKey.ToSafeFileName(shortStringHelper);

/// <inheritdoc/>
public override async Task<IEnumerable<uSyncAction>> ReportElementAsync(XElement node, string filename, HandlerSettings settings, uSyncImportOptions options)
{
if (IsOneWay(settings))
{
// we check if there is no change, we don't report it.
// if we find it then there is no change.
var item = await GetExistingItemAsync(filename);
if (item != null)
{
return uSyncActionHelper<IDictionaryItem>
.ReportAction(ChangeType.NoChange, item.ItemKey, node.GetPath(), syncFileService.GetSiteRelativePath(filename), item.Key, this.Alias, "Existing Item will not be overwritten")
.AsEnumerableOfOne<uSyncAction>();
}
}

return await base.ReportElementAsync(node, filename, settings, options);
}

private static bool IsOneWay(HandlerSettings? config)
=> config?.GetSetting("OneWay", false) == true;
}


7 changes: 7 additions & 0 deletions uSync.BackOffice/SyncHandlers/SyncHandlerRoot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1189,6 +1189,13 @@ public virtual async Task<IEnumerable<uSyncAction>> ReportElementAsync(XElement
{
try
{
if ((await ShouldImportAsync(node, settings)) is false)
{
return uSyncActionHelper<TObject>.ReportAction(ChangeType.NoChange, node.GetAlias(), node.GetPath(), syncFileService.GetSiteRelativePath(filename), node.GetKey(),
this.Alias, "Will not be imported (Based on configuration)")
.AsEnumerableOfOne<uSyncAction>();
Comment thread
KevinJump marked this conversation as resolved.
}

// starting reporting notification
// this lets us intercept a report and
// shortcut the checking (sometimes).
Expand Down
Loading