Esempio n. 1
0
        public bool TryGetProject(ReferenceInfo reference, out ProjectInfo info)
        {
            int ordinal = -1;

            if (reference.ProjectGuid.HasValue && _byProjectId.TryGetValue(reference.ProjectGuid.Value, out ordinal))
            {
            }
            else if (reference.ProjectFile != null && _byProject.TryGetValue(reference.ProjectFile, out ordinal))
            {
            }
            else if (reference.HintPath != null && _byOutputFile.TryGetValue(reference.HintPath, out ordinal))
            {
            }
            else if (reference.Assembly != null && reference.Assembly.Name != null &&
                     _byAssembly.TryGetValue(reference.Assembly.Name, out ordinal))
            {
            }
            else
            {
                info = null;
                return(false);
            }
            info = _projects[ordinal];
            return(true);
        }
        int PrepareBuild(IEnumerable <ProjectInfo> projectFiles)
        {
            Dictionary <string, WorkItem> working = new Dictionary <string, WorkItem>(StringComparer.OrdinalIgnoreCase);

            ProjectInfo refProj;

            foreach (ProjectInfo pi in projectFiles)
            {
                ReferenceInfo lastRef = null;
                try
                {
                    WorkItem item = new WorkItem(pi);

                    item.Depends.AddRange(pi.Dependencies);
                    foreach (ReferenceInfo r in pi.References)
                    {
                        lastRef = r;
                        if (_projects.TryGetProject(r, out refProj))
                        {
                            item.Depends.Add(refProj.ProjectFile);
                        }
                    }
                    working.Add(pi.ProjectFile, item);
                }
                catch (Exception e)
                {
                    throw new ApplicationException(
                              String.Format("Unable to parse references from {0}, reference={1}, error={2}",
                                            pi.ProjectFile, lastRef, e.Message), e);
                }
            }

            using (Log.Start("Sorting {0} projects", _projects.Count))
            {
                int lastCount = 0;
                while (working.Count > 0 && lastCount != working.Count)
                {
                    lastCount = working.Count;//every loop should peel at least one project out...

                    List <KeyValuePair <string, WorkItem> > loop = new List <KeyValuePair <string, WorkItem> >(working);
                    loop.Sort(SortWork);

                    foreach (KeyValuePair <string, WorkItem> item in loop)
                    {
                        bool canBuild = true;
                        while (item.Value.Depends.Count > 0)
                        {
                            string fileref = item.Value.Depends[0];
                            if (!working.ContainsKey(fileref))
                            {
                                item.Value.Depends.RemoveAt(0);
                            }
                            else
                            {
                                canBuild = false;
                                break;
                            }
                        }

                        if (canBuild)
                        {
                            _buildList.Add(item.Value.Project);
                            working.Remove(item.Key);
                        }
                    }
                }

                if (working.Count > 0)
                {
                    try { ReportCycles(working); } catch { }
                    throw new ApplicationException(String.Format("Aborted {0} Projects: Circular reference(s) in projects.", working.Count));
                }

                return(0);
            }
        }