473,566 Members | 3,307 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Configuration File

Jay
I want to store various text settings in a configuration file, that I will read into C# and make use
of. Here's a simplified example of the file:

#comment
loop(var=1:5){
deviceundertest freq:5.6e6 power:3.7
analyser freq:5.6e6 span:1e3 resbw:100 atten:20
}

As you can see, the configuration file will define:
- comments, which start with the # character
- looping - the loop line effectively means for(int var=1; var<=5; var++){ }
- equpment settings (eg analyser is the name of some equipments, and what follows are parameters
that are sent to the equipment)

There is no requirement to write this file from C# - it will be written and edited in (eg) Notepad.
Is there any support within C# and .net for this type of file, or should I simply read it as a text
file and parse it with my own code? I thought I'd ask the question before I start to write the
parsing code.

Thank everyone...
Jan 19 '07 #1
5 2079
No direct support, all the configuration stuff in dotnet relies on XML.
You could rewrite it as xml simply enough and use the inbuilt support.
You would still have to write all the logic to process the loops and
would still be subject to typo's, so your idea of just reading the file
and processing it from your own format seems sound.

If you seperate the logic for reading the file from the logic of
processing the data within you will find it easier to replace the
format later if necessary. Do so via an interface you could support a
number of formats.

As for the processing, you've got regex's but in this case I'd just
process it with string methods.

Jay wrote:
I want to store various text settings in a configuration file, that I will read into C# and make use
of. Here's a simplified example of the file:

#comment
loop(var=1:5){
deviceundertest freq:5.6e6 power:3.7
analyser freq:5.6e6 span:1e3 resbw:100 atten:20
}

As you can see, the configuration file will define:
- comments, which start with the # character
- looping - the loop line effectively means for(int var=1; var<=5; var++){ }
- equpment settings (eg analyser is the name of some equipments, and what follows are parameters
that are sent to the equipment)

There is no requirement to write this file from C# - it will be written and edited in (eg) Notepad.
Is there any support within C# and .net for this type of file, or should I simply read it as a text
file and parse it with my own code? I thought I'd ask the question before I start to write the
parsing code.

Thank everyone...
Jan 19 '07 #2
As long as you are using a proprietary configuration file format, you'll
have to write a proprietary parser for it.

--
HTH,

Kevin Spencer
Microsoft MVP
Software Composer
http://unclechutney.blogspot.com

In case of Minimalism, break Philip Glass.

"Jay" <nospamwrote in message
news:OP******** ******@TK2MSFTN GP03.phx.gbl...
>I want to store various text settings in a configuration file, that I will
read into C# and make use
of. Here's a simplified example of the file:

#comment
loop(var=1:5){
deviceundertest freq:5.6e6 power:3.7
analyser freq:5.6e6 span:1e3 resbw:100 atten:20
}

As you can see, the configuration file will define:
- comments, which start with the # character
- looping - the loop line effectively means for(int var=1; var<=5;
var++){ }
- equpment settings (eg analyser is the name of some equipments, and what
follows are parameters
that are sent to the equipment)

There is no requirement to write this file from C# - it will be written
and edited in (eg) Notepad.
Is there any support within C# and .net for this type of file, or should I
simply read it as a text
file and parse it with my own code? I thought I'd ask the question before
I start to write the
parsing code.

Thank everyone...


Jan 19 '07 #3
Jay
Thanks for your replies Kevin and DeveloperX.

I don't have a reason in principle for not using XML, but I didn't think I'd be able to code the
loop in XML. Some of the loops will be nested too.

loop(var=1:5){
deviceundertest freq:5.6e6 power:3.7
loop(%f=2e3, 3e3, 4e3, 5e3){
analyser freq:%f span:1e3 resbw:100 atten:20
}
}

The file format is to be developed by me, so I can completely change it if necessary.

I know very little about XML apart from seeing a few simple examples ( eg, a car, model,
manufacturer example).

If someone could show me an example of coding the loop, that would be very helpful.

Jay
"Kevin Spencer" <un**********@n othinks.comwrot e in message
news:ex******** ******@TK2MSFTN GP02.phx.gbl...
As long as you are using a proprietary configuration file format, you'll
have to write a proprietary parser for it.

--
HTH,

Kevin Spencer
Microsoft MVP
Software Composer
http://unclechutney.blogspot.com

In case of Minimalism, break Philip Glass.

"Jay" <nospamwrote in message
news:OP******** ******@TK2MSFTN GP03.phx.gbl...
>I want to store various text settings in a configuration file, that I will
read into C# and make use
of. Here's a simplified example of the file:

#comment
loop(var=1:5){
deviceundertest freq:5.6e6 power:3.7
analyser freq:5.6e6 span:1e3 resbw:100 atten:20
}

As you can see, the configuration file will define:
- comments, which start with the # character
- looping - the loop line effectively means for(int var=1; var<=5;
var++){ }
- equpment settings (eg analyser is the name of some equipments, and what
follows are parameters
that are sent to the equipment)

There is no requirement to write this file from C# - it will be written
and edited in (eg) Notepad.
Is there any support within C# and .net for this type of file, or should I
simply read it as a text
file and parse it with my own code? I thought I'd ask the question before
I start to write the
parsing code.

Thank everyone...



Jan 19 '07 #4
I knocked up something that should work, but I can't get it to you
until Monday (and there's a bit that doesn't work I need to tweak (I
don't code much xml tbh)). If you drop me a note to n n t p d e v at o
p e r a m a i l dot c o m (don't know why I did that it's a spam
account anyway...) I'll email it over on Monday. It's not big or
clever, just takes an xml file that conforms to your requirements (I
believe) and turns it into a set of tests to be executed. It's no more
than a hundred lines of code. Only thing I need to know is what's
supposed to happen in your nested loop, should the inner loop be run 5
times with the same values, or does the outer loop affect the inner
loops variables, or option c?
Jay wrote:
Thanks for your replies Kevin and DeveloperX.

I don't have a reason in principle for not using XML, but I didn't think I'd be able to code the
loop in XML. Some of the loops will be nested too.

loop(var=1:5){
deviceundertest freq:5.6e6 power:3.7
loop(%f=2e3, 3e3, 4e3, 5e3){
analyser freq:%f span:1e3 resbw:100 atten:20
}
}

The file format is to be developed by me, so I can completely change it if necessary.

I know very little about XML apart from seeing a few simple examples ( eg, a car, model,
manufacturer example).

If someone could show me an example of coding the loop, that would be very helpful.

Jay
"Kevin Spencer" <un**********@n othinks.comwrot e in message
news:ex******** ******@TK2MSFTN GP02.phx.gbl...
As long as you are using a proprietary configuration file format, you'll
have to write a proprietary parser for it.

--
HTH,

Kevin Spencer
Microsoft MVP
Software Composer
http://unclechutney.blogspot.com

In case of Minimalism, break Philip Glass.

"Jay" <nospamwrote in message
news:OP******** ******@TK2MSFTN GP03.phx.gbl...
I want to store various text settings in a configuration file, that I will
read into C# and make use
of. Here's a simplified example of the file:

#comment
loop(var=1:5){
deviceundertest freq:5.6e6 power:3.7
analyser freq:5.6e6 span:1e3 resbw:100 atten:20
}

As you can see, the configuration file will define:
- comments, which start with the # character
- looping - the loop line effectively means for(int var=1; var<=5;
var++){ }
- equpment settings (eg analyser is the name of some equipments, and what
follows are parameters
that are sent to the equipment)

There is no requirement to write this file from C# - it will be written
and edited in (eg) Notepad.
Is there any support within C# and .net for this type of file, or should I
simply read it as a text
file and parse it with my own code? I thought I'd ask the question before
I start to write the
parsing code.

Thank everyone...
Jan 19 '07 #5
Jay
Thanks very much DeveloperX for putting this together for me - I will email my email address
directly to you shortly.

My example wasn't that great, so let me improve it to illustrate how the loops work. Also, I going
to assume that all loop variables are doubles, not ints as before. As you can see, my ideas for the
configuration file are still being developed! Sorry for the lack of clarity in my last posting.

- comments start with #
- loop variables start with % to make it easier for the parser to spot them

loop(%p=1:15:2) { #means start:stop:step
deviceundertest freq:5.6e6 power:%p #use outer loop variable (%p)
loop(%f=2e3, 3e3, 4.3e3, 9.1e4){
analyser freq:%f span:1e3 reflev=%p resbw:100 atten:20 #use both outer and inner loop
variables (%p and %f)
}
}
The loops are equivalent to this C# code (I'm a C-programmer new to C# so it may have syntax
errors...

delta=1e-6;
double[] fArray = {2.0e3, 3.0e3, 4.3e3, 9.1e4}
for(double p=1.0; p<=15.0+delta; p+=2.0){ //delta prevents rounding problems
//make use of outer loop variable (p) in the settings for "deviceundertes t"
...
foreach(double f in fArray){
//make use of outer and inner loop variables (p and f) in the settings for "analyser"
...
}
}
Thanks again for all your help...

Jay
"DeveloperX " <nn*****@operam ail.comwrote in message
news:11******** **************@ l53g2000cwa.goo glegroups.com.. .
I knocked up something that should work, but I can't get it to you
until Monday (and there's a bit that doesn't work I need to tweak (I
don't code much xml tbh)). If you drop me a note to n n t p d e v at o
p e r a m a i l dot c o m (don't know why I did that it's a spam
account anyway...) I'll email it over on Monday. It's not big or
clever, just takes an xml file that conforms to your requirements (I
believe) and turns it into a set of tests to be executed. It's no more
than a hundred lines of code. Only thing I need to know is what's
supposed to happen in your nested loop, should the inner loop be run 5
times with the same values, or does the outer loop affect the inner
loops variables, or option c?
Jay wrote:
Thanks for your replies Kevin and DeveloperX.

I don't have a reason in principle for not using XML, but I didn't think I'd be able to code the
loop in XML. Some of the loops will be nested too.

loop(var=1:5){
deviceundertest freq:5.6e6 power:3.7
loop(%f=2e3, 3e3, 4e3, 5e3){
analyser freq:%f span:1e3 resbw:100 atten:20
}
}

The file format is to be developed by me, so I can completely change it if necessary.

I know very little about XML apart from seeing a few simple examples ( eg, a car, model,
manufacturer example).

If someone could show me an example of coding the loop, that would be very helpful.

Jay
"Kevin Spencer" <un**********@n othinks.comwrot e in message
news:ex******** ******@TK2MSFTN GP02.phx.gbl...
As long as you are using a proprietary configuration file format, you'll
have to write a proprietary parser for it.

--
HTH,

Kevin Spencer
Microsoft MVP
Software Composer
http://unclechutney.blogspot.com

In case of Minimalism, break Philip Glass.

"Jay" <nospamwrote in message
news:OP******** ******@TK2MSFTN GP03.phx.gbl...
I want to store various text settings in a configuration file, that I will
read into C# and make use
of. Here's a simplified example of the file:

#comment
loop(var=1:5){
deviceundertest freq:5.6e6 power:3.7
analyser freq:5.6e6 span:1e3 resbw:100 atten:20
}

As you can see, the configuration file will define:
- comments, which start with the # character
- looping - the loop line effectively means for(int var=1; var<=5;
var++){ }
- equpment settings (eg analyser is the name of some equipments, and what
follows are parameters
that are sent to the equipment)

There is no requirement to write this file from C# - it will be written
and edited in (eg) Notepad.
Is there any support within C# and .net for this type of file, or should I
simply read it as a text
file and parse it with my own code? I thought I'd ask the question before
I start to write the
parsing code.

Thank everyone...

Jan 20 '07 #6

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

Similar topics

2
8666
by: Alexander Kienzle | last post by:
I'm new to Java programming. I'm developing a Servlet for tomcat which needs an external configuration file. With external I mean a file (in XML format) which is customizable and not contained in my package. I don't want to hardcode any path and I would like to be independent of the application server (tomcat, websphere,...). Until now, I...
2
3443
by: kathy | last post by:
What Application Configuration File is? And when/where/how to use it? Any documents on that? MSDN has somrthings scatter everywhere - hard to follow. thanks,
4
2723
by: Jessard | last post by:
Hi Guys and Girls, I have a situation where I am wishing to deploy a .NET dll onto a number of servers. The classes in the DLL will be used by VBScripts. When one of the classes - Connection - is instantiated from a VBScript the code looks to a simple text file for initialisation of certain variables. I want this text file to reside with...
3
2875
by: Florida Coder | last post by:
I have the need to store some application specific configuration data to be used by a class library and or a windows service. I would like to do this in a fashion similar to the way we do with applications and web services without having to use the machine.config file. I know that I could use the code below to do this but the problem...
0
5306
by: phillip | last post by:
This is interesting, I have attached my web.config file and the exception I have been logging. I created a library which provide data access to a database and a control system. The library is written in C#. I created a small .exe file to test that the library builds propertly from configuration and that it communicates properly. This work...
1
2840
by: Ramanfromoz | last post by:
Hi, Developing a new we application. Everything okay on my local WIN XP PROFESSIONAL, IIS 5.0 running locally. The website is running smoothly. Now, the same code I am copying over to a WINDOWS 2003 SERVER, I created a new website, allocated port number 6000. Created a release version on my local machine and copied the WEB project from my...
10
3692
by: Rider | last post by:
Hi, simple(?) question about asp.net configuration.. I've installed ASP.NET 2.0 QuickStart Sample successfully. But, When I'm first start application the follow message shown. ========= Server Error in '/QuickStartv20' Application. -------------------------------------------------------------------------------- Configuration Error...
0
1485
by: sean rogers | last post by:
hello im using the configuration block and have created the main config file for the application - the file that contains the paths to the other configuration sections i.e. - (my other configuration section is called dataConfiguration.) <configuration> <configSections> <section name="enterpriselibrary.configurationSettings"
6
4794
by: Jeff Hegedus | last post by:
I have a dll that requires some configuration data. I put the configuration data in a custom configuration section in a config file that is loaded in the installation folder of the dll. If I install the dll to the same directory as the exe which uses it, everything works as expected but if I load the dll in any other directory, I get the...
3
12036
by: Mike | last post by:
Hi I have problem as folow: Caught Exception: System.Configuration.ConfigurationErrorsException: An error occurred loading a configuration file: Request for the permission of type 'System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed. (machine.config) --->...
0
7893
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7645
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7953
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6263
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5485
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5213
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3626
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1202
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
926
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.