Ejemplo n.º 1
0
        private void WriteFilesAsync(List <FileToWrite> files)
        {
            var project = new ProjectFile(files, AddNewFilesToProject, Tfs);

            if (UseTfsToCheckoutFiles)
            {
                DisplayMessage("Creating Required Directories");
                foreach (var dir in files.Select(f => f.Directory).Distinct())
                {
                    if (dir != null && !Directory.Exists(dir))
                    {
                        Directory.CreateDirectory(dir);
                    }
                }
                DisplayMessage("Getting Latest from TFS");
                // Get Latest Version of all files
                foreach (var batch in files.Select(f => f.Path).Batch(50))
                {
                    Tfs.Get(true, batch.ToArray());
                }

                if (Debugger.IsAttached)
                {
                    DisplayMessage("Creating Temporary Files");
                    foreach (var file in files)
                    {
                        WriteFilesForTfs(project, file);
                    }
                    CheckoutChangedFiles(files);
                    DisplayMessage("Updating Changed Files");
                    foreach (var file in files)
                    {
                        CopyChangedFiles(file);
                    }
                }
                else
                {
                    DisplayMessage("Creating Temporary Files");
                    Parallel.ForEach(files, f => WriteFilesForTfs(project, f));
                    CheckoutChangedFiles(files);
                    DisplayMessage("Updating Changed Files");
                    Parallel.ForEach(files, CopyChangedFiles);
                }
            }
            else
            {
                if (Debugger.IsAttached)
                {
                    foreach (var file in files)
                    {
                        WriteFileIfDifferent(project, file);
                    }
                }
                else
                {
                    Parallel.ForEach(files, f => WriteFileIfDifferent(project, f));
                }
            }

            if (AddNewFilesToProject && !project.ProjectFound)
            {
                Log("Unable to find a Project file to add newly created files to.  Either output the files into a directory that has a single project in it's path, or uncheck the \"Add New Files to Project\" Setting");
            }

            if (project.ProjectUpdated)
            {
                WriteFileIfDifferent(new ProjectFile(null, false, null), new FileToWrite(project.ProjectPath, project.GetContents()));
            }
        }