-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
147 additions
and
5 deletions.
There are no files selected for viewing
This file contains 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 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
16 changes: 16 additions & 0 deletions
16
src/Geta.Optimizely.GenericLinks/Extensions/DependencyInjectionExtensions.cs
This file contains 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,16 @@ | ||
using EPiServer.Core.Transfer; | ||
using Geta.Optimizely.GenericLinks; | ||
using Geta.Optimizely.GenericLinks.Transfer; | ||
|
||
namespace Microsoft.Extensions.DependencyInjection | ||
{ | ||
public static class DependencyInjectionExtensions | ||
{ | ||
public static void AddLinkDataExportTransform<TLinkData>(this IServiceCollection services) | ||
where TLinkData : LinkData, new() | ||
{ | ||
services.AddSingleton<PropertyLinkDataCollectionTransform<TLinkData>>().Forward<PropertyLinkDataCollectionTransform<TLinkData>, IPropertyTransform>(); | ||
services.AddSingleton<PropertyLinkDataTransform<TLinkData>>().Forward<PropertyLinkDataTransform<TLinkData>, IPropertyTransform>(); | ||
} | ||
} | ||
} |
This file contains 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
56 changes: 56 additions & 0 deletions
56
src/Geta.Optimizely.GenericLinks/Transfer/PropertyLinkDataCollectionTransform.cs
This file contains 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,56 @@ | ||
// Copyright (c) Geta Digital. All rights reserved. | ||
// Licensed under Apache-2.0. See the LICENSE file in the project root for more information | ||
|
||
using EPiServer.Core.Transfer; | ||
using EPiServer.Core; | ||
using EPiServer; | ||
using EPiServer.Core.Transfer.Internal; | ||
using System.Linq; | ||
using Geta.Optimizely.GenericLinks.Html; | ||
|
||
namespace Geta.Optimizely.GenericLinks.Transfer | ||
{ | ||
public sealed class PropertyLinkDataCollectionTransform<TLinkData> : PropertyTransform<PropertyLinkDataCollection<TLinkData>> | ||
where TLinkData : ILinkData, new() | ||
{ | ||
private readonly IContentLoader _contentLoader; | ||
private readonly ILinkHtmlSerializer _linkHtmlSerializer; | ||
private readonly IImplicitContentExporter _implicitContentExporter; | ||
|
||
public PropertyLinkDataCollectionTransform( | ||
IImplicitContentExporter implicitContentExporter, | ||
ILinkHtmlSerializer linkHtmlSerializer, | ||
IContentLoader contentLoader) | ||
{ | ||
_implicitContentExporter = implicitContentExporter; | ||
_linkHtmlSerializer = linkHtmlSerializer; | ||
_contentLoader = contentLoader; | ||
} | ||
|
||
protected override bool TransformForExport( | ||
PropertyLinkDataCollection<TLinkData> source, | ||
RawProperty output, | ||
PropertyExportContext context) | ||
{ | ||
if (source.Value is null) | ||
{ | ||
output.Value = null; | ||
return true; | ||
} | ||
|
||
var sourceLinks = source.Links!.Select(l => l.ReferencedPermanentLinkIds); | ||
|
||
foreach (var guids in sourceLinks) | ||
{ | ||
foreach (var contentGuid in guids) | ||
{ | ||
if (_contentLoader.TryGet<IContent>(contentGuid, out var content)) | ||
_implicitContentExporter.ExportDependentContent(content, context.TransferContext); | ||
} | ||
} | ||
|
||
output.Value = _linkHtmlSerializer.Serialize(source.Links, StringMode.InternalMode); | ||
return true; | ||
} | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
src/Geta.Optimizely.GenericLinks/Transfer/PropertyLinkDataTransform.cs
This file contains 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,47 @@ | ||
// Copyright (c) Geta Digital. All rights reserved. | ||
// Licensed under Apache-2.0. See the LICENSE file in the project root for more information | ||
|
||
using EPiServer.Core.Transfer; | ||
using EPiServer; | ||
using EPiServer.Core.Transfer.Internal; | ||
using EPiServer.Core; | ||
using Geta.Optimizely.GenericLinks.Html; | ||
|
||
namespace Geta.Optimizely.GenericLinks.Transfer | ||
{ | ||
public sealed class PropertyLinkDataTransform<TLinkData> : PropertyTransform<PropertyLinkData<TLinkData>> | ||
where TLinkData : LinkData, new() | ||
{ | ||
private readonly IContentLoader _contentLoader; | ||
private readonly IImplicitContentExporter _implicitContentExporter; | ||
private readonly ILinkHtmlSerializer _linkHtmlSerializer; | ||
|
||
public PropertyLinkDataTransform( | ||
IImplicitContentExporter implicitContentExporter, | ||
ILinkHtmlSerializer linkHtmlSerializer, | ||
IContentLoader contentLoader) | ||
{ | ||
_implicitContentExporter = implicitContentExporter; | ||
_linkHtmlSerializer = linkHtmlSerializer; | ||
_contentLoader = contentLoader; | ||
} | ||
|
||
protected override bool TransformForExport(PropertyLinkData<TLinkData> source, RawProperty output, PropertyExportContext context) | ||
{ | ||
if (source.Value is null) | ||
{ | ||
output.Value = null; | ||
return true; | ||
} | ||
|
||
foreach (var referencedPermanentLinkId in source.Link!.ReferencedPermanentLinkIds) | ||
{ | ||
if (_contentLoader.TryGet(referencedPermanentLinkId, out IContent content)) | ||
_implicitContentExporter.ExportDependentContent(content, context.TransferContext); | ||
} | ||
|
||
output.Value = _linkHtmlSerializer.Serialize(source.Link, StringMode.InternalMode); | ||
return true; | ||
} | ||
} | ||
} |