示例#1
0
        public static Dictionary <string, string> GetConstants(string scraperOutputDir)
        {
            Dictionary <string, string> namesAndTypes = new();

            System.Threading.Tasks.ParallelOptions opt = new System.Threading.Tasks.ParallelOptions()
            {
                MaxDegreeOfParallelism = Environment.ProcessorCount * 2
            };

            IEnumerable <string> allFiles = Directory.GetFiles(scraperOutputDir, "*.cs", SearchOption.AllDirectories);

#if MakeSingleThreaded
            opt.MaxDegreeOfParallelism = 1;
#endif

            System.Threading.Tasks.Parallel.ForEach(allFiles.Where(f => IsValidCsSourceFile(f)), opt, (sourceFile) =>
            {
                string fileToRead = Path.GetFullPath(sourceFile);
                SyntaxTree tree   = CSharpSyntaxTree.ParseText(File.ReadAllText(fileToRead), null, fileToRead);
                Dictionary <string, string> currentNamesAndTypes = ConstantsFinder.GetConstantsNamesAndTypes(tree);

                lock (namesAndTypes)
                {
                    foreach (var item in currentNamesAndTypes)
                    {
                        namesAndTypes[item.Key] = item.Value;
                    }
                }
            });

            return(namesAndTypes);
        }
示例#2
0
        public static HashSet <string> GetConstants(string sourceDirectory)
        {
            HashSet <string> names = new HashSet <string>();

            var sourceFiles = Directory.GetFiles(sourceDirectory, "*.cs", SearchOption.AllDirectories).Where(f => IsValidCsSourceFile(f));

            System.Threading.Tasks.ParallelOptions opt = new System.Threading.Tasks.ParallelOptions()
            {
                MaxDegreeOfParallelism = Environment.ProcessorCount * 2
            };

#if MakeSingleThreaded
            opt.MaxDegreeOfParallelism = 1;
#endif

            System.Threading.Tasks.Parallel.ForEach(sourceFiles, opt, (sourceFile) =>
            {
                string fileToRead = Path.GetFullPath(sourceFile);
                var tree          = CSharpSyntaxTree.ParseText(File.ReadAllText(fileToRead), null, fileToRead);
                var currentNames  = ConstantsFinder.GetConstantsNames(tree);

                lock (names)
                {
                    names.UnionWith(currentNames);
                }
            });

            return(names);
        }
示例#3
0
        public static void Initialize(string projectPath = null, bool showErrorMsg = true)
        {
            //if (check)
            //    CheckFilesAndFolders();

            string headerFilesPath  = "\\headerFiles";
            string moduleFilesPath  = "\\moduleFiles";
            string moduleSystemPath = "\\moduleSystem";

            if (projectPath == null)
            {
                //projectPath = CodeReader.FILES_PATH + @"tmp";
                //if (!Directory.Exists(projectPath))
                //    Directory.CreateDirectory(projectPath);
                //ShowErrorMsg("Pfad des Projekts wurde in " + Path.GetFullPath(projectPath) + " geändert!");
                ShowErrorMsg("No project found!");
                return;
            }

            currentProjectPath = projectPath;

            if (!IsInLastOpenedProjectPaths(projectPath))
            {
                AddProjectPathToLastOpened(projectPath);
            }

            headerFilesPath  = projectPath + headerFilesPath;
            moduleFilesPath  = projectPath + moduleFilesPath;
            moduleSystemPath = projectPath + moduleSystemPath;

            //if (!Directory.Exists(headerFilesPath))
            Directory.CreateDirectory(headerFilesPath);
            //if (!Directory.Exists(moduleFilesPath))
            Directory.CreateDirectory(moduleFilesPath);
            //if (!Directory.Exists(moduleSystemPath))
            Directory.CreateDirectory(moduleSystemPath);

            CodeReader.ProjectPath       = projectPath;
            moduleFilesPath             += '\\';
            SourceWriter.ModuleFilesPath = moduleFilesPath;

            if (SetModPath(showErrorMsg))
            {
                CodeReader.LoadAll();
                ImportsManager importsManager = new ImportsManager(CodeReader.FILES_PATH);
                //SourceWriter.MakeBackup = !SourceWriter.MakeBackup; /// --> DEFAULT IS NOW FALSE ///
                SourceWriter.SetImportsForModuleFiles(importsManager.ReadDataBankInfos());
                ConstantsFinder.InitializeConstants(CodeReader.FILES_PATH + "module_constants.py");

                CopyDefaultFiles();
            }
        }