Ejemplo n.º 1
0
        internal static T ActivateHostAdapter <T>(PartialToken pipeline, IContract addIn)
        {
            if (pipeline == null)
            {
                throw new ArgumentNullException("pipeline");
            }
            if (addIn == null)
            {
                throw new ArgumentNullException("addIn");
            }
            System.Diagnostics.Contracts.Contract.EndContractBlock();

            ContractComponent contract    = pipeline._contract;
            HostAdapter       hostAdapter = pipeline._hostAdapter;

            Type hostAdapterType;
            Type contractType;

            LoadContractAndHostAdapter(contract, hostAdapter, out contractType, out hostAdapterType);

            // This assembly resolve event exists to:
            //    1) To upgrade the contract assembly from the LoadFrom context to
            //       the default loader context
            ResolverHelper      resolver         = new ResolverHelper(contract);
            ResolveEventHandler assemblyResolver = new ResolveEventHandler(resolver.ResolveAssemblyForHostAdapter);

            AppDomain.CurrentDomain.AssemblyResolve += assemblyResolver;

            T hav;

            InvokerDelegate myInvokerDelegate = CreateConsInvoker(hostAdapterType, contractType);

            try
            {
                hav = (T)myInvokerDelegate(addIn);
            }
            catch (ArgumentException e)
            {
                CheckForLoaderContextProblems(contract, pipeline._addinAdapter, e);
                throw;
            }
            finally
            {
                AppDomain.CurrentDomain.AssemblyResolve -= assemblyResolver;
            }

            return(hav);
        }
Ejemplo n.º 2
0
        internal void ConnectPipeline(Collection <String> warnings)
        {
            List <PartialToken> result = new List <PartialToken>();

            // For ease of maintanence & debugging for users of the add-in
            // model, we must make it easy to report which parts are not
            // usable, due to missing connections with other parts of the
            // pipeline.

            // Real connect loop.
            foreach (HostAdapter hostAdapter in HostAdapters)
            {
                foreach (ContractComponent contract in Contracts)
                {
                    if (!hostAdapter.Constructors.Contains(contract.TypeInfo))
                    {
                        continue;
                    }

                    hostAdapter.ConnectedToNeighbors = true;

                    foreach (AddInAdapter addinAdapter in AddInAdapters)
                    {
                        if (!addinAdapter.Contracts.Contains(contract.TypeInfo))
                        {
                            continue;
                        }

                        contract.ConnectedToNeighbors = true;

                        foreach (AddInBase addinBase in AddInBases)
                        {
                            if (!addinAdapter.CanConnectTo(addinBase))
                            {
                                continue;
                            }

                            addinAdapter.ConnectedToNeighbors = true;
                            addinBase.ConnectedToNeighbors    = true;
                            PartialToken partialToken = new PartialToken(hostAdapter, contract, addinAdapter, addinBase);
                            result.Add(partialToken);
                        } // foreach addinBase
                    }     // foreach addinAdapter
                }         // foreach contract
            }             // foreach hostAdapter

            // Look for unconnected parts.
            int unconnectedParts = 0;

            unconnectedParts += LookForUnconnectedParts(HostAdapters, warnings);
            unconnectedParts += LookForUnconnectedParts(Contracts, warnings);
            unconnectedParts += LookForUnconnectedParts(AddInAdapters, warnings);
            unconnectedParts += LookForUnconnectedParts(AddInBases, warnings);

#if ADDIN_VERBOSE_WARNINGS
            warnings.Add(String.Format(CultureInfo.CurrentCulture, "PipelineDeploymentState::Connect: Found {0} valid pipelines.", result.Count));
#endif
            if (unconnectedParts > 0)
            {
                warnings.Add(String.Format(CultureInfo.CurrentCulture, Res.CouldntConnectNInvalidParts, unconnectedParts));
            }

            _partialTokens = result;
        }