Need config file for loading PRISM modules - wpf

I am trying to use PRISM for my application. I have been following Mike Taulty's video s on the same. I would like to know, if there is any sample code available for app.config file mentioned while loading modules without references. What I mean is I am looking to copy paste the configuration related information, instead of typing them from start to avoid mistakes. Also I would liek to know if the version number of the assembly is needed or not in the config file while we follow this approach.

My ModulesCatalog.xaml looks like this:
<Modularity:ModuleCatalog xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:Modularity="clr-namespace:Microsoft.Practices.Prism.Modularity;assembly=Microsoft.Practices.Prism">
<Modularity:ModuleInfoGroup InitializationMode="WhenAvailable">
<Modularity:ModuleInfo
Ref="MyCo.Module.SystemManager.SL.xap"
ModuleName="MembershipModule"
ModuleType="MyCo.Module.SystemManager.Module, MyCo.Module.SystemManager.SL, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" />
</Modularity:ModuleInfoGroup>
<Modularity:ModuleInfoGroup InitializationMode="OnDemand">
<Modularity:ModuleInfo
Ref="MyCo.Module.Mobile.SL.xap"
ModuleName="MobileModule"
ModuleType="MyCo.Module.Mobile.Module, MyCo.Module.Mobile.SL, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" />
<Modularity:ModuleInfo
Ref="MyCo.Module.Dispatch.SL.xap"
ModuleName="DispatchModule"
ModuleType="MyCo.Module.Dispatch.Module, MyCo.Module.Dispatch.SL, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" />
<Modularity:ModuleInfo
Ref="MyCo.Module.Assets.SL.xap"
ModuleName="AssetsModule"
ModuleType="MyCo.Module.Assets.Module, MyCo.Module.Assets.SL, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" />
</Modularity:ModuleInfoGroup>
</Modularity:ModuleCatalog>
I would also check PRISM samples (in PRISM installation folder)
Version needed, yes

Related

Where are the settings saved in a .NET 5 WinForms app?

In a .NET Framework WinForms project, there was an App.config file in the project, which was an XML file that contained a configSection that would reference a class in System.Configuration, and a section for the userSettings themselves, like so:
<configSections>
<sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561944e089">
<section name="MyAppName.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561944e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
</sectionGroup>
</configSections>
<userSettings>
<MyAppName.Properties.Settings>
<setting name="Test" serializeAs="String">
<value>Some Value</value>
</setting>
</MyAppName.Properties.Settings>
</userSettings>
And this created a file in the build folder with the app name plus .exe.config, as in MyAppName.exe.config.
But when I create a new WinForms project using .NET:
There is no App.config in the solution. I can edit the settings using the project properties:
And I can access these values, and update them using the same Properties object and methods:
namespace WindowsFormsApp1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
textBox1.Text = Properties.Settings.Default.Test;
}
private void button1_Click(object sender, EventArgs e)
{
Properties.Settings.Default.Test = textBox1.Text;
Properties.Settings.Default.Save();
}
}
}
And everything seems to work, but when I examine the bin folder, there is no file that I can see for where the values are actually stored.
Where is .NET 5 storing the saved application settings if not in a file in the same folder as the application's exe?
User settings are stored in user.config file in the following path:
%userprofile%\appdata\local\<Application name>\<Application uri hash>\<Application version>
Application settings file are not created by default (unexpectedly), however if you create them manually beside the dll/exe file of your application, the configuration system respect to it. The file name should be <Application name>.dll.config. Pay attention to the file extension which is .dll.config.
You may want to take a look at the source code of the following classes:
LocalFileSettingsProvider (The default setting provider)
ClientSettingsStore
ConfigurationManagerInternal
ClientConfigurationPaths
At the time of writing this answer Application Settings for Windows Forms still doesn't have any entry for .NET 5 and redirects to 4.x documentations.
First of all, this is a known (to .NET team) issue: https://github.com/dotnet/project-system/issues/7772.
Secondly the issue and the solution are pretty much described in your question:
(before) ..there was an App.config file in the project,..
(now) There is no App.config in the solution...
Add the missing app.config and everything will work just like it did before.

log4net connection type invalid in AdoNetAppender

I have implemented log4net ver 1.2.13.0 without major problems.(.Net ver 4.51 C#4)
I add an AdoNetAppender following documentation.
But here is my piece of code causing some troubles :
<appender name ="AdoNetAppender" type="log4net.Appender.AdoNetAppender">
<bufferSize value ="1" />
<connectionType value="System.Data.SqlClient.SqlConnection, System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
I have a warning message not blocking my app but annoying and very disturbing :
The 'value' attribute is invalid - The value
'System.Data.SqlClient.SqlConnection, System.Data, Version=4.0.0.0,
Culture=neutral, PublicKeyToken=b77a5c561934e089' is invalid according
to its datatype 'connectionTypeTypes' - The Enumeration constraint
failed.
Where is the problem and the solution to get rid off this message ?
Many thanks in advance.
The log4net schema file (http://csharptest.net/downloads/schema/log4net.xsd) has this definition:
<xs:enumeration value="System.Data.SqlClient.SqlConnection, System.Data" />
If you change your setting to match this value, the warning will disappear.

How can i rename the log file with Modified date by using Rolling Flat File Trace Listener

My desire output is, if "rolling.log" file was created and modified by 26-06-2012, next day(27-06-2012) that file should be renamed with "rolling-26-06-2012..log". Now output is "rolling-27-06-2012.log" file.
Below is my current logging setting in web.config file.
<*loggingConfiguration name="" tracingEnabled="true" defaultCategory="myTestLog">
<*listeners>
<*add name="Rolling Flat File Trace Listener" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.RollingFlatFileTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.505.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.RollingFlatFileTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.505.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
fileName="C:\Project\Others\Testing\testMSLogging\rolling.log"
formatter="Text Formatter" rollFileExistsBehavior="Increment"
rollInterval="Minute" rollSizeKB="50" timeStampPattern="yyMMdd"
filter="Information" />
<*add name="Flat File Trace Listener" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.FlatFileTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.505.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.FlatFileTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.505.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
fileName="C:\Project\Others\Testing\testMSLogging\testMSLogging\trace.log"
formatter="Text Formatter" filter="Error" />
</listeners>
<*formatters>
<*add type="Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.505.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
template="Timestamp: {timestamp}{newline}
Message: {message}{newline}
Category: {category}{newline}
Priority: {priority}{newline}
EventId: {eventid}{newline}
Severity: {severity}{newline}
Title:{title}{newline}
Machine: {localMachine}{newline}
App Domain: {localAppDomain}{newline}
ProcessId: {localProcessId}{newline}
Process Name: {localProcessName}{newline}
Thread Name: {threadName}{newline}
Win32 ThreadId:{win32ThreadId}{newline}
Extended Properties: {dictionary({key} - {value}{newline})}"
name="Text Formatter" />
</formatters>
<*categorySources>
<*add switchValue="All" name="myTestLog">
<*listeners>
<add name="Rolling Flat File Trace Listener" />
</listeners>
</add>
</categorySources>
<*specialSources>
<*allEvents switchValue="All" name="All Events" />
<*notProcessed switchValue="All" name="Unprocessed Category" />
<*errors switchValue="All" name="Logging Errors & Warnings">
<listeners>
<add name="Flat File Trace Listener" />
</listeners>
</errors>
</specialSources>
Please anyone help me. Thanks a lot.
Unfortunately this is the way it works in Enterprise Library. The philosophy behind its default flat file roller is that it records all the output in FILE.LOG and when the roll event happens, it renames it to FILE-ROLL-NAME.LOG and creates a new FILE.LOG
If you need a different behavior, you may need to create your own logging trace listener or use other tools out there like log4net.

System.DirectoryServices compilation problems

I'm using the code here : ASP.NET How to get List of Groups in Active Directory
Specifically :
using System.DirectoryServices;
DirectoryEntry objADAM = default(DirectoryEntry); //compiler error!
Problem: compiler says that it doesn't know what DirectoryEntry is.
I tried to add it to my web.config:
<assemblies>
<!-- ... -->
<add assembly="System.DirectoryServices, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
</assemblies>
But it didn't seem to help so I tried to add a reference:
Someone suggested setting Copy Local = True but that didn't help either.
I noticed that I don't see a reference for System.DirectoryServices - only System.DirectoryServices.Accountmanagement
Can anyone help me get this code to compile? I'm not sure what to try next.
Take the .net 3.5 filter off in the Add Reference dialog, and then put a reference in your project to:
System.DirectoryServices, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
You can take the filter off by changing you project setting : http://msdn.microsoft.com/en-us/library/bb398202.aspx
If you want to use the DirectoryEntry from the System.DirectoryServices namespace - you need to add a reference to the System.DirectoryServices assembly - NOT the System.DirectoryServices.AccountManagement assembly!

wpf & validation application block > message localization > messageTemplateResource Name&Type

I'm trying to write validation rules for my data objects in a WPF application. I'm writing them in the configuration file, and so far they are working fine.
I'm stumped on how to localize the messages using messageTemplateResourceName and messageTemplateResourceType. What I know is that the strings can be writen in a resource file, given a name and referenced by that name. I get the idea, but i haven't been able to make this work.
<ruleset name="Rule Set">
<properties>
<property name="StringValue">
<validator lowerBound="0" lowerBoundType="Ignore" upperBound="25"
upperBoundType="Inclusive" negated="false" messageTemplate=""
messageTemplateResourceName="msg1" messageTemplateResourceType="Resources"
tag=""
type="Microsoft.Practices.EnterpriseLibrary.Validation.Validators.StringLengthValidator, Microsoft.Practices.EnterpriseLibrary.Validation"
name="String Length Validator" />
</property>
</properties>
</ruleset>
Where is the resource file and what value do I pass to messageTemplateResourceType?
I have tried writing the messages in the shell project's resource file but no sucess trying to retrieve the value. I only get the default built-in message.
I've tried
messageTemplateResourceType="typeof(Resources)"
messageTemplateResourceType="Resources"
messageTemplateResourceType="Resources.resx"
messageTemplateResourceType="typeof(Shell)"
messageTemplateResourceType="Shell"
messageTemplateResourceType="Shell,
Version=1.0.0.0, Culture=neutral,
PublicKeyToken=null"
I've also tried adding a new resource file in the shell project, and adding a resource file to the data object's library. I'm all out of ideas Does anyone have any suggestions? I'm not even married to the idea of resource files, so if there are other ways to localize these messages I'd love to know!
thanks
You need to create your own resource file and then point the messageTemplateResourceType attribute to your fully qualified resource type. As long as the resource file can be loaded at runtime you should be fine.
<ruleset name="Rule Set">
...
messageTemplateResourceName="msg1"
messageTemplateResourceType="My.Fully.Qualified.ResourceType, My.AssemblyName, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"
...
</ruleset>
An alternate way to do it would be use the messageTemplate as a key and write custom code to look up the actual localized string based on the messageTemplate key (either from a resource file or from a database or wherever else you are storing it).

Resources