good code organization

J

J

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!
 
J

Justin Rogers

This is a Tool... When writing tools inline code organization is completely
valid.
You've partially segmented items into functional areas which is excellent. Later
if the tool becomes more complex you can easily break out functionality into
more namespaces, classes, etc... In short, your current model is acceptable
and in the future has the ability to be extensible. Good job.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top