Exemplo n.º 1
0
        public static void AddFiles(this IProjectSystem project,
                                    IEnumerable <IPackageFile> files,
                                    IDictionary <string, IPackageFileTransformer> fileTransformers)
        {
            // BUG 636: We add the files with the longest path first so that vs picks up code behind files.
            // This shouldn't matter for any other scenario.
            foreach (IPackageFile file in files.OrderByDescending(p => p.Path))
            {
                // Remove the redundant folder from the path
                string path = ResolvePath(project, file.Path);

                // Try to get the package file modifier for the extension
                string extension = Path.GetExtension(file.Path);
                IPackageFileTransformer transformer;
                if (fileTransformers.TryGetValue(extension, out transformer))
                {
                    // Remove the extension to get the target path
                    path = RemoveExtension(path);

                    if (project.IsSupportedFile(path))
                    {
                        // If the transform was done then continue
                        transformer.TransformFile(file, path, project);
                    }
                }
                else if (project.IsSupportedFile(path))
                {
                    project.AddFileWithCheck(path, file.GetStream);
                }
            }
        }
Exemplo n.º 2
0
        public static void AddFiles(this IProjectSystem project,
                                    IEnumerable <IPackageFile> files,
                                    IDictionary <string, IPackageFileTransformer> fileTransformers)
        {
            // Convert files to a list
            List <IPackageFile> fileList = files.ToList();

            // See if the project system knows how to sort the files
            var fileComparer = project as IComparer <IPackageFile>;

            if (fileComparer != null)
            {
                fileList.Sort(fileComparer);
            }

            var batchProcessor = project as IBatchProcessor <string>;

            try
            {
                if (batchProcessor != null)
                {
                    var paths = fileList.Select(file => ResolvePath(fileTransformers, file.EffectivePath));
                    batchProcessor.BeginProcessing(paths, PackageAction.Install);
                }

                foreach (IPackageFile file in fileList)
                {
                    if (file.IsEmptyFolder())
                    {
                        continue;
                    }

                    IPackageFileTransformer transformer;

                    // Resolve the target path
                    string path = ResolveTargetPath(project,
                                                    fileTransformers,
                                                    file.EffectivePath,
                                                    out transformer);

                    if (project.IsSupportedFile(path))
                    {
                        // Try to get the package file modifier for the extension
                        if (transformer != null)
                        {
                            // If the transform was done then continue
                            transformer.TransformFile(file, path, project);
                        }
                        else
                        {
                            project.AddFileWithCheck(path, file.GetStream);
                        }
                    }
                }
            }
            finally
            {
                if (batchProcessor != null)
                {
                    batchProcessor.EndProcessing();
                }
            }
        }