How can i read/write the app.config file from another Solution? - app-config

Is it possible to read/write the app.config file from another solution at runtime?
Regards,
Raks

If you are looking to expose configuration settings between applications... or exposing settings in AppA that AppB can monitor and manage, then you can write a WMI Provider for your application that exposes those properties to a 'MyApp' WMI namespace (which your provider registers with WMI)... then other applications (.NET, PowerShell) can view and manage those settings...
http://msdn.microsoft.com/en-us/library/bb404677(v=vs.90).aspx
This describes how to create a MortgageCalcWMIProvider class... it first registers the root/MortgageCalc namespace... which is used by the Calculator app below:
http://msdn.microsoft.com/en-us/library/bb404679(v=vs.90).aspx
O

Related

How to remove EntityFramework.SqlServer Reference from WebApplication project in a DDD Solution

I have a highly standardized project in DDD (Domain-Driven Design), so it means that each layer has it's responsibilities and no layer knows other than itself and the Domain Layer.
Here's the structure of my project:
My Infra.Data layer is responsible for connecting with the Database, and i'm persisting using EntityFramework.
My problem is: in order to make it work with SQLServer Databases, i need to add a reference to EntityFramework.SqlServer in my WebApplication layer, which breaks my separation of concerns concept, as you can see below.
Even having the same reference in my Infra.Data layer, which is where it only should be, as you can see below.
If i remove the EntityFramework.SqlServer reference from the WebApplication layer, it stops working, and throws exception every time i try to persist data, as you can see below.
I need to know how to remove this reference to keep separation of concerns, because the way it is now, i'll have to change my WebApplication if i want to change my persistence. My Web layer is prohibited to even have anything with the word "EntityFramework" in it. I want FULL separation of concerns to change any layer without affecting no other.
If i register my <entityFramework> provider in my Web.config file, it will only works if i have the EntityFramework.SqlServer in the project, but without the EntityFramework.SqlServer reference on the WebApplication, it miss namespaces and complain about it.
Note: My project also connects to MySql Databases successfully, and i don't need no references to MySql.Data or any other MySql library in my WebApplication layer, as expected.
Please help me, my DDD/Separation of Concerns OCD is cracking on it, thanks.
You can!
Just create this class in your Infra.Data project:
internal static class ForceEFToCopyDllToOutput
{
private static SqlProviderServices instance = SqlProviderServices.Instance;
}
When you do this you let the compiler know that the specific resource is used and should be available in the bin folder.
Some consider this a hack but it's useful if you want to keep your layers free from infrastructure concerns.
You can read more about this here: DLL reference not copying into project bin
EDIT:
All you'll need now is to copy the connection string from your Infra.Data app.config to your WebApplication web.config
<connectionStrings>
<add name="DatabaseConnectionString" providerName="System.Data.SqlClient" connectionString="..." />
</connectionStrings>
You would not be able to get rid of Entity-framework configuration and the required DLL in your Web-application :
Lets say your infrastructure layer and domain layer need to depend on Entity-framework. This means these two libraries need to have physical access to Entity Framework DLLs(Have Entity-framework package installed) and configured.
When you run your web application which has dependency on infrastructure and domain libraries, all Dlls used by underlying libraries (infrastructure and domain) need to be present physically and configured otherwise you will have run time issue(program might be compile-able but you will get run-time errors).
Morale of the story : If application x [Irrespective of the layer it belongs to] has dependency to library y,z and library y,z rely on some dll and require configuration, for application x to work at run-time you need to have all dlls needed by y,z available and provide their configuration (web.config) in your instance.
You can obviously provide some workarounds such as copying the files directly and providing separate config files for each layer but I strongly advise against it because it would get extremely messy and very hard to maintain in the long run.

MVC Localization

I'm trying to do localization in MVC3, and I want to use a database to store the resources. I've read up on resource providers, but I haven't found a way of using a resource provider without losing the strongly-typed access that a regular resource file has.
So, what is the best way to do localization, while maintaining strongly-typed access? (Ideally with a database too)
If you want to store the entries in a database you can do the same trick as the normal resource files in Visual Studio are doing for you.
Normally the resource file is parsed and a static class is generated from it. In your case you could us a T4 template(Code Generation and T4) to connect to the database and build a resource class from the 'Id' columns in your database you have the same resource class.
On startup you could load the translated strings from the database and initialize your T4 resource class with it.
The simple and effective way to do it, is just to use the NuGet package dedicated for storing resources in database and generating the Strongly Typed Resources.
NuGet Package: http://www.nuget.org/packages/Globsite.Globalization.Mvc
Project Site: http://globsite.net/GlobsiteGlobalizationLibrary
This package contains the ready to use and complex infrastructure for database stored resources, which implements .NET Resource-Provider Model.
Generated classes can be synchronized with a database with the T4 Template run, what can be done, for example, on each build.
You can use the resources like this:
#using MyResources.SampleSet
#Resources.SampleKey

Generate Silverlight service proxies with same namespace

I need to generate service proxies for multiple WCF services within the same namespace, which is not possible when using the Add Service Reference function of Visual Studio.
How can I do this in an automated way? I've considered using SLsvcUtil, but that would require that I make sure that I have my WCF services accessible, and, assuming I'm using the ASP.NET Development Server, I'd need to manually check the URL.
Ideally, I'd have some way of specifying an assembly, a service type, the configuration (web|app.config) and a target namespace, and then my code would be generated. Any Ideas?
Edit
To clarify, I'm trying to solve the same problem that is outlined in this connect issue:
http://connect.microsoft.com/VisualStudio/feedback/details/426791/adding-multiple-service-references-from-same-application-should-not-require-multiple-namespaces
I want a no-hassle, automated way to generate service proxies within a single namespace. It's unacceptable for me to have to specify a unique namespace for each service reference. Using SLsvcUtil is an option, but it requires that I have my service up-and-running so it can read the metadata - which is a problem because I don't always have the latest version of the service running at any given point in time.
The "Add Service Reference" functionality in VS handles this well - it automatically hosts the service just long enough to grab the metadata, and then generates the service contract interfaces and proxies. Once again, it requires that each service be code-gen'd in its own, unique namespace, which I don't want.
All I need is a way to generate the service proxies with a single, shared namespace, without having to go through the hassle of manually hosting and firing up an instance of my services. Ideally, I'd just double click a script file.
What I normally do is to inform a composite namespace. When the "Add Service Reference" dialog pops up, I put in the namespace something like Services.ServiceA or Services.ServiceB. Then all service namespaces share the common root Services.*.
If I'm understanding the question correctly, you're concerned because the way Add Service Reference functions, the ServiceContract interfaces are not exactly the same as the ones you define in your source assembly.
The only real difference is that the ServiceContract interface that Add Service Reference generates for SL has asynchronous operations defined (since SL doesn't support synchronous WCF calls). The rest of it (the XXXClient : ClientBase class) can be completely bypassed if you just use the ChannelFactory<TServiceContractInterface> directly.
I personally ended up sharing the synchronous ServiceContract interface, but creating a service contract with asynchronous operations using a System.Reflection.Emit.TypeBuilder. Then using a custom ChannelFactory, I created a wrapper around the dynamically generated asynchronous ServiceContract interface.
I hope that helps.

Windows Service with WPF management tool

i'm trying to create a windows service with C# in .net that runs before the user is logged on...
then when a user is logged on a symbol should appear in the system tray (next to the clock) to show the user that the service is running..
by double clicking that symbol a configuration utility (written in wpf) should be shown to the user, so he can configure the service, read data from it and so on ..
is there a possibility to do this within one application?
thanks in advance for any help!!!
No, you can't do this with one application as services run with a different user in a different session. You need to create two applications and implement some communication between both.
I would not recommend using named pipes directly (like Kieren Johnstone suggested), but to have a look at WCF which was designed for interprocess communication and nicely abstracts implementation details of the communication technology away from you. Here is a link that can propably help you with WCF: http://www.switchonthecode.com/tutorials/wcf-tutorial-basic-interprocess-communication.
Best Regards,
Oliver Hanappi
Within one application, no. Services run in session 0, please see here:
http://www.microsoft.com/whdc/system/sysinternals/session0changes.mspx
Your best bet is to used Named Pipes, see here:
http://www.switchonthecode.com/tutorials/dotnet-35-adds-named-pipes-support
....or a memory mapped file, see here:
http://msdn.microsoft.com/en-us/library/dd997372.aspx
Within the scope of more-.NETty, you could also use Remoting. You'll need to come up with some interface or protocol to facilitate communication between the service and the management utility. Managing the process start/stop would be easier and you could use the ServiceController class (MSDN ref).
Hope that helps (and itsn't too discouraging)!

How do I load a module catalog from a database in Prism?

I'm using Prism in my WPF application and up to now, I've been loading the modules via var moduleCatalog = new ConfigurationModuleCatalog();. I'd like to get the module catalog from a database. The Prism documentation indicates that this is possible, but it doesn't go into any details.
Has anyone done this and can provide some guidance?
This is a theoretical possibility, but it's not in any samples I've seen.
Basically what you'd do is either base64 encode the DLLs / Files into the database or zip them up and store them in one blob. You'd download them in your bootstrapper and copy them locally (in a temp directory) and then allows them to load normally from the filesystem using the DirectoryModuleCatalog. If you wanted it to be a bit more elegant, you could write your own ModuleCatalog that encapsulates this logic.
This is very similar to what I do... I actually download a zip file of all of the modules from a website at launch time and unzip them and load them with the DirectoryModuleCatalog.
You can write your own ModuleCatalog implementation by implementing IModuleCatalog. Your implementation can then populate the catalog by any means you define.
You could also use the CreateFromXAML overload that accepts a Stream and implement a webservice that delivers the ModuleCatalog in XAML over HTTP.

Resources