惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

H
Help Net Security
博客园 - Franky
GbyAI
GbyAI
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
爱范儿
爱范儿
IT之家
IT之家
酷 壳 – CoolShell
酷 壳 – CoolShell
aimingoo的专栏
aimingoo的专栏
博客园_首页
MongoDB | Blog
MongoDB | Blog
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
Recent Announcements
Recent Announcements
Scott Helme
Scott Helme
有赞技术团队
有赞技术团队
M
MIT News - Artificial intelligence
C
CERT Recently Published Vulnerability Notes
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
Jina AI
Jina AI
F
Fortinet All Blogs
N
Netflix TechBlog - Medium
L
LangChain Blog
L
LINUX DO - 最新话题
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
H
Hacker News: Front Page
MyScale Blog
MyScale Blog
P
Palo Alto Networks Blog
G
Google Developers Blog
Google DeepMind News
Google DeepMind News
AI
AI
T
Troy Hunt's Blog
Microsoft Azure Blog
Microsoft Azure Blog
阮一峰的网络日志
阮一峰的网络日志
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
Vercel News
Vercel News
Microsoft Security Blog
Microsoft Security Blog
罗磊的独立博客
S
Secure Thoughts
大猫的无限游戏
大猫的无限游戏
博客园 - 叶小钗
人人都是产品经理
人人都是产品经理
Blog — PlanetScale
Blog — PlanetScale
博客园 - 司徒正美
Apple Machine Learning Research
Apple Machine Learning Research
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
博客园 - 三生石上(FineUI控件)
S
Security @ Cisco Blogs
Cloudbric
Cloudbric
E
Exploit-DB.com RSS Feed
Attack and Defense Labs
Attack and Defense Labs

博客园 - 于斯人也

JsonHelper MergeJsonTemplate Add Indexer to DynamicJson Etw EventSourceProvider_EventsProducer.cs OopConsoleTraceEventListenerMonitor_TraceControllerEventsConsumer.cs WorkFlowHelper ConcurrentAsyncQueue 2014-09-07 KeyedPriorityQueue JsonHelper developed by using Newtonsoft.Json.NET, Deserialize to <T> object , XmlToJson/JsonToXml, QuoteName by using JToken Path. Udp SocketAsyncEventArgs SocketAsyncDataHandler C#: using JsonReader avoid Deserialize Json to dynamic XmlValidationHelper XSD、Schema(XmlSchemaSet)、XmlReader(XmlValidationSettings)、XmlDocument、XDocument Validate SharePoint 2013 Apps TokenHelper SharePointContext OAuth Provider-Hosted App (抄袭,测试 csc.rsp 用) nuget packages batch install csc.rsp Nuget MVC/WebAPI、SignalR、Rx、Json、EntityFramework、OAuth、Spatial SQL 2012 Group By Rollup, Grouping SQL 2012 Restore HeaderOnly EasyPerformanceCounterHelper 并发异步处理队列 .NET 4.5+ (改进性能计数器) 2013-11-16 CodeTimerPerformance EasyPerformanceCounterHelper .NET 4.5 csc.rsp Nuget MVC/WebAPI 5.0、SignalR 2.0、Rx、Json、Azure、EntityFramework、OAuth、Spatial
MEF Parts Sample
于斯人也 · 2013-09-07 · via 博客园 - 于斯人也

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) =>
                                                        {
                                                        }
                                                    );
    }
}