Пример #1
0
 public PipelineSegmentSource(SegmentType type, SymbolTable symbols)
 {
     _type  = type;
     _name  = symbols.GetAssemblyName(type);
     _files = new List <SourceFile>();
 }
 public PipelineSegmentSource(SegmentType type, SymbolTable symbols)
 {
     _type = type;
     _name = symbols.GetAssemblyName(type);
     _files = new List<SourceFile>();
 }
        public List<PipelineSegmentSource> BuildPipeline()
        {
            //If we haven't loaded the contract assembly yet it means we want to avoid loading the contract assembly in this domain
            //and should do it remotely. Once we're in the new domain we'll have loaded the contract asm and we'll fall through this
            //and do the work.
            if (_contractAsm == null)
            {
                List<PipelineSegmentSource> source =  BuildRemotePipeline();
                return source;
            }
            _symbols = new SymbolTable(_contractAsm);
            _typeHierarchy = new Dictionary<Type, List<Type>>();
            List<PipelineSegmentSource> components = new List<PipelineSegmentSource>();
            _aib = new PipelineSegmentSource(SegmentType.AIB, _symbols);
            _asa = new PipelineSegmentSource(SegmentType.ASA, _symbols);
            _hsa = new PipelineSegmentSource(SegmentType.HSA, _symbols);
            _hav = new PipelineSegmentSource(SegmentType.HAV, _symbols);
            _view = new PipelineSegmentSource(SegmentType.VIEW, _symbols);
            components.Add(_asa);
            components.Add(_hsa);

            //If the contract assembly is marked as having the views shared we should add a generic "view" component.
            //If not then we build both add-in side and host-side view source files.
            if (ShouldShareViews())
            {
                components.Add(_view);
            }
            else
            {
                components.Add(_aib);
                components.Add(_hav);
            }
            //Parse the type hierarchy in the contract so we know how to express it in the views.
            BuildUpCastableTypeHierarchy();

            //Iterate through all of the contract types
            foreach (Type t in _contractAsm.GetExportedTypes())
            {
                //Check to see if the type is a contract
                if (typeof(IContract).IsAssignableFrom(t))
                {
                    bool activatable = false;
                    //Check to see if type is an activatable contract
                    foreach (object obj in t.GetCustomAttributes(false))
                    {
                        if (obj.GetType().Equals(typeof(System.AddIn.Pipeline.AddInContractAttribute)))
                        {
                            activatable = true;
                            break;
                        }
                    }
                    PipelineHints.PipelineSegment customSettings = PipelineHints.PipelineSegment.None;
                    if (t.GetCustomAttributes(typeof(PipelineHints.CustomPipelineAttribute), false).Length > 0)
                    {
                        customSettings = ((PipelineHints.CustomPipelineAttribute)t.GetCustomAttributes(typeof(PipelineHints.CustomPipelineAttribute), false)[0]).Segment;
                    }
                    //Build host, add-in views, and shared views
                    if ((customSettings & PipelineHints.PipelineSegment.AddInView) != PipelineHints.PipelineSegment.AddInView)
                    {
                        BuildView(t, _aib, SegmentType.AIB, activatable);
                    }
                    if ((customSettings & PipelineHints.PipelineSegment.HostView) != PipelineHints.PipelineSegment.HostView)
                    {
                        BuildView(t, _hav, SegmentType.HAV, activatable);
                    }
                    if ((customSettings & PipelineHints.PipelineSegment.Views) != PipelineHints.PipelineSegment.Views)
                    {
                        BuildView(t, _view, SegmentType.VIEW, activatable);
                    }
                    //Build add-in side adapters
                    if ((customSettings & PipelineHints.PipelineSegment.AddInSideAdapter) != PipelineHints.PipelineSegment.AddInSideAdapter)
                    {
                        BuildViewToContractAdapter(t, _asa, SegmentType.ASA, activatable);
                        BuildContractToViewAdapter(t, _asa, SegmentType.ASA, false);
                    }
                    BuildStaticAdapters(t, _asa, SegmentType.ASA);
                    //Build host side adapters
                    if ((customSettings & PipelineHints.PipelineSegment.HostSideAdapter) != PipelineHints.PipelineSegment.HostSideAdapter)
                    {
                        BuildViewToContractAdapter(t, _hsa, SegmentType.HSA, false);
                        BuildContractToViewAdapter(t, _hsa, SegmentType.HSA, activatable);
                    }
                    BuildStaticAdapters(t, _hsa, SegmentType.HSA);
                }
                else if (t.IsEnum)
                {
                    //If type is an enum build adapters and view for that
                    BuildEnumView(t, _aib, SegmentType.AIB);
                    BuildEnumView(t, _hav, SegmentType.HAV);
                    BuildEnumView(t, _view, SegmentType.VIEW);
                    BuildStaticAdapters(t, _hsa, SegmentType.HSA);
                    BuildStaticAdapters(t, _asa, SegmentType.ASA);
                    BuildStaticAdapters(t.MakeArrayType(), _hsa, SegmentType.HSA);
                    BuildStaticAdapters(t.MakeArrayType(), _asa, SegmentType.ASA);
                }
                else if (t.IsValueType)
                {
                    ValidateStructContract(t);
                    PipelineHints.PipelineSegment customSettings = PipelineHints.PipelineSegment.None;
                    if (t.GetCustomAttributes(typeof(PipelineHints.CustomPipelineAttribute), false).Length > 0)
                    {
                        customSettings = ((PipelineHints.CustomPipelineAttribute)t.GetCustomAttributes(typeof(PipelineHints.CustomPipelineAttribute), false)[0]).Segment;
                    }
                    //Build host, add-in views, and shared views
                    if ((customSettings & PipelineHints.PipelineSegment.AddInView) != PipelineHints.PipelineSegment.AddInView)
                    {
                        BuildStructView(t, _aib, SegmentType.AIB);
                    }
                    if ((customSettings & PipelineHints.PipelineSegment.HostView) != PipelineHints.PipelineSegment.HostView)
                    {
                        BuildStructView(t, _hav, SegmentType.HAV);
                    }
                    if ((customSettings & PipelineHints.PipelineSegment.Views) != PipelineHints.PipelineSegment.Views)
                    {
                        BuildStructView(t, _view, SegmentType.VIEW);
                    }
                    Type arrayVersion = t.MakeArrayType();
                    //Build add-in side adapters
                    if ((customSettings & PipelineHints.PipelineSegment.AddInSideAdapter) != PipelineHints.PipelineSegment.AddInSideAdapter)
                    {
                        BuildStaticAdapters(t, _asa, SegmentType.ASA);

                    }
                    BuildStaticAdapters(arrayVersion, _asa, SegmentType.ASA);
                    //Build host side adapters
                    if ((customSettings & PipelineHints.PipelineSegment.HostSideAdapter) != PipelineHints.PipelineSegment.HostSideAdapter)
                    {
                        BuildStaticAdapters(t, _hsa, SegmentType.HSA);
                    }
                    BuildStaticAdapters(arrayVersion, _hsa, SegmentType.HSA);

                }
            }
            return components;
        }