Home > Net >  What is the mode of store configuration more efficient programs with c #
What is the mode of store configuration more efficient programs with c #

Time:11-17

Recently in to write A small program, there is A listview control that winform runtime to add web host for the first time information, network communication types (TCP, udp) IP address, port number, etc., I'd like to have these information stored, in order to start the next time can immediately communication, the question now is don't know in what way is better, Internet information useful ini, XML, config mode, this have several ways to say who is efficient, and what is the difference between, data volume is not large, dozens of data, there is A question is asked, when the program starts next time reading accessories files, which is how to distinguish information which corresponding to the remote host, such as the initial configuration has A, B, C three host information, the next startup, how to distinguish between A corresponding to A host, A great god, please provide the solution, in this thank you very much!

CodePudding user response:

How much is inefficient, you have to give a quantitative indicators,

CodePudding user response:

Software programming is not speaking out of turn "wrong", but will be subject to the test, will be subject to practice the truth at that time, you want to save configuration data to a UI, the premise is that you understand the first lock configuration data form each line each column represents what, otherwise there would be no need to begin to write code, all all of the problems and solve a sequence, to determine whether the energy spent, necessary ever more important technical need to learn, don't the contradiction,

CodePudding user response:

You say can all three, and the file is read, then controls bound data, also just a few seconds, the efficiency

CodePudding user response:

Ini, XML format is like this, it's very good to distinguish the ABC

INI

[A]
A1=A1
A2=A2
[B]
B1=B1
B2=B2
[C]
.


XML







CodePudding user response:

According to the characteristics of computer hardware, usually read/write memory is faster than a hard disk, but put the memory configuration information not reality, on the hard disk is the same, on the network and slower, monitoring equipment for sale

CodePudding user response:

Storing configuration information stored in a static class, when using the class stored in the XML serialization way, read the deserialized to the class

CodePudding user response:

Dozens of data with what is important? Anyway, you said that a few are text, speaking, reading and writing... There is no difference between

CodePudding user response:

XML should be the most efficient (considering), if you don't consider the scalability, cross-platform and other requirements, I think the DataTable is right choice, can be directly serialize into XML, it is easy to deserialize back, used to hold a two-dimensional table data is easy to implement, and easy to understand, ini don't recommend the use of mandarin (Microsoft),

CodePudding user response:

This need not struggle, if you play with.net core,

In your program. In the cs 2 words

Var host_bd=new HostBuilder ();
Host_bd. ConfigureAppConfiguration ((context, ConfigurationBinder)=& gt;
{
ConfigurationBinder. AddJsonFile (" appsettings. Json ");
})

Here is the requirement that you return a IConfigurationBuilder, that is for our programmers, way of thinking is not like what blog garden those guys like entangled with what vs yyy "XXX," "mine is better than XXX", for our programmers, we don't consider this,

He is a IConfigurationBuilder, as for you is to provide the realization of the ini, provide json, provide yaml, provide the realization of the ado.net, provide the realization of the redis, provide the realization of XML, we actually don't care,

As here I used a json, so what? You told me you want to use yaml, no problem, I only need nuget a yaml implementation, then it is good to modify a word here,

So, you may have about XXX vs yyy?

CodePudding user response:

Programmers do not either/or,

Programmers to do things, neither left nor right, we stood in the middle, depend on abstract

Microsoft to your abstract is currently IConfigurationBuilder interface, who is Provided for implementing this interface, the programmer does not care about, do you want to left we left, the left side is bad, you say we go to the right,

CodePudding user response:

Optional.
TXT, INI, XML, SQLITE can even.

CodePudding user response:

reference 4 floor Bridge_go response:
ini, XML format is like this, it's very good to distinguish the ABC

INI

[A]
A1=A1
A2=A2
[B]
B1=B1
B2=B2
[C]
.


XML







Finally choose the json approach, less code, but still didn't know method how to distinguish, because in the listview is dynamically created host information, the current column 1 with guid for ID, used to distinguish each object, how judging by the ID, I'm stuck in the use of fixed value judgement can do but to write dead, not easy to maintain

CodePudding user response:

refer to 12th floor met the lion's reply:
finally choose the json approach, less code, but still didn't know method how to distinguish, because in the listview is dynamically create host information, the current column 1 with guid for ID, used to distinguish each object, how I am stuck in the judging by the ID, using fixed value judgment can do but just write dead, not easy to maintain


Determine what? Don't judge,

Reference: IP address and domain name,
I said to open the "baidu" -- -- -- -- -- -- -- what you do is open a browser input "www.baidu.com" to yao, not enter an address for
?
So, you give him a name is good, in fact there is no judgement here,

Please connect "Mars explorer" 1 this is the way, please connect device "XXXXX - XXXXXXX - XXXXX - XXXX" this is the practice of the machine, the only difference we humans don't like that kind of meaningless symbols

CodePudding user response:

Mars is a number is equal to XXXXX - XXXXXXX - XXXXX - XXXX

As you have said, I guid identifier only, that doesn't stop us from another to give him a human name is easy to remember

CodePudding user response:

1 the ini, XML, config which casually, you use it,
Don't say efficiency performance of dozens of data such as topic,
you'll have to solve the problem is that users read and write access to files,

2 A, B, C host, don't know the corresponding storage?
You store a key - value,
App. Config/web. Config understand? It is ok to store a key - value,

CodePudding user response:

For general simple configuration, do not need multiple servers to share the configuration, you don't need to put in like redis cache, you can own in the ini, XML, config, into the cache, the cache dependence, so the fastest, because the machine server cache is read, the most is the machine the file on the server,

CodePudding user response:

Initially popular ini in the ini, later popular use XML with XML, now I like to use json config, because serialized object convenient ah, extraction for object serialization parameter to processing, preservation, the object serialization one-time preservation, than XML search positioning changes, or the XML serialization is convenient!

However, the system level configuration, I still use the app. Config, coding standards is very important,

CodePudding user response:

Try my open source library

https://github.com/dotnet-campus/dotnetCampus.Configurations
  •  Tags:  
  • C #
  • Related