예제 #1
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);
        }
예제 #2
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  = ProjectDefinition.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);
        }
예제 #3
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);
        }
예제 #4
0
 public ResourceReference(ProjectDefinition file, XmlElement element)
 {
     DefinitionFile = file;
     Element        = element;
 }