Skip to content

Commit

Permalink
format fix
Browse files Browse the repository at this point in the history
  • Loading branch information
tkrch committed Oct 21, 2024
1 parent 77dbaf0 commit e342010
Show file tree
Hide file tree
Showing 8 changed files with 1,755 additions and 1,755 deletions.
2 changes: 1 addition & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# * text=auto
* text eol=crlf

# Ensure binary files are not treated as text https://stackoverflow.com/a/32278635/939634
*.png binary
Expand Down
1,438 changes: 719 additions & 719 deletions KVA/Migration.Tool.Source/Handlers/MigratePagesCommandHandler.cs

Large diffs are not rendered by default.

158 changes: 79 additions & 79 deletions KVA/Migration.Tool.Source/Helpers/PageBuilderWidgetsPatcher.cs
Original file line number Diff line number Diff line change
@@ -1,79 +1,79 @@
using Migration.Tool.Common.Helpers;
using Migration.Tool.Common.Model;
using Newtonsoft.Json.Linq;

namespace Migration.Tool.Source.Helpers;

public static class PageBuilderWidgetsPatcher
{
public static EditableAreasConfiguration DeferredPatchConfiguration(EditableAreasConfiguration configuration, TreePathConvertor convertor, out bool anythingChanged)
{
anythingChanged = false;
foreach (var configurationEditableArea in configuration.EditableAreas ?? [])
{
foreach (var sectionConfiguration in configurationEditableArea.Sections ?? [])
{
foreach (var sectionConfigurationZone in sectionConfiguration.Zones ?? [])
{
foreach (var configurationZoneWidget in sectionConfigurationZone.Widgets ?? [])
{
DeferredPatchWidget(configurationZoneWidget, convertor, out bool anythingChangedTmp);
anythingChanged = anythingChanged || anythingChangedTmp;
}
}
}
}

return configuration;
}

private static void DeferredPatchWidget(WidgetConfiguration? configurationZoneWidget, TreePathConvertor convertor, out bool anythingChanged)
{
anythingChanged = false;
if (configurationZoneWidget == null)
{
return;
}

var list = configurationZoneWidget.Variants ?? [];
for (int i = 0; i < list.Count; i++)
{
if (list[i] is { } variantJson)
{
var variant = JObject.FromObject(variantJson);
DeferredPatchProperties(variant, convertor, out bool anythingChangedTmp);

list[i] = variant.ToObject<WidgetVariantConfiguration>();
anythingChanged = anythingChanged || anythingChangedTmp;
}
}
}

public static void DeferredPatchProperties(JObject propertyContainer, TreePathConvertor convertor, out bool anythingChanged)
{
anythingChanged = false;
if (propertyContainer?["properties"] is JObject { Count: 1 } properties)
{
foreach ((string key, var value) in properties)
{
switch (key)
{
case "TreePath" when value?.Value<string>() is { } nodeAliasPath:
{
string treePath = convertor.GetConvertedOrUnchangedAssumingChannel(nodeAliasPath);
if (!TreePathConvertor.TreePathComparer.Equals(nodeAliasPath, treePath))
{
properties["TreePath"] = JToken.FromObject(treePath);
anythingChanged = true;
}

break;
}

default:
break;
}
}
}
}
}
using Migration.Tool.Common.Helpers;
using Migration.Tool.Common.Model;
using Newtonsoft.Json.Linq;

namespace Migration.Tool.Source.Helpers;

public static class PageBuilderWidgetsPatcher
{
public static EditableAreasConfiguration DeferredPatchConfiguration(EditableAreasConfiguration configuration, TreePathConvertor convertor, out bool anythingChanged)
{
anythingChanged = false;
foreach (var configurationEditableArea in configuration.EditableAreas ?? [])
{
foreach (var sectionConfiguration in configurationEditableArea.Sections ?? [])
{
foreach (var sectionConfigurationZone in sectionConfiguration.Zones ?? [])
{
foreach (var configurationZoneWidget in sectionConfigurationZone.Widgets ?? [])
{
DeferredPatchWidget(configurationZoneWidget, convertor, out bool anythingChangedTmp);
anythingChanged = anythingChanged || anythingChangedTmp;
}
}
}
}

return configuration;
}

private static void DeferredPatchWidget(WidgetConfiguration? configurationZoneWidget, TreePathConvertor convertor, out bool anythingChanged)
{
anythingChanged = false;
if (configurationZoneWidget == null)
{
return;
}

var list = configurationZoneWidget.Variants ?? [];
for (int i = 0; i < list.Count; i++)
{
if (list[i] is { } variantJson)
{
var variant = JObject.FromObject(variantJson);
DeferredPatchProperties(variant, convertor, out bool anythingChangedTmp);

list[i] = variant.ToObject<WidgetVariantConfiguration>();
anythingChanged = anythingChanged || anythingChangedTmp;
}
}
}

public static void DeferredPatchProperties(JObject propertyContainer, TreePathConvertor convertor, out bool anythingChanged)
{
anythingChanged = false;
if (propertyContainer?["properties"] is JObject { Count: 1 } properties)
{
foreach ((string key, var value) in properties)
{
switch (key)
{
case "TreePath" when value?.Value<string>() is { } nodeAliasPath:
{
string treePath = convertor.GetConvertedOrUnchangedAssumingChannel(nodeAliasPath);
if (!TreePathConvertor.TreePathComparer.Equals(nodeAliasPath, treePath))
{
properties["TreePath"] = JToken.FromObject(treePath);
anythingChanged = true;
}

break;
}

default:
break;
}
}
}
}
}
218 changes: 109 additions & 109 deletions KVA/Migration.Tool.Source/KsCoreDiExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,109 +1,109 @@
using CMS.DataEngine;
using CMS.FormEngine;
using CMS.MediaLibrary;
using CMS.Membership;
using CMS.Modules;
using CMS.OnlineForms;
using CMS.Websites;

using Kentico.Xperience.UMT;

using MediatR;

using Microsoft.Extensions.DependencyInjection;

using Migration.Tool.Common;
using Migration.Tool.Common.Abstractions;
using Migration.Tool.Common.MigrationProtocol;
using Migration.Tool.Common.Services;
using Migration.Tool.Common.Services.BulkCopy;
using Migration.Tool.Common.Services.Ipc;
using Migration.Tool.KXP.Models;
using Migration.Tool.Source.Auxiliary;
using Migration.Tool.Source.Behaviors;
using Migration.Tool.Source.Contexts;
using Migration.Tool.Source.Helpers;
using Migration.Tool.Source.Mappers;
using Migration.Tool.Source.Model;
using Migration.Tool.Source.Providers;
using Migration.Tool.Source.Services;

namespace Migration.Tool.Source;

public static class KsCoreDiExtensions
{
public static IServiceProvider ServiceProvider { get; private set; } = null!;
public static void InitServiceProvider(IServiceProvider serviceProvider) => ServiceProvider = serviceProvider;

public static IServiceCollection UseKsToolCore(this IServiceCollection services, bool? migrateMediaToMediaLibrary = false)
{
var printService = new PrintService();
services.AddSingleton<IPrintService>(printService);
HandbookReference.PrintService = printService;
LogExtensions.PrintService = printService;

services.AddTransient<IModuleLoader, ModuleLoader>();

services.AddSingleton<ModelFacade>();
services.AddSingleton<ISpoiledGuidContext, SpoiledGuidContext>();
services.AddSingleton(s => s.GetRequiredService<ISpoiledGuidContext>() as SpoiledGuidContext ?? throw new InvalidOperationException());

services.AddSingleton<ISourceGuidContext, SourceGuidContext>();
services.AddSingleton<EntityIdentityFacade>();
services.AddSingleton<IdentityLocator>();
services.AddSingleton<IAssetFacade, AssetFacade>();
services.AddSingleton<MediaLinkServiceFactory>();
services.AddSingleton<ClassMappingProvider>();
services.AddTransient<PageBuilderPatcher>();

services.AddTransient<BulkDataCopyService>();
services.AddTransient<CmsRelationshipService>();
services.AddTransient<CoupledDataService>();
if (migrateMediaToMediaLibrary ?? false)
{
services.AddScoped<IAttachmentMigrator, AttachmentMigratorToMediaLibrary>();
services.AddScoped<IMediaFileMigrator, MediaFileMigrator>();
}
else
{
services.AddScoped<IAttachmentMigrator, AttachmentMigratorToContentItem>();
services.AddScoped<IMediaFileMigrator, MediaFileMigratorToContentItem>();
}
services.AddScoped<PageTemplateMigrator>();
services.AddScoped<ClassService>();

services.AddMediatR(cfg => cfg.RegisterServicesFromAssembly(typeof(KsCoreDiExtensions).Assembly));
services.AddTransient(typeof(IPipelineBehavior<,>), typeof(RequestHandlingBehavior<,>));
services.AddTransient(typeof(IPipelineBehavior<,>), typeof(CommandConstraintBehavior<,>));
services.AddTransient(typeof(IPipelineBehavior<,>), typeof(XbKApiContextBehavior<,>));

services.AddSingleton<SourceInstanceContext>();
services.AddSingleton<DeferredPathService>();
services.AddTransient<IpcService>();
services.AddTransient<ReusableSchemaService>();

services.AddScoped<PrimaryKeyMappingContext>();
services.AddScoped<IPrimaryKeyMappingContext, PrimaryKeyMappingContext>(s => s.GetRequiredService<PrimaryKeyMappingContext>());
services.AddScoped<IPrimaryKeyLocatorService, PrimaryKeyLocatorService>();

// umt mappers
services.AddTransient<IUmtMapper<CmsTreeMapperSource>, ContentItemMapper>();
services.AddTransient<IUmtMapper<TagModelSource>, TagMapper>();

// mappers
services.AddTransient<IEntityMapper<CmsAttachmentMapperSource, MediaFileInfo>, CmsAttachmentMapper>();
services.AddTransient<IEntityMapper<ICmsClass, DataClassInfo>, CmsClassMapper>();
services.AddTransient<IEntityMapper<ICmsForm, BizFormInfo>, CmsFormMapper>();
services.AddTransient<IEntityMapper<ICmsForm, CmsForm>, CmsFormMapperEf>();
services.AddTransient<IEntityMapper<ICmsResource, ResourceInfo>, ResourceMapper>();
services.AddTransient<IEntityMapper<AlternativeFormMapperSource, AlternativeFormInfo>, AlternativeFormMapper>();
services.AddTransient<IEntityMapper<MemberInfoMapperSource, MemberInfo>, MemberInfoMapper>();
services.AddTransient<IEntityMapper<ICmsPageTemplateConfiguration, PageTemplateConfigurationInfo>, PageTemplateConfigurationMapper>();
services.AddTransient<IEntityMapper<MediaLibraryInfoMapperSource, MediaLibraryInfo>, MediaLibraryInfoMapper>();
services.AddTransient<IEntityMapper<MediaFileInfoMapperSource, MediaFileInfo>, MediaFileInfoMapper>();

services.AddUniversalMigrationToolkit();

return services;
}
}
using CMS.DataEngine;
using CMS.FormEngine;
using CMS.MediaLibrary;
using CMS.Membership;
using CMS.Modules;
using CMS.OnlineForms;
using CMS.Websites;

using Kentico.Xperience.UMT;

using MediatR;

using Microsoft.Extensions.DependencyInjection;

using Migration.Tool.Common;
using Migration.Tool.Common.Abstractions;
using Migration.Tool.Common.MigrationProtocol;
using Migration.Tool.Common.Services;
using Migration.Tool.Common.Services.BulkCopy;
using Migration.Tool.Common.Services.Ipc;
using Migration.Tool.KXP.Models;
using Migration.Tool.Source.Auxiliary;
using Migration.Tool.Source.Behaviors;
using Migration.Tool.Source.Contexts;
using Migration.Tool.Source.Helpers;
using Migration.Tool.Source.Mappers;
using Migration.Tool.Source.Model;
using Migration.Tool.Source.Providers;
using Migration.Tool.Source.Services;

namespace Migration.Tool.Source;

public static class KsCoreDiExtensions
{
public static IServiceProvider ServiceProvider { get; private set; } = null!;
public static void InitServiceProvider(IServiceProvider serviceProvider) => ServiceProvider = serviceProvider;

public static IServiceCollection UseKsToolCore(this IServiceCollection services, bool? migrateMediaToMediaLibrary = false)
{
var printService = new PrintService();
services.AddSingleton<IPrintService>(printService);
HandbookReference.PrintService = printService;
LogExtensions.PrintService = printService;

services.AddTransient<IModuleLoader, ModuleLoader>();

services.AddSingleton<ModelFacade>();
services.AddSingleton<ISpoiledGuidContext, SpoiledGuidContext>();
services.AddSingleton(s => s.GetRequiredService<ISpoiledGuidContext>() as SpoiledGuidContext ?? throw new InvalidOperationException());

services.AddSingleton<ISourceGuidContext, SourceGuidContext>();
services.AddSingleton<EntityIdentityFacade>();
services.AddSingleton<IdentityLocator>();
services.AddSingleton<IAssetFacade, AssetFacade>();
services.AddSingleton<MediaLinkServiceFactory>();
services.AddSingleton<ClassMappingProvider>();
services.AddTransient<PageBuilderPatcher>();

services.AddTransient<BulkDataCopyService>();
services.AddTransient<CmsRelationshipService>();
services.AddTransient<CoupledDataService>();
if (migrateMediaToMediaLibrary ?? false)
{
services.AddScoped<IAttachmentMigrator, AttachmentMigratorToMediaLibrary>();
services.AddScoped<IMediaFileMigrator, MediaFileMigrator>();
}
else
{
services.AddScoped<IAttachmentMigrator, AttachmentMigratorToContentItem>();
services.AddScoped<IMediaFileMigrator, MediaFileMigratorToContentItem>();
}
services.AddScoped<PageTemplateMigrator>();
services.AddScoped<ClassService>();

services.AddMediatR(cfg => cfg.RegisterServicesFromAssembly(typeof(KsCoreDiExtensions).Assembly));
services.AddTransient(typeof(IPipelineBehavior<,>), typeof(RequestHandlingBehavior<,>));
services.AddTransient(typeof(IPipelineBehavior<,>), typeof(CommandConstraintBehavior<,>));
services.AddTransient(typeof(IPipelineBehavior<,>), typeof(XbKApiContextBehavior<,>));

services.AddSingleton<SourceInstanceContext>();
services.AddSingleton<DeferredPathService>();
services.AddTransient<IpcService>();
services.AddTransient<ReusableSchemaService>();

services.AddScoped<PrimaryKeyMappingContext>();
services.AddScoped<IPrimaryKeyMappingContext, PrimaryKeyMappingContext>(s => s.GetRequiredService<PrimaryKeyMappingContext>());
services.AddScoped<IPrimaryKeyLocatorService, PrimaryKeyLocatorService>();

// umt mappers
services.AddTransient<IUmtMapper<CmsTreeMapperSource>, ContentItemMapper>();
services.AddTransient<IUmtMapper<TagModelSource>, TagMapper>();

// mappers
services.AddTransient<IEntityMapper<CmsAttachmentMapperSource, MediaFileInfo>, CmsAttachmentMapper>();
services.AddTransient<IEntityMapper<ICmsClass, DataClassInfo>, CmsClassMapper>();
services.AddTransient<IEntityMapper<ICmsForm, BizFormInfo>, CmsFormMapper>();
services.AddTransient<IEntityMapper<ICmsForm, CmsForm>, CmsFormMapperEf>();
services.AddTransient<IEntityMapper<ICmsResource, ResourceInfo>, ResourceMapper>();
services.AddTransient<IEntityMapper<AlternativeFormMapperSource, AlternativeFormInfo>, AlternativeFormMapper>();
services.AddTransient<IEntityMapper<MemberInfoMapperSource, MemberInfo>, MemberInfoMapper>();
services.AddTransient<IEntityMapper<ICmsPageTemplateConfiguration, PageTemplateConfigurationInfo>, PageTemplateConfigurationMapper>();
services.AddTransient<IEntityMapper<MediaLibraryInfoMapperSource, MediaLibraryInfo>, MediaLibraryInfoMapper>();
services.AddTransient<IEntityMapper<MediaFileInfoMapperSource, MediaFileInfo>, MediaFileInfoMapper>();

services.AddUniversalMigrationToolkit();

return services;
}
}
Loading

0 comments on commit e342010

Please sign in to comment.