Skip to content

Commit

Permalink
editor config update + autofix
Browse files Browse the repository at this point in the history
  • Loading branch information
tkrch committed Jul 15, 2024
1 parent 9f5f9df commit 899f2e9
Show file tree
Hide file tree
Showing 1,411 changed files with 6,281 additions and 8,723 deletions.
419 changes: 340 additions & 79 deletions .editorconfig

Large diffs are not rendered by default.

17 changes: 5 additions & 12 deletions KVA/Migration.Toolkit.Source/Auxiliary/NodeXmlAdapter.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
namespace Migration.Toolkit.Source.Auxiliary;

using System;
using System.Xml.Linq;

using Migration.Toolkit.Common;
using Migration.Toolkit.Common.Enumerations;

namespace Migration.Toolkit.Source.Auxiliary;
internal class NodeXmlAdapter
{
private readonly XElement _xClass;
Expand All @@ -26,15 +25,9 @@ public NodeXmlAdapter(string xml)
}
}

public string? GetValue(string columnName)
{
return _xClass.Element(columnName)?.Value;
}
public string? GetValue(string columnName) => _xClass.Element(columnName)?.Value;

public bool HasValueSet(string columnName)
{
return _xClass.Element(columnName) != null;
}
public bool HasValueSet(string columnName) => _xClass.Element(columnName) != null;

public int? NodeID => _xClass.Element(NodeXmlColumns.NODE_ID)?.Value<int>();
public string? NodeAliasPath => _xClass.Element(NodeXmlColumns.NODE_ALIAS_PATH)?.Value;
Expand Down Expand Up @@ -75,4 +68,4 @@ public bool HasValueSet(string columnName)
public string? ClassName => _xClass.Element(NodeXmlColumns.CLASS_NAME)?.Value;

public string? DocumentPageTemplateConfiguration => _xClass.Element(NodeXmlColumns.DOCUMENT_PAGE_TEMPLATE_CONFIGURATION)?.Value;
}
}
22 changes: 12 additions & 10 deletions KVA/Migration.Toolkit.Source/Behaviors/CommandConstraintBehavior.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
namespace Migration.Toolkit.Source.Behaviors;

using MediatR;

using Microsoft.Extensions.Logging;

using Migration.Toolkit.Common.Abstractions;
using Migration.Toolkit.Common.MigrationProtocol;
using Migration.Toolkit.Source.Model;

namespace Migration.Toolkit.Source.Behaviors;
public class CommandConstraintBehavior<TRequest, TResponse>(
ILogger<CommandConstraintBehavior<TRequest, TResponse>> logger,
IMigrationProtocol protocol,
Expand All @@ -18,7 +20,7 @@ public async Task<TResponse> Handle(TRequest request, RequestHandlerDelegate<TRe
{
try
{
var criticalCheckPassed = PerformChecks(request);
bool criticalCheckPassed = PerformChecks(request);
if (!criticalCheckPassed)
{
return (TResponse)(CommandResult)new CommandCheckFailedResult(criticalCheckPassed);
Expand All @@ -36,7 +38,7 @@ public async Task<TResponse> Handle(TRequest request, RequestHandlerDelegate<TRe

private bool PerformChecks(TRequest request)
{
var criticalCheckPassed = true;
bool criticalCheckPassed = true;

var sourceSites = modelFacade.SelectAll<ICmsSite>()
.ToList();
Expand All @@ -59,15 +61,15 @@ private bool PerformChecks(TRequest request)

private bool CheckSite(List<ICmsSite> sourceSites, int sourceSiteId)
{
var criticalCheckPassed = true;
bool criticalCheckPassed = true;
if (sourceSites.All(s => s.SiteID != sourceSiteId))
{
var supportedSites = sourceSites.Select(x => new
{
x.SiteName,
x.SiteID
}).ToArray();
var supportedSitesStr = string.Join(", ", supportedSites.Select(x => x.ToString()));
string supportedSitesStr = string.Join(", ", supportedSites.Select(x => x.ToString()));
logger.LogCritical("Unable to find site with ID '{SourceSiteId}'. Check --siteId parameter. Supported sites: {SupportedSites}", sourceSiteId,
supportedSitesStr);
protocol.Append(HandbookReferences.CommandConstraintBroken("Site exists")
Expand All @@ -86,20 +88,20 @@ private bool CheckSite(List<ICmsSite> sourceSites, int sourceSiteId)
private bool CheckCulture(ICultureReliantCommand cultureReliantCommand, List<ICmsSite> sourceSites, List<ICmsCulture> cultures, List<ICmsSiteCulture> cmsSiteCultures)
{

var criticalCheckPassed = true;
var cultureCode = cultureReliantCommand.CultureCode;
bool criticalCheckPassed = true;
string cultureCode = cultureReliantCommand.CultureCode;

foreach (var site in sourceSites)
{
var siteCultures = cmsSiteCultures
string?[] siteCultures = cmsSiteCultures
.Where(x => x.SiteID == site.SiteID)
.Select(x => cultures.FirstOrDefault(c => c.CultureID == x.CultureID)?.CultureCode)
.Where(x => !string.IsNullOrWhiteSpace(x))
.ToArray();

if (!siteCultures.Contains(cultureCode.ToLowerInvariant()))
{
var supportedCultures = string.Join(", ", siteCultures);
string supportedCultures = string.Join(", ", siteCultures);
logger.LogCritical("Unable to find culture '{Culture}' mapping to site '{SiteId}'. Check --culture parameter. Supported cultures for site: {SupportedCultures}", cultureCode,
site.SiteID, supportedCultures);
protocol.Append(HandbookReferences.CommandConstraintBroken("Culture is mapped to site")
Expand All @@ -111,4 +113,4 @@ private bool CheckCulture(ICultureReliantCommand cultureReliantCommand, List<ICm

return criticalCheckPassed;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
namespace Migration.Toolkit.Source.Behaviors;

using System.Diagnostics;

using MediatR;

using Microsoft.Extensions.Logging;

using Migration.Toolkit.Common.Abstractions;
using Migration.Toolkit.Common.MigrationProtocol;

namespace Migration.Toolkit.Source.Behaviors;
public class RequestHandlingBehavior<TRequest, TResponse>(
ILogger<RequestHandlingBehavior<TRequest, TResponse>> logger,
IMigrationProtocol protocol) : IPipelineBehavior<TRequest, TResponse>
Expand Down Expand Up @@ -34,4 +37,4 @@ public async Task<TResponse> Handle(TRequest request, RequestHandlerDelegate<TRe
logger.LogInformation("Handled {CommandName} in elapsed: {Elapsed}", typeof(TRequest).Name, sw.Elapsed);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
namespace Migration.Toolkit.Source.Behaviors;

using CMS.Base;
using CMS.Membership;

using MediatR;

using Microsoft.Extensions.Logging;

using Migration.Toolkit.Common.Abstractions;
using Migration.Toolkit.Common.MigrationProtocol;
using Migration.Toolkit.KXP.Api;

namespace Migration.Toolkit.Source.Behaviors;
public class XbKApiContextBehavior<TRequest, TResponse>(
ILogger<XbKApiContextBehavior<TRequest, TResponse>> logger,
IMigrationProtocol protocol,
Expand Down Expand Up @@ -36,4 +39,4 @@ public async Task<TResponse> Handle(TRequest request, RequestHandlerDelegate<TRe
return await next();
}
}
}
}
66 changes: 34 additions & 32 deletions KVA/Migration.Toolkit.Source/Contexts/PrimaryKeyMappingContext.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
namespace Migration.Toolkit.Source.Contexts;

using System.Diagnostics;
using System.Linq.Expressions;
using System.Reflection;

using Microsoft.Extensions.Logging;

using Migration.Toolkit.Common;
using Migration.Toolkit.Source.Services;

namespace Migration.Toolkit.Source.Contexts;
public class PrimaryKeyMappingContext(
ILogger<PrimaryKeyMappingContext> logger,
IPrimaryKeyLocatorService primaryKeyLocatorService,
Expand All @@ -17,7 +19,10 @@ public class PrimaryKeyMappingContext(

private int? GetExplicitMappingOrNull<T>(string memberName, int? sourceId)
{
if (sourceId == null) return null;
if (sourceId == null)
{
return null;
}

var mappings = toolkitConfiguration.EntityConfigurations?.GetEntityConfiguration<T>().ExplicitPrimaryKeyMapping;
if (mappings?.TryGetValue(memberName, out var memberMappings) ?? false)
Expand All @@ -28,10 +33,7 @@ public class PrimaryKeyMappingContext(
return null;
}

private static string CreateKey<T>(Expression<Func<T, object>> keyNameSelector, int sourceId)
{
return $"{typeof(T).FullName}.{keyNameSelector.GetMemberName()}.{sourceId}";
}
private static string CreateKey<T>(Expression<Func<T, object>> keyNameSelector, int sourceId) => $"{typeof(T).FullName}.{keyNameSelector.GetMemberName()}.{sourceId}";

public void SetMapping(Type type, string keyName, int sourceId, int targetId)
{
Expand All @@ -43,23 +45,23 @@ public void SetMapping(Type type, string keyName, int sourceId, int targetId)

Debug.Assert(foundProp != null, "foundProp != null");

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

_mappings[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)
{
var fullKeyName = CreateKey(keyNameSelector, sourceId);
string fullKeyName = CreateKey(keyNameSelector, sourceId);
_mappings[fullKeyName] = targetId;
logger.LogTrace("{Key}: {SourceValue}=>{TargetValue}", fullKeyName, sourceId, targetId);
}

public int RequireMapFromSource<T>(Expression<Func<T, object>> keyNameSelector, int sourceId)
{
var memberName = keyNameSelector.GetMemberName();
var fullKeyName = CreateKey(keyNameSelector, sourceId);
string memberName = keyNameSelector.GetMemberName();
string fullKeyName = CreateKey(keyNameSelector, sourceId);
if (sourceId == 0)
{
throw new MappingFailureException(fullKeyName, $"Cannot satisfy required mapping {fullKeyName} - source Id cannot be 0.");
Expand All @@ -71,14 +73,14 @@ public int RequireMapFromSource<T>(Expression<Func<T, object>> keyNameSelector,
return explicitlyMappedId;
}

if (_mappings.TryGetValue(fullKeyName, out var resultId))
if (_mappings.TryGetValue(fullKeyName, out int resultId))
{
logger.LogTrace("{Key} resolved as {Value}", fullKeyName, resultId);
return resultId;
}

logger.LogTrace("TryLocate {Key}", fullKeyName);
if (primaryKeyLocatorService.TryLocate(keyNameSelector, sourceId, out var targetId))
if (primaryKeyLocatorService.TryLocate(keyNameSelector, sourceId, out int targetId))
{
SetMapping(keyNameSelector, sourceId, targetId); // cache id
logger.LogTrace("{Key} located as {Value}", fullKeyName, resultId);
Expand All @@ -91,13 +93,13 @@ public int RequireMapFromSource<T>(Expression<Func<T, object>> keyNameSelector,
public bool TryRequireMapFromSource<T>(Expression<Func<T, object>> keyNameSelector, int? sourceId, out int targetIdResult)
{
targetIdResult = -1;
if (!(sourceId is int sid))
if (sourceId is not int sid)
{
return false;
}

var memberName = keyNameSelector.GetMemberName();
var fullKeyName = CreateKey(keyNameSelector, sid);
string memberName = keyNameSelector.GetMemberName();
string fullKeyName = CreateKey(keyNameSelector, sid);
if (sid == 0)
{
throw new MappingFailureException(fullKeyName, $"Cannot satisfy required mapping {fullKeyName} - source Id cannot be 0.");
Expand All @@ -110,15 +112,15 @@ public bool TryRequireMapFromSource<T>(Expression<Func<T, object>> keyNameSelect
return true;
}

if (_mappings.TryGetValue(fullKeyName, out var resultId))
if (_mappings.TryGetValue(fullKeyName, out int resultId))
{
logger.LogTrace("{Key} resolved as {Value}", fullKeyName, resultId);
targetIdResult = resultId;
return true;
}

logger.LogTrace("TryLocate {Key}", fullKeyName);
if (primaryKeyLocatorService.TryLocate(keyNameSelector, sid, out var targetId))
if (primaryKeyLocatorService.TryLocate(keyNameSelector, sid, out int targetId))
{
SetMapping(keyNameSelector, sid, targetId); // cache id
logger.LogTrace("{Key} located as {Value}", fullKeyName, targetId);
Expand All @@ -136,8 +138,8 @@ public bool TryRequireMapFromSource<T>(Expression<Func<T, object>> keyNameSelect
return null;
}

var memberName = keyNameSelector.GetMemberName();
var fullKeyName = CreateKey(keyNameSelector, sid);
string memberName = keyNameSelector.GetMemberName();
string fullKeyName = CreateKey(keyNameSelector, sid);
if (sid == 0)
{
logger.LogWarning("{Key} Key locator invalid argument, cannot supply 0 as argument", fullKeyName);
Expand All @@ -150,14 +152,14 @@ public bool TryRequireMapFromSource<T>(Expression<Func<T, object>> keyNameSelect
return explicitlyMappedId;
}

if (_mappings.TryGetValue(fullKeyName, out var resultId))
if (_mappings.TryGetValue(fullKeyName, out int resultId))
{
logger.LogTrace("{Key} resolved as {Value}", fullKeyName, resultId);
return resultId;
}

logger.LogTrace("TryLocate {Key}", fullKeyName);
if (primaryKeyLocatorService.TryLocate(keyNameSelector, sid, out var targetId))
if (primaryKeyLocatorService.TryLocate(keyNameSelector, sid, out int targetId))
{
SetMapping(keyNameSelector, sid, targetId); // cache id
logger.LogTrace("{Key} located as {Value}", fullKeyName, targetId);
Expand All @@ -174,8 +176,8 @@ public bool TryRequireMapFromSource<T>(Expression<Func<T, object>> keyNameSelect
return null;
}

var memberName = keyNameSelector.GetMemberName();
var fullKeyName = CreateKey(keyNameSelector, sid);
string memberName = keyNameSelector.GetMemberName();
string fullKeyName = CreateKey(keyNameSelector, sid);
if (sid == 0)
{
logger.LogWarning("{Key} Key locator invalid argument, cannot supply 0 as argument", fullKeyName);
Expand All @@ -188,14 +190,14 @@ public bool TryRequireMapFromSource<T>(Expression<Func<T, object>> keyNameSelect
return explicitlyMappedId;
}

if (_mappings.TryGetValue(fullKeyName, out var resultId))
if (_mappings.TryGetValue(fullKeyName, out int resultId))
{
logger.LogTrace("{Key} resolved as {Value}", fullKeyName, resultId);
return resultId;
}

logger.LogTrace("TryLocate {Key}", fullKeyName);
if (primaryKeyLocatorService.TryLocate(keyNameSelector, sid, out var targetId))
if (primaryKeyLocatorService.TryLocate(keyNameSelector, sid, out int targetId))
{
SetMapping(keyNameSelector, sid, targetId); // cache id
logger.LogTrace("{Key} located as {Value}", fullKeyName, targetId);
Expand All @@ -212,8 +214,8 @@ public MapSourceIdResult MapSourceId<T>(Expression<Func<T, object>> keyNameSelec
return new MapSourceIdResult(true, null);
}

var memberName = keyNameSelector.GetMemberName();
var fullKeyName = CreateKey(keyNameSelector, sid);
string memberName = keyNameSelector.GetMemberName();
string fullKeyName = CreateKey(keyNameSelector, sid);
if (sid == 0)
{
logger.LogWarning("{Key} Key locator invalid argument, cannot supply 0 as argument", fullKeyName);
Expand All @@ -226,14 +228,14 @@ public MapSourceIdResult MapSourceId<T>(Expression<Func<T, object>> keyNameSelec
return new MapSourceIdResult(true, explicitlyMappedId);
}

if (_mappings.TryGetValue(fullKeyName, out var resultId))
if (_mappings.TryGetValue(fullKeyName, out int resultId))
{
logger.LogTrace("{Key} resolved as {Value}", fullKeyName, resultId);
return new MapSourceIdResult(true, resultId);
}

logger.LogTrace("TryLocate {Key}", fullKeyName);
if (useLocator && primaryKeyLocatorService.TryLocate(keyNameSelector, sid, out var targetId))
if (useLocator && primaryKeyLocatorService.TryLocate(keyNameSelector, sid, out int targetId))
{
SetMapping(keyNameSelector, sid, targetId); // cache id
logger.LogTrace("{Key} located as {Value}", fullKeyName, targetId);
Expand All @@ -258,8 +260,8 @@ public bool HasMapping<T>(Expression<Func<T, object>> keyNameSelector, int? sour
return true;
}

var memberName = keyNameSelector.GetMemberName();
var fullKeyName = CreateKey(keyNameSelector, sid);
string memberName = keyNameSelector.GetMemberName();
string fullKeyName = CreateKey(keyNameSelector, sid);
if (sid == 0)
{
return true;
Expand All @@ -282,4 +284,4 @@ public bool HasMapping<T>(Expression<Func<T, object>> keyNameSelector, int? sour

return false;
}
}
}
Loading

0 comments on commit 899f2e9

Please sign in to comment.