예제 #1
0
        public static ProjectExplorer CreateProject(string projectDirectoryPath, ImportPipeline importPipeline)
        {
            var directoryInfo = new DirectoryInfo(projectDirectoryPath);

            // Ensure the directory exists.
            if (!directoryInfo.Exists)
            {
                Directory.CreateDirectory(directoryInfo.FullName);
            }

            string bprojPath = Path.Combine(directoryInfo.FullName, $"{directoryInfo.Name}.bproj");

            File.WriteAllText(bprojPath, "<Project>\r\n\t\r\n</Project>");

            return(Load(projectDirectoryPath, importPipeline));
        }
예제 #2
0
        public static async Task <ProjectExplorer> LoadAsync(string projectPath, ImportPipeline importPipeline)
        {
            string bprojPath = null;

            if (projectPath.EndsWith(".bproj"))
            {
                bprojPath   = projectPath;
                projectPath = new DirectoryInfo(projectPath).Parent.FullName;
            }
            else
            {
                foreach (string rootFile in Directory.EnumerateFiles(projectPath, "*.bproj"))
                {
                    bprojPath = rootFile;
                    break;
                }
            }

            var archive = new FileSystemArchive(new DirectoryInfo(projectPath));

            var resources = new Dictionary <string, ProjectResource>();

            var rootDirectiory = new ProjectDirectory("", "", null);

            var projectExplorer = new ProjectExplorer
            {
                Archive       = archive,
                Definition    = ProjectDefinition.Load(bprojPath),
                Resources     = new ProjectResourceCollection(resources),
                RootDirectory = rootDirectiory
            };

            void ImportDirectory(IArchiveDirectory directory, ProjectDirectory projectDirectory)
            {
                foreach (var childDirectory in directory.Directories)
                {
                    ImportDirectory(childDirectory,
                                    new ProjectDirectory(childDirectory.Name, childDirectory.FullName, projectDirectory));
                }

                foreach (var file in directory.Files)
                {
                    if (file.FullName.StartsWith("bin/") ||
                        file.FullName.EndsWith(".bproj") ||
                        !importPipeline.IsResource(file))
                    {
                        continue;
                    }

                    var resource = importPipeline.ImportResource(projectExplorer, projectDirectory, file, file.FullName);

                    projectExplorer.Resources.Add(resource.FullName, resource);
                    projectDirectory.Resources.Add(resource.Name, resource);
                }
            }

            ImportDirectory(archive.RootDirectory, rootDirectiory);

            foreach (var resource in projectExplorer.Resources)
            {
                foreach (var dependency in resource.Dependencies)
                {
                    var dependencyResource = dependency.Resource;

                    if (dependencyResource == null)
                    {
                        Console.WriteLine($"ERROR: Unable to resolve dependency for \"{dependency.Key}\"");
                    }
                    else
                    {
                        dependencyResource.Dependants.dependencies.Add(new ProjectResourceDependency(projectExplorer, resource.FullName, dependency.metdadata));
                    }
                }
            }

            // Size Calculation
            long uncompressedSize = 0;

            foreach (var resource in projectExplorer.Resources)
            {
                uncompressedSize += resource.UncompressedSize;
            }
            projectExplorer.UncompressedSize = uncompressedSize;

            // Tag Indexing
            var tags = new Dictionary <string, IResourceCollection>();

            foreach (var resource in projectExplorer.Resources)
            {
                foreach (string tag in resource.Tags)
                {
                    if (!tags.TryGetValue(tag, out var taggedResourcesCollection))
                    {
                        taggedResourcesCollection = new ProjectResourceCollection();
                        tags[tag] = taggedResourcesCollection;
                    }

                    var taggedResources = (ProjectResourceCollection)taggedResourcesCollection;
                    taggedResources.Add(resource.FullName, resource);
                }
            }

            projectExplorer.Tags = new PackageTagsCollection(tags);

            return(projectExplorer);
        }
예제 #3
0
 public static ProjectExplorer Load(string projectPath, ImportPipeline importPipeline)
 {
     return(LoadAsync(projectPath, importPipeline).Result);
 }
예제 #4
0
        private static ProjectDirectory CreateDirectory(string normalisedRootPath, string directoryPath, string projectKey, ProjectExplorer projectExplorer, ImportPipeline importPipeline)
        {
            var newRootDirectory = new ProjectDirectory(projectKey);

            foreach (string filePath in Directory.EnumerateFiles(directoryPath, "*", SearchOption.TopDirectoryOnly))
            {
                var resourceFileInfo = new FileInfo(filePath);

                if (resourceFileInfo.Extension == ".bproj")
                {
                    continue;
                }

                string resourceProjectKey = filePath
                                            .Replace('\\', '/')
                                            .Replace(normalisedRootPath + "/", "");

                var resource = importPipeline.ImportResource(projectExplorer, resourceFileInfo, resourceProjectKey);

                projectExplorer.Resources.Add(resource);

                newRootDirectory.AddChildResource(resource);
            }

            foreach (string directoryFullName in Directory.EnumerateDirectories(directoryPath, "*", SearchOption.AllDirectories))
            {
                var directoryInformation = new DirectoryInfo(directoryFullName);

                if (directoryInformation.Name == "bin")
                {
                    continue;
                }

                string directoryProjectKey = directoryFullName
                                             .Replace('\\', '/')
                                             .Replace(normalisedRootPath + "/", "");

                var childDirectory = CreateDirectory(normalisedRootPath, directoryFullName, directoryProjectKey, projectExplorer, importPipeline);

                newRootDirectory.AddChildDirectory(childDirectory);
            }

            return(newRootDirectory);
        }
예제 #5
0
        public static ProjectExplorer Load(string projectPath, ImportPipeline importPipeline)
        {
            string bprojPath = null;

            if (projectPath.EndsWith(".bproj"))
            {
                bprojPath   = projectPath;
                projectPath = new DirectoryInfo(projectPath).Parent.FullName;
            }
            else
            {
                foreach (string rootFile in Directory.EnumerateFiles(projectPath, "*.bproj"))
                {
                    bprojPath = rootFile;
                    break;
                }
            }

            var resources = new Dictionary <string, ProjectResource>();

            var projectExplorer = new ProjectExplorer
            {
                ProjectPath = projectPath,
                Definition  = ProjectDefinitionFile.Load(bprojPath),
                resources   = new ProjectResourceCollection(resources)
            };

            projectExplorer.rootDirectory = CreateDirectory(
                projectPath.Replace('\\', '/'),
                projectPath,
                "/",
                projectExplorer,
                importPipeline
                );

            // Size Calculation
            long uncompressedSize = 0;

            foreach (var resource in projectExplorer.Resources)
            {
                uncompressedSize += resource.UncompressedSize;
            }
            projectExplorer.UncompressedSize = uncompressedSize;

            // Tag Indexing
            var tags = new Dictionary <string, IResourceCollection>();

            foreach (var resource in projectExplorer.Resources)
            {
                foreach (string tag in resource.Tags)
                {
                    if (!tags.TryGetValue(tag, out var taggedResourcesCollection))
                    {
                        taggedResourcesCollection = new ProjectResourceCollection();
                        tags[tag] = taggedResourcesCollection;
                    }

                    var taggedResources = (ProjectResourceCollection)taggedResourcesCollection;
                    taggedResources.Add(resource);
                }
            }

            projectExplorer.tags = new PackageTagsCollection(tags);

            return(projectExplorer);
        }
예제 #6
0
        public static async Task <ProjectExplorer> LoadAsync(string projectPath, ImportPipeline importPipeline)
        {
            string bprojPath = null;

            if (projectPath.EndsWith(".bproj"))
            {
                bprojPath   = projectPath;
                projectPath = new DirectoryInfo(projectPath).Parent.FullName;
            }
            else
            {
                foreach (string rootFile in Directory.EnumerateFiles(projectPath, "*.bproj"))
                {
                    bprojPath = rootFile;
                    break;
                }
            }

            var archive = new FileSystemArchive(new DirectoryInfo(projectPath));

            var resources = new Dictionary <string, ProjectResource>();

            var rootDirectiory = new ProjectDirectory("", "", null);

            ProjectDirectory ForPath(string path)
            {
                int currentIndex     = 0;
                var currentDirectory = rootDirectiory;

                while (true)
                {
                    int nextIndex = path.IndexOf('/', currentIndex);
                    if (nextIndex == -1)
                    {
                        break;
                    }
                    string segment = path.Substring(currentIndex, nextIndex - currentIndex);

                    bool found = false;
                    foreach (var directory in currentDirectory.Directories)
                    {
                        if (directory.Name == segment)
                        {
                            currentDirectory = directory;
                            found            = true;
                            break;
                        }
                    }
                    if (!found)
                    {
                        var newDirectory = new ProjectDirectory(segment, path, currentDirectory);
                        currentDirectory.Directories.Add(newDirectory);
                        currentDirectory = newDirectory;
                    }

                    currentIndex = nextIndex + 1;
                }

                return(currentDirectory);
            }

            var projectExplorer = new ProjectExplorer
            {
                Archive       = archive,
                Definition    = ProjectDefinition.Load(bprojPath),
                Resources     = new ProjectResourceCollection(resources),
                RootDirectory = rootDirectiory
            };

            // Resources
            foreach (var projectEntry in archive.Files)
            {
                if (projectEntry.FullName.StartsWith("bin/") ||
                    projectEntry.FullName.EndsWith(".bproj"))
                {
                    continue;
                }

                if (!importPipeline.IsResource(projectEntry))
                {
                    continue;
                }

                var forPath = ForPath(projectEntry.FullName);

                var resource = importPipeline.ImportResource(projectExplorer, forPath, projectEntry, projectEntry.FullName);

                projectExplorer.Resources.Add(resource.FullName, resource);
                forPath.Resources.Add(resource.Name, resource);
            }

            foreach (var resource in projectExplorer.Resources)
            {
                foreach (var dependency in resource.Dependencies)
                {
                    var dependencyResource = dependency.Resource;

                    if (dependencyResource == null)
                    {
                        Console.WriteLine($"ERROR: Unable to resolve dependency for \"{dependency.Key}\"");
                    }
                    else
                    {
                        dependencyResource.Dependants.dependencies.Add(new ProjectResourceDependency(projectExplorer, resource.FullName, dependency.metdadata));
                    }
                }
            }

            // Size Calculation
            long uncompressedSize = 0;

            foreach (var resource in projectExplorer.Resources)
            {
                uncompressedSize += resource.UncompressedSize;
            }
            projectExplorer.UncompressedSize = uncompressedSize;

            // Tag Indexing
            var tags = new Dictionary <string, IResourceCollection>();

            foreach (var resource in projectExplorer.Resources)
            {
                foreach (string tag in resource.Tags)
                {
                    if (!tags.TryGetValue(tag, out var taggedResourcesCollection))
                    {
                        taggedResourcesCollection = new ProjectResourceCollection();
                        tags[tag] = taggedResourcesCollection;
                    }

                    var taggedResources = (ProjectResourceCollection)taggedResourcesCollection;
                    taggedResources.Add(resource.FullName, resource);
                }
            }

            projectExplorer.Tags = new PackageTagsCollection(tags);

            return(projectExplorer);
        }
예제 #7
0
 public BuildPipeline()
 {
     ImportPipeline = new ImportPipeline();
     Exporters      = new List <ResourceExporter>();
     BuildActions   = new List <IBuildAction>();
 }