コード例 #1
0
        private void PopulateSolutionProjects(List<int> projList, int? queIndex)
        {
            projList.RunFuncForEach(projIndex => this.ProjectFiles.Add(projIndex));
            int count = 0;

            // foreach (int projIndex in this.ProjectFiles.Where(x => x != -1))
            foreach (int projIndex in projList)
            {
                var proj = Projects.ProjectList[projIndex];
                if (proj.ReferenceProjects != null)
                {
                    continue;
                }

                // not postive this is correct, so far the way to determine if projects references have been checked
                if (proj.ReferenceProjects == null)
                {
                    proj.ReferenceProjects = new List<int>();
                }

                List<int> addedProjects = new List<int>();
                foreach (var refPath in proj.ReferencePaths)
                {
                    int refIndex = Array.FindIndex(Projects.ProjectList, x => Helper.FileCompare(x.BuildProjectOutputPath.FullName, refPath.FullName));
                    if (refIndex != -1 && !proj.ReferenceProjects.Contains(refIndex))
                    {
                        proj.ReferenceProjects.Add(refIndex);
                        addedProjects.Add(refIndex);
                    }

                }

                ProjectFile.PopulateNeedsToBeBuilt(proj);

                int index = queIndex ?? count;
                if (addedProjects.Count != 0)
                {
                    this.PopulateSolutionProjects(addedProjects, index);

                    this.ProjectQueues[index].Add(projIndex);
                }
                else
                {
                    proj.ReadyToBuild = true; // no other projects need to be built for this project to build correctly, no refd projects

                    this.ProjectQueues[index].Insert(0, projIndex);
                }

                count++;
            }
        }
コード例 #2
0
ファイル: Projects.cs プロジェクト: tacketra/BuildSolution
        /// <summary>
        /// Populates static member ProjectList with all c# projects on the computer. Projects have references to dll's from other
        /// projects and from a dll it is impossible to tell what project they came from. So we need all projects on the computer 
        /// to search through and match them to the appropiate project.
        /// </summary>
        void PopulateAllProjects(bool runInParallel)
        {
            DirectoryInfo dir = new DirectoryInfo(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile));
            List<ProjectFile> tempProjectList = new List<ProjectFile>();

            if (!runInParallel)
            {
                Console.WriteLine("searchFolder Normal time: " + Helper.TimeFunction(() => SearchFolder("*.csproj", dir, tempProjectList)));
            }
            else
            {
                int processorCount = Environment.ProcessorCount;
                var dirFiInfos = dir.GetFileSystemInfos().ToList();
                var dirInfos = new List<FileSystemInfo>[processorCount];
                List<ProjectFile>[] projArray = new List<ProjectFile>[processorCount];

                int interval = 0;
                int j = -1;
                for (int i = 0; i < dirFiInfos.Count; i++)
                {
                    if (i >= interval)
                    {
                        j++;
                        projArray[j] = new List<ProjectFile>();

                        dirInfos[j] = new List<FileSystemInfo>();
                        interval += (dirFiInfos.Count / 4) + 1;
                    }

                    dirInfos[j].Add(dirFiInfos[i]);
                }

                var watch = System.Diagnostics.Stopwatch.StartNew();

                var threadList = new List<System.Threading.Thread>();
                for (int i = 0; i < processorCount; i++)
                {
                    int index = i;
                    System.Threading.Thread t = new System.Threading.Thread(new System.Threading.ThreadStart(() => SearchFolderUsingInfos(".csproj", projArray[index], dirInfos[index].ToArray())));
                    t.Start();
                    threadList.Add(t);
                }

                foreach (var t in threadList)
                {
                    t.Join();
                }

                projArray.RunFuncForEach(x => tempProjectList.AddRange(x));

                watch.Stop();

                Console.WriteLine("searchFolder Parallel time: " + watch.ElapsedMilliseconds / 1000d);
            }

            Projects.ProjectList = tempProjectList.ToArray();
        }