|
1 |
| -using System; |
| 1 | +#if NETFRAMEWORK |
| 2 | +using System; |
2 | 3 | using System.Collections.Generic;
|
3 |
| -using System.Net.Http; |
4 | 4 | using System.Threading.Tasks;
|
5 | 5 |
|
6 |
| - |
7 | 6 | using Umbraco.Cms.Integrations.Automation.Zapier.Services;
|
8 | 7 | using Umbraco.Core;
|
9 |
| - |
10 |
| -#if NETCOREAPP |
11 |
| -using Microsoft.Extensions.Logging; |
12 |
| -using Umbraco.Cms.Core.Events; |
13 |
| -using Umbraco.Cms.Core.Notifications; |
14 |
| -#else |
15 | 8 | using Umbraco.Core.Composing;
|
16 | 9 | using Umbraco.Core.Events;
|
17 | 10 | using Umbraco.Core.Logging;
|
18 | 11 | using Umbraco.Core.Services;
|
19 | 12 | using Umbraco.Core.Services.Implement;
|
20 |
| -#endif |
21 | 13 |
|
22 | 14 | namespace Umbraco.Cms.Integrations.Automation.Zapier.Components
|
23 | 15 | {
|
24 |
| -#if NETCOREAPP |
25 |
| - public class NewContentPublishedNotification : INotificationHandler<ContentPublishedNotification> |
26 |
| - { |
27 |
| - private readonly ZapConfigService _zapConfigService; |
28 |
| - |
29 |
| - private readonly ZapierService _zapierService; |
30 |
| - |
31 |
| - private readonly ILogger<NewContentPublishedNotification> _logger; |
32 |
| - |
33 |
| - public NewContentPublishedNotification(ZapConfigService zapConfigService, ZapierService zapierService, ILogger<NewContentPublishedNotification> logger) |
34 |
| - { |
35 |
| - _zapConfigService = zapConfigService; |
36 |
| - |
37 |
| - _zapierService = zapierService; |
38 |
| - |
39 |
| - _logger = logger; |
40 |
| - } |
41 |
| - |
42 |
| - public void Handle(ContentPublishedNotification notification) |
43 |
| - { |
44 |
| - foreach (var node in notification.PublishedEntities) |
45 |
| - { |
46 |
| - var zapContentConfig = _zapConfigService.GetByName(node.ContentType.Name); |
47 |
| - if (zapContentConfig == null) continue; |
48 |
| - |
49 |
| - var content = new Dictionary<string, string> |
50 |
| - { |
51 |
| - { Constants.Content.Name, node.Name }, |
52 |
| - { Constants.Content.PublishDate, DateTime.UtcNow.ToString() } |
53 |
| - }; |
54 | 16 |
|
55 |
| - var t = Task.Run(async () => await _zapierService.TriggerAsync(zapContentConfig.WebHookUrl, content)); |
56 |
| - |
57 |
| - var result = t.Result; |
58 |
| - |
59 |
| - if (!string.IsNullOrEmpty(result)) |
60 |
| - _logger.LogError(result); |
61 |
| - } |
62 |
| - } |
63 |
| - } |
64 |
| -#else |
65 | 17 | [RuntimeLevel(MinLevel = RuntimeLevel.Run)]
|
66 | 18 | public class NewContentPublishedComposer : ComponentComposer<NewContentPublishedComponent>
|
67 | 19 | { }
|
@@ -115,5 +67,5 @@ private void ContentServiceOnPublished(IContentService sender, ContentPublishedE
|
115 | 67 | }
|
116 | 68 | }
|
117 | 69 | }
|
118 |
| -#endif |
119 | 70 | }
|
| 71 | +#endif |
0 commit comments