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
15 changes: 9 additions & 6 deletions uSync.BackOffice/Configuration/uSyncSettings.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.Collections.Generic;
using System.ComponentModel;
using System.Text.Json.Serialization;

namespace uSync.BackOffice.Configuration;

Expand Down Expand Up @@ -97,15 +98,15 @@ public class uSyncSettings
/// <summary>
/// Export when an item is saved in Umbraco
/// </summary>
[DefaultValue("All")]
public string ExportOnSave { get; set; } = "All";
[DefaultValue(uSync.EverythingGroupName)]
public string ExportOnSave { get; set; } = uSync.EverythingGroupName;


/// <summary>
/// The handler groups that are enabled in the UI.
/// </summary>
[DefaultValue("All")]
public string UIEnabledGroups { get; set; } = "All";
[DefaultValue(uSync.EverythingGroupName)]
public string UIEnabledGroups { get; set; } = uSync.EverythingGroupName;

/// <summary>
/// Debug reports (creates an export into a temp folder for comparison)
Expand Down Expand Up @@ -176,8 +177,8 @@ public class uSyncSettings
/// <summary>
/// Handler group(s) to run on first boot, default is All (so full import)
/// </summary>
[DefaultValue("All")]
public string FirstBootGroup { get; set; } = "All";
[DefaultValue(uSync.EverythingGroupName)]
public string FirstBootGroup { get; set; } = uSync.EverythingGroupName;

/// <summary>
/// Disable the default dashboard (so people can't accidently press the buttons).
Expand Down Expand Up @@ -264,6 +265,7 @@ public class uSyncSettings
/// <summary>
/// uSync's folder mode - normal, root or production
/// </summary>
[JsonConverter(typeof(JsonStringEnumConverter<SyncFolderMode>))]
public enum SyncFolderMode
{
/// <summary>
Expand All @@ -285,6 +287,7 @@ public enum SyncFolderMode
/// <summary>
/// Mode is where the processing happens - normal or background
/// </summary>
[JsonConverter(typeof(JsonStringEnumConverter<SyncProcessingMode>))]
public enum SyncProcessingMode
{
/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion uSync.BackOffice/Extensions/uSyncActionExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public static int CountChanges(this IEnumerable<uSyncAction> actions)
public static bool IsValidAction(this HandlerActions requestedAction, IEnumerable<string> actions)
=> requestedAction == HandlerActions.None ||
!actions.Any() ||
actions.InvariantContains("all") ||
actions.InvariantContains(uSync.EverythingGroupName) ||
actions.InvariantContains(requestedAction.ToString());

/// <summary>
Expand Down
6 changes: 6 additions & 0 deletions uSync.BackOffice/Models/SyncActionOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ public class SyncActionOptions
/// </summary>
public string? Set { get; set; }


/// <summary>
/// the group within the set that is being processed - e.g settings, content, media etc.
/// </summary>
public string? Group { get; set; }

/// <summary>
/// SyncActions to use as the source for all individual actions
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class CancelableuSyncBulkNotification : uSyncBulkNotification, ICancelabl
/// Notification constructor
/// </summary>
public CancelableuSyncBulkNotification()
: base(Enumerable.Empty<uSyncAction>())
: base(Enumerable.Empty<uSyncAction>(), null)
{ }

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;

using Umbraco.Cms.Core.Notifications;

Expand All @@ -13,11 +14,23 @@ public class uSyncBulkNotification : INotification
/// generate new BulkNotificationObject
/// </summary>
/// <param name="actions"></param>
public uSyncBulkNotification(IEnumerable<uSyncAction> actions, string? group)
{
this.Group = group;
this.Actions = actions;
}

[Obsolete("Use the constructor with group and actions instead - will be removed in v19")]
public uSyncBulkNotification(IEnumerable<uSyncAction> actions)
{
this.Actions = actions;
}

/// <summary>
/// The group e.g settings, content that this action ran under.
/// </summary>
public string? Group { get; set; }

/// <summary>
/// actions that have occured during the bulk operation
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;

namespace uSync.BackOffice;

Expand All @@ -7,8 +8,12 @@ namespace uSync.BackOffice;
/// </summary>
public class uSyncExportCompletedNotification : uSyncBulkNotification
{
/// <inheritdoc/>
public uSyncExportCompletedNotification(IEnumerable<uSyncAction> actions, string? group)
: base(actions, group) { }

/// <inheritdoc/>
[Obsolete("Use the constructor with the group parameter instead will be removed in v19")]
public uSyncExportCompletedNotification(IEnumerable<uSyncAction> actions)
: base(actions) { }
: base(actions, null) { }
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;

namespace uSync.BackOffice;

Expand All @@ -7,7 +8,13 @@ namespace uSync.BackOffice;
/// </summary>
public class uSyncImportCompletedNotification : uSyncBulkNotification
{

/// <inheritdoc/>
public uSyncImportCompletedNotification(IEnumerable<uSyncAction> actions, string? group)
: base(actions, group) { }

/// <inheritdoc/>
[Obsolete("Use the constructor with the group parameter instead will be removed in v19")]
public uSyncImportCompletedNotification(IEnumerable<uSyncAction> actions)
: base(actions) { }
: base(actions, null) { }
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@ namespace uSync.BackOffice;
/// </summary>
public class uSyncReportCompletedNotification : uSyncBulkNotification
{
/// <inheritdoc/>
public uSyncReportCompletedNotification(IEnumerable<uSyncAction> actions, string? group )
: base(actions, group) { }


/// <inheritdoc/>
public uSyncReportCompletedNotification(IEnumerable<uSyncAction> actions)
: base(actions) { }
: base(actions, null) { }
}
8 changes: 7 additions & 1 deletion uSync.BackOffice/Services/ISyncService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -152,14 +152,20 @@ public interface ISyncService
/// </summary>
Task StartBulkProcessAsync(HandlerActions action);


/// <summary>
/// trigger the end of the bulk process
/// </summary>
[Obsolete("Use StartBulkProcessAsync(HandlerActions action, string group) instead")]
Task FinishBulkProcessAsync(HandlerActions action, IEnumerable<uSyncAction> actions);

/// <summary>
/// trigger the end of the bulk process
/// </summary>
Task FinishBulkProcessAsync(HandlerActions action, string? group, IEnumerable<uSyncAction> actions);

/// <summary>
/// merge the given folders in single 'production' files for each handler.
/// </summary>
Task<int> MergeExportFolder(string[] paths, IEnumerable<HandlerConfigPair> handlers);

}
2 changes: 1 addition & 1 deletion uSync.BackOffice/Services/SyncActionService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ public async Task StartProcessAsync(HandlerActions action)
/// <inheritdoc/>
public async Task<SyncActionResult> FinishProcessAsync(SyncFinalActionRequest request)
{
await _uSyncService.FinishBulkProcessAsync(request.HandlerAction, request.Actions);
await _uSyncService.FinishBulkProcessAsync(request.HandlerAction, request.ActionOptions.Group, request.Actions);

_timer?.Stop();
var elapsed = _timer?.ElapsedMilliseconds ?? 0;
Expand Down
4 changes: 2 additions & 2 deletions uSync.BackOffice/Services/SyncService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ public async Task<IEnumerable<uSyncAction>> ImportAsync(string[] folders, bool f
var results = await SyncService.PerformPostImportAsync(handlers, actions);

// fire complete
await _mutexService.FireBulkCompleteAsync(new uSyncImportCompletedNotification(actions));
await _mutexService.FireBulkCompleteAsync(new uSyncImportCompletedNotification(actions, handlerOptions.Group));

_logger.LogInformation("uSync Import: {handlerCount} handlers, processed {itemCount} items, {changeCount} changes in {ElapsedMilliseconds}ms",
handlers.Count(),
Expand Down Expand Up @@ -402,7 +402,7 @@ public async Task<IEnumerable<uSyncAction>> ExportAsync(string folder, IEnumerab
summary.UpdateMessage("Export Completed");
callbacks?.Callback?.Invoke(summary);

await _mutexService.FireBulkCompleteAsync(new uSyncExportCompletedNotification(actions));
await _mutexService.FireBulkCompleteAsync(new uSyncExportCompletedNotification(actions, null));

sw.Stop();

Expand Down
14 changes: 10 additions & 4 deletions uSync.BackOffice/Services/SyncService_Handlers.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.Data;
using System.IO;
using System.Linq;
Expand Down Expand Up @@ -154,19 +155,24 @@ public async Task StartBulkProcessAsync(HandlerActions action)
}

/// <inheritdoc/>>
[Obsolete("Use the overload with the group parameter instead")]
public async Task FinishBulkProcessAsync(HandlerActions action, IEnumerable<uSyncAction> actions)
=> await FinishBulkProcessAsync(action, uSync.EverythingGroupName, actions);

/// <inheritdoc/>>
public async Task FinishBulkProcessAsync(HandlerActions action, string? group, IEnumerable<uSyncAction> actions)
{
switch (action)
{
case HandlerActions.Export:
await WriteVersionFileAsync(_uSyncConfig.GetWorkingFolder());
await _mutexService.FireBulkCompleteAsync(new uSyncExportCompletedNotification(actions));
await _mutexService.FireBulkCompleteAsync(new uSyncExportCompletedNotification(actions, group));
break;
case HandlerActions.Import:
await _mutexService.FireBulkCompleteAsync(new uSyncImportCompletedNotification(actions));
await _mutexService.FireBulkCompleteAsync(new uSyncImportCompletedNotification(actions, group));
break;
case HandlerActions.Report:
await _mutexService.FireBulkCompleteAsync(new uSyncReportCompletedNotification(actions));
await _mutexService.FireBulkCompleteAsync(new uSyncReportCompletedNotification(actions, group));
break;
}
}
Expand Down
4 changes: 3 additions & 1 deletion uSync.BackOffice/SyncHandlers/Models/HandlerActionNames.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
using System;
using System.Text.Json.Serialization;

namespace uSync.BackOffice.SyncHandlers.Models;

/// <summary>
/// Possible actions a handler can do (stored in config)
/// </summary>
[JsonConverter(typeof(JsonStringEnumConverter<HandlerActions>))]
public enum HandlerActions
{
/// <summary>
Expand Down Expand Up @@ -40,7 +42,7 @@ public enum HandlerActions
/// <summary>
/// All actions
/// </summary>
[SyncActionName("All")]
[SyncActionName(uSync.EverythingGroupName)]
All
}

Expand Down
2 changes: 1 addition & 1 deletion uSync.BackOffice/SyncHandlers/Models/HandlerConfigPair.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public static bool IsEnabled(this HandlerConfigPair handlerAndConfig)
public static bool IsValidGroup(this HandlerConfigPair handlerAndConfig, string group)
{
// empty means all as does 'all'
if (string.IsNullOrWhiteSpace(group) || group.InvariantEquals("all")) return true;
if (string.IsNullOrWhiteSpace(group) || group.InvariantEquals(uSync.EverythingGroupName)) return true;

var handlerGroup = handlerAndConfig.Handler.Group;
if (!string.IsNullOrWhiteSpace(handlerAndConfig.Settings.Group))
Expand Down
2 changes: 1 addition & 1 deletion uSync.BackOffice/SyncHandlers/SyncHandlerRoot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1370,7 +1370,7 @@ protected bool ShouldProcessEvent()

var group = !string.IsNullOrWhiteSpace(DefaultConfig.Group) ? DefaultConfig.Group : this.Group;

if (uSyncConfig.Settings.ExportOnSave.InvariantContains("All") ||
if (uSyncConfig.Settings.ExportOnSave.InvariantContains(uSync.EverythingGroupName) ||
uSyncConfig.Settings.ExportOnSave.InvariantContains(group))
{
return HandlerActions.Save.IsValidAction(DefaultConfig.Actions);
Expand Down
10 changes: 10 additions & 0 deletions uSync.BackOffice/Tracker/ISyncTrackerService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using System;
using System.Threading.Tasks;

namespace uSync.BackOffice.Tracker;

public interface ISyncTrackerService
{
Task<DateTime?> GetLastSync(string group);
Task SaveLastSync(string group);
}
15 changes: 15 additions & 0 deletions uSync.BackOffice/Tracker/SyncTrackerBuilderExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using Microsoft.Extensions.DependencyInjection;

using Umbraco.Cms.Core.DependencyInjection;

namespace uSync.BackOffice.Tracker;

internal static class SyncTrackerBuilderExtensions
{
public static IUmbracoBuilder AddSyncTracker(this IUmbracoBuilder builder)
{
builder.Services.AddSingleton<ISyncTrackerService, SyncTrackerService>();
builder.AddNotificationAsyncHandler<uSyncImportCompletedNotification, SyncTrackerNotificationHandler>();
return builder;
}
}
22 changes: 22 additions & 0 deletions uSync.BackOffice/Tracker/SyncTrackerNotificationHandler.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using System.Threading;
using System.Threading.Tasks;

using Umbraco.Cms.Core.Events;

namespace uSync.BackOffice.Tracker;

internal class SyncTrackerNotificationHandler
: INotificationAsyncHandler<uSyncImportCompletedNotification>
{
private readonly ISyncTrackerService _syncTrackerService;

public SyncTrackerNotificationHandler(ISyncTrackerService syncTrackerService)
{
_syncTrackerService = syncTrackerService;
}

public async Task HandleAsync(uSyncImportCompletedNotification notification, CancellationToken cancellationToken)
{
await _syncTrackerService.SaveLastSync(notification.Group ?? uSync.EverythingGroupName);
}
}
Loading