Пример #1
0
        private Library AutoSelectLibrary(ProjectComboData pcd, LibraryCategory lc)
        {
            Library   defaultLib    = null;
            Library   stubLib       = null;
            Library   bootLoaderLib = null;
            Library   generateLib   = null;
            Library   clrLib        = null;
            bool      fTooManyLibs  = false;
            MFProject proj          = pcd.Proj;


            FeatureAssociation fa = GetFeatureAssociation(lc);

            foreach (Library lib in m_helper.GetLibrariesOfType(lc))
            {
                if (proj.ValidateLibrary(lib, m_solution, m_solutionProc, m_helper))
                {
                    if (m_pcdAll.Proj.Libraries.Contains(new MFComponent(MFComponentType.Library, lib.Name, lib.Guid)))
                    {
                        clrLib = lib;
                    }

                    if (lib.IsStub)
                    {
                        stubLib = lib;
                    }
                    else if (lib.IsBootloaderLibrary())
                    {
                        bootLoaderLib = lib;
                    }
                    else if (lib.Name == c_GenerateTemplateString)
                    {
                        generateLib = lib;
                    }
                    else if (defaultLib == null)
                    {
                        defaultLib = lib;
                    }
                    else if (fa != FeatureAssociation.NotSelected)
                    {
                        // there are now too many libraries for us to choose from
                        // so we can not auto-select unless this is a cloned solution
                        // in which case we will look for common libraries.
                        fTooManyLibs = true;
                    }
                }
            }

            // if the solution is cloned then lets try to choose common libraries where possible
            if (m_solution.m_cloneSolution != null)
            {
                MFProject cloneProj = null;

                // for "all projects" choose the TinyCLR project
                bool fAllProj = (0 == string.Compare(proj.Name, Properties.Resources.AllProjects, true));

                // match libraries from the given project
                foreach (MFProject prj in m_solution.m_cloneSolution.Projects)
                {
                    if (fAllProj)
                    {
                        if (prj.IsClrProject)
                        {
                            cloneProj = prj;
                            break;
                        }
                    }
                    else if (0 == string.Compare(prj.Name, proj.Name, true))
                    {
                        cloneProj = prj;
                        break;
                    }
                }

                // Only match libraries from common projects
                if (cloneProj != null)
                {
                    // search the cloned solution for the common library category
                    foreach (MFComponent cloneLib in cloneProj.Libraries)
                    {
                        Library cl = m_helper.FindLibrary(cloneLib);

                        if (cl == null && m_solution.m_clonedLibraryMap.ContainsKey(cloneLib.Guid.ToUpper()))
                        {
                            cl = m_solution.m_clonedLibraryMap[cloneLib.Guid.ToUpper()];
                        }

                        if (cl != null)
                        {
                            if (cl.HasLibraryCategory && (0 == string.Compare(lc.Guid, cl.LibraryCategory.Guid, true)))
                            {
                                // if the library is a solution dependent library, then choose to generate it (which will
                                // at a later stage copy the code from the clone solution).
                                if (cl.ProjectPath.ToLower().Contains("\\solutions\\" + m_solution.m_cloneSolution.Name.ToLower() + "\\"))
                                {
                                    if (generateLib == null)
                                    {
                                        // it is possible that we haven't created the "Generate Template" library yet.
                                        generateLib = AddGenerateTemplateNode(pcd, lc);
                                    }

                                    if (fa == FeatureAssociation.Selected || fa == FeatureAssociation.None)
                                    {
                                        return(generateLib);
                                    }
                                    else
                                    {
                                        defaultLib = generateLib;
                                    }
                                }
                                ///
                                /// if the associated feature is not selected than use the cloned projects selection
                                /// as the default
                                ///
                                else if (fa != FeatureAssociation.Selected)
                                {
                                    defaultLib = cl;
                                }
                                ///
                                /// If the feature is selected use the cloned projects selection if it is not a stub
                                ///
                                else if (!cl.IsStub)
                                {
                                    return(cl);
                                }
                                break;
                            }
                        }
                    }
                }
            }

            switch (fa)
            {
            case FeatureAssociation.Selected:
                if (proj.IsBootloaderProject())
                {
                    if (bootLoaderLib != null)
                    {
                        return(bootLoaderLib);
                    }
                    else if (lc.IsTransport && m_solution.m_transportType.Equals(lc))
                    {
                        if (!fTooManyLibs)
                        {
                            return(defaultLib);
                        }
                    }
                    else if (stubLib != null)
                    {
                        return(stubLib);
                    }
                    else if (!fTooManyLibs && defaultLib != null && (generateLib == null || !string.IsNullOrEmpty(defaultLib.CustomFilter) || !string.IsNullOrEmpty(defaultLib.ProcessorSpecific.Guid)))
                    {
                        return(defaultLib);
                    }
                }
                else
                {
                    if (!fTooManyLibs && defaultLib != null)
                    {
                        return(defaultLib);
                    }
                    else if (clrLib != null)
                    {
                        return(clrLib);
                    }
                }
                break;

            case FeatureAssociation.NotSelected:
                if (!lc.IsTransport || !m_solution.m_transportType.Equals(lc))
                {
                    return(stubLib);
                }
                break;

            case FeatureAssociation.None:
                // if we don't have a stub library then we should be able to select the appropriate library
                // automatically
                if (proj.IsBootloaderProject())
                {
                    if (bootLoaderLib != null)
                    {
                        return(bootLoaderLib);
                    }
                    else if (stubLib != null)
                    {
                        return(stubLib);
                    }
                    else if (!fTooManyLibs)
                    {
                        return(defaultLib);
                    }
                }
                else if (!fTooManyLibs && defaultLib != null && ((stubLib == null && generateLib == null) || !string.IsNullOrEmpty(defaultLib.CustomFilter) || !string.IsNullOrEmpty(defaultLib.ProcessorSpecific.Guid)))
                {
                    return(defaultLib);
                }
                else if (clrLib != null)
                {
                    return(clrLib);
                }
                break;
            }

            return(null);
        }