Skip to content

Commit

Permalink
style: applied code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
DrBarnabus committed Jan 6, 2022
1 parent c46b414 commit e1d9f28
Show file tree
Hide file tree
Showing 68 changed files with 2,113 additions and 2,033 deletions.
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<LangVersion>latest</LangVersion>
<Nullable>enable</Nullable>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<WarningsAsErrors />
<WarningsAsErrors/>
</PropertyGroup>

</Project>
2 changes: 1 addition & 1 deletion NuGet.config
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3"/>
</packageSources>
</configuration>
84 changes: 43 additions & 41 deletions src/DacTools.Deployment.Core/Arguments.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,54 +4,56 @@
using DacTools.Deployment.Core.Logging;
using Microsoft.SqlServer.Dac;

namespace DacTools.Deployment.Core
namespace DacTools.Deployment.Core;

public class Arguments
{
public class Arguments
{
public readonly ISet<string> DatabaseNames = new HashSet<string>();
public DacDeployOptions DacDeployOptions;
public readonly ISet<string> DatabaseNames = new HashSet<string>();

public string? DacPacFilePath;
public bool IsBlacklist;
public bool IsHelp;
public bool IsVersion;
public LogLevel LogLevel = LogLevel.Info;
public string? LogFilePath = null;
public string? MasterConnectionString;
public int Threads;
public bool AzPipelines;
public DacDeployOptions DacDeployOptions;

public bool AzPipelines;
public string? DacPacFilePath;
public bool IsBlacklist;
public bool IsHelp;
public bool IsVersion;
public string? LogFilePath = null;
public LogLevel LogLevel = LogLevel.Info;
public string? MasterConnectionString;
public int Threads;

public Arguments()
{
DacDeployOptions = new DacDeployOptions();
SetDefaultDacDeployOptions();
}
public Arguments()
{
DacDeployOptions = new DacDeployOptions();
SetDefaultDacDeployOptions();
}

public void AddDatabaseName(string databaseName) => DatabaseNames.Add(databaseName);
public void AddDatabaseName(string databaseName)
{
DatabaseNames.Add(databaseName);
}

public void SetDefaultDacDeployOptions()
public void SetDefaultDacDeployOptions()
{
DacDeployOptions = new DacDeployOptions
{
DacDeployOptions = new DacDeployOptions
BlockOnPossibleDataLoss = false,
DropIndexesNotInSource = false,
IgnorePermissions = true,
IgnoreRoleMembership = true,
IgnoreFileAndLogFilePath = true,
GenerateSmartDefaults = true,
DropObjectsNotInSource = true,
DoNotDropObjectTypes = new[]
{
BlockOnPossibleDataLoss = false,
DropIndexesNotInSource = false,
IgnorePermissions = true,
IgnoreRoleMembership = true,
IgnoreFileAndLogFilePath = true,
GenerateSmartDefaults = true,
DropObjectsNotInSource = true,
DoNotDropObjectTypes = new[]
{
ObjectType.Filegroups,
ObjectType.Files,
ObjectType.Logins,
ObjectType.Permissions,
ObjectType.RoleMembership,
ObjectType.Users
},
CommandTimeout = 0 // Infinite Timeout
};
}
ObjectType.Filegroups,
ObjectType.Files,
ObjectType.Logins,
ObjectType.Permissions,
ObjectType.RoleMembership,
ObjectType.Users
},
CommandTimeout = 0 // Infinite Timeout
};
}
}
85 changes: 44 additions & 41 deletions src/DacTools.Deployment.Core/AsyncTasks/AsyncTaskBase.cs
Original file line number Diff line number Diff line change
@@ -1,64 +1,67 @@
// Copyright (c) 2022 DrBarnabus

using DacTools.Deployment.Core.Common;
using System;
using System.Threading;
using System.Threading.Tasks;
using DacTools.Deployment.Core.Common;
using DacTools.Deployment.Core.DatabaseListGenerators;
using DacTools.Deployment.Core.Logging;

namespace DacTools.Deployment.Core.AsyncTasks
namespace DacTools.Deployment.Core.AsyncTasks;

public abstract class AsyncTaskBase : IAsyncTask
{
public abstract class AsyncTaskBase : IAsyncTask
{
private readonly ILog _log;
private readonly IActiveBuildServer _buildServer;
private readonly IActiveBuildServer _buildServer;
private readonly ILog _log;

protected AsyncTaskBase(Arguments arguments, ILog log, IActiveBuildServer buildServer)
{
Arguments = arguments;
_log = log;
_buildServer = buildServer;
}
protected AsyncTaskBase(Arguments arguments, ILog log, IActiveBuildServer buildServer)
{
Arguments = arguments;
_log = log;
_buildServer = buildServer;
}

protected Arguments Arguments { get; }
protected Arguments Arguments { get; }

protected Action<IAsyncTask, bool, long>? ProgressUpdate { get; private set; }
protected Action<IAsyncTask, bool, long>? ProgressUpdate { get; private set; }

public DatabaseInfo? DatabaseInfo { get; private set; }
public DatabaseInfo? DatabaseInfo { get; private set; }

public void Setup(DatabaseInfo databaseInfo, Action<IAsyncTask, bool, long> progressUpdate)
{
DatabaseInfo = databaseInfo ?? throw new ArgumentNullException(nameof(databaseInfo));
ProgressUpdate = progressUpdate ?? throw new ArgumentNullException(nameof(progressUpdate));
}
public void Setup(DatabaseInfo databaseInfo, Action<IAsyncTask, bool, long> progressUpdate)
{
DatabaseInfo = databaseInfo ?? throw new ArgumentNullException(nameof(databaseInfo));
ProgressUpdate = progressUpdate ?? throw new ArgumentNullException(nameof(progressUpdate));
}

public abstract Task Run(CancellationToken cancellationToken);
public abstract Task Run(CancellationToken cancellationToken);

protected void LogError(string source, string formatString, params object[] args)
{
_log.Error($"'{DatabaseInfo}' {source} - {formatString}", args);
protected void LogError(string source, string formatString, params object[] args)
{
_log.Error($"'{DatabaseInfo}' {source} - {formatString}", args);

if (_buildServer.IsActive && _buildServer.Instance is not null)
_log.WriteRaw(LogLevel.Error, _buildServer.Instance.GenerateLogIssueErrorMessage(string.Format($"'{DatabaseInfo}' {source} - {formatString}", args)));
}
if (_buildServer.IsActive && _buildServer.Instance is not null)
_log.WriteRaw(LogLevel.Error,
_buildServer.Instance.GenerateLogIssueErrorMessage(
string.Format($"'{DatabaseInfo}' {source} - {formatString}", args)));
}

protected void LogWarning(string source, string formatString, params object[] args)
{
_log.Warning($"'{DatabaseInfo}' {source} - {formatString}", args);
protected void LogWarning(string source, string formatString, params object[] args)
{
_log.Warning($"'{DatabaseInfo}' {source} - {formatString}", args);

if (_buildServer.IsActive && _buildServer.Instance is not null)
_log.WriteRaw(LogLevel.Warn, _buildServer.Instance.GenerateLogIssueWarningMessage(string.Format($"'{DatabaseInfo}' {source} - {formatString}", args)));
}
if (_buildServer.IsActive && _buildServer.Instance is not null)
_log.WriteRaw(LogLevel.Warn,
_buildServer.Instance.GenerateLogIssueWarningMessage(
string.Format($"'{DatabaseInfo}' {source} - {formatString}", args)));
}

protected void LogInfo(string source, string formatString, params object[] args)
{
_log.Info($"'{DatabaseInfo}' {source} - {formatString}", args);
}
protected void LogInfo(string source, string formatString, params object[] args)
{
_log.Info($"'{DatabaseInfo}' {source} - {formatString}", args);
}

protected void LogDebug(string source, string formatString, params object[] args)
{
_log.Debug($"'{DatabaseInfo}' {source} - {formatString}", args);
}
protected void LogDebug(string source, string formatString, params object[] args)
{
_log.Debug($"'{DatabaseInfo}' {source} - {formatString}", args);
}
}
32 changes: 17 additions & 15 deletions src/DacTools.Deployment.Core/AsyncTasks/AsyncTaskFactory.cs
Original file line number Diff line number Diff line change
@@ -1,26 +1,28 @@
// Copyright (c) 2022 DrBarnabus

using DacTools.Deployment.Core.Common;
using System;
using DacTools.Deployment.Core.Common;
using DacTools.Deployment.Core.Logging;
using Microsoft.Extensions.Options;

namespace DacTools.Deployment.Core.AsyncTasks
namespace DacTools.Deployment.Core.AsyncTasks;

public class AsyncTaskFactory<TAsyncTask> : IAsyncTaskFactory<TAsyncTask>
where TAsyncTask : AsyncTaskBase
{
public class AsyncTaskFactory<TAsyncTask> : IAsyncTaskFactory<TAsyncTask>
where TAsyncTask : AsyncTaskBase
{
private readonly Arguments _arguments;
private readonly ILog _log;
private readonly IActiveBuildServer _buildServer;
private readonly Arguments _arguments;
private readonly IActiveBuildServer _buildServer;
private readonly ILog _log;

public AsyncTaskFactory(IOptions<Arguments> arguments, ILog log, IActiveBuildServer buildServer)
{
_arguments = arguments.Value;
_log = log;
_buildServer = buildServer;
}
public AsyncTaskFactory(IOptions<Arguments> arguments, ILog log, IActiveBuildServer buildServer)
{
_arguments = arguments.Value;
_log = log;
_buildServer = buildServer;
}

public TAsyncTask CreateAsyncTask() => (TAsyncTask)Activator.CreateInstance(typeof(TAsyncTask), _arguments, _log, _buildServer);
public TAsyncTask CreateAsyncTask()
{
return (TAsyncTask)Activator.CreateInstance(typeof(TAsyncTask), _arguments, _log, _buildServer);
}
}
29 changes: 16 additions & 13 deletions src/DacTools.Deployment.Core/AsyncTasks/AsyncTaskRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,30 @@
using System.Threading.Tasks;
using System.Threading.Tasks.Dataflow;

namespace DacTools.Deployment.Core.AsyncTasks
namespace DacTools.Deployment.Core.AsyncTasks;

public class AsyncTaskRunner<TAsyncTask> where TAsyncTask : IAsyncTask
{
public class AsyncTaskRunner<TAsyncTask> where TAsyncTask : IAsyncTask
public AsyncTaskRunner(int maxDegreeOfParallelism, CancellationToken cancellationToken)
{
public AsyncTaskRunner(int maxDegreeOfParallelism, CancellationToken cancellationToken)
{
ActionBlock = new ActionBlock<TAsyncTask>(async at => await at.Run(cancellationToken), new ExecutionDataflowBlockOptions
ActionBlock = new ActionBlock<TAsyncTask>(async at => await at.Run(cancellationToken),
new ExecutionDataflowBlockOptions
{
MaxDegreeOfParallelism = maxDegreeOfParallelism,
CancellationToken = cancellationToken
});
}
}

public ActionBlock<TAsyncTask> ActionBlock { get; }
public ActionBlock<TAsyncTask> ActionBlock { get; }

public void AddTask(TAsyncTask asyncTask) => ActionBlock.Post(asyncTask);
public void AddTask(TAsyncTask asyncTask)
{
ActionBlock.Post(asyncTask);
}

public async Task WaitForCompletion()
{
ActionBlock.Complete();
await ActionBlock.Completion;
}
public async Task WaitForCompletion()
{
ActionBlock.Complete();
await ActionBlock.Completion;
}
}
Loading

0 comments on commit e1d9f28

Please sign in to comment.