473,325 Members | 2,671 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,325 software developers and data experts.

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 2059
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**************@TK2MSFTNGP03.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**********@nothinks.comwrote in message
news:ex**************@TK2MSFTNGP02.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**************@TK2MSFTNGP03.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**********@nothinks.comwrote in message
news:ex**************@TK2MSFTNGP02.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**************@TK2MSFTNGP03.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 "deviceundertest"
...
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*****@operamail.comwrote in message
news:11**********************@l53g2000cwa.googlegr oups.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**********@nothinks.comwrote in message
news:ex**************@TK2MSFTNGP02.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**************@TK2MSFTNGP03.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
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...
2
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
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 -...
3
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...
0
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...
1
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...
10
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...
0
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...
6
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...
3
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...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.