473,395 Members | 1,791 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

good code organization

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!
Nov 16 '05 #1
1 1565
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.
--
Justin Rogers
DigiTec Web Consultants, LLC.
Blog: http://weblogs.asp.net/justin_rogers

"J" <so*********@nowhere.com> wrote in message
news:eL**************@TK2MSFTNGP11.phx.gbl...
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!

Nov 16 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Anthony Abbot | last post by:
Hi I have a requirement to use the Application Center Test (part of Visual Studio.Net Enterprise architect) program, to simulate loading on my Web servers. Does anyone know if it is any good? I...
6
by: cody | last post by:
What are multi file assemblies good for? What are the advantages of using multiple assemblies (A.DLL+B.DLL) vs. a single multi file assembly (A.DLL+A.NETMODULE)?
39
by: Suresh | last post by:
Hi, I am new to C and curious to know some basic questions about C. Why C is good? In what way its better than any other languages? If it is no longer a choice of programming language...why...
171
by: tshad | last post by:
I am just trying to decide whether to split my code and uses code behind. I did it with one of my pages and found it was quite a bit of trouble. I know that most people (and books and articles)...
5
by: Allan Ebdrup | last post by:
Hi We have a large class library of different classes, now we are going to implement a lot of usage statistics that we need, stuff like how many times a user has logged in, how many times a...
2
by: Bart Van der Donck | last post by:
Hello, I'm posting the software for one-FAQ-a-day as described on http://tinyurl.com/qcxw7 (comp.lang.javascript, July 18 2006, titled "CLJ newsgroup FAQ) and on http://tinyurl.com/ppt2s...
6
by: Jeff Gardner | last post by:
Greetings: I am attempting to get conditional output based on POSTed form data. If the posted value is either the key or value of an array, $x=key and $q=foo. elseif it is neither key nor...
20
by: weight gain 2000 | last post by:
Hello all! I'm looking for a very good book for an absolute beginner on VB.net or VB 2005 with emphasis on databases. What would you reccommend? Thanks!
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.