Skip to content

Commit

Permalink
R# fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
ErikEJ committed Mar 31, 2017
1 parent cca05a6 commit 3cdec47
Show file tree
Hide file tree
Showing 18 changed files with 135 additions and 162 deletions.
7 changes: 3 additions & 4 deletions src/DestinationTableDefaultMetadata.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlServerCe;
using System.Globalization;
Expand Down Expand Up @@ -30,9 +29,9 @@ public bool HasDefault

public DestinationTableDefaultMetadata(IDataReader reader)
{
this.ColumnName = (reader.GetString(0) ?? string.Empty).ToUpper(CultureInfo.InvariantCulture);
this.IsNullable = reader.GetString(1).Equals("YES", StringComparison.OrdinalIgnoreCase) ? true : false;
this.HasDefault = reader.GetBoolean(2);
ColumnName = (reader.GetString(0) ?? string.Empty).ToUpper(CultureInfo.InvariantCulture);
IsNullable = reader.GetString(1).Equals("YES", StringComparison.OrdinalIgnoreCase);
HasDefault = reader.GetBoolean(2);
}

public static List<DestinationTableDefaultMetadata> GetDataForTable(SqlCeConnection conn, SqlCeTransaction transaction, string tableName)
Expand Down
2 changes: 1 addition & 1 deletion src/ForeignKeyLib/ColumnList.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System.Collections.Generic;
using System.Text;

namespace ErikEJ.SqlCeScripting
namespace ErikEJ.SqlCe.ForeignKeyLib
{
public class ColumnList : List<string>
{
Expand Down
2 changes: 1 addition & 1 deletion src/ForeignKeyLib/Constraint.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace ErikEJ.SqlCeScripting
namespace ErikEJ.SqlCe.ForeignKeyLib
{
public class Constraint
{
Expand Down
24 changes: 12 additions & 12 deletions src/ForeignKeyLib/DBRepository.cs
Original file line number Diff line number Diff line change
@@ -1,32 +1,32 @@
using System.Collections.Generic;
using System.Data.SqlServerCe;

namespace ErikEJ.SqlCeScripting
namespace ErikEJ.SqlCe.ForeignKeyLib
{
public sealed class DBRepository : IRepository
internal class DbRepository : IRepository
{
private SqlCeConnection cn;
private SqlCeConnection _cn;
private delegate void AddToListDelegate<T>(ref List<T> list, SqlCeDataReader dr);

/// <summary>
/// Initializes a new instance of the <see cref="DBRepository"/> class.
/// Initializes a new instance of the <see cref="DbRepository"/> class.
/// </summary>
/// <param name="connectionString">The connection string.</param>
public DBRepository(string connectionString)
public DbRepository(string connectionString)
{
cn = new SqlCeConnection(connectionString);
cn.Open();
_cn = new SqlCeConnection(connectionString);
_cn.Open();
}

/// <summary>
/// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
/// </summary>
public void Dispose()
{
if (cn != null)
if (_cn != null)
{
cn.Close();
cn = null;
_cn.Close();
_cn = null;
}
}

Expand Down Expand Up @@ -55,7 +55,7 @@ private static void AddToListConstraints(ref List<Constraint> list, SqlCeDataRea
private List<T> ExecuteReader<T>(string commandText, AddToListDelegate<T> AddToListMethod)
{
List<T> list = new List<T>();
using (var cmd = new SqlCeCommand(commandText, cn))
using (var cmd = new SqlCeCommand(commandText, _cn))
{
using (var dr = cmd.ExecuteReader())
{
Expand Down Expand Up @@ -124,7 +124,7 @@ public void RunCommand(string sql)
{
using (SqlCeCommand cmd = new SqlCeCommand())
{
cmd.Connection = cn;
cmd.Connection = _cn;
cmd.CommandText = sql;
cmd.ExecuteNonQuery();
}
Expand Down
25 changes: 10 additions & 15 deletions src/ForeignKeyLib/ForeignKeyRepository.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
using System;
using System.Collections.Generic;
using System.Text;
using ErikEJ.SqlCeScripting;
using System.Linq;

namespace ErikEJ.SqlCeScripting
namespace ErikEJ.SqlCe.ForeignKeyLib
{
public class ForeignKeyRepository
{
Expand All @@ -21,20 +19,20 @@ protected ForeignKeyRepository() { }

public List<Constraint> GetConstraints()
{
using (var repo = new DBRepository(_connectionString))
using (var repo = new DbRepository(_connectionString))
{
return repo.GetAllForeignKeys().Where(c => c.ConstraintTableName == _tableName).ToList();
}
}

public void DropConstraints()
{
using (var repo = new DBRepository(_connectionString))
using (var repo = new DbRepository(_connectionString))
{
var constraints = repo.GetAllForeignKeys().Where(c => c.ConstraintTableName == _tableName).ToArray();
foreach (var constraint in constraints)
{
var generator = new Generator(repo);
var generator = new Generator();
generator.GenerateForeignKeyDrop(constraint);
repo.RunCommand(generator.GeneratedScript);
}
Expand All @@ -44,25 +42,22 @@ public void DropConstraints()
public string GetAddConstraintStatements(List<Constraint> constraints)
{
var script = string.Empty;
using (var repo = new DBRepository(_connectionString))
foreach (var constraint in constraints)
{
foreach (var constraint in constraints)
{
var generator = new Generator(repo);
generator.GenerateForeignKey(constraint);
script = script + generator.GeneratedScript + Environment.NewLine;
}
var generator = new Generator();
generator.GenerateForeignKey(constraint);
script = script + generator.GeneratedScript + Environment.NewLine;
}
return script;
}

public void AddConstraints(List<Constraint> constraints)
{
using (var repo = new DBRepository(_connectionString))
using (var repo = new DbRepository(_connectionString))
{
foreach (var constraint in constraints)
{
var generator = new Generator(repo);
var generator = new Generator();
generator.GenerateForeignKey(constraint);
repo.RunCommand(generator.GeneratedScript);
}
Expand Down
8 changes: 2 additions & 6 deletions src/ForeignKeyLib/Generator.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace ErikEJ.SqlCeScripting
namespace ErikEJ.SqlCe.ForeignKeyLib
{
/// <summary>
/// Class for generating scripts
Expand All @@ -11,12 +10,9 @@ namespace ErikEJ.SqlCeScripting
public class Generator : IGenerator
{
private readonly StringBuilder _sbScript;
private readonly List<Constraint> _allForeignKeys;

public Generator(IRepository repository)
public Generator()
{
_sbScript = new StringBuilder(10485760);
_allForeignKeys = repository.GetAllForeignKeys();
}

public void GenerateForeignKey(Constraint constraint)
Expand Down
2 changes: 1 addition & 1 deletion src/ForeignKeyLib/IGenerator.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace ErikEJ.SqlCeScripting
namespace ErikEJ.SqlCe.ForeignKeyLib
{
public interface IGenerator
{
Expand Down
2 changes: 1 addition & 1 deletion src/ForeignKeyLib/IRepository.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System;
using System.Collections.Generic;

namespace ErikEJ.SqlCeScripting
namespace ErikEJ.SqlCe.ForeignKeyLib
{
public interface IRepository : IDisposable
{
Expand Down
4 changes: 2 additions & 2 deletions src/ForeignKeyLib/RepositoryHelper.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
using System.Collections.Generic;
using System.Linq;

namespace ErikEJ.SqlCeScripting
namespace ErikEJ.SqlCe.ForeignKeyLib
{
public class RepositoryHelper
internal class RepositoryHelper
{
// Contrib from hugo on CodePlex - thanks!
public static List<Constraint> GetGroupForeingKeys(List<Constraint> foreignKeys, List<string> allTables)
Expand Down
6 changes: 1 addition & 5 deletions src/ISqlCeBulkCopyInsertAdapter.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace ErikEJ.SqlCe
namespace ErikEJ.SqlCe
{
/// <summary>
/// Interface used by the adapters so we are able to remove the duplicate code.
Expand Down
Loading

0 comments on commit 3cdec47

Please sign in to comment.