Skip to content

Commit

Permalink
naming conventions update, obsolete class removal
Browse files Browse the repository at this point in the history
  • Loading branch information
tkrch committed Jul 22, 2024
1 parent 45d664a commit d2e4440
Show file tree
Hide file tree
Showing 98 changed files with 1,147 additions and 2,099 deletions.
83 changes: 42 additions & 41 deletions KVA/Migration.Toolkit.Source/Auxiliary/NodeXmlAdapter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,75 +2,76 @@

using Migration.Toolkit.Common;
using Migration.Toolkit.Common.Enumerations;
// ReSharper disable InconsistentNaming // generated class

namespace Migration.Toolkit.Source.Auxiliary;

internal class NodeXmlAdapter
{
private readonly XElement _xClass;
private readonly XElement xClass;

public NodeXmlAdapter(string xml)
{
var xDoc = XDocument.Parse(xml);
if (xDoc.Root?.FirstNode is XElement dClass)
{
_xClass = dClass;
xClass = dClass;
ParsingSuccessful = true;
}
else
{
_xClass = null!;
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>();
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 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();
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? 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 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? DocumentPageTemplateConfiguration => xClass.Element(NodeXmlColumns.DOCUMENT_PAGE_TEMPLATE_CONFIGURATION)?.Value;

public string? GetValue(string columnName) => _xClass.Element(columnName)?.Value;
public string? GetValue(string columnName) => xClass.Element(columnName)?.Value;

public bool HasValueSet(string columnName) => _xClass.Element(columnName) != null;
public bool HasValueSet(string columnName) => xClass.Element(columnName) != null;
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class PrimaryKeyMappingContext(
ToolkitConfiguration toolkitConfiguration)
: IPrimaryKeyMappingContext
{
private readonly Dictionary<string, int> _mappings = new(StringComparer.OrdinalIgnoreCase);
private readonly Dictionary<string, int> mappingCache = new(StringComparer.OrdinalIgnoreCase);

public void SetMapping(Type type, string keyName, int sourceId, int targetId)
{
Expand All @@ -29,14 +29,14 @@ public void SetMapping(Type type, string keyName, int sourceId, int targetId)

string fullKeyName = $"{type.FullName}.{foundProp.Name}.{sourceId}";

_mappings[fullKeyName] = targetId;
mappingCache[fullKeyName] = targetId;
logger.LogTrace("Primary key for {FullKeyName} stored. {SourceId} maps to {TargetId}", fullKeyName, sourceId, targetId);
}

public void SetMapping<T>(Expression<Func<T, object>> keyNameSelector, int sourceId, int targetId)
{
string fullKeyName = CreateKey(keyNameSelector, sourceId);
_mappings[fullKeyName] = targetId;
mappingCache[fullKeyName] = targetId;
logger.LogTrace("{Key}: {SourceValue}=>{TargetValue}", fullKeyName, sourceId, targetId);
}

Expand All @@ -55,7 +55,7 @@ public int RequireMapFromSource<T>(Expression<Func<T, object>> keyNameSelector,
return explicitlyMappedId;
}

if (_mappings.TryGetValue(fullKeyName, out int resultId))
if (mappingCache.TryGetValue(fullKeyName, out int resultId))
{
logger.LogTrace("{Key} resolved as {Value}", fullKeyName, resultId);
return resultId;
Expand Down Expand Up @@ -94,7 +94,7 @@ public bool TryRequireMapFromSource<T>(Expression<Func<T, object>> keyNameSelect
return true;
}

if (_mappings.TryGetValue(fullKeyName, out int resultId))
if (mappingCache.TryGetValue(fullKeyName, out int resultId))
{
logger.LogTrace("{Key} resolved as {Value}", fullKeyName, resultId);
targetIdResult = resultId;
Expand Down Expand Up @@ -134,7 +134,7 @@ public bool TryRequireMapFromSource<T>(Expression<Func<T, object>> keyNameSelect
return explicitlyMappedId;
}

if (_mappings.TryGetValue(fullKeyName, out int resultId))
if (mappingCache.TryGetValue(fullKeyName, out int resultId))
{
logger.LogTrace("{Key} resolved as {Value}", fullKeyName, resultId);
return resultId;
Expand Down Expand Up @@ -172,7 +172,7 @@ public bool TryRequireMapFromSource<T>(Expression<Func<T, object>> keyNameSelect
return explicitlyMappedId;
}

if (_mappings.TryGetValue(fullKeyName, out int resultId))
if (mappingCache.TryGetValue(fullKeyName, out int resultId))
{
logger.LogTrace("{Key} resolved as {Value}", fullKeyName, resultId);
return resultId;
Expand Down Expand Up @@ -210,7 +210,7 @@ public MapSourceIdResult MapSourceId<T>(Expression<Func<T, object>> keyNameSelec
return new MapSourceIdResult(true, explicitlyMappedId);
}

if (_mappings.TryGetValue(fullKeyName, out int resultId))
if (mappingCache.TryGetValue(fullKeyName, out int resultId))
{
logger.LogTrace("{Key} resolved as {Value}", fullKeyName, resultId);
return new MapSourceIdResult(true, resultId);
Expand Down Expand Up @@ -254,7 +254,7 @@ public bool HasMapping<T>(Expression<Func<T, object>> keyNameSelector, int? sour
return true;
}

if (_mappings.TryGetValue(fullKeyName, out _))
if (mappingCache.TryGetValue(fullKeyName, out _))
{
return true;
}
Expand Down
20 changes: 10 additions & 10 deletions KVA/Migration.Toolkit.Source/Contexts/SourceInstanceContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,34 +12,34 @@ public class SourceInstanceContext(
ToolkitConfiguration configuration,
ModelFacade modelFacade)
{
private readonly Dictionary<string, SourceInstanceDiscoveredInfo> _cachedInfos = new(StringComparer.InvariantCultureIgnoreCase);
private readonly Dictionary<string, SourceInstanceDiscoveredInfo> cachedInfos = new(StringComparer.InvariantCultureIgnoreCase);

private bool _sourceInfoLoaded;
private bool sourceInfoLoaded;

public bool HasInfo => _cachedInfos.Count > 0 && _sourceInfoLoaded;
public bool HasInfo => cachedInfos.Count > 0 && sourceInfoLoaded;

public bool IsQuerySourceInstanceEnabled() => configuration.OptInFeatures?.QuerySourceInstanceApi?.Enabled ?? false;

public async Task<bool> RequestSourceInstanceInfo()
{
if (!_sourceInfoLoaded)
if (!sourceInfoLoaded)
{
var result = await ipcService.GetSourceInstanceDiscoveredInfos();
foreach ((string key, var value) in result)
{
_cachedInfos.Add(key, value);
cachedInfos.Add(key, value);
logger.LogInformation("Source instance info loaded for site '{SiteName}' successfully", key);
}

_sourceInfoLoaded = true;
sourceInfoLoaded = true;
}

return _sourceInfoLoaded;
return sourceInfoLoaded;
}

public List<EditingFormControlModel>? GetWidgetPropertyFormComponents(string siteName, string widgetIdentifier)
{
if (_cachedInfos.TryGetValue(siteName, out var info))
if (cachedInfos.TryGetValue(siteName, out var info))
{
return info.WidgetProperties != null && info.WidgetProperties.TryGetValue(widgetIdentifier, out var widgetProperties)
? widgetProperties
Expand All @@ -51,7 +51,7 @@ public async Task<bool> RequestSourceInstanceInfo()

public List<EditingFormControlModel>? GetPageTemplateFormComponents(string siteName, string pageTemplateIdentifier)
{
if (_cachedInfos.TryGetValue(siteName, out var info))
if (cachedInfos.TryGetValue(siteName, out var info))
{
return info.PageTemplateProperties != null && info.PageTemplateProperties.TryGetValue(pageTemplateIdentifier, out var pageTemplate)
? pageTemplate
Expand Down Expand Up @@ -85,7 +85,7 @@ public async Task<bool> RequestSourceInstanceInfo()
modelFacade.SelectById<ICmsSite>(siteId)?.SiteName
?? throw new InvalidOperationException($"Source site with SiteID '{siteId}' not exists");

if (_cachedInfos.TryGetValue(siteName, out var info))
if (cachedInfos.TryGetValue(siteName, out var info))
{
return info.SectionProperties != null && info.SectionProperties.TryGetValue(sectionIdentifier, out var sectionFcs)
? sectionFcs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ public class MigrateCustomTablesHandler(
BulkDataCopyService bulkDataCopyService,
IEntityMapper<ICmsClass, DataClassInfo> dataClassMapper,
PrimaryKeyMappingContext primaryKeyMappingContext
// ReusableSchemaService reusableSchemaService
// ReusableSchemaService reusableSchemaService
)
: IRequestHandler<MigrateCustomTablesCommand, CommandResult>
{
private readonly Guid _resourceGuidNamespace = new("C4E3F5FD-9220-4300-91CE-8EB565D3235E");
private ResourceInfo? _customTableResource;
private readonly Guid resourceGuidNamespace = new("C4E3F5FD-9220-4300-91CE-8EB565D3235E");
private ResourceInfo? customTableResource;

public async Task<CommandResult> Handle(MigrateCustomTablesCommand request, CancellationToken cancellationToken)
{
Expand All @@ -45,13 +45,13 @@ public async Task<CommandResult> Handle(MigrateCustomTablesCommand request, Canc

private async Task<ResourceInfo> EnsureCustomTablesResource()
{
if (_customTableResource != null)
if (customTableResource != null)
{
return _customTableResource;
return customTableResource;
}

const string resourceName = "customtables";
var resourceGuid = GuidV5.NewNameBased(_resourceGuidNamespace, resourceName);
var resourceGuid = GuidV5.NewNameBased(resourceGuidNamespace, resourceName);
var resourceInfo = await ResourceInfoProvider.ProviderObject.GetAsync(resourceGuid);
if (resourceInfo == null)
{
Expand All @@ -67,7 +67,7 @@ private async Task<ResourceInfo> EnsureCustomTablesResource()
ResourceInfoProvider.ProviderObject.Set(resourceInfo);
}

_customTableResource = resourceInfo;
customTableResource = resourceInfo;
return resourceInfo;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ ToolkitConfiguration configuration
)
: IRequestHandler<MigrateFormsCommand, CommandResult>, IDisposable
{
private KxpContext _kxpContext = kxpContextFactory.CreateDbContext();
private KxpContext kxpContext = kxpContextFactory.CreateDbContext();

public void Dispose() => _kxpContext.Dispose();
public void Dispose() => kxpContext.Dispose();

public async Task<CommandResult> Handle(MigrateFormsCommand request, CancellationToken cancellationToken)
{
Expand All @@ -63,7 +63,7 @@ public async Task<CommandResult> Handle(MigrateFormsCommand request, Cancellatio
{
protocol.FetchedSource(ksCmsForm);

var kxoCmsForm = _kxpContext.CmsForms.FirstOrDefault(f => f.FormGuid == ksCmsForm.FormGUID);
var kxoCmsForm = kxpContext.CmsForms.FirstOrDefault(f => f.FormGuid == ksCmsForm.FormGUID);

protocol.FetchedTarget(kxoCmsForm);

Expand All @@ -79,14 +79,14 @@ public async Task<CommandResult> Handle(MigrateFormsCommand request, Cancellatio
{
if (newInstance)
{
_kxpContext.CmsForms.Add(cmsForm);
kxpContext.CmsForms.Add(cmsForm);
}
else
{
_kxpContext.CmsForms.Update(cmsForm);
kxpContext.CmsForms.Update(cmsForm);
}

await _kxpContext.SaveChangesAsync(cancellationToken);
await kxpContext.SaveChangesAsync(cancellationToken);
logger.LogEntitySetAction(newInstance, cmsForm);

primaryKeyMappingContext.SetMapping<CmsForm>(
Expand All @@ -97,8 +97,8 @@ public async Task<CommandResult> Handle(MigrateFormsCommand request, Cancellatio
}
catch (Exception ex)
{
await _kxpContext.DisposeAsync(); // reset context errors
_kxpContext = await kxpContextFactory.CreateDbContextAsync(cancellationToken);
await kxpContext.DisposeAsync(); // reset context errors
kxpContext = await kxpContextFactory.CreateDbContextAsync(cancellationToken);

protocol.Append(HandbookReferences
.ErrorCreatingTargetInstance<CmsForm>(ex)
Expand Down
Loading

0 comments on commit d2e4440

Please sign in to comment.