Esempio n. 1
0
        /// <summary>
        /// Loads a project from a path.
        /// </summary>
        /// <param name="path">Path to the project file.</param>
        /// <returns>Loaded project or null if unsuccessful</returns>
        public static Project LoadFromPath(string path)
        {
            using FileStream fileStream = File.OpenRead(path);

            if (ProjectSerializer.ReadObject(fileStream) is Project project)
            {
                project.Path = path;

                // Load classes
                ConcurrentBag <ClassGraph> classes = new ConcurrentBag <ClassGraph>();

                Parallel.ForEach(project.ClassPaths, classPath =>
                {
                    ClassGraph cls = SerializationHelper.LoadClass(System.IO.Path.Combine(System.IO.Path.GetDirectoryName(project.Path), classPath));
                    cls.Project    = project;
                    classes.Add(cls);
                });

                project.Classes.ReplaceRange(classes.OrderBy(c => c.Name));

                return(project);
            }

            return(null);
        }
Esempio n. 2
0
        /// <summary>
        /// Loads a project from a path.
        /// </summary>
        /// <param name="path">Path to the project file.</param>
        /// <returns>Loaded project or null if unsuccessful</returns>
        public static Project LoadFromPath(string path, int depth = 0)
        {
            if (depth > 25)
            {
                throw new Exception("Probably recursive project references");
            }

            using FileStream fileStream = File.OpenRead(path);

            if (ProjectSerializer.ReadObject(fileStream) is Project project)
            {
                project.Path = path;

                foreach (var reference in project.References)
                {
                    reference.Project = project;
                }

                ConcurrentBag <ClassGraph> classes = new();
                Parallel.ForEach(project.ClassPaths, classPath =>
                {
                    ClassGraph cls = SerializationHelper.LoadClass(System.IO.Path.Combine(System.IO.Path.GetDirectoryName(project.Path), classPath));
                    cls.SetOwningProject(project);
                    classes.Add(cls);
                });
                project.Classes.ReplaceRange(classes.OrderBy(c => c.Name));

                ConcurrentBag <Project> packages = new();
                Parallel.ForEach(project.References.OfType <PackageReference>(), reference =>
                {
                    var package             = LoadFromPath(reference.PackagePath, depth + 1);
                    reference.LoadedPackage = package;
                    packages.Add(package);
                });

                foreach (var package in packages)
                {
                    project.LoadPackage(package);
                }

                return(project);
            }

            return(null);
        }
Esempio n. 3
0
 public string GetClassStoragePath(ClassGraph cls)
 {
     return($"{cls.FullName}.netpc");
 }