generated from Kentico/repo-template
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #271 from Kentico/fix/fomatting-fix
formatting fix
- Loading branch information
Showing
1,427 changed files
with
109,112 additions
and
109,112 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
192 changes: 96 additions & 96 deletions
192
KVA/Migration.Tool.Source/Auxiliary/EntityIdentityImpl.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 |
---|---|---|
@@ -1,96 +1,96 @@ | ||
using System.Collections.Frozen; | ||
using CMS.DataEngine; | ||
using Microsoft.Extensions.Logging; | ||
using Migration.Tool.Common.Helpers; | ||
|
||
namespace Migration.Tool.Source.Auxiliary; | ||
|
||
public interface ISourceGuidContext | ||
{ | ||
int[]? GetSiteIds<T>(Guid entityGuid) where T : ISourceGuidEntity; | ||
} | ||
|
||
public class SourceGuidContext(ModelFacade modelFacade, ILogger<ISourceGuidContext> logger) : ISourceGuidContext | ||
{ | ||
private static class Cache<T> | ||
{ | ||
// ReSharper disable once StaticMemberInGenericType | ||
public static FrozenDictionary<Guid, int[]>? SourceGuidSites; | ||
} | ||
|
||
public int[]? GetSiteIds<T>(Guid entityGuid) where T : ISourceGuidEntity | ||
{ | ||
var cache = Cache<T>.SourceGuidSites ??= T.Load(modelFacade); | ||
int[]? result = cache.GetValueOrDefault(entityGuid); | ||
switch (result) | ||
{ | ||
case { Length: 0 }: | ||
{ | ||
logger.LogDebug("Guid {Guid} has no site at all", entityGuid); | ||
return []; | ||
} | ||
case { Length: 1 }: | ||
{ | ||
return result; | ||
} | ||
case null: | ||
{ | ||
logger.LogDebug("Guid {Guid} is not found at all", entityGuid); | ||
return null; | ||
} | ||
default: | ||
{ | ||
logger.LogDebug("Guid {Guid} is present on multiple sites {Sites}", entityGuid, string.Join("|", result)); | ||
return result; | ||
} | ||
} | ||
} | ||
} | ||
|
||
public record EntityIdentityGuidResult(bool IsFixed, Guid Identity); | ||
public class EntityIdentityFacade(ISourceGuidContext sourceGuidContext) | ||
{ | ||
public EntityIdentityGuidResult Translate<T>(Guid guid, int? siteId) where T : ISourceGuidEntity => | ||
sourceGuidContext.GetSiteIds<T>(guid) switch | ||
{ | ||
// not found => leave it as it is or throw | ||
{ Length: 0 } => new EntityIdentityGuidResult(false, guid), | ||
// OK! lets leave guid unchanged | ||
{ Length: 1 } => new EntityIdentityGuidResult(false, guid), | ||
// BAD, guid is not unique, we cannot use it in XbyK | ||
_ => new EntityIdentityGuidResult(true, GuidV5.NewNameBased(T.NewGuidNs, $"{guid}|{siteId ?? -1}")) | ||
}; | ||
|
||
public EntityIdentityGuidResult Translate<T>(T s) where T : ISourceGuidEntity => | ||
s.GetIdentity() is var (guid, siteId) | ||
? Translate<T>(guid, siteId) | ||
: throw new InvalidOperationException($"Unable to determine source entity identity: {s}"); | ||
} | ||
|
||
public class IdentityLocator(EntityIdentityFacade entityIdentityFacade, ILogger<IdentityLocator> logger) | ||
{ | ||
public (TTarget target, bool guidIsFixed) LocateTarget<TTarget, TSource>(Guid entityGuid, int? siteId) | ||
where TTarget : AbstractInfoBase<TTarget>, IInfoWithGuid, new() | ||
where TSource : ISourceGuidEntity | ||
{ | ||
(bool isFixed, var safeAttachmentGuid) = entityIdentityFacade.Translate<TSource>(entityGuid, siteId); | ||
var target = Provider<TTarget>.Instance.Get(safeAttachmentGuid); | ||
|
||
logger.LogTrace("Located {Target} from source {Source}", | ||
new { ID = target.Generalized.ObjectID, CodeName = target.Generalized.ObjectCodeName, type = target.TypeInfo.ObjectClassName }, | ||
new { type = typeof(TSource).Name, entityGuid, siteId } | ||
); | ||
|
||
return (target, isFixed); | ||
} | ||
|
||
public (TTarget target, bool guidIsFixed) LocateTarget<TTarget, TSource>(TSource s) | ||
where TTarget : AbstractInfoBase<TTarget>, IInfoWithGuid, new() | ||
where TSource : ISourceGuidEntity | ||
{ | ||
// TODO tomas.krch: 2024-07-23 specialized approach for CMS_USER and CMS_MEMBER | ||
|
||
(var entityGuid, int? siteId) = s.GetIdentity(); | ||
return LocateTarget<TTarget, TSource>(entityGuid, siteId); | ||
} | ||
} | ||
using System.Collections.Frozen; | ||
using CMS.DataEngine; | ||
using Microsoft.Extensions.Logging; | ||
using Migration.Tool.Common.Helpers; | ||
|
||
namespace Migration.Tool.Source.Auxiliary; | ||
|
||
public interface ISourceGuidContext | ||
{ | ||
int[]? GetSiteIds<T>(Guid entityGuid) where T : ISourceGuidEntity; | ||
} | ||
|
||
public class SourceGuidContext(ModelFacade modelFacade, ILogger<ISourceGuidContext> logger) : ISourceGuidContext | ||
{ | ||
private static class Cache<T> | ||
{ | ||
// ReSharper disable once StaticMemberInGenericType | ||
public static FrozenDictionary<Guid, int[]>? SourceGuidSites; | ||
} | ||
|
||
public int[]? GetSiteIds<T>(Guid entityGuid) where T : ISourceGuidEntity | ||
{ | ||
var cache = Cache<T>.SourceGuidSites ??= T.Load(modelFacade); | ||
int[]? result = cache.GetValueOrDefault(entityGuid); | ||
switch (result) | ||
{ | ||
case { Length: 0 }: | ||
{ | ||
logger.LogDebug("Guid {Guid} has no site at all", entityGuid); | ||
return []; | ||
} | ||
case { Length: 1 }: | ||
{ | ||
return result; | ||
} | ||
case null: | ||
{ | ||
logger.LogDebug("Guid {Guid} is not found at all", entityGuid); | ||
return null; | ||
} | ||
default: | ||
{ | ||
logger.LogDebug("Guid {Guid} is present on multiple sites {Sites}", entityGuid, string.Join("|", result)); | ||
return result; | ||
} | ||
} | ||
} | ||
} | ||
|
||
public record EntityIdentityGuidResult(bool IsFixed, Guid Identity); | ||
public class EntityIdentityFacade(ISourceGuidContext sourceGuidContext) | ||
{ | ||
public EntityIdentityGuidResult Translate<T>(Guid guid, int? siteId) where T : ISourceGuidEntity => | ||
sourceGuidContext.GetSiteIds<T>(guid) switch | ||
{ | ||
// not found => leave it as it is or throw | ||
{ Length: 0 } => new EntityIdentityGuidResult(false, guid), | ||
// OK! lets leave guid unchanged | ||
{ Length: 1 } => new EntityIdentityGuidResult(false, guid), | ||
// BAD, guid is not unique, we cannot use it in XbyK | ||
_ => new EntityIdentityGuidResult(true, GuidV5.NewNameBased(T.NewGuidNs, $"{guid}|{siteId ?? -1}")) | ||
}; | ||
|
||
public EntityIdentityGuidResult Translate<T>(T s) where T : ISourceGuidEntity => | ||
s.GetIdentity() is var (guid, siteId) | ||
? Translate<T>(guid, siteId) | ||
: throw new InvalidOperationException($"Unable to determine source entity identity: {s}"); | ||
} | ||
|
||
public class IdentityLocator(EntityIdentityFacade entityIdentityFacade, ILogger<IdentityLocator> logger) | ||
{ | ||
public (TTarget target, bool guidIsFixed) LocateTarget<TTarget, TSource>(Guid entityGuid, int? siteId) | ||
where TTarget : AbstractInfoBase<TTarget>, IInfoWithGuid, new() | ||
where TSource : ISourceGuidEntity | ||
{ | ||
(bool isFixed, var safeAttachmentGuid) = entityIdentityFacade.Translate<TSource>(entityGuid, siteId); | ||
var target = Provider<TTarget>.Instance.Get(safeAttachmentGuid); | ||
|
||
logger.LogTrace("Located {Target} from source {Source}", | ||
new { ID = target.Generalized.ObjectID, CodeName = target.Generalized.ObjectCodeName, type = target.TypeInfo.ObjectClassName }, | ||
new { type = typeof(TSource).Name, entityGuid, siteId } | ||
); | ||
|
||
return (target, isFixed); | ||
} | ||
|
||
public (TTarget target, bool guidIsFixed) LocateTarget<TTarget, TSource>(TSource s) | ||
where TTarget : AbstractInfoBase<TTarget>, IInfoWithGuid, new() | ||
where TSource : ISourceGuidEntity | ||
{ | ||
// TODO tomas.krch: 2024-07-23 specialized approach for CMS_USER and CMS_MEMBER | ||
|
||
(var entityGuid, int? siteId) = s.GetIdentity(); | ||
return LocateTarget<TTarget, TSource>(entityGuid, siteId); | ||
} | ||
} |
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 |
---|---|---|
@@ -1,77 +1,77 @@ | ||
using System.Xml.Linq; | ||
|
||
using Migration.Tool.Common; | ||
using Migration.Tool.Common.Enumerations; | ||
// ReSharper disable InconsistentNaming // generated class | ||
|
||
namespace Migration.Tool.Source.Auxiliary; | ||
|
||
internal class NodeXmlAdapter | ||
{ | ||
private readonly XElement xClass; | ||
|
||
public NodeXmlAdapter(string xml) | ||
{ | ||
var xDoc = XDocument.Parse(xml); | ||
if (xDoc.Root?.FirstNode is XElement dClass) | ||
{ | ||
xClass = dClass; | ||
ParsingSuccessful = true; | ||
} | ||
else | ||
{ | ||
xClass = null!; | ||
ParsingSuccessful = false; | ||
} | ||
} | ||
|
||
public bool ParsingSuccessful { get; } | ||
|
||
public int? NodeID => xClass.Element(NodeXmlColumns.NODE_ID)?.Value<int>(); | ||
public string? NodeAliasPath => xClass.Element(NodeXmlColumns.NODE_ALIAS_PATH)?.Value; | ||
public string? NodeName => xClass.Element(NodeXmlColumns.NODE_NAME)?.Value; | ||
public string? NodeAlias => xClass.Element(NodeXmlColumns.NODE_ALIAS)?.Value; | ||
public int? NodeClassID => xClass.Element(NodeXmlColumns.NODE_CLASS_ID)?.Value<int>(); | ||
public int? NodeParentID => xClass.Element(NodeXmlColumns.NODE_PARENT_ID)?.Value<int>(); | ||
public int? NodeLevel => xClass.Element(NodeXmlColumns.NODE_LEVEL)?.Value<int>(); | ||
public int? NodeSiteID => xClass.Element(NodeXmlColumns.NODE_SITE_ID)?.Value<int>(); | ||
|
||
[Obsolete("NodeGUID is not unique, use other means of node identification", true)] | ||
public Guid? NodeGUID => xClass.Element(NodeXmlColumns.NODE_GUID)?.Value<Guid>(); | ||
|
||
public int? NodeOrder => xClass.Element(NodeXmlColumns.NODE_ORDER)?.Value<int>(); | ||
public int? NodeOwner => xClass.Element(NodeXmlColumns.NODE_OWNER)?.Value<int>(); | ||
public bool? NodeHasChildren => xClass.Element(NodeXmlColumns.NODE_HAS_CHILDREN)?.ValueAsBool(); | ||
public bool? NodeHasLinks => xClass.Element(NodeXmlColumns.NODE_HAS_LINKS)?.ValueAsBool(); | ||
public int? NodeOriginalNodeID => xClass.Element(NodeXmlColumns.NODE_ORIGINAL_NODE_ID)?.Value<int>(); | ||
public bool? NodeIsPage => xClass.Element(NodeXmlColumns.NODE_IS_PAGE)?.ValueAsBool(); | ||
public bool? NodeIsSecured => xClass.Element(NodeXmlColumns.NODE_IS_SECURED)?.ValueAsBool(); | ||
public int? DocumentID => xClass.Element(NodeXmlColumns.DOCUMENT_ID)?.Value<int>(); | ||
public string? DocumentName => xClass.Element(NodeXmlColumns.DOCUMENT_NAME)?.Value; | ||
public DateTime? DocumentModifiedWhen => xClass.Element(NodeXmlColumns.DOCUMENT_MODIFIED_WHEN)?.Value<DateTime>(); | ||
public int? DocumentModifiedByUserID => xClass.Element(NodeXmlColumns.DOCUMENT_MODIFIED_BY_USER_ID)?.Value<int>(); | ||
public int? DocumentCreatedByUserID => xClass.Element(NodeXmlColumns.DOCUMENT_CREATED_BY_USER_ID)?.Value<int>(); | ||
public DateTime? DocumentCreatedWhen => xClass.Element(NodeXmlColumns.DOCUMENT_CREATED_WHEN)?.Value<DateTime>(); | ||
public int? DocumentCheckedOutVersionHistoryID => xClass.Element(NodeXmlColumns.DOCUMENT_CHECKED_OUT_VERSION_HISTORY_ID)?.Value<int>(); | ||
public int? DocumentPublishedVersionHistoryID => xClass.Element(NodeXmlColumns.DOCUMENT_PUBLISHED_VERSION_HISTORY_ID)?.Value<int>(); | ||
public int? DocumentWorkflowStepID => xClass.Element(NodeXmlColumns.DOCUMENT_WORKFLOW_STEP_ID)?.Value<int>(); | ||
public string? DocumentCulture => xClass.Element(NodeXmlColumns.DOCUMENT_CULTURE)?.Value; | ||
public int? DocumentNodeID => xClass.Element(NodeXmlColumns.DOCUMENT_NODE_ID)?.Value<int>(); | ||
public string? DocumentContent => xClass.Element(NodeXmlColumns.DOCUMENT_CONTENT)?.Value; | ||
public string? DocumentLastVersionNumber => xClass.Element(NodeXmlColumns.DOCUMENT_LAST_VERSION_NUMBER)?.Value; | ||
public bool? DocumentIsArchived => xClass.Element(NodeXmlColumns.DOCUMENT_IS_ARCHIVED)?.ValueAsBool(); | ||
|
||
[Obsolete("DocumentGUID is not unique, use other means of document identification", true)] | ||
public Guid? DocumentGUID => xClass.Element(NodeXmlColumns.DOCUMENT_GUID)?.Value<Guid>(); | ||
|
||
public Guid? DocumentWorkflowCycleGUID => xClass.Element(NodeXmlColumns.DOCUMENT_WORKFLOW_CYCLE_GUID)?.Value<Guid>(); | ||
public bool? DocumentCanBePublished => xClass.Element(NodeXmlColumns.DOCUMENT_CAN_BE_PUBLISHED)?.ValueAsBool(); | ||
public string? DocumentPageBuilderWidgets => xClass.Element(NodeXmlColumns.DOCUMENT_PAGE_BUILDER_WIDGETS)?.Value; | ||
public string? ClassName => xClass.Element(NodeXmlColumns.CLASS_NAME)?.Value; | ||
|
||
public string? DocumentPageTemplateConfiguration => xClass.Element(NodeXmlColumns.DOCUMENT_PAGE_TEMPLATE_CONFIGURATION)?.Value; | ||
|
||
public string? GetValue(string columnName) => xClass.Element(columnName)?.Value; | ||
|
||
public bool HasValueSet(string columnName) => xClass.Element(columnName) != null; | ||
} | ||
using System.Xml.Linq; | ||
|
||
using Migration.Tool.Common; | ||
using Migration.Tool.Common.Enumerations; | ||
// ReSharper disable InconsistentNaming // generated class | ||
|
||
namespace Migration.Tool.Source.Auxiliary; | ||
|
||
internal class NodeXmlAdapter | ||
{ | ||
private readonly XElement xClass; | ||
|
||
public NodeXmlAdapter(string xml) | ||
{ | ||
var xDoc = XDocument.Parse(xml); | ||
if (xDoc.Root?.FirstNode is XElement dClass) | ||
{ | ||
xClass = dClass; | ||
ParsingSuccessful = true; | ||
} | ||
else | ||
{ | ||
xClass = null!; | ||
ParsingSuccessful = false; | ||
} | ||
} | ||
|
||
public bool ParsingSuccessful { get; } | ||
|
||
public int? NodeID => xClass.Element(NodeXmlColumns.NODE_ID)?.Value<int>(); | ||
public string? NodeAliasPath => xClass.Element(NodeXmlColumns.NODE_ALIAS_PATH)?.Value; | ||
public string? NodeName => xClass.Element(NodeXmlColumns.NODE_NAME)?.Value; | ||
public string? NodeAlias => xClass.Element(NodeXmlColumns.NODE_ALIAS)?.Value; | ||
public int? NodeClassID => xClass.Element(NodeXmlColumns.NODE_CLASS_ID)?.Value<int>(); | ||
public int? NodeParentID => xClass.Element(NodeXmlColumns.NODE_PARENT_ID)?.Value<int>(); | ||
public int? NodeLevel => xClass.Element(NodeXmlColumns.NODE_LEVEL)?.Value<int>(); | ||
public int? NodeSiteID => xClass.Element(NodeXmlColumns.NODE_SITE_ID)?.Value<int>(); | ||
|
||
[Obsolete("NodeGUID is not unique, use other means of node identification", true)] | ||
public Guid? NodeGUID => xClass.Element(NodeXmlColumns.NODE_GUID)?.Value<Guid>(); | ||
|
||
public int? NodeOrder => xClass.Element(NodeXmlColumns.NODE_ORDER)?.Value<int>(); | ||
public int? NodeOwner => xClass.Element(NodeXmlColumns.NODE_OWNER)?.Value<int>(); | ||
public bool? NodeHasChildren => xClass.Element(NodeXmlColumns.NODE_HAS_CHILDREN)?.ValueAsBool(); | ||
public bool? NodeHasLinks => xClass.Element(NodeXmlColumns.NODE_HAS_LINKS)?.ValueAsBool(); | ||
public int? NodeOriginalNodeID => xClass.Element(NodeXmlColumns.NODE_ORIGINAL_NODE_ID)?.Value<int>(); | ||
public bool? NodeIsPage => xClass.Element(NodeXmlColumns.NODE_IS_PAGE)?.ValueAsBool(); | ||
public bool? NodeIsSecured => xClass.Element(NodeXmlColumns.NODE_IS_SECURED)?.ValueAsBool(); | ||
public int? DocumentID => xClass.Element(NodeXmlColumns.DOCUMENT_ID)?.Value<int>(); | ||
public string? DocumentName => xClass.Element(NodeXmlColumns.DOCUMENT_NAME)?.Value; | ||
public DateTime? DocumentModifiedWhen => xClass.Element(NodeXmlColumns.DOCUMENT_MODIFIED_WHEN)?.Value<DateTime>(); | ||
public int? DocumentModifiedByUserID => xClass.Element(NodeXmlColumns.DOCUMENT_MODIFIED_BY_USER_ID)?.Value<int>(); | ||
public int? DocumentCreatedByUserID => xClass.Element(NodeXmlColumns.DOCUMENT_CREATED_BY_USER_ID)?.Value<int>(); | ||
public DateTime? DocumentCreatedWhen => xClass.Element(NodeXmlColumns.DOCUMENT_CREATED_WHEN)?.Value<DateTime>(); | ||
public int? DocumentCheckedOutVersionHistoryID => xClass.Element(NodeXmlColumns.DOCUMENT_CHECKED_OUT_VERSION_HISTORY_ID)?.Value<int>(); | ||
public int? DocumentPublishedVersionHistoryID => xClass.Element(NodeXmlColumns.DOCUMENT_PUBLISHED_VERSION_HISTORY_ID)?.Value<int>(); | ||
public int? DocumentWorkflowStepID => xClass.Element(NodeXmlColumns.DOCUMENT_WORKFLOW_STEP_ID)?.Value<int>(); | ||
public string? DocumentCulture => xClass.Element(NodeXmlColumns.DOCUMENT_CULTURE)?.Value; | ||
public int? DocumentNodeID => xClass.Element(NodeXmlColumns.DOCUMENT_NODE_ID)?.Value<int>(); | ||
public string? DocumentContent => xClass.Element(NodeXmlColumns.DOCUMENT_CONTENT)?.Value; | ||
public string? DocumentLastVersionNumber => xClass.Element(NodeXmlColumns.DOCUMENT_LAST_VERSION_NUMBER)?.Value; | ||
public bool? DocumentIsArchived => xClass.Element(NodeXmlColumns.DOCUMENT_IS_ARCHIVED)?.ValueAsBool(); | ||
|
||
[Obsolete("DocumentGUID is not unique, use other means of document identification", true)] | ||
public Guid? DocumentGUID => xClass.Element(NodeXmlColumns.DOCUMENT_GUID)?.Value<Guid>(); | ||
|
||
public Guid? DocumentWorkflowCycleGUID => xClass.Element(NodeXmlColumns.DOCUMENT_WORKFLOW_CYCLE_GUID)?.Value<Guid>(); | ||
public bool? DocumentCanBePublished => xClass.Element(NodeXmlColumns.DOCUMENT_CAN_BE_PUBLISHED)?.ValueAsBool(); | ||
public string? DocumentPageBuilderWidgets => xClass.Element(NodeXmlColumns.DOCUMENT_PAGE_BUILDER_WIDGETS)?.Value; | ||
public string? ClassName => xClass.Element(NodeXmlColumns.CLASS_NAME)?.Value; | ||
|
||
public string? DocumentPageTemplateConfiguration => xClass.Element(NodeXmlColumns.DOCUMENT_PAGE_TEMPLATE_CONFIGURATION)?.Value; | ||
|
||
public string? GetValue(string columnName) => xClass.Element(columnName)?.Value; | ||
|
||
public bool HasValueSet(string columnName) => xClass.Element(columnName) != null; | ||
} |
Oops, something went wrong.