namespace Microshaoft.MEF.Contracts
{
using System;
public delegate void ExceptionEventHandler<TSender>(TSender sender, Exception exception);
}
namespace Microshaoft.MEF.Contracts
{
using System;
public interface IMefChainedProcessorPart<TContainer, TPartKey, TResult, TParameter>
{
IMefChainedProcessorPart<TContainer, TPartKey, TResult, TParameter> Instance
{
get;
}
int Priority
{
get;
}
TPartKey Key
{
get;
}
void OnOnceProcessAction(params TParameter[] parameters);
TResult OnOnceProcessFunc(params TParameter[] parameters);
void OnChainedOnceProcessAction(out ChainedProcessNextStep next, params TParameter[] parameters);
TResult OnChainedOnceProcessFunc(out ChainedProcessNextStep next, params TParameter[] parameters);
void OnChainedOnceAsyncQueueProcessAction(out ChainedProcessNextStep next, params TParameter[] parameters);
bool OnChainedOnceAsyncQueueProcessFunc(out ChainedProcessNextStep next, params TParameter[] parameters);
event ExceptionEventHandler<IMefChainedProcessorPart<TContainer, TPartKey ,TResult, TParameter>> OnCaughtExceptionInContainer;
string GetRuntimeTypeFullName();
Type GetRuntimeType();
}
public enum ChainedProcessNextStep
{
Continue
, Break
}
}
namespace Microshaoft.MEF.Contracts
{
using System;
using System.Xml;
public interface IMefPartsCompositionContainer<TPart, TPartKey, TResult, TInvokeParameter>
{
TPart[] Parts
{
get;
}
void ImportManyExports(string path);
void ChainedInvokeAllPartsProcessAction(params TInvokeParameter[] parameters);
TResult ChainedInvokeAllPartsProcessFunc(params TInvokeParameter[] parameters);
TResult InvokeOnePartProcessFunc(TPartKey PartKey, params TInvokeParameter[] parameters);
void InvokeOnePartProcessAction(TPartKey PartKey, params TInvokeParameter[] parameters);
}
}
//=============================================================================================================================
namespace Microshaoft.MEF.CompositionContainers
{
using Microshaoft;
using Microshaoft.MEF.Contracts;
using System;
using System.Collections.Concurrent;
using System.ComponentModel.Composition;
using System.Linq;
public class XmlMessageProcessorsCompositionContainer
: IMefPartsCompositionContainer
<
IMefChainedProcessorPart
<
XmlMessageProcessorsCompositionContainer
, string
, string
, string
>
, string
, string
, string
>
{
[ImportMany(typeof(IMefChainedProcessorPart<XmlMessageProcessorsCompositionContainer,string, string, string>))]
public IMefChainedProcessorPart<XmlMessageProcessorsCompositionContainer,string, string, string>[] Parts
{
get;
private set;
}
ConcurrentDictionary<string, IMefChainedProcessorPart<XmlMessageProcessorsCompositionContainer,string, string, string>> _dictionary;
public void ImportManyExports(string path)
{
MEFHelper.ImportManyExportsComposeParts<XmlMessageProcessorsCompositionContainer>
(
path
, this
);
var result = Parts.OrderBy(x => x.Priority);
if (_dictionary == null)
{
_dictionary = new ConcurrentDictionary<string, IMefChainedProcessorPart<XmlMessageProcessorsCompositionContainer, string, string, string>>();
}
result.ToList().ForEach
(
x
=>
{
_dictionary[x.Key] = x;
}
);
}
public void ChainedInvokeAllPartsProcessAction(params string[] parameters)
{
throw new NotImplementedException();
}
public string ChainedInvokeAllPartsProcessFunc(params string[] parameters)
{
throw new NotImplementedException();
}
public string InvokeOnePartProcessFunc(string PartKey, params string[] parameters)
{
string r = string.Empty;
IMefChainedProcessorPart<XmlMessageProcessorsCompositionContainer,string, string, string> part;
if (_dictionary.TryGetValue(PartKey, out part))
{
r = part.OnOnceProcessFunc(parameters[0]);
}
return r;
}
public void InvokeOnePartProcessAction(string PartKey, params string[] parameters)
{
throw new NotImplementedException();
}
}
}
namespace Microshaoft.MEF.CompositionContainersManagers
{
using Microshaoft.MEF.CompositionContainers;
public static class CompositionContainersManager
{
private static XmlMessageProcessorsCompositionContainer _xmlMessageProcessorsCompositionContainer =
new XmlMessageProcessorsCompositionContainer();
public static XmlMessageProcessorsCompositionContainer xmlMessageProcessorsCompositionContainer
{
get { return CompositionContainersManager._xmlMessageProcessorsCompositionContainer; }
set { CompositionContainersManager._xmlMessageProcessorsCompositionContainer = value; }
}
}
}
namespace Microshaoft
{
using System.ComponentModel.Composition;
using System.ComponentModel.Composition.Hosting;
public static class MEFHelper
{
public static void ImportManyExportsComposeParts<T>(string path, T attributedPart)
{
var catalog = new AggregateCatalog();
catalog.Catalogs.Add(new DirectoryCatalog(path));
var container = new CompositionContainer(catalog);
container.ComposeParts(attributedPart);
}
}
}
//=====================================================================================================================
//可扩展部件样例
namespace Microshaoft.MEF.Parts
{
using Microshaoft.MEF.Contracts;
using Microshaoft.MEF.CompositionContainers;
using System;
using System.ComponentModel.Composition;
[Export(typeof(IMefChainedProcessorPart<XmlMessageProcessorsCompositionContainer, string, string, string>))]
public class SampleXmlMessageProcessorPart : IMefChainedProcessorPart<XmlMessageProcessorsCompositionContainer, string, string, string>
{
public IMefChainedProcessorPart<XmlMessageProcessorsCompositionContainer, string, string, string> Instance
{
get { throw new NotImplementedException(); }
}
public int Priority
{
get
{
return 100;
}
}
public string Key
{
get
{
return "SampleXmlMessageProcessorPart";
}
}
public void OnOnceProcessAction(params string[] parameters)
{
throw new NotImplementedException();
}
public string OnOnceProcessFunc(params string[] parameters)
{
return "";
}
public void OnChainedOnceProcessAction(out ChainedProcessNextStep next, params string[] parameters)
{
throw new NotImplementedException();
}
public string OnChainedOnceProcessFunc(out ChainedProcessNextStep next, params string[] parameters)
{
throw new NotImplementedException();
}
public void OnChainedOnceAsyncQueueProcessAction(out ChainedProcessNextStep next, params string[] parameters)
{
throw new NotImplementedException();
}
public bool OnChainedOnceAsyncQueueProcessFunc(out ChainedProcessNextStep next, params string[] parameters)
{
throw new NotImplementedException();
}
public string GetRuntimeTypeFullName()
{
throw new NotImplementedException();
}
public Type GetRuntimeType()
{
throw new NotImplementedException();
}
void SampleXmlMessageProcessorPart_OnCaughtExceptionInContainer(IMefChainedProcessorPart<XmlMessageProcessorsCompositionContainer, string, string, string> sender, Exception exception)
{
throw new NotImplementedException();
}
public event ExceptionEventHandler<IMefChainedProcessorPart<XmlMessageProcessorsCompositionContainer, string, string, string>>
OnCaughtExceptionInContainer =
(
(x, y) =>
{
}
);
}
}

MEF Parts Sample的更多相关文章

  1. MEF and AppDomain z

    MEF and AppDomain - Remove Assemblies On The Fly This article will give an idea of what's involved i ...

  2. MEF引起的内存泄露

    也许你编程的时候很小心,注意不引起内存泄露,例如不要被全局Static的变量引用上,注意Singleton的static引用,注意Event Handler注销,注意IDisposable接口实现,而 ...

  3. poj3417 LCA + 树形dp

    Network Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 4478   Accepted: 1292 Descripti ...

  4. UVA 507 - Jill Rides Again 动态规划

      Jill Rides Again  Jill likes to ride her bicycle, but since the pretty city of Greenhills where sh ...

  5. Network POJ - 3417(LCA+dfs)

    Yixght is a manager of the company called SzqNetwork(SN). Now she's very worried because she has jus ...

  6. poj3417Network【LCA】【树形DP】

    Yixght is a manager of the company called SzqNetwork(SN). Now she's very worried because she has jus ...

  7. poj3417 Network 树上差分+LCA

    题目传送门 题目大意:给出一棵树,再给出m条非树边,先割掉一条树边,再割掉一条非树边,问有几种割法,使图变成两部分. 思路:每一条 非树边会和一部分的树边形成一个环,分三种情况: 对于那些没有形成环的 ...

  8. POJ3417Network

    Network Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 5311   Accepted: 1523 Descripti ...

  9. POJ3417Network(LCA+树上查分||树剖+线段树)

    Yixght is a manager of the company called SzqNetwork(SN). Now she's very worried because she has jus ...

随机推荐

  1. C#文本写入文件,追加写入文件

    写入文件和这个对象 StreamWriter using (StreamWriter fs = new StreamWriter(path, true)) { fs.WriteLine(strLog) ...

  2. 【CityHunter】Unity3D设计AR探索模式

    为了增加游戏的乐趣性,我对项目进行了Unity3D的引入,经过一番折腾,终于做出了一个基本的AR探索模式的基本雏形. 途中的小方块就是虚拟物体,因为是静态图片,所以也不能看出什么来,只能文字形容一下: ...

  3. <<< MyEclipse软件中的快捷键

    -------------------------------------MyEclipse 快捷键1(CTRL)-------------------------------------Ctrl+1 ...

  4. zTree 循环树

    /// <summary> /// 初始化第一次节点加载 /// </summary> /// protected string _menu = string.Empty; p ...

  5. Java都有什么进阶技术

    Java都有什么进阶技术?   看到有人给题主推荐<代码整洁之道>,评论有人说那不是JAVA进阶的书- 私以为,一些人对JAVA进阶的理解片面了,JAVA不过也是一门语言,提升和进阶还是内 ...

  6. [UML]UML系列——类图class的实现关系Realization

    系列文章 [UML]UML系列——用例图Use Case       [UML]UML系列——用例图中的各种关系(include.extend)       [UML]UML系列——类图Class   ...

  7. Jquery实现花瓣随机飘落(收藏自慕课网)

    这个东西实际上慕课的艾伦大大先写的. 然后别人推荐给我,偶一直收藏着,然后偶再推荐给偶的队友们,然后呢,这帮货就懒得都不肯去看... 接着今天受伤在家就提出来了一点东西放在我博客顶上... 然后艾伦的 ...

  8. 大熊君大话NodeJS之------Connect中间件模块(第一季)

    一,开篇分析 截止到今天来说,NodeJS系列文章已经有将近十篇了,让我们回顾一下: (1),大熊君大话NodeJS之开篇------Why NodeJS(将Javascript进行到底) (2),大 ...

  9. 布局之按钮的图片分辨率--Android Studio

    在布局页面,想把取消按钮和确认钮大小一致,刚开始想法是错的,不用在控制层设置,也不用在布局层压缩图片,有两个方法法: 1.直接用美图秀秀“尺寸”功能,修改成另一按钮一样的分辨率. 2.设置按钮相同高度 ...

  10. NOSDK--SDK一键打包及统一接入的实现(前言)

    前言 一,一键打包的实现 1.1 shell脚本执行流程介绍 1.2 自动刷新mk文件的脚本介绍 1.3 编译及拷贝资源的脚本介绍 1.4 打包及签名的脚本介绍 1.5 mac下的脚本环境配置及脚本的 ...