-
Notifications
You must be signed in to change notification settings - Fork 7
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 #64 from max-ieremenko/powershell/dependency-loader
load internal dependencies into private context
- Loading branch information
Showing
26 changed files
with
372 additions
and
158 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
using SqlDatabase.Adapter; | ||
using SqlDatabase.CommandLine; | ||
using SqlDatabase.Configuration; | ||
|
||
namespace SqlDatabase.PowerShell.Internal; | ||
|
||
public static class CmdLetExecutor | ||
{ | ||
// only for tests | ||
internal static ISqlDatabaseProgram? Program { get; set; } | ||
|
||
public static void RunCreate(IDictionary<string, object?> param, string currentDirectory, Action<string> writeInfo, Action<string> writeError) | ||
{ | ||
var commandLine = new CreateCommandLine | ||
{ | ||
Database = (string)param[nameof(CreateCommandLine.Database)]!, | ||
Configuration = (string?)param[nameof(CreateCommandLine.Configuration)], | ||
Log = (string?)param[nameof(CreateCommandLine.Log)], | ||
WhatIf = (bool)param[nameof(CreateCommandLine.WhatIf)]! | ||
}; | ||
|
||
CommandLineTools.AppendFrom(commandLine.From, false, (string[]?)param[nameof(CreateCommandLine.From)]); | ||
CommandLineTools.AppendVariables(commandLine.Variables, (string[]?)param[nameof(CreateCommandLine.Variables)]); | ||
|
||
Run(commandLine, currentDirectory, writeInfo, writeError); | ||
} | ||
|
||
public static void RunExecute(IDictionary<string, object?> param, string currentDirectory, Action<string> writeInfo, Action<string> writeError) | ||
{ | ||
var commandLine = new ExecuteCommandLine | ||
{ | ||
Database = (string)param[nameof(ExecuteCommandLine.Database)]!, | ||
Transaction = (TransactionMode)((int)param[nameof(ExecuteCommandLine.Transaction)]!), | ||
Configuration = (string?)param[nameof(ExecuteCommandLine.Configuration)], | ||
Log = (string?)param[nameof(ExecuteCommandLine.Log)], | ||
WhatIf = (bool)param[nameof(ExecuteCommandLine.WhatIf)]! | ||
}; | ||
|
||
CommandLineTools.AppendFrom(commandLine.From, false, (string[]?)param[nameof(ExecuteCommandLine.From)]); | ||
CommandLineTools.AppendFrom(commandLine.From, true, (string[]?)param["FromSql"]); | ||
CommandLineTools.AppendVariables(commandLine.Variables, (string[]?)param[nameof(ExecuteCommandLine.Variables)]); | ||
|
||
Run(commandLine, currentDirectory, writeInfo, writeError); | ||
} | ||
|
||
public static void RunExport(IDictionary<string, object?> param, string currentDirectory, Action<string> writeInfo, Action<string> writeError) | ||
{ | ||
var commandLine = new ExportCommandLine | ||
{ | ||
Database = (string)param[nameof(ExportCommandLine.Database)]!, | ||
Configuration = (string?)param[nameof(ExportCommandLine.Configuration)], | ||
DestinationFileName = (string?)param[nameof(ExportCommandLine.DestinationFileName)], | ||
DestinationTableName = (string?)param[nameof(ExportCommandLine.DestinationTableName)], | ||
Log = (string?)param[nameof(ExecuteCommandLine.Log)] | ||
}; | ||
|
||
CommandLineTools.AppendFrom(commandLine.From, false, (string[]?)param[nameof(ExportCommandLine.From)]); | ||
CommandLineTools.AppendFrom(commandLine.From, true, (string[]?)param["FromSql"]); | ||
CommandLineTools.AppendVariables(commandLine.Variables, (string[]?)param[nameof(ExportCommandLine.Variables)]); | ||
|
||
Run(commandLine, currentDirectory, writeInfo, writeError); | ||
} | ||
|
||
public static void RunUpdate(IDictionary<string, object?> param, string currentDirectory, Action<string> writeInfo, Action<string> writeError) | ||
{ | ||
var commandLine = new UpgradeCommandLine | ||
{ | ||
Database = (string)param[nameof(UpgradeCommandLine.Database)]!, | ||
Transaction = (TransactionMode)((int)param[nameof(UpgradeCommandLine.Transaction)]!), | ||
Configuration = (string?)param[nameof(UpgradeCommandLine.Configuration)], | ||
Log = (string?)param[nameof(UpgradeCommandLine.Log)], | ||
WhatIf = (bool)param[nameof(UpgradeCommandLine.WhatIf)]!, | ||
FolderAsModuleName = (bool)param[nameof(UpgradeCommandLine.FolderAsModuleName)]! | ||
}; | ||
|
||
CommandLineTools.AppendFrom(commandLine.From, false, (string[]?)param[nameof(UpgradeCommandLine.From)]); | ||
CommandLineTools.AppendVariables(commandLine.Variables, (string[]?)param[nameof(UpgradeCommandLine.Variables)]); | ||
|
||
Run(commandLine, currentDirectory, writeInfo, writeError); | ||
} | ||
|
||
public static string GetDefaultConfigurationFile() => ConfigurationManager.GetDefaultConfigurationFile(); | ||
|
||
private static void Run(ICommandLine commandLine, string currentDirectory, Action<string> writeInfo, Action<string> writeError) | ||
{ | ||
var program = Program ?? new SqlDatabaseProgram(new CmdLetLogger(writeInfo, writeError), currentDirectory); | ||
program.ExecuteCommand(commandLine); | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,19 @@ | ||
using SqlDatabase.Log; | ||
|
||
namespace SqlDatabase.PowerShell.Internal; | ||
|
||
internal sealed class CmdLetLogger : LoggerBase | ||
{ | ||
private readonly Action<string> _writeInfo; | ||
private readonly Action<string> _writeError; | ||
|
||
public CmdLetLogger(Action<string> writeInfo, Action<string> writeError) | ||
{ | ||
_writeInfo = writeInfo; | ||
_writeError = writeError; | ||
} | ||
|
||
protected override void WriteError(string message) => _writeError(message); | ||
|
||
protected override void WriteInfo(string message) => _writeInfo(message); | ||
} |
File renamed without changes.
File renamed without changes.
4 changes: 4 additions & 0 deletions
4
Sources/SqlDatabase.PowerShell.Internal/Properties/AssemblyInfo.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 |
---|---|---|
@@ -0,0 +1,4 @@ | ||
using System.Runtime.CompilerServices; | ||
|
||
[assembly: InternalsVisibleTo("SqlDatabase.PowerShell.Test, PublicKey=002400000480000094000000060200000024000052534131000400000100010055AB0DC1F8A24FB41E7358B65A606EC92141F1ABAFBFF062635AB5FAEB22308CFFBC8B54F3436694F14F6FD6C145D4F16C13A3E739FFCA837902BB78E2D51B890D964CC7384C2CC6B844AE37323F501F29E3EDC2DFADA82C99F5FBB5197ED757D795C2E5408DCB3FBAF9DDDF39E60B137ED0A23603A361EA811E6ADB605DFECC")] | ||
[assembly: InternalsVisibleTo("DynamicProxyGenAssembly2, PublicKey=0024000004800000940000000602000000240000525341310004000001000100c547cac37abd99c8db225ef2f6c8a3602f3b3606cc9891605d02baa56104f4cfc0734aa39b93bf7852f7d9266654753cc297e7d2edfe0bac1cdcf9f717241550e0a7b191195b7667bb4f64bcb8e2121380fd1d9d46ad2d92d2d15605093924cceaf74c4861eff62abf69b9291ed0a340e113be11e6a7d3113e92484cf7045cc7")] |
13 changes: 13 additions & 0 deletions
13
Sources/SqlDatabase.PowerShell.Internal/SqlDatabase.PowerShell.Internal.csproj
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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>netstandard2.0</TargetFramework> | ||
<OutputPath>..\..\bin\SqlDatabase.PowerShell</OutputPath> | ||
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\SqlDatabase\SqlDatabase.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
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
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
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
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
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
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
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
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
Oops, something went wrong.