Пример #1
0
        internal PluginManager()
        {
            //An aggregate catalog that combines multiple catalogs
            var catalog = new AggregateCatalog();

            //Adds all the parts found in same directory where the application is running!
            var currentPath = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetAssembly(typeof(PluginManager)).Location);

            catalog.Catalogs.Add(new DirectoryCatalog(currentPath));

            //Create the CompositionContainer with the parts in the catalog
            var container = new CompositionContainer(catalog);

            //Fill the imports of this object
            try
            {
                container.ComposeParts(this);
            }
            catch (CompositionException compositionException)
            {
                Console.WriteLine(compositionException.ToString());
            }


            if (NodeTaskPlugin != null)
            {
                Injector.Instance.Bind <INodeTask>(NodeTaskPlugin.GetType());
            }

            if (Socket != null)
            {
                Injector.Instance.Bind <ISocket>(Socket.GetType());
            }

            if (BroadcastSocket != null)
            {
                Injector.Instance.Bind <IBroadcastSocket>(BroadcastSocket.GetType());
            }

            if (LogProvider != null)
            {
                Injector.Instance.Bind <ILogProvider>(LogProvider.GetType());
            }

            if (ObservableQueue != null)
            {
                Injector.Instance.Bind <IObservableQueue <ClientProcess> >(ObservableQueue.GetType());
            }

            if (SerialiserAutoDiscoveryMessage != null)
            {
                Injector.Instance.Bind <ISerialiser <AutoDiscoveryMessage, byte[]> >(SerialiserAutoDiscoveryMessage.GetType());
            }

            if (SerialiserClientMessage != null)
            {
                Injector.Instance.Bind <ISerialiser <ClientMessage, byte[]> >(SerialiserClientMessage.GetType());
            }

            if (SerialiserClientProcess != null)
            {
                Injector.Instance.Bind <ISerialiser <ClientProcess, byte[]> >(SerialiserClientProcess.GetType());
            }

            if (SerialiserClientResultMessage != null)
            {
                Injector.Instance.Bind <ISerialiser <ClientResultMessage, byte[]> >(SerialiserClientResultMessage.GetType());
            }

            if (SerialiserInterNodeCommunicationMessage != null)
            {
                Injector.Instance.Bind <ISerialiser <InterNodeCommunicationMessage, byte[]> >(SerialiserInterNodeCommunicationMessage.GetType());
            }

            if (SerialiserObservableQueue != null)
            {
                Injector.Instance.Bind <ISerialiser <IObservableQueue <ClientProcess>, byte[]> >(SerialiserObservableQueue.GetType());
            }
        }