Micsoroft Enterprise Validation framework -> How to have one config file per validated Type - app-config

I am using microsoft enterprise validation framework. And I'm linking the file 'validation.config' in my app.config file.
<section name="validation" type="Microsoft.Practices.EnterpriseLibrary.Validation.Configuration.ValidationSettings, Microsoft.Practices.EnterpriseLibrary.Validation, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
allowLocation="true" allowDefinition="MachineToApplication" restartOnExternalChanges="false" />
<validation configSource="LocalConfiguration\validation.config" />
In 'validation.config' file i have
<?xml version="1.0" encoding="utf-8" ?>
<validation>
<type name="Car">
<ruleset>
<properties>
<validators>...</validators>
</properties>
</ruleset>
</type>
<type name="Human">
<ruleset>
<properties>
<validators>...</validators>
</properties>
</ruleset>
</type>
</validation>
The question is: Can i put the 'Car' and 'Human' types in different files and link those files in validation.config or is there any other way of separation because my validators are too many and I want it to be clean and easy to read.

#.NETJunkie has a blog post on Splitting up Validation Application Block configuration into multiple files which should address your needs.

Related

How to make the application read keys from app.config file of class library dynamically

My requirement is as follows.
1)I want to use the application settings to read a location path and use it in my project to read the files in that folder.
--- I achieved this by creating a setting with the path and I used to read the path from that settings in the project as follows
Properties.Settings.Default.XMLModelPath
2)Now the actual requirement is I want that app.config of the class library to be available in the bin so that I can update the path if there are any changes required later and every time I run the application, the settings of that project should read this file and update its value.
Is there a way to achieve this or suggest any other possible ways.?
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
<section name="MyClass.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</sectionGroup>
</configSections>
<applicationSettings>
<MyClass.Properties.Settings>
<setting name="XMLModelPath" serializeAs="String">
<value>C:\Resources\</value>
</setting>
</MyClass.Properties.Settings>
</applicationSettings>
</configuration>
This is my app.config file of the class. I want this to be available in bin and the settings of the project to be updated everytime I run my application.

How to specify Entity Framework Code First connection string in external Enterprise Library config file

I am creating a WPF application, having classical architecture: UI layer, business logic layer and infrastructure layer. I decided to split configuration in two files: app.config file, containing common app configuration, and dll.config, containing connection string to use in DbContext for domain model storage. The second .config file should be sticked to business logic DLL, while first file sticked to corresponding UI executable (there will be one more UI with it's own configuration).
app.config:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="enterpriseLibrary.ConfigurationSource" type="Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ConfigurationSourceSection, Microsoft.Practices.EnterpriseLibrary.Common, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="true" />
</configSections>
<enterpriseLibrary.ConfigurationSource selectedSource="Winter DAL Configuration">
<sources>
<add name="Winter DAL Configuration" type="Microsoft.Practices.EnterpriseLibrary.Common.Configuration.FileConfigurationSource, Microsoft.Practices.EnterpriseLibrary.Common, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
filePath="dll.config" />
</sources>
</enterpriseLibrary.ConfigurationSource>
</configuration>
dll.config:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="dataConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings, Microsoft.Practices.EnterpriseLibrary.Data, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="true" />
</configSections>
<dataConfiguration defaultDatabase="WinterContext" />
<connectionStrings>
<add name="WinterContext" connectionString="Data Source=Winter.sdf"
providerName="System.Data.SqlServerCe.4.0" />
</connectionStrings>
</configuration>
Now, when I'm starting the app, DbContext throws an exception saying it cannot find connection string with specified name. If I move connection string from dll.config to app.config - all working fine.
Maybe I must explicitly load configuration somehow? Or?.. What do I do wrong?
Thx in advance!
Based on the config files supplied, Entity Framework went looking in app.config of root in start project and didnt find the EF content. Especially the Connection string.
When you first used UF it would have created such entries, perhaps in the model project.
IM using EF5.0 so careful with cut and paste on Entity Section .
<configuration>
<configSections>
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
<parameters>
<parameter value="v11.0" />
</parameters>
</defaultConnectionFactory>
</entityFramework>
<connectionStrings>
<add name="CONTEXT_NAME_HERE"
providerName="System.Data.SqlClient"
connectionString="Data Source=YOURDB_SERVER;Initial Catalog=YOUR_DBNAME;Integrated Security=True;MultipleActiveResultSets=True;App=EntityFramework" />
</connectionStrings>
</configuration>
I hope I understood your question, you want to structure your app.configs as a hierarchy, which is valid, in web applications that is very common, the easiest way to let .net help you with the merging is specifiying the regions of app.config in all those configurations that need to be bounded, and in the inner configurations you can override the values until you have the last one, for example:
ROOT APPCONFIG
<configuration>
<commonCollection>
<add key="first" value="1" />
<add key="second" value="2" />
<add key="third" value="3" />
</commonCollection>
</configuration>
INNER APPCONFIG
<configuration>
<commonCollection>
<remove key="first" />
<add key="first" value="10" />
</commonCollection>
</configuration>
Results:
ROOT APPCONFIG
first : 1
second: 2
third: 3
INNER APPCONFIG
first: 10
second: 2
third: 3
EDIT
for your EF context, to set the connection string in the constructor :
public MyContextDB() :base("name=DefaultConnection")
{
//other initializers
}
hope it helps,

edit key->value in .exe.config in SmartClient

I'll start here: I know nothing about SmartClient, .Net, DotNetNuke, etc etc. This is a "see if alison can help" project for a client's app/ site developed 6 years ago by a company that won't help. I'm just a front-end developer- I've googled all I can. If I don't understand the advice given here, I'm passing on assisting the client. Just thought I would give it a whirl. Here goes:
We simply need to change a key -> value in the configuration of their desktop app which connects to a web service (ASEPublisher). I have FTP and SQL Server access, but that's it.
The desktop app folder contains the following files:
DataPublisher.exe
DataPublisher.exe.config
DataPublisher.pdb
OleDBDataAccess.dll
OleDbDataAccess.pdb
Their website contains a folder called "smartclient" that contains the same files.
I just need to change all of the urls in the code below and have the application update to use the new urls. Obviously just changing this file on the desktop and restarting the app didn't do it. So, here I am. I hope this isn't too vague. If you need more info, I can try to provide it.
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
<section name="DataPublisher.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</sectionGroup>
</configSections>
<appSettings>
<add key="DefaultFilePath" value="I:\Staff\fakefolder\database\SA Data.mdb" />
<add key="DefaultASEFilePath" value="I:\Staff\fakefolder\database\SA Data.mdb" />
<add key="CNN" value="Provider=Microsoft.Jet.OLEDB.4.0;User ID=Admin;Data Source=" />
<add key="WebSvcUrl" value="http://www.fakedomain.org/admin/ClassPublisher.asmx" />
<add key="ASEWebSvcUrl" value="http://www.fakedomain.org/admin/ASEWebService.asmx" />
</appSettings>
<applicationSettings>
<DataPublisher.Properties.Settings>
<setting name="DataPublisher_ClassPublisherWS_ClassPublisher"
serializeAs="String">
<value>http://www.fakedomain.org/admin/ClassPublisher.asmx</value>
</setting>
<setting name="DataPublisher_ASEPublisherWS_ASEWebService" serializeAs="String">
<value>http://www.fakedomain.org/admin/ASEWebService.asmx</value>
</setting>
</DataPublisher.Properties.Settings>
</applicationSettings>
</configuration>

Silverlight 4 Assembly Caching for Project References

I have several Silverlight utility and control projects that I re-use in several different applications with-in my web application. These are all worked on in the same solution. Each Silverlight application has it's own page.
Example Setup
Utilities
CommonResources
I've strong name keyed and created extmap for these projects, but the dll's are still in the xaps. The version is defnied as 1.0.0.0 in the assembly.cs.
CommonResources
1.0.0.0
{public key here}
Silverlight.Common.CommonResources.dll
These all reference Utilities and CommonResources
- ManageFoo
- ManageBar
- etc
Can I assembly cache the utilities and CommonResources dll?
You may try adding an XML file (e.g. named Common.CommonResources.extmap.xml) to the CommonResources project, and set “Copy to Output Directory” to “Copy if newer”, with the following content:
<?xml version="1.0"?>
<manifest xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<assembly>
<name>Common.CommonResources</name>
<version>*.*.*.*</version>
<publickeytoken>*</publickeytoken>
<relpath>Common.CommonResources.dll</relpath>
<extension downloadUri="Common.CommonResources.zip" />
</assembly>
</manifest>
I don't see why you couldn't in this scenario. In fact it seems to be the ideal candidate.
You'll need to make sure you generate extmap files for your Utilities and CommonResources dlls. The file looks like this:
<?xml version="1.0"?>
<manifest xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<assembly>
<name>System.Windows.Controls.Data.DataForm.Toolkit</name>
<version>2.0.5.0</version>
<publickeytoken>31bf3856ad364e35</publickeytoken>
<relpath>System.Windows.Controls.Data.DataForm.Toolkit.dll</relpath>
<extension downloadUri="System.Windows.Controls.Data.DataForm.Toolkit.zip" />
</assembly>
</manifest>
and has the name of the form:
<dllname>.extmap.dll
and must be in the same location as the dll itself.

How can I place multiple project dlls in the same Assembly Cache zip for Silverlight?

I'm using the very helpful MvvmLight toolkit and want to package both dlls into a single zip with Assembly Caching turned on. I tried to set the for both the main and the Extras.dll, but the app can no find the Extras dll in the zip. Is this possible to do with Silverlight?
EDIT: I'm using Assembly Caching so that the toolkit (and other dlls) are not in the XAP. Then the user will only need to download these one time, instead of once for every Silverlight app. We have a ASP.NET app with several different pages exposing different Silverlight apps.
I've found that I can use the same zip file in each extmap file now. I'm not sure if I did it wrong before or what...
<?xml version="1.0"?>
<manifest xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<assembly>
<name>GalaSoft.MvvmLight.Extras.SL4</name>
<version>3.0.0.30106</version>
<publickeytoken>918f02b0f4b4b116</publickeytoken>
<relpath>GalaSoft.MvvmLight.SL4.Extras.dll</relpath>
<extension downloadUri="GalaSoft.MvvmLight.SL4.zip" />
</assembly>
</manifest>
<?xml version="1.0"?>
<manifest xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<assembly>
<name>GalaSoft.MvvmLight.SL4</name>
<version>3.0.0.30106</version>
<publickeytoken>918f02b0f4b4b116</publickeytoken>
<relpath>GalaSoft.MvvmLight.SL4.dll</relpath>
<extension downloadUri="GalaSoft.MvvmLight.SL4.zip" />
</assembly>
</manifest>

Resources