Skip to content

Commit

Permalink
Move a few classes to NBi.Extensibility and uniformize the classes fo…
Browse files Browse the repository at this point in the history
…r EtlRunner and BatchRunner
  • Loading branch information
Cédric L. Charlier committed Sep 14, 2019
1 parent ec175b0 commit d1b1ae1
Show file tree
Hide file tree
Showing 93 changed files with 415 additions and 129 deletions.
1 change: 1 addition & 0 deletions NBi.Core/Assemblies/AssemblyManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Linq;
using System.Reflection;
using System.IO;
using NBi.Extensibility;

namespace NBi.Core.Assemblies
{
Expand Down
1 change: 1 addition & 0 deletions NBi.Core/Assemblies/Decoration/AbstractCustomFactory.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using NBi.Core.Scalar.Resolver;
using NBi.Extensibility;
using NBi.Extensibility.Decoration;
using System;
using System.Collections.Generic;
Expand Down
2 changes: 2 additions & 0 deletions NBi.Core/Assemblies/Decoration/ICustomCommandArgs.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using NBi.Core.Decoration;
using NBi.Core.Scalar.Resolver;
using NBi.Extensibility;
using NBi.Extensibility.Decoration;
using System;
using System.Collections.Generic;
using System.Linq;
Expand Down
1 change: 1 addition & 0 deletions NBi.Core/CommandTimeoutException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Data.SqlClient;
using Microsoft.AnalysisServices.AdomdClient;
using System.Data;
using NBi.Extensibility;

namespace NBi.Core
{
Expand Down
1 change: 1 addition & 0 deletions NBi.Core/ConnectionException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Data.OleDb;
using System.Data.SqlClient;
using Microsoft.AnalysisServices.AdomdClient;
using NBi.Extensibility;

namespace NBi.Core
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using NBi.Core.Query.Client;
using NBi.Extensibility;
using System;
using System.Collections.Generic;
using System.Data;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using NBi.Core.Query.Client;
using NBi.Extensibility.DataEngineering;
using NBi.Core.Decoration.DataEngineering;
using System;
using System.Collections.Generic;
using System.Data;
Expand All @@ -18,38 +18,20 @@ class BatchRunCommand : IDecorationCommand

public BatchRunCommand(IBatchRunCommandArgs args) => this.args = args;

public void Execute() => Execute(PathExtensions.CombineOrRoot(args.BasePath, args.Path.Execute(), args.Name.Execute()), args.Version.Execute(), args.ConnectionString);
public void Execute()
=> Execute(
PathExtensions.CombineOrRoot(args.BasePath, args.Path.Execute(), args.Name.Execute())
, args.Version.Execute()
, args.ConnectionString
);

public void Execute(string fullPath, string version, string connectionString)
{
var directory = AssemblyDirectory;
var filename = $"NBi.Core.{version}.dll";
var filepath = $"{directory}\\{filename}";
if (!File.Exists(filepath))
throw new InvalidOperationException($"Can't find the dll for version '{version}' in '{directory}'. NBi was expecting to find a dll named '{filename}'.");

var assembly = Assembly.LoadFrom(filepath);
var types = assembly.GetTypes()
.Where(m => m.IsClass && m.GetInterface("IBatchRunCommand") != null);

if (types.Count() == 0)
throw new InvalidOperationException(string.Format("Can't find a class implementing 'IBatchRunCommand' in '{0}'.", assembly.FullName));
if (types.Count() > 1)
throw new InvalidOperationException(string.Format("Found more than one class implementing 'IBatchRunCommand' in '{0}'.", assembly.FullName));

var batchRunCommand = Activator.CreateInstance(types.ElementAt(0)) as IBatchRunCommand;
batchRunCommand.Execute(fullPath, new SqlConnection(args.ConnectionString));
}

private static string AssemblyDirectory
protected void Execute(string fullPath, string version, string connectionString)
{
get
{
string codeBase = Assembly.GetExecutingAssembly().CodeBase;
UriBuilder uri = new UriBuilder(codeBase);
string path = Uri.UnescapeDataString(uri.Path);
return Path.GetDirectoryName(path);
}
var provider = new BatchRunnerProvider();
var factory = provider.Instantiate(version);
var args = new BatchRunnerArgs() { FullPath = fullPath, ConnectionString = connectionString };
var runner = factory.Instantiate(args);
runner.Execute();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using NBi.Extensibility.Decoration.DataEngineering;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace NBi.Core.Decoration.DataEngineering.Commands.SqlServer
{
class BatchRunnerArgs : IBatchRunnerArgs
{
public string FullPath { get; set; }
public string ConnectionString { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
using NBi.Extensibility.Decoration.DataEngineering;
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;

namespace NBi.Core.Decoration.DataEngineering
{
class BatchRunnerProvider
{
public IBatchRunnerFactory Instantiate(string version)
{
var directory = AssemblyDirectory;
var filename = $"NBi.Core.{version}.dll";
var filepath = $"{directory}\\{filename}";
if (!File.Exists(filepath))
throw new InvalidOperationException($"Can't find the dll for version '{version}' in '{directory}'. NBi was expecting to find a dll named '{filename}'.");

var assembly = Assembly.LoadFrom(filepath);
var types = assembly.GetTypes()
.Where(m => m.IsClass && m.GetInterface(typeof(IBatchRunnerFactory).Name) != null);

if (types.Count() == 0)
throw new InvalidOperationException($"Can't find a class implementing '{typeof(IBatchRunnerFactory).Name}' in '{assembly.FullName}'.");
if (types.Count() > 1)
throw new InvalidOperationException($"Found more than one class implementing '{typeof(IBatchRunnerFactory).Name}' in '{assembly.FullName}'.");

return Activator.CreateInstance(types.ElementAt(0)) as IBatchRunnerFactory;
}

private static string AssemblyDirectory
{
get
{
string codeBase = Assembly.GetExecutingAssembly().CodeBase;
UriBuilder uri = new UriBuilder(codeBase);
string path = Uri.UnescapeDataString(uri.Path);
return Path.GetDirectoryName(path);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ internal void Execute(string connectionString, string tableName, string filename
{
// make sure to enable triggers
// more on triggers in next post
SqlBulkCopy bulkCopy =
using (var bulkCopy =
new SqlBulkCopy
(
connection,
Expand All @@ -33,15 +33,18 @@ internal void Execute(string connectionString, string tableName, string filename
{
// set the destination table name
DestinationTableName = tableName
};
connection.Open();
}
)
{
connection.Open();

// write the data in the "dataTable"
var fileReader = new CsvReader();
var dataTable = fileReader.ToDataTable(filename, false);
bulkCopy.WriteToServer(dataTable);
// write the data in the "dataTable"
var fileReader = new CsvReader();
var dataTable = fileReader.ToDataTable(filename, false);
bulkCopy.WriteToServer(dataTable);

connection.Close();
connection.Close();
}
}

}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
using NBi.Core.Etl;
using NBi.Extensibility.DataEngineering;
using NBi.Core.Decoration.DataEngineering;
using System;
using System.IO;
using System.Linq;
using System.Reflection;
using NBi.Extensibility.Decoration.DataEngineering;

namespace NBi.Core.Decoration.DataEngineering
{
Expand All @@ -18,8 +19,9 @@ public class EtlRunCommand : IDecorationCommand
protected void Execute(IEtlArgs args)
{
var provider = new EtlRunnerProvider();
var etl = provider.Instantiate(args);
etl.Execute();
var factory = provider.Instantiate(args.Version);
var runner = factory.Instantiate(args);
runner.Execute();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
using System.Text;
using System.Threading.Tasks;

namespace NBi.Extensibility.DataEngineering
namespace NBi.Core.Decoration.DataEngineering
{
public interface IBatchRunCommand
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using NBi.Core.Decoration.DataEngineering;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using NBi.Core.Decoration;
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
Expand Down
4 changes: 2 additions & 2 deletions NBi.Core/Decoration/DataEngineering/IEtlRunCommandArgs.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
using NBi.Core.Etl;
using NBi.Core.Scalar.Resolver;
using NBi.Extensibility.DataEngineering;
using NBi.Core.Decoration.DataEngineering;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NBi.Extensibility.Decoration.DataEngineering;

namespace NBi.Core.Decoration.DataEngineering
{
public interface IEtlRunCommandArgs : IDataEngineeringCommandArgs
{
string Version { get; }
IEtlArgs Etl { get; }
}
}
1 change: 1 addition & 0 deletions NBi.Core/Decoration/DataEngineering/ILoadCommandArgs.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using NBi.Core.Scalar.Resolver;
using NBi.Core.Decoration.DataEngineering;
using System;
using System.Collections.Generic;
using System.Linq;
Expand Down
1 change: 1 addition & 0 deletions NBi.Core/Decoration/DataEngineering/IResetCommandArgs.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using NBi.Core.Scalar.Resolver;
using NBi.Core.Decoration.DataEngineering;
using System;
using System.Collections.Generic;
using System.Linq;
Expand Down
2 changes: 2 additions & 0 deletions NBi.Core/Decoration/DecorationFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
using NBi.Core.Decoration.Process;
using NBi.Core.Decoration.Grouping;
using NBi.Core.Assemblies.Decoration;
using NBi.Extensibility;
using NBi.Extensibility.Decoration;

namespace NBi.Core.Decoration
{
Expand Down
3 changes: 2 additions & 1 deletion NBi.Core/Decoration/Grouping/Commands/ParallelCommand.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using NBi.Extensibility.Decoration;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
Expand Down
4 changes: 3 additions & 1 deletion NBi.Core/Decoration/Grouping/Commands/SequentialCommand.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System;
using NBi.Extensibility;
using NBi.Extensibility.Decoration;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
Expand Down
3 changes: 2 additions & 1 deletion NBi.Core/Decoration/Grouping/IGroupCommandArgs.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using NBi.Extensibility.Decoration;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
Expand Down
1 change: 1 addition & 0 deletions NBi.Core/Decoration/IO/Commands/CopyCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.IO;
using NBi.Core.Decoration.IO;
using System.Diagnostics;
using NBi.Extensibility;

namespace NBi.Core.Decoration.IO.Commands
{
Expand Down
1 change: 1 addition & 0 deletions NBi.Core/Decoration/IO/Commands/CopyExtensionCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.IO;
using NBi.Core.Decoration.IO;
using System.Diagnostics;
using NBi.Extensibility;

namespace NBi.Core.Decoration.IO.Commands
{
Expand Down
1 change: 1 addition & 0 deletions NBi.Core/Decoration/IO/Commands/CopyPatternCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.IO;
using NBi.Core.Decoration.IO;
using System.Diagnostics;
using NBi.Extensibility;

namespace NBi.Core.Decoration.IO.Commands
{
Expand Down
1 change: 1 addition & 0 deletions NBi.Core/Decoration/IO/Commands/DeleteExtensionCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.IO;
using NBi.Core.Decoration.IO;
using System.Diagnostics;
using NBi.Extensibility;

namespace NBi.Core.Decoration.IO.Commands
{
Expand Down
1 change: 1 addition & 0 deletions NBi.Core/Decoration/IO/Commands/DeletePatternCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.IO;
using NBi.Core.Decoration.IO;
using System.Diagnostics;
using NBi.Extensibility;

namespace NBi.Core.Decoration.IO.Commands
{
Expand Down
1 change: 1 addition & 0 deletions NBi.Core/Decoration/IO/IIoCommandArgs.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using NBi.Core.Scalar.Resolver;
using NBi.Extensibility.Decoration;
using System;
using System.Collections.Generic;
using System.Linq;
Expand Down
5 changes: 3 additions & 2 deletions NBi.Core/Decoration/Process/Commands/RunCommand.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using NBi.Extensibility;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
Expand Down Expand Up @@ -52,7 +53,7 @@ public void Execute(string fullPath, string argument, int timeOut)
}
else
{
Trace.WriteLineIf(Extensibility.NBiTraceSwitch.TraceInfo, "Not waiting the end of the process.");
Trace.WriteLineIf(NBiTraceSwitch.TraceInfo, "Not waiting the end of the process.");
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion NBi.Core/Decoration/Process/IProcessCommandArgs.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using NBi.Extensibility.Decoration;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
Expand Down
Loading

0 comments on commit d1b1ae1

Please sign in to comment.