I'm early in my C# larval stage, so I'd like a little direction to help
understand good code organization. Take for example a program I have
written in another language that does the following:
On a regular basis, check a 'hot directory' for incoming files. (Maybe every
15 minutes during business hrs.)
For each file
move to an archive directory
decrypt the file
validate the data
write the data into db records
write a text file
Here's a rough sketch of how I would organize this in C#:
namespace importProgram
{
class Program
{
Main()
{
// fire off ProcessFiles in here using a timer.
}
ProcessFiles()
{
// Process the list of files found in the directory.
string[] fileEntries = Directory.GetFiles(targetDirectory);
foreach (string fileName in fileEntries)
{
File.Move(source, target);
decryptFile(filename, newfilename);
validateFileData(newfilename);
writeDBRecord(newfilename);
writeTextFile(newfilename);
}
}
decryptFile(filename,newfilename)
}
{
validateFileData(newfilename)
}
{
writeDBRecord(newfilename)
}
{
writeTextFile(newfilename)
{
}
}
}
Am I heading in the right direction?
Would using one namespace and only one class make sense here?
Would making say 'decryptFile' a class make more sense?
what's the best way to pass back to ProcessFiles() whether the other
functions were successful?
Thanks!