Add multiple sections to App.Config - app-config

I need to add a section to my app.config programmatically.
currently i use the Configuration editor where in there is seperate project which contains a class file with al configsection attributes set .I then use the configuration editor access this dll created and add a section .Now i want to access this same ConfigurationClass fill in values programmatically and add multiple sections to the app.config?
Need for this is i have a winForm which contains the server,dbname,usernameand password ,user can connect to multiple databases ovr a server so i need to save this information somewhere .
Thanks ,

Is the config file the best place for this information? Certainly, updating it programatically could lead to runtime errors, which aren't desireable.
Can you supply more information about what the different databases are, for example Live / Test etc or just for different aspects within the same environment?

Related

How to design permissions and conditional loading in extjs

Background
I have to migrte a existing javascript application (one page app) to extjs. The display and behavior of the application depends on the users permission.
Current design
The application is divided into plugins, which represent a feature set to which permissions are granted. Each of those plugins consists of a single javascript file. A user can have permissions for one or more plugins. Depending on the permissions, those files are loaded in the head of the page. Each of these plugins will add its entries to the main menu and expose the methods used to drive the application.
The permissions are stored in a mysql database.
ExtJs's default design
In ExtJs the source files contain each a class. During the build process, all .js files are concatenated to yield one big .js file, that contains everything.
What would be the best design approach?
I considered to use custom compilation with sencha cmd, and create that way a .js file for each plugin. Then I could load these plugins the same way I do it now. But this results in a complicated build and deployment process.
I also thought about creating one and only .js file with a standard Ext build process. I would then load the permissions from the server via ajax in order to construct the menu. All the objects and methods would exist, but only those are accessible where the user has permissions.
In my opinion, the second approach is much easier maintainable, but it seens to have a security problem, because everyone could look at the source and find out about the data interfaces exposed on the server and consumed by ajax.
Any comments, ideas or advices are welcome. Thanks !
Number two would be the way to go. If you keep your server side permissions in check (while updating data etc) you only need ExtJS to show/hide menu items based on permissions. That way, malicious users can turn certain plugins/items on or off, but they can never execute something that requires more permissions then they would normally have.

How do I use the CakePHP Configure class?

I am trying to use the Configure class in CakePHP, but I'm not sure if I am using it correctly. I have read through the cook book and the API, but I can't seem to do what I want.
I have created a configuration file: app/config/config.php. I can directly edit this file and set variables in there and access them using Configure::read().
Is it possible to update the values of the configuration file from the application itself, i.e., from a controller? I have tried using Configure::write(), but this does not seem to change the value.
app/config/config.php isn't a file that's automatically loaded by Cake. Either move these variables into app/config/bootstrap.php or tell your bootstrap.php file to load your custom file. You could also put your variables in app/config/core.php, but I'd recommend against that. I tend to like leaving that file alone and adding/overwriting values in bootstrap.php.
According to the API, Configure is supposed to be used "for managing runtime configuration information".
You can use its methods to create, read, update and delete (CRUD) configuration variables at runtime. The Configure class is available everywhere in your CakePHP application and therefore CRUD operations performed on its data in any place, including a controller.
If you are looking for persistent storage, you could consider a database (SQL or NoSQL). I would not recommend using a text file, as it raises a lot of security concerns. Even if security is not an issue, a database is propably a more fitting solution.
More on the Configure class in the Cookbook.

How to vary a config by host-header

I need multiple sites to all point to a common application, varying by host-header.
While the code / content for each each site is identicial each site does need a unique config, for things like connection strings.
What would be the best approach to set this up?
(The site is actually a Silverlight / WCF application, although I don't think that should matter.)
Either use msi installation package and allow set up all these values in installation wizard or use new web.config transformation syntax introduced in .NET 4.0 (you will have separate config and build target for each host header).
Edit - I didn't understand your question first:
You will have to install the application multiple times. You can't have single site with multiple different configs. But you don't have to copy libraries multiple times - you can use links (mklink.exe). It means you will have one central directory holding your shared content like bin directory and you will have separate directory for each site. Each of sites' directories will contain its own web.config and some content placed to root of your site + links to central directory. You will create create separate application for each site in IIS and map single host header to each application.
Other possiblity is handling this in your code and having everything in single web.config but IMO it is pretty bad and dangerous solution.

how to include XSD schema files in Silverlight library?

Within a Silverlight library, I need to validate incoming XML against a schema. The schema is composed of 5 interdependent .xsd files; the main file uses "xs:import" to reference all of the others, and there are other references among them.
Assuming that the .xsd files need to be distributed with the library (i.e. not hosted on some well-known external URL), how should I structure my project to include them?
I have found that I can embed them in the library project with build type "Resource" and then load them (individually) using Application.GetResourceStream() and a relative URI with the ";content" flag in it. But if I take this approach, can I validate against the interdependent set of 5 files? What happens when the schema parser tries to resolve the interdependencies?
Or should I embed them with build type "Content" and access the main one with some other sort of URL?
Or???
To summarize: how should I use these 5 .xsd files in my project so that I will be able to validate XML against them?
EDIT: It's not clear whether it's even possible to validate in Silverlight. I spun off a related question.
I cannot say much about Silverlight limitations with respect to validation, but the question itself is more generic - one might want to store .xsd files as resources in a desktop .NET application, for example - so I will answer that part.
You can have full control over resolution of URIs in xs:import by means of XmlSchemaSet.XmlResolver property. Just create your own subclass of XmlResolver, override GetEntity() method, and implement it using GetResourceStream(), or GetManifestResourceStream(), or whichever other way you prefer.

How should I store per-user data in WinForms?

In my WinForms app, I have a few textboxes that the user typed some data into. I want to store the data, but I don't want to use a database. In my stone-age C++ days, I'd just use a .ini. Somehow, app.config doesn't seem like the right place to store this data, though.
What are my other options?
I would say the .config file is the right place. Just be sure to use the User scoped area of the Settings.settings file rather than the Application scope.
This works well for simple data types and when you have fixed values that will need to be saved because you need to define what variables you want to store at design time. So if your textboxes are dynamically created and you don't know many values you need to store it is not very useful.
Using IsolatedStorage might be another good option. You can create your own file in any format you want (keeping any values you need) and store it to the local machine in "IsolatedStorage".
You can create a folder somewhere on the disk and simply write a file in any suitable format (XML, plain text, your choice). You could for instance do this under the path pointed out by Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) or Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData).
I would look into isolated storage. It is easy to set up per-user. And since it requires only partial trust, it will work for any deployment scenario.
Check this introduction.
Depending on how many variables/data you're looking to save the app.config/settings file can be the ideal place.
Check out the Settings Tab in the Project properties and note that you can set both Application settings and User settings. Application settings affect the entire application. User settings are stored per user.
The section of the app.config that contains user settings will be saved to the user directory when they are saved and reincorporated when they restart the app.
Check this url for an introduction to Application/user settings on MSDN and also this SO url for a similiar question.:
You could also look into storing your familiar old .ini files in a per user .ini by checking out the Special Folders enum as per this url.
I believe the proper place to store user settings in WinForms 2.0 would be in the settings file (not the config file). Here's a quick article for explanation.
Create a .config or other data file (e.g. xml) in the application data for the specific user.
use system.environment.specialfolder to get the ApplicationData folder, add a subfolder with your company name, within this a subfolder with your application name, within this your data file for this specific user. Thus,
Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\YourCompany\\YourApplication\\YourData.config"

Resources