PC Review


Reply
Thread Tools Rate Thread

Configuration File

 
 
Jay
Guest
Posts: n/a
 
      19th Jan 2007
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...


 
Reply With Quote
 
 
 
 
DeveloperX
Guest
Posts: n/a
 
      19th Jan 2007
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...


 
Reply With Quote
 
Kevin Spencer
Guest
Posts: n/a
 
      19th Jan 2007
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" <nospam> wrote in message
news:(E-Mail Removed)...
>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...
>
>



 
Reply With Quote
 
Jay
Guest
Posts: n/a
 
      19th Jan 2007
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
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" <nospam> wrote in message
news:(E-Mail Removed)...
>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...
>
>




 
Reply With Quote
 
DeveloperX
Guest
Posts: n/a
 
      19th Jan 2007
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" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> 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" <nospam> wrote in message
> news:(E-Mail Removed)...
> >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...
> >
> >


 
Reply With Quote
 
Jay
Guest
Posts: n/a
 
      20th Jan 2007
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
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" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> 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" <nospam> wrote in message
> news:(E-Mail Removed)...
> >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...
> >
> >



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Is the .NET configuration file cache not refreshed when the sourceconfig file is modified? Water Cooler v2 Microsoft C# .NET 1 24th Sep 2009 05:18 AM
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, PublicK Mike Microsoft ASP .NET 5 15th Aug 2007 09:57 AM
Configuration Application Block: Multiple configuration sections in one file: probashi Microsoft C# .NET 1 21st Mar 2005 10:50 AM
Windows service configuration - registry or configuration file? Ken Brady Microsoft Dot NET Framework 1 18th Feb 2005 03:52 PM
RE: Resource File Versus Configuration File =?Utf-8?B?Sm9obiBQYXVsLiBB?= Microsoft Dot NET Framework 0 28th Jul 2004 11:21 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:37 AM.