Skip to content

Instantly share code, notes, and snippets.

@nickpreston24
Created February 6, 2020 08:25
Show Gist options
  • Select an option

  • Save nickpreston24/4f8810df31ff50dd0b5ab697a1503894 to your computer and use it in GitHub Desktop.

Select an option

Save nickpreston24/4f8810df31ff50dd0b5ab697a1503894 to your computer and use it in GitHub Desktop.
Scratch of the Document Import I'm working on.
using System;
using System.IO;
using System.Text.RegularExpressions;
namespace DocImportStrategies
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello World!");
}
}
// As-is, for now...
interface IDocImporter
{
protected IImportStrategy<T> Import<T>();
/*The following are default Import strategies that go in the abstract base class*/
// FileInfo GetFiles(params string[] delimiters);
// FileInfo GetFiles(Regex pattern);
}
abstract class DocImporter
{
public DocImporter(IImportStrategy<object> strategy)
{
}
protected abstract bool Import<T>();
}
class GovInsImporter : DocImporter
{
// Implements the running of import steps for this importer
void Feature1()
{
}
void Feature2()
{
}
public GovInsImporter(IImportStrategy<object> strategy) : base(strategy)
{
}
protected override bool Import<T>() => throw new NotImplementedException();
}
interface IImportStrategy<out TDocType>
{
IImportStrategy<TDocType> Step1();
IImportStrategy<TDocType> Step2();
TDocType Finish(); //Final step of import
}
// Employ the extract() extension method on DocumentParts
abstract class ImportDoc
{
// Accessed by the Importer's strategy
public Regex Pattern { get; }
ImportDoc(string pattern){}
// Actual data:
protected FileInfo Document { get;}
FileNameParts Parts { get; }
}
// The delimited pieces of a file's name
class FileNameParts
{
public string LoanNumber { get; }
public string SpecificType1 { get; }
public string SpecificType2 { get; }
public string MersMinNumber { get; }
public string Time { get; }
// etc.
}
public partial interface ISpecification<in TSubject>
{
bool IsSatisfiedBy(TSubject candidate);
}
interface ImportableDoc
{
// Detect a file name match
Regex pattern { get; }
// Updates the pattern with delimiters
ImportableDoc Delimit(string[] delimiters);
}
class HVAADoc : ImportableDoc
{
public Regex pattern { get; }
public ImportableDoc Delimit(string[] delimiters) => throw new NotImplementedException();
}
class NotesDoc : ImportableDoc
{
public Regex pattern { get; }
public ImportableDoc Delimit(string[] delimiters) => throw new NotImplementedException();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment