- compositewpfapp_src.zip
- CompositeWpfApp
- Common
- CWA.Infrastructure
- CWA.ResourceLibrary
- CWA.UIControls
- Composite Application Library
- Microsoft.Practices.Composite.dll
- Microsoft.Practices.Composite.Presentation.dll
- Microsoft.Practices.Composite.UnityExtensions.dll
- Microsoft.Practices.ObjectBuilder2.dll
- Microsoft.Practices.ServiceLocation.dll
- Microsoft.Practices.Unity.dll
- CompositeWpfApp.gpState
- CompositeWpfApp.sln
- CompositeWpfApp.suo
- CompositeWpfApp
- Modules
- CWA.Module.DefaultModule
- CWA.Module.Documents
- CWA.Module.ModuleSelector
- CWA.Module.Security
- CWA.Module.ServerSelector
- CWA.Module.StatusArea
- CWA.Module.Users
|
//
// ServerController.cs
// Author: Eugene Pankov
// January 31, 2009
//
// Subscribes to following CompositePresentationEvent events:
// ServerContextAddEvent
// ServerContextChangeEvent
// ServerContextRemoveEvent
//
// Publishes CompositePresentationEvent events:
// ServerContextChangedEvent
// ServerContextClearedEvent
//
using System;
using Microsoft.Practices.Unity;
using Microsoft.Practices.Composite.Events;
using Microsoft.Practices.Composite.Modularity;
using Microsoft.Practices.Composite.Regions;
using Microsoft.Practices.Composite.Presentation.Events;
using CWA.Infrastructure;
namespace CompositeWpfApp.Controllers
{
/// <summary>
/// Class <see cref="ServerController"/> is used to add/remove/change server contexts.
/// </summary>
public class ServerController : IGeneralController
{
private readonly IEventAggregator eventAggregator;
private readonly IServerContextService serverContextService;
public ServerController(IEventAggregator eventAggregator, IServerContextService serverContextService)
{
this.eventAggregator = eventAggregator;
this.serverContextService = serverContextService;
}
#region IGeneralController Members
public void Run()
{
// Subscribe to events, fired in the ServerSelector
eventAggregator.GetEvent<ServerContextAddEvent>().Subscribe(AddServerContext, ThreadOption.UIThread, true);
eventAggregator.GetEvent<ServerContextChangeEvent>().Subscribe(ChangeServerContext, ThreadOption.UIThread, true);
eventAggregator.GetEvent<ServerContextRemoveEvent>().Subscribe(RemoveServerContext, ThreadOption.UIThread, true);
}
#endregion
/// <summary>
/// Adds a server context.
/// </summary>
/// <param name="serverContext">ServerContext to add.</param>
/// <exception cref="ArgumentNullException">Illegal server context.</exception>
public void AddServerContext(ServerContext serverContext)
{
if (serverContext == null)
throw new ArgumentNullException("serverContext", "Illegal server context.");
if (serverContextService.ServerContexts.Contains(serverContext))
throw new ArgumentException("Server context already exists.");
serverContextService.ServerContexts.Add(serverContext);
// ServerContext is added
eventAggregator.GetEvent<ServerContextAddedEvent>().Publish(serverContext);
}
/// <summary>
/// Change server context to the specified by the <paramref name="serverContext" /> parameter.
/// </summary>
/// <param name="serverContext">ServerContext</param>
/// <exception cref="ArgumentNullException">Illegal server context.</exception>
public void ChangeServerContext(ServerContext serverContext)
{
if (serverContext == null)
throw new ArgumentNullException("serverContext", "Illegal server context.");
if (serverContextService.ServerContexts.Contains(serverContext))
{
serverContextService.CurrentServerContext = serverContext;
// ServerContext is changed
eventAggregator.GetEvent<ServerContextChangedEvent>().Publish(serverContext);
}
}
/// <summary>
/// Removes <paramref name="serverContext" /> from the list of servers.
/// </summary>
/// <param name="serverContext">ServerContext</param>
/// <exception cref="ArgumentNullException">Illegal server context.</exception>
public void RemoveServerContext(ServerContext serverContext)
{
if (serverContext == null)
throw new ArgumentNullException("serverContext", "Illegal server context.");
if (serverContextService.ServerContexts.Contains(serverContext))
{
serverContextService.ServerContexts.Remove(serverContext);
// ServerContext is removed
eventAggregator.GetEvent<ServerContextRemovedEvent>().Publish(serverContext);
}
if (serverContextService.ServerContexts.Count == 0)
{
serverContextService.CurrentServerContext = null;
eventAggregator.GetEvent<ServerContextClearedEvent>().Publish(null);
// Load DefaultModule
eventAggregator.GetEvent<ModuleChangeEvent>().Publish(ModuleNames.DefaultModule);
}
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
Jevgenij lives in Riga, Latvia. He started his programmer's career in 1983 developing software for radio equipment CAD systems. Created computer graphics for TV. Developed Internet credit card processing systems for banks.
Now he is System Analyst in Accenture.