Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
anle committed Aug 7, 2018
1 parent 85bddea commit 9b5d8a2
Show file tree
Hide file tree
Showing 144 changed files with 7,809 additions and 0 deletions.
31 changes: 31 additions & 0 deletions ETLBox.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.27428.2005
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ETLBox", "ETLBox\ETLBox.csproj", "{0C7548BA-A597-488A-8ADD-2F628BE691D6}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ETLBoxTest", "ETLBoxTest\ETLBoxTest.csproj", "{E18C5029-9FA4-4846-828C-1B42D5D18C3C}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{0C7548BA-A597-488A-8ADD-2F628BE691D6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{0C7548BA-A597-488A-8ADD-2F628BE691D6}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0C7548BA-A597-488A-8ADD-2F628BE691D6}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0C7548BA-A597-488A-8ADD-2F628BE691D6}.Release|Any CPU.Build.0 = Release|Any CPU
{E18C5029-9FA4-4846-828C-1B42D5D18C3C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E18C5029-9FA4-4846-828C-1B42D5D18C3C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E18C5029-9FA4-4846-828C-1B42D5D18C3C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E18C5029-9FA4-4846-828C-1B42D5D18C3C}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {A83E1CF2-2A7A-4315-8474-C060C51E118C}
EndGlobalSection
EndGlobal
93 changes: 93 additions & 0 deletions ETLBox/Definitions/ConnectionManager/DbConnectionManager.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
using System;
using System.Data;
using System.Threading.Tasks;

namespace ALE.ETLBox {
public abstract class DbConnectionManager<Connection, Command> : IDisposable, IDbConnectionManager
where Connection : class, IDbConnection, new()
where Command : class, IDbCommand, new() {
public int MaxLoginAttempts { get; set; } = 20;

public ConnectionString ConnectionString { get; set; }

internal Connection DbConnection { get; set; }

internal bool IsConnectionOpen => DbConnection?.State == ConnectionState.Open;

public DbConnectionManager() { }

public DbConnectionManager(ConnectionString connectionString) : this() {
this.ConnectionString = connectionString;
}

public void Open() {
DbConnection = new Connection();
if (!IsConnectionOpen) {
DbConnection.ConnectionString = ConnectionString.Value;
bool successfullyConnected = false;
Exception lastException = null;
for (int i = 1; i <= MaxLoginAttempts; i++) {
try {
DbConnection.Open();
successfullyConnected = true;
} catch (Exception e) {
successfullyConnected = false;
lastException = e;
Task.Delay(500 * i).Wait();
}
if (successfullyConnected) break;
}
if (!successfullyConnected)
throw lastException ?? new Exception("Could not connect to database!");
}
}

//public void CloseConnection() => Close();

public Command CreateCommand(string commandText) {
var cmd = DbConnection.CreateCommand();
cmd.CommandTimeout = 0;
cmd.CommandText = commandText;
return cmd as Command;
}

public int ExecuteNonQuery(string commandText) {
Command sqlcmd = CreateCommand(commandText);
return sqlcmd.ExecuteNonQuery();
}

public object ExecuteScalar(string commandText) {
Command cmd = CreateCommand(commandText);
return cmd.ExecuteScalar();
}

public IDataReader ExecuteReader(string commandText) {
Command cmd = CreateCommand(commandText);
return cmd.ExecuteReader();

}

public abstract void BulkInsert(IDataReader data, IColumnMappingCollection columnMapping, string tableName);

#region IDisposable Support
private bool disposedValue = false; // To detect redundant calls

protected void Dispose(bool disposing) {
if (!disposedValue) {
if (disposing) {
if (DbConnection != null)
DbConnection.Close();
DbConnection = null;
}
disposedValue = true;
}
}

public void Dispose() => Dispose(true);
public void Close() => Dispose();

public abstract IDbConnectionManager Clone();
#endregion

}
}
10 changes: 10 additions & 0 deletions ETLBox/Definitions/ConnectionManager/IConnectionManager.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using System;

namespace ALE.ETLBox {
public interface IConnectionManager : IDisposable {
ConnectionString ConnectionString { get; }
void Open();
void Close();

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace ALE.ETLBox {
public interface ICubeConnectionManager : IConnectionManager {
void Process();
void DropIfExists();
ICubeConnectionManager Clone();
}
}
11 changes: 11 additions & 0 deletions ETLBox/Definitions/ConnectionManager/IDbConnectionManager.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using System.Data;

namespace ALE.ETLBox {
public interface IDbConnectionManager : IConnectionManager {
int ExecuteNonQuery(string command);
object ExecuteScalar(string command);
IDataReader ExecuteReader(string command);
void BulkInsert(IDataReader data, IColumnMappingCollection columnMapping, string tableName);
IDbConnectionManager Clone();
}
}
5 changes: 5 additions & 0 deletions ETLBox/Definitions/DataFlow/IDataFlowDestination.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
namespace ALE.ETLBox {
public interface IDataFlowDestination<TInput> : IDataFlowLinkTarget<TInput> {
void Wait();
}
}
7 changes: 7 additions & 0 deletions ETLBox/Definitions/DataFlow/IDataFlowLinkSource.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
using System.Threading.Tasks.Dataflow;

namespace ALE.ETLBox {
public interface IDataFlowLinkSource<TOutput> {
ISourceBlock<TOutput> SourceBlock { get; }
}
}
7 changes: 7 additions & 0 deletions ETLBox/Definitions/DataFlow/IDataFlowLinkTarget.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
using System.Threading.Tasks.Dataflow;

namespace ALE.ETLBox {
public interface IDataFlowLinkTarget<TInput> {
ITargetBlock<TInput> TargetBlock { get; }
}
}
6 changes: 6 additions & 0 deletions ETLBox/Definitions/DataFlow/IDataFlowSource.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace ALE.ETLBox {
public interface IDataFlowSource<TOutput> : IDataFlowLinkSource<TOutput> {
void ExecuteAsync();
void LinkTo(IDataFlowLinkTarget<TOutput> target);
}
}
4 changes: 4 additions & 0 deletions ETLBox/Definitions/DataFlow/IDataFlowTransformation.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
namespace ALE.ETLBox {
public interface IDataFlowTransformation<TInput,TOutput> : IDataFlowLinkSource<TOutput>, IDataFlowLinkTarget<TInput> {
}
}
25 changes: 25 additions & 0 deletions ETLBox/Definitions/DataFlow/TypeInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using System;
using System.Reflection;

namespace ALE.ETLBox {
public class TypeInfo {
public PropertyInfo[] PropertyInfos { get; set; }
public int PropertyLength { get; set; }
public bool IsArray { get; set; } = true;

public TypeInfo() {

}

public TypeInfo(Type typ) {
GatherTypeInfos(typ);
}
private void GatherTypeInfos(Type typ) {
IsArray = typ.IsArray;
if (!typ.IsArray) {
PropertyInfos = typ.GetProperties();
PropertyLength = PropertyInfos.Length;
}
}
}
}
16 changes: 16 additions & 0 deletions ETLBox/Definitions/Database/ITableColumn.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
namespace ALE.ETLBox {
public interface ITableColumn {
string Name { get; }
string DataType { get; }
bool AllowNulls { get; }
bool IsIdentity { get; }
int? IdentitySeed { get; }
int? IdentityIncrement { get; }
bool IsPrimaryKey { get; }
string DefaultValue { get; }
string DefaultConstraintName { get; }
string Collation { get; }
string ComputedColumn { get; }

}
}
25 changes: 25 additions & 0 deletions ETLBox/Definitions/Database/ProcedureDefinition.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using System.Collections.Generic;

namespace ALE.ETLBox {
public class ProcedureDefinition {
public string Name { get; set; }
public string Definition { get; set; }

public List<ProcedureParameter> Parameter { get; set; }

public ProcedureDefinition() {
Parameter = new List<ProcedureParameter>();
}

public ProcedureDefinition(string name, string definition) : this() {
Name = name;
Definition = definition;
}

public ProcedureDefinition(string name, string definition, List<ProcedureParameter> parameter) : this(name, definition) {
Parameter = parameter;
}


}
}
37 changes: 37 additions & 0 deletions ETLBox/Definitions/Database/ProcedureParameter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using System;

namespace ALE.ETLBox {
public class ProcedureParameter {
public string Name { get; set; }
public string DataType { get; set; }
public string DefaultValue { get; set; }
public bool HasDefaultValue => !String.IsNullOrWhiteSpace(DefaultValue);
public bool ReadOnly { get; set; }
public bool Out { get; set; }
public string Sql {
get {
string sql = $@"@{Name} {DataType}";
if (HasDefaultValue)
sql += $" = {DefaultValue}";
if (Out)
sql += " OUT";
if (ReadOnly)
sql += " READONLY";
return sql;
}
}

public ProcedureParameter() {
}

public ProcedureParameter(string name, string dataType) : this() {
Name = name;
DataType = dataType;
}

public ProcedureParameter(string name, string dataType, string defaultValue) : this(name, dataType) {
DefaultValue = defaultValue;
}

}
}
54 changes: 54 additions & 0 deletions ETLBox/Definitions/Database/TableColumn.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
using System;
using System.Data;

namespace ALE.ETLBox {
public class TableColumn : ITableColumn, IColumnMapping {
private string _dataSetColumn;
private string _sourceColumn;

public string Name { get; set; }
public string DataType { get; set; }
public bool AllowNulls { get; set; }
public bool IsIdentity { get; set; }
public int? IdentitySeed { get; set; }
public int? IdentityIncrement { get; set; }
public bool IsPrimaryKey { get; set; }
public string DefaultValue { get; set; }
public string DefaultConstraintName { get; set; }
public string Collation { get; set; }
public string ComputedColumn { get; set; }
public System.Type NETDataType => Type.GetType(DataTypeConverter.GetObjectTypeString(DataType));


public string DataSetColumn {
get { return String.IsNullOrWhiteSpace(_dataSetColumn) ? Name : _dataSetColumn; }
set {
_dataSetColumn = value;
}
}
public string SourceColumn {
get { return String.IsNullOrWhiteSpace(_sourceColumn) ? Name : _sourceColumn; }
set {
_sourceColumn = value;
}
}

public TableColumn() { }
public TableColumn(string name, string dataType) : this() {
Name = name;
DataType = dataType;
}

public TableColumn(string name, string dataType, bool allowNulls) : this(name, dataType) {
AllowNulls = allowNulls;
}

public TableColumn(string name, string dataType, bool allowNulls, bool isPrimaryKey) : this(name, dataType, allowNulls) {
IsPrimaryKey = isPrimaryKey;
}

public TableColumn(string name, string dataType, bool allowNulls, bool isPrimaryKey, bool isIdentity) : this(name, dataType, allowNulls, isPrimaryKey) {
IsIdentity = isIdentity;
}
}
}
Loading

0 comments on commit 9b5d8a2

Please sign in to comment.