PipelineDeploymentState.cs source code in C# .NET

Source code for the .NET framework in C#

                        

Code:

/ 4.0 / 4.0 / untmp / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / AddIn / AddIn / System / Addin / Hosting / PipelineDeploymentState.cs / 1305376 / PipelineDeploymentState.cs

                            // ==++== 
//
//   Copyright (c) Microsoft Corporation.  All rights reserved.
//
// ==--== 
/*============================================================
** 
** Class:  PipelineDeploymentState 
**
** Purpose: Represents all the add-in pipeline components 
**          in a directory structure.
**
===========================================================*/
using System; 
using System.Collections.Generic;
using System.Collections.ObjectModel; 
using System.Globalization; 
using System.IO;
using System.Text; 
using System.Reflection;
using System.AddIn.MiniReflection;
using System.Diagnostics.Contracts;
 
namespace System.AddIn.Hosting
{ 
    [Serializable] 
    internal sealed class PipelineDeploymentState : DeploymentState
    { 
        private List _hostAdapters;
        private List _contracts;
        private List _addinAdapters;
        private List _addinBases; 

        private List _partialTokens; 
        private List _fileCounts; 

        internal PipelineDeploymentState() 
        {
            _hostAdapters = new List();
            _contracts = new List();
            _addinAdapters = new List(); 
            _addinBases = new List();
 
            _fileCounts = new List(new int[]{0,0,0,0}); 
        }
 
        internal List HostAdapters {
            get { return _hostAdapters; }
        }
 
        internal List Contracts {
            get { return _contracts; } 
        } 

        internal List AddInAdapters { 
            get { return _addinAdapters; }
        }

        internal List AddInBases { 
            get { return _addinBases; }
        } 
 
        internal List PartialTokens {
            get { return _partialTokens; } 
        }

        internal List FileCounts {
            get { return _fileCounts; } 
        }
 
        internal void ConnectPipeline(Collection warnings) 
        {
            List result = new List(); 
            // 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;
        } 
 
        private static int LookForUnconnectedParts(IEnumerable parts, Collection warnings) where T : PipelineComponent
        { 
            int numUnconnected = 0;
            foreach (PipelineComponent part in parts) {
                if (!part.ConnectedToNeighbors) {
                    warnings.Add(String.Format(CultureInfo.CurrentCulture, Res.CouldntConnectOnePart, part.ToString())); 
                    numUnconnected++;
                } 
            } 
            return numUnconnected;
        } 
    }
}

// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
                        

Link Menu

Network programming in C#, Network Programming in VB.NET, Network Programming in .NET
This book is available now!
Buy at Amazon US or
Buy at Amazon UK