Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
patrick-rodgers committed Apr 15, 2020
1 parent 13d54cb commit dbbc194
Show file tree
Hide file tree
Showing 9 changed files with 708 additions and 420 deletions.
10 changes: 10 additions & 0 deletions src/Delegates.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace IdFix
{
public delegate void SetDisplayDelegate(string message);
}
151 changes: 151 additions & 0 deletions src/Files.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;

namespace IdFix
{
enum FileTypes
{
Verbose,
Apply,
Error,
Duplicate,
Filtered,
Merge,
}

class Files
{
private string _fileBase;

public Files(string seed = null)
{
if (string.IsNullOrEmpty(seed))
{
seed = new Regex(@"[/:]").Replace(DateTime.Now.ToString(), "-");
}
this._fileBase = seed;
}

public string VerboseFileName
{
get
{
return string.Format("Verbose {0}.txt", this._fileBase);
}
}

public string ApplyFileName
{
get
{
return string.Format("Update {0}.ldf", this._fileBase);
}
}

public string DuplicateFileName
{
get
{
return string.Format("Duplicate {0}.txt", this._fileBase);
}
}

public string ErrorFileName
{
get
{
return string.Format("Error {0}.txt", this._fileBase);
}
}

public string MergeFileName
{
get
{
return string.Format("Merge {0}.txt", this._fileBase);
}
}

public string FilteredFileName
{
get
{
return string.Format("Filtered {0}.txt", this._fileBase);
}
}

public void AppendTo(FileTypes type, Action<StreamWriter> action)
{
using (var writer = new StreamWriter(this.GetNameFromType(type), true))
{
action(writer);
}
}

public void ReadFrom(FileTypes type, Action<StreamReader> action)
{
using (var reader = new StreamReader(this.GetNameFromType(type)))
{
action(reader);
}
}

public bool ExistsByType(FileTypes type)
{
return File.Exists(this.GetNameFromType(type));
}

public void DeleteByType(FileTypes type)
{
if (File.Exists(this.GetNameFromType(type)))
{
File.Delete(this.GetNameFromType(type));
}
}

public void DeleteAll()
{
this.DeleteByType(FileTypes.Apply);
this.DeleteByType(FileTypes.Duplicate);
this.DeleteByType(FileTypes.Error);
this.DeleteByType(FileTypes.Filtered);
this.DeleteByType(FileTypes.Merge);
this.DeleteByType(FileTypes.Verbose);
}

private string GetNameFromType(FileTypes type)
{
string fileName;
switch (type)
{
case FileTypes.Apply:
fileName = this.ApplyFileName;
break;
case FileTypes.Verbose:
fileName = this.VerboseFileName;
break;
case FileTypes.Duplicate:
fileName = this.DuplicateFileName;
break;
case FileTypes.Error:
fileName = this.ErrorFileName;
break;
case FileTypes.Filtered:
fileName = this.FilteredFileName;
break;
case FileTypes.Merge:
fileName = this.MergeFileName;
break;
default:
fileName = this.VerboseFileName;
break;
}
return fileName;
}
}
}
Loading

0 comments on commit dbbc194

Please sign in to comment.