What I wanted to do with the implementation was to create a
base for all the checks and validation and any child class to provide their own
implementation of the algorithm. I decided to leave the IDisposable since later
own new check or a base implementation could be added.
|
/// <summary> /// RepositorySynch will contain basic functionality for
validation and property holding. /// </summary> public abstract class RepositorySynch : IDisposable { //
Properties public
string SourcePath { get;
private set;
} public
string DestinationPath { get; private set; } public
DirectoryInfo SourceDirectory { get; private set; } public
DirectoryInfo DestinationDirectory { get; private set; } public
RepositorySynch(string SourcePath, string DestinationPath) { this.SourcePath
= SourcePath; this.DestinationPath
= DestinationPath; } /// <summary> /// Validate both source and destination path and create a
new instance of the directory info. /// </summary> protected
void ValidatePaths() { if
(Directory.Exists(SourcePath)) SourceDirectory = new DirectoryInfo(SourcePath); else throw
new DirectoryNotFoundException(string.Format("Unabled
to find source: {0}.", SourcePath)); if
(Directory.Exists(DestinationPath)) DestinationDirectory = new DirectoryInfo(DestinationPath); else throw
new DirectoryNotFoundException(string.Format("Unabled
to find destination: {0}.", DestinationPath)); } public
virtual void
Synch() { ValidatePaths(); } public
void Dispose() { } } |
The second code listing illustrates an implementation
with a specific logic set and naming convention rules. The idea below was to
leverage linq as much as possible to assist in filtering the data and getting
down to the files the needed to be copied.

Join the conversation! Your thoughts help the community grow.