|
Hi,
I'm about to start on a new project and want to get a good starting point. What is the issue with .ini files why have they been replaced with XML and what is the best way of using them I have had a look and haven't found any real reason.....
Glenn
a good example would help had a look on CP didn't find one!
|
|
|
|
|
|
Easiest way is to use the .NET settings mechanism:
1) Open your projects Properties in the solution explorer, and double click on "Settings.settings"
2) In the resulting grid, change the Name to "MySetting", and set the Value to "Defaulted value". Leave Type and Scope as "string" and "User" respectively.
3) Save and close the settings window.
4) To read your setting:
string s = Properties.Settings.Default.MySetting;
5) To write your setting:
Properties.Settings.Default.MySetting = "My new setting value";
Properties.Settings.Default.Save();
Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water
|
|
|
|
|
Note that one problem with that idiom is that the configuratoin file is no longer really a 'configuration' file.
The reason for that is that there is no way to add documentation and/or formatting to that file because if you touch it in the IDE again then all of those changes are lost.
And so expecting someone to use that file via something like notepad to set up an application will not really work if there are more than a couple of values.
|
|
|
|
|
I agree - but I would not expect to make a user manually edit a config file anyway. Heck, most of them couldn't be trusted to get it right! And I'd prefer to document the settings where they are used, rather than where they are stored. The settings are no use without the program, but the program can be used without the settings file if you have info on what they are for.
Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water
|
|
|
|
|
I write servers. And the targetted users are paid to get it right but I code defensively to insure logical behavior for mistakes.
The settings are not intended to be modified on a regular basis. Providing an alternative way to edit them would be significantly additional work. And it doesn't insure that problems will not occur since the file can still be manually edited.
|
|
|
|
|
What I don't like about that is that I find it very limiting in what you can do with it. Whereas, by rolling my own, I can have exactly the flexibility I want, rather than what Microsoft thought I would want. For example, I have applications sharing config files and config files that refer to other config files.
And, like jschell pointed out, I prefer to be able to edit my config files when the need arises without fear that some tool will wipe out my changes. That doesn't mean I require my users to do so as well, only that they can if they need to (not that I have any users anyway).
|
|
|
|
|
It is limited - but is is simple, and quick to set up and use.
For simple tasks, it is fine - for more complex stuff I roll my own, but that would be more likely to be a datafile or a template than an INI file anyway.
No users? Lucky you! They just pay you to produce software nobody uses?
Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water
|
|
|
|
|
Sooo...,
For maximum flexibly still the old ground hugging ini file is best it appears to the best, users can open see and scr*w up!
if (File.Exists(INIPath + "\\MeteringData.ini"))
{
StreamReader sr = new StreamReader(INIPath + "\\MeteringData.ini");
Defaults = sr.ReadToEnd();
sr.Close();
string[] Values = Defaults.Split(delimetersChars);
foreach (string v in Values)
{
a++;
char[] separator = { '=' };
string[] Key = v.Split(separator);
if (Key.Length != 2) continue;
Key[0] = Key[0].Trim();
Key[1] = Key[1].Trim();
if(Key[0] == "Location")
{
LocationData = Key[1];
}
The really nice thing is when you get a panic stricken email/phone call "we have broken something help" send them a fresh version of the ini file modded to their specs and 'Hussar!' it works.
Glenn
|
|
|
|
|
glennPattonWork wrote: For maximum flexibly
XML.
|
|
|
|
|
XML, really? I need a good example of how to do it, also with our clients editing/modding the file must be stupidly easy. The number times I have received an Email at quarter to home on Friday that basically says "<thing> does not run we need <thing> running for a demo on Saturday am", (I mean a Demo on Saturday morning?)....
|
|
|
|
|
glennPattonWork wrote: with our clients editing/modding the file must be stupidly easy.
Write an editor for them to use and/or have something like Tools/Options.
|
|
|
|
|
That depends on the product and user base but defensive programming can minimize many problems.
|
|
|
|
|
OriginalGriff wrote: produce software nobody uses
Batch processing, Windows Services, etc.
And stuff that I write for myself that no one else uses.
|
|
|
|
|
Hi Gurus,
I am using RegEx class for parsing some strings of the following format
[Hello World message 234...]
What is the expression that I need to use to format the above string??
Thanks...
Sunil
|
|
|
|
|
What do you mean by "formatting the above string"??
Are you looking to pull information out of the string?? What would that data be??
|
|
|
|
|
Hi Dave,
This is my requirement. I read a line from a file, which is in the following format: [Some message 123...]
So I would want to create a RegEx pattern for the above format. What would be the expression for this case. I tried this but it failed while calling method RegEx.Match():
RegEx _exp = new Regex(@"^\[(?<message>\w+)]", RegexOptions.IgnoreCase);
Sunil
|
|
|
|
|
That still doesn't help. Why do you need a regex, what problem is it supposed to solve?
|
|
|
|
|
sunilkpv wrote: So I would want to create a RegEx pattern for the above format
TO DO WHAT??
|
|
|
|
|
Why are you using a RegEx when you can easily separate the tokens of the message with the String.Split() [^] method? Perhaps if you explain exactly what you are trying to do we can make some more informed suggestions.
Unrequited desire is character building. OriginalGriff
I'm sitting here giving you a standing ovation - Len Goodman
|
|
|
|
|
There is a Regular Expression forum.
Perhaps you should provide more examples and the results you want.
If you want to separate the message part from the number part, perhaps something like this might help:
@"(?'message'[^\d]*)(?'number'[\d]*)"
or
@"(?'message'.*?) message (?'number'.*)"
|
|
|
|
|
Good Morning,
Please,
Is there a limit memory on the Windows to an application c#?
Ex: I have a program that carry different informations and that information are equals 2 GB for example
but when I go to do other process I can't do because it's give me Exception System.out.of.memory
how can I change this limit?
thanks
William
|
|
|
|
|
Not enough information.
How much memory is in the machine? Which version of Windows are you running? What code is throwing this exception? How big is the object you're allocating?
Under .NET, OutOfMemory exceptions cover a lot of things, some of which have nothing to do with running out of memory.
Also, no single object in .NET can be larger than 2GB. So, if you're trying to allocate say, an array of integers greater than 512 million elements, it's going to fail.
|
|
|
|
|
I'm using 8GB of Memory Ram, Windows 7 Professional 64 bits. Virtual Memory 6144 MB.
I carry a HashTable With 5 000 000 of records, this equivalent 2GB, but when I go to create other array of 25000 positions give me System out of memory exception.
If I stop the code in this section and instantiate the array in another application works perfect, so I have memory on the machine, so I see that the problem is the limitation of each application
thanks
|
|
|
|
|
Three thoughts:
1. is your app running in x-64 mode? how did you build it: x-86, x-64, or "Any CPU"?
2. could it be a fragmentation problem: objects larger than 80KB go in the Large Object Heap, which never gets compacted, hence could fragment when many different sized objects get allocated and freed in random order.
3. do you really need/want that big a hash table, wouldn't a database be more appropriate? or a completely different algorithm? (we don't know what it is your app is doing...)
|
|
|
|