|
using System.Collections.Generic;
using Wide.Interfaces;
using Wide.Interfaces.Services;
using Microsoft.Practices.Unity;
namespace Wide.Core.Services
{
internal sealed class ContentHandlerRegistry : IContentHandlerRegistry
{
private List<IContentHandler> _contentHandlers;
private IUnityContainer _container;
public ContentHandlerRegistry(IUnityContainer container)
{
_contentHandlers = new List<IContentHandler>();
_container = container;
}
public bool Register(IContentHandler handler)
{
_contentHandlers.Add(handler);
return true;
}
public bool Unregister(IContentHandler handler)
{
return _contentHandlers.Remove(handler);
}
#region Get the view model
public ContentViewModel GetViewModel(object info)
{
foreach (var opener in _contentHandlers)
{
if(opener.ValidateContentType(info))
{
ContentViewModel vm = opener.OpenContent(info);
vm.Handler = opener;
return vm;
}
}
return null;
}
public ContentViewModel GetViewModelFromContentId(string contentId)
{
foreach (var opener in _contentHandlers)
{
if (opener.ValidateContentFromId(contentId))
{
ContentViewModel vm = opener.OpenContentFromId(contentId);
vm.Handler = opener;
return vm;
}
}
return null;
}
#endregion
}
}
|
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.
Hello! I'm a 26 year old, WPF/C# self-learned software developer, musician from India with a Master's degree in Computer science. I believe that every piece of software and information/knowledge is available for free for those who seek it.
My projects are available in
my Webpage hosted on Github. I am eager to learn new things everyday, explore new technologies and solve problems.