Tips
From WikiPET
Contents |
Installing TPC C#/.NET source codes in your local computer
Before you are able to compile and build any software, you need to install, obviously, Visual Studio 2008. Additionally, you need to install NUnit.
To build documentation, you need to download and install doxygen and to include diagrams and graphs in doxygen documents install also dot tool.
Installing TPCLib
Installing TPCLib binaries
Download zipped TPCLib.dll from http://www.turkupetcentre.net/programs/tpc_csharp.html and unzip the DLL file into folder where Windows can locate it.
Installing and building TPCLib from sources
Download zipped source and documentation folder from http://www.turkupetcentre.net/programs/tpc_csharp.html or (if you are connected to TPC network) export it from our svn server.
Source folder contains file README.TXT, which you should read to get up-to-date information.
If you have Visual Studio 2008 and NUnit already installed, you can just double-click the Visual Studio project file, TPClib.csproj, and the library project will open in Visual Studio. There you can build the sources. TPClib will be created in bin\Release folder.
Installing small program (level 1) VS project
Download the source code from http://www.turkupetcentre.net/programs/tpc_csharp.html (if you are connected to TPC network) export or checkout it from our svn server. Source code folder contains Visual Studio prject file; open it and build the project in Visual Studio.
General program design
Main
Write as little code in the Main() as possible. Instead, write all actual code in separate .cs files, so that they are easy to be moved into the library, or used from within another larger program, or programs with different data flow interfaces, e.g. programs designed to work in PowerShell piping data objects.
GUI versus command-line interface
If the previous advice is followed, then it is easy to write two versions of each program, one with GUI and another with command-line interface. This will make automation of testing much easier, when only GUI part may need to be tested manually.
Writing small command-line programs (Level 1)
Starting new project in Visual Studio
In Visual Studio 2008 (VS), click File, New, Project. A "New Project" dialog box opens: From upper right corner select .NET Framewrok 2.0 (since currently TPCLib is designed and tested to work in .NET 2.0). From installed templates select "Console Application". Give also more descriptive name for your project and program than the default one.
Example 1: Program for doing arithmetics with TAC data files
Open new VS project and name it "taccalc". VS opens a new file, Program.cs, which contains the initial framework code:
pic1
To the very beginning of the source code file, add first the copyright text before you forget it. Then add the necessary namespaces, at least System.IO and in our case, TPCLib:
pic2
Change the introduction of our program class, from the default "class Program" to "public class Program: ConsoleProgram". Write documentation to this function by pressing enter in the beginning of the name, writing '///' and filling the space that VS will offer. Document also Main function, and change the type of Main to "public static int Main(string[] args)":
pic3
Add the code and contents for program information, and command-line options and arguments, see file.
Return values
All command-line programs must return 0 when execution is successful and >0 in case of an error. That means that you must define the Main() function like this:
static int Main(string[] args)
{
if (allwentwell) return 0; else return 1;
}
Also all other methods must be written similarly, and when they are called, the return value must be checked, unless there is a good reason to do otherwise. That reason should then be documented in the comments.
Command-line arguments
Setting command line arguments in VS for debug/test execution
From the menu, click Project > Properties. From left side, select Debug. Fill in the arguments and options under Start Options, Command line arguments. Remember that the first argument in C# has index 0.
If these fields are not writable (gray), then your program may be executing (debugging); quit it and then try again.

