-
Notifications
You must be signed in to change notification settings - Fork 78
V17/last synced date #898
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
V17/last synced date #898
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
30da7f2
Add explicity JsonConverters to all enums, so they are always seriali…
KevinJump 2f5317e
Adds a last syned date/time for imports, so in theory we can add that…
KevinJump 2aa4d3c
Add last imported on hover of title of group
KevinJump 89d6f88
Make "all" a constant *(BackOffice.uSync.EverythingGroupName)*
KevinJump File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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
22
uSync.BackOffice/Tracker/SyncTrackerNotificationHandler.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 ?? "all"); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| using Microsoft.Extensions.Logging; | ||
|
|
||
| using System; | ||
| using System.Threading.Tasks; | ||
|
|
||
| using Umbraco.Cms.Core.Services; | ||
|
|
||
| namespace uSync.BackOffice.Tracker; | ||
|
|
||
|
|
||
| internal class SyncTrackerService : ISyncTrackerService | ||
| { | ||
| const string _keyPrefix = "uSync.SyncTracker."; | ||
|
|
||
| private readonly ILogger<SyncTrackerService> _logger; | ||
| private readonly IKeyValueService _keyValueService; | ||
|
|
||
| public SyncTrackerService(IKeyValueService keyValueService, ILogger<SyncTrackerService> logger) | ||
| { | ||
| _keyValueService = keyValueService; | ||
| _logger = logger; | ||
| } | ||
|
|
||
| public Task SaveLastSync(string group) | ||
| { | ||
| try | ||
| { | ||
| var key = $"{_keyPrefix}{group}"; | ||
| _keyValueService.SetValue(key, DateTime.UtcNow.ToString("o")); | ||
| } | ||
| catch (Exception ex) | ||
| { | ||
| _logger.LogWarning(ex, "Error saving last sync time for group {Group}", group); | ||
| } | ||
| return Task.CompletedTask; | ||
|
|
||
| } | ||
|
|
||
| public async Task<DateTime?> GetLastSync(string group) | ||
| { | ||
| var lastSync = await InternalGetLastSync(group); | ||
| var lastAllSync = await InternalGetLastSync("All"); | ||
| return lastSync > lastAllSync ? lastSync : lastAllSync; | ||
| } | ||
|
|
||
| private Task<DateTime?> InternalGetLastSync(string group) | ||
| { | ||
| try | ||
| { | ||
| var key = $"{_keyPrefix}{group}"; | ||
| var value = _keyValueService.GetValue(key); | ||
| if (DateTime.TryParse(value, null, System.Globalization.DateTimeStyles.RoundtripKind, out var result)) | ||
| { | ||
| return Task.FromResult<DateTime?>(result); | ||
| } | ||
| } | ||
| catch(Exception ex) | ||
| { | ||
| _logger.LogWarning(ex, "Error retrieving last sync time for group {Group}", group); | ||
| } | ||
|
|
||
| return Task.FromResult<DateTime?>(null); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.