Skip to content

Commit f457fe0

Browse files
authored
Merge pull request #7 from Relewise/feat/minor-refactorings-export
feat: minor changes to integration/extension
2 parents c8125a3 + 8a2b473 commit f457fe0

13 files changed

+109
-53
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
22
<s:Boolean x:Key="/Default/UserDictionary/Words/=dataset/@EntryIndexedValue">True</s:Boolean>
3+
<s:Boolean x:Key="/Default/UserDictionary/Words/=recommender/@EntryIndexedValue">True</s:Boolean>
34
<s:Boolean x:Key="/Default/UserDictionary/Words/=Relewise/@EntryIndexedValue">True</s:Boolean>
45
<s:Boolean x:Key="/Default/UserDictionary/Words/=Trackable/@EntryIndexedValue">True</s:Boolean>
56
<s:Boolean x:Key="/Default/UserDictionary/Words/=Umbraco/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>

src/Integrations.Umbraco/App_Plugins/Relewise.Dashboard/dashboard.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ <h2>Relewise</h2>
33
<umb-box>
44
<umb-box-content>
55
<p>
6-
Welcome to the Relewise dashboard - Here you can perform export functions get all your content exported into Relewise.<br />
6+
Welcome to the Relewise dashboard - here you can perform export functions to get all your content exported into Relewise.<br />
77
It's also possible to see the settings for Relewise directly here.
88
</p>
99
<div class="button-box">
@@ -24,11 +24,11 @@ <h3>Settings</h3>
2424
<umb-box>
2525
<umb-box-content>
2626
<p>
27-
These are the settings registered with for Relewise.
27+
These are the settings registered with Relewise.
2828
</p>
2929

3030
<p class="error" ng-if="vm.configurationError">
31-
No options has been configured. Please check your call to the 'services.AddRelewise(options => { /* options goes here */ })'-method.
31+
No options have been configured. Please check your call to the 'services.AddRelewise(options => { /* options goes here */ })'-method in 'Startup.cs'.
3232
</p>
3333
<div ng-if="vm.configuration !== null">
3434
Tracked content types are: <strong>{{vm.configuration.trackedContentTypes.join(', ')}}</strong><br />

src/Integrations.Umbraco/Controllers/DashboardApiController.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Diagnostics.CodeAnalysis;
23
using System.Linq;
34
using System.Threading;
45
using System.Threading.Tasks;
@@ -92,12 +93,14 @@ public IActionResult Configuration()
9293

9394
return Ok(new
9495
{
95-
TrackedContentTypes = _configuration.TrackedContentTypes,
96-
ExportedContentTypes = _configuration.ExportedContentTypes,
96+
_configuration.TrackedContentTypes,
97+
_configuration.ExportedContentTypes,
9798
Named = named
9899
});
99100
}
100101

102+
[SuppressMessage("ReSharper", "MemberCanBePrivate.Local")]
103+
[SuppressMessage("ReSharper", "UnusedAutoPropertyAccessor.Local")]
101104
private class NamedOptionsViewObject
102105
{
103106
public NamedOptionsViewObject(string name, ClientOptionsViewObject tracker, ClientOptionsViewObject recommender, ClientOptionsViewObject searcher)
@@ -115,6 +118,8 @@ public NamedOptionsViewObject(string name, ClientOptionsViewObject tracker, Clie
115118
public ClientOptionsViewObject Searcher { get; }
116119
}
117120

121+
[SuppressMessage("ReSharper", "MemberCanBePrivate.Local")]
122+
[SuppressMessage("ReSharper", "UnusedAutoPropertyAccessor.Local")]
118123
private class ClientOptionsViewObject
119124
{
120125
public ClientOptionsViewObject(RelewiseClientOptions options)
Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,33 @@
11
using System.Linq;
2+
using System.Threading;
3+
using System.Threading.Tasks;
24
using Relewise.Client;
35
using Relewise.Client.DataTypes;
46
using Relewise.Client.Requests.Filters;
7+
using Relewise.Integrations.Umbraco.Services;
58
using Umbraco.Cms.Core.Events;
69
using Umbraco.Cms.Core.Notifications;
710

811
namespace Relewise.Integrations.Umbraco.NotificationHandlers;
912

10-
internal class RelewiseContentDeletedNotificationNotificationHandler : INotificationHandler<ContentDeletedNotification>
13+
internal class RelewiseContentDeletedNotificationNotificationHandler : INotificationAsyncHandler<ContentDeletedNotification>
1114
{
15+
private readonly IExportContentService _exportContentService;
1216
private readonly RelewiseUmbracoConfiguration _configuration;
13-
private readonly ITracker _tracker;
1417

15-
public RelewiseContentDeletedNotificationNotificationHandler(RelewiseUmbracoConfiguration configuration, ITracker tracker)
18+
public RelewiseContentDeletedNotificationNotificationHandler(IExportContentService exportContentService, RelewiseUmbracoConfiguration configuration)
1619
{
20+
_exportContentService = exportContentService;
1721
_configuration = configuration;
18-
_tracker = tracker;
1922
}
2023

21-
public void Handle(ContentDeletedNotification notification)
24+
public async Task HandleAsync(ContentDeletedNotification notification, CancellationToken cancellationToken)
2225
{
26+
ITracker? tracker = _exportContentService.GetTrackerOrNull();
27+
28+
if (tracker == null)
29+
return;
30+
2331
string[] ids = notification.DeletedEntities
2432
.Where(x => _configuration.CanMap(x))
2533
.Select(x => x.Id.ToString())
@@ -28,10 +36,12 @@ public void Handle(ContentDeletedNotification notification)
2836
if (ids.Length == 0)
2937
return;
3038

31-
_tracker.Track(new ContentAdministrativeAction(
39+
var action = new ContentAdministrativeAction(
3240
Language.Undefined,
3341
Currency.Undefined,
3442
new FilterCollection(new ContentIdFilter(ids)),
35-
ContentAdministrativeAction.UpdateKind.PermanentlyDelete));
43+
ContentAdministrativeAction.UpdateKind.PermanentlyDelete);
44+
45+
await tracker.TrackAsync(action, cancellationToken);
3646
}
3747
}
Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,35 @@
11
using System.Linq;
2+
using System.Threading;
3+
using System.Threading.Tasks;
24
using Relewise.Client;
35
using Relewise.Client.DataTypes;
46
using Relewise.Client.Requests.Filters;
7+
using Relewise.Integrations.Umbraco.Services;
58
using Umbraco.Cms.Core.Events;
69
using Umbraco.Cms.Core.Notifications;
710

811
namespace Relewise.Integrations.Umbraco.NotificationHandlers;
912

10-
internal class RelewiseContentMovedNotificationHandler : INotificationHandler<ContentMovedNotification>
13+
internal class RelewiseContentMovedNotificationHandler : INotificationAsyncHandler<ContentMovedNotification>
1114
{
1215
private const int TrashCanId = -1;
1316

17+
private readonly IExportContentService _exportContentService;
1418
private readonly RelewiseUmbracoConfiguration _configuration;
15-
private readonly ITracker _tracker;
1619

17-
public RelewiseContentMovedNotificationHandler(RelewiseUmbracoConfiguration configuration, ITracker tracker)
20+
public RelewiseContentMovedNotificationHandler(IExportContentService exportContentService, RelewiseUmbracoConfiguration configuration)
1821
{
22+
_exportContentService = exportContentService;
1923
_configuration = configuration;
20-
_tracker = tracker;
2124
}
2225

23-
public void Handle(ContentMovedNotification notification)
26+
public async Task HandleAsync(ContentMovedNotification notification, CancellationToken cancellationToken)
2427
{
28+
ITracker? tracker = _exportContentService.GetTrackerOrNull();
29+
30+
if (tracker == null)
31+
return;
32+
2533
string[] ids = notification.MoveInfoCollection
2634
.Where(x => _configuration.CanMap(x.Entity) && x.NewParentId == TrashCanId)
2735
.Select(x => x.Entity.Id.ToString())
@@ -30,10 +38,12 @@ public void Handle(ContentMovedNotification notification)
3038
if (ids.Length == 0)
3139
return;
3240

33-
_tracker.Track(new ContentAdministrativeAction(
41+
var action = new ContentAdministrativeAction(
3442
Language.Undefined,
3543
Currency.Undefined,
3644
new FilterCollection(new ContentIdFilter(ids)),
37-
ContentAdministrativeAction.UpdateKind.DisableInRecommendations));
45+
ContentAdministrativeAction.UpdateKind.DisableInRecommendations);
46+
47+
await tracker.TrackAsync(action, cancellationToken);
3848
}
3949
}
Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
using System.Linq;
22
using System.Threading;
3+
using System.Threading.Tasks;
34
using Relewise.Integrations.Umbraco.Services;
45
using Umbraco.Cms.Core.Events;
56
using Umbraco.Cms.Core.Notifications;
67

78
namespace Relewise.Integrations.Umbraco.NotificationHandlers;
89

9-
internal class RelewiseContentPublishedNotificationHandler : INotificationHandler<ContentPublishedNotification>
10+
internal class RelewiseContentPublishedNotificationHandler : INotificationAsyncHandler<ContentPublishedNotification>
1011
{
1112
private readonly IExportContentService _exportContentService;
1213

@@ -15,8 +16,8 @@ public RelewiseContentPublishedNotificationHandler(IExportContentService exportC
1516
_exportContentService = exportContentService;
1617
}
1718

18-
public void Handle(ContentPublishedNotification notification)
19+
public async Task HandleAsync(ContentPublishedNotification notification, CancellationToken cancellationToken)
1920
{
20-
_exportContentService.Export(new ExportContent(notification.PublishedEntities.ToArray()), CancellationToken.None);
21+
await _exportContentService.Export(new ExportContent(notification.PublishedEntities.ToArray()), cancellationToken);
2122
}
2223
}
Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,34 @@
11
using System.Linq;
2+
using System.Threading;
3+
using System.Threading.Tasks;
24
using Relewise.Client;
35
using Relewise.Client.DataTypes;
46
using Relewise.Client.Requests.Filters;
7+
using Relewise.Integrations.Umbraco.Services;
58
using Umbraco.Cms.Core.Events;
69
using Umbraco.Cms.Core.Notifications;
710
using Language = Relewise.Client.DataTypes.Language;
811

912
namespace Relewise.Integrations.Umbraco.NotificationHandlers;
1013

11-
internal class RelewiseContentUnpublishedNotificationHandler : INotificationHandler<ContentUnpublishedNotification>
14+
internal class RelewiseContentUnpublishedNotificationHandler : INotificationAsyncHandler<ContentUnpublishedNotification>
1215
{
16+
private readonly IExportContentService _exportContentService;
1317
private readonly RelewiseUmbracoConfiguration _configuration;
14-
private readonly ITracker _tracker;
1518

16-
public RelewiseContentUnpublishedNotificationHandler(RelewiseUmbracoConfiguration configuration, ITracker tracker)
19+
public RelewiseContentUnpublishedNotificationHandler(IExportContentService exportContentService, RelewiseUmbracoConfiguration configuration)
1720
{
21+
_exportContentService = exportContentService;
1822
_configuration = configuration;
19-
_tracker = tracker;
2023
}
2124

22-
public void Handle(ContentUnpublishedNotification notification)
25+
public async Task HandleAsync(ContentUnpublishedNotification notification, CancellationToken cancellationToken)
2326
{
27+
ITracker? tracker = _exportContentService.GetTrackerOrNull();
28+
29+
if (tracker == null)
30+
return;
31+
2432
string[] ids = notification.UnpublishedEntities
2533
.Where(x => _configuration.CanMap(x))
2634
.Select(x => x.Id.ToString())
@@ -29,10 +37,12 @@ public void Handle(ContentUnpublishedNotification notification)
2937
if (ids.Length == 0)
3038
return;
3139

32-
_tracker.Track(new ContentAdministrativeAction(
40+
var action = new ContentAdministrativeAction(
3341
Language.Undefined,
3442
Currency.Undefined,
3543
new FilterCollection(new ContentIdFilter(ids)),
36-
ContentAdministrativeAction.UpdateKind.DisableInRecommendations));
44+
ContentAdministrativeAction.UpdateKind.DisableInRecommendations);
45+
46+
await tracker.TrackAsync(action, cancellationToken);
3747
}
3848
}

src/Integrations.Umbraco/Services/ContentMapper.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public ContentMapper(RelewiseUmbracoConfiguration configuration, IUmbracoContext
2727
_provider = provider;
2828
}
2929

30-
public async Task<MapContentResult> Map(MapContent content)
30+
public async Task<MapContentResult> Map(MapContent content, CancellationToken token)
3131
{
3232
if (!_configuration.CanMap(content.PublishedContent.ContentType.Alias))
3333
return MapContentResult.Failed;
@@ -50,7 +50,7 @@ public async Task<MapContentResult> Map(MapContent content)
5050
CategoryPaths = GetCategoryPaths(content, culturesToPublish)
5151
});
5252

53-
await AutoMapOrUseMapper(content, culturesToPublish, contentUpdate, content.Token);
53+
await AutoMapOrUseMapper(content, culturesToPublish, contentUpdate, token);
5454

5555
return new MapContentResult(contentUpdate);
5656
}

src/Integrations.Umbraco/Services/ExportContentService.cs

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -36,29 +36,28 @@ public ExportContentService(IContentMapper contentMapper, IUmbracoContextFactory
3636
public async Task<ExportContentResult> Export(ExportContent exportContent, CancellationToken token)
3737
{
3838
if (exportContent == null) throw new ArgumentNullException(nameof(exportContent));
39+
3940
if (exportContent.Contents.Length == 0)
4041
return new ExportContentResult();
4142

4243
using UmbracoContextReference umbracoContextReference = _umbracoContextFactory.EnsureUmbracoContext();
4344

4445
IPublishedContentCache contentCache = umbracoContextReference.UmbracoContext.Content;
4546

46-
ITracker tracker;
47-
try
48-
{
49-
var factory = _provider.GetRequiredService<IRelewiseClientFactory>();
50-
tracker = factory.GetClient<ITracker>(Constants.NamedClientName);
51-
}
52-
catch
53-
{
54-
// tracker is not setup correctly so we just fail silently
47+
ITracker? tracker = GetTrackerOrNull();
48+
49+
if (tracker == null)
5550
return new ExportContentResult();
56-
}
5751

5852
List<ContentUpdate> contentUpdates = new List<ContentUpdate>();
59-
foreach (Task<MapContentResult> map in exportContent.Contents.Select(x => _contentMapper.Map(new MapContent(contentCache.GetById(x.Id), exportContent.Version, token))))
53+
54+
IEnumerable<Task<MapContentResult>> contentMapping = exportContent.Contents
55+
.Select(x => _contentMapper.Map(new MapContent(contentCache.GetById(x.Id), exportContent.Version), token));
56+
57+
foreach (Task<MapContentResult> map in contentMapping)
6058
{
6159
MapContentResult result = await map;
60+
6261
if (result.Successful)
6362
contentUpdates.Add(result.ContentUpdate!);
6463
}
@@ -108,4 +107,19 @@ await tracker.TrackAsync(new ContentAdministrativeAction(
108107

109108
return new ExportAllContentResult();
110109
}
110+
111+
public ITracker? GetTrackerOrNull()
112+
{
113+
try
114+
{
115+
var factory = _provider.GetRequiredService<IRelewiseClientFactory>();
116+
117+
return factory.GetClient<ITracker>(Constants.NamedClientName);
118+
}
119+
catch
120+
{
121+
// tracker is not setup correctly so we just fail silently
122+
return null;
123+
}
124+
}
111125
}
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
using System.Threading.Tasks;
1+
using System.Threading;
2+
using System.Threading.Tasks;
23

34
namespace Relewise.Integrations.Umbraco.Services;
45

56
internal interface IContentMapper
67
{
7-
Task<MapContentResult> Map(MapContent content);
8+
Task<MapContentResult> Map(MapContent content, CancellationToken token);
89
}

0 commit comments

Comments
 (0)