Пример #1
0
        static void Main(string[] args)
        {
            // ** Only works if run from VSDev Command prompt **
            //
            //var instances = MSBuildLocator.QueryVisualStudioInstances().ToList();
            //var instanceToUse = instances.First(a => a.Version.Major == 15);
            //Environment.SetEnvironmentVariable("VSINSTALLDIR", instanceToUse.VisualStudioRootPath);

            Environment.SetEnvironmentVariable("VSINSTALLDIR", @"C:\Program Files (x86)\Microsoft Visual Studio\2017\Community");
            Environment.SetEnvironmentVariable("VisualStudioVersion", "15.0");

            string matterControlRoot = GetMatterControlDirectory();

            var properties = new Dictionary <string, string>
            {
                { "Configuration", "Debug" },
                { "Platform", "AnyCPU" }
            };
            //var workspace = MSBuildWorkspace.Create(properties);
            var workspace = MSBuildWorkspace.Create();

            workspace.WorkspaceFailed += (s, e) => Console.WriteLine(e.Diagnostic.Message);
            workspace.LoadMetadataForReferencedProjects = true;

            string solutionPath = Path.GetFullPath(Path.Combine(matterControlRoot, "..", "MatterControl.sln"));

            Solution solution = workspace.OpenSolutionAsync(solutionPath).Result;

            var translationStrings = new HashSet <string>();

            DiagnosticAnalyzer analyzer = new LocalizeDetector((locstring) =>
            {
                // Add detected Localize() strings to translations list
                translationStrings.AddLocalization(locstring);
            });

            ProjectDependencyGraph projectGraph = solution.GetProjectDependencyGraph();

            // Use Roslyn to find localize calls
            foreach (ProjectId projectId in projectGraph.GetTopologicallySortedProjects())
            {
                var project = solution.GetProject(projectId);
                var compilationWithAnalyzers = project.GetCompilationAsync().Result.WithAnalyzers(ImmutableArray.Create(analyzer));
                var diags = compilationWithAnalyzers.GetAnalyzerDiagnosticsAsync().Result;
            }

            // Push properies.json results into newResults
            string json = File.ReadAllText(Path.Combine(matterControlRoot, "StaticData", "SliceSettings", "Properties.json"));

            foreach (var setting in JsonConvert.DeserializeObject <List <SettingItem> >(json))
            {
                translationStrings.AddLocalization(setting.HelpText);
                translationStrings.AddLocalization(setting.PresentationName);
                if (!string.IsNullOrWhiteSpace(setting.Units))
                {
                    translationStrings.AddLocalization(setting.Units);
                }
            }

            // Push layouts.txt results into newResults
            foreach (var line in File.ReadAllLines(Path.Combine(matterControlRoot, "StaticData", "SliceSettings", "Layouts.txt")).Select(s => s.Trim()))
            {
                var isSliceSettingsKey = line.Contains("_") && !line.Contains(" ");
                if (!isSliceSettingsKey)
                {
                    translationStrings.AddLocalization(line);
                }
            }

            string outputPath = Path.Combine(matterControlRoot, "StaticData", "Translations", "Master.txt");

            using (var outstream = new StreamWriter(outputPath))
            {
                foreach (var line in translationStrings.OrderBy(x => x).ToArray())
                {
                    outstream.WriteLine($"English:{line}");
                    outstream.WriteLine($"Translated:{line}");
                    outstream.WriteLine("");
                }
            }

            System.Diagnostics.Process.Start(outputPath);

            //GenerateComparisonData();
        }
Пример #2
0
        static void Main(string[] args)
        {
            MSBuildLocator.RegisterDefaults();

            string matterControlRoot = GetMatterControlDirectory();

            var workspace = MSBuildWorkspace.Create(new Dictionary <string, string>
            {
                ["Configuration"] = "Debug",
                ["Platform"]      = "AnyCPU"
            });

            workspace.WorkspaceFailed += (s, e) => Console.WriteLine(e.Diagnostic.Message);
            workspace.LoadMetadataForReferencedProjects = true;

            string solutionPath = Path.GetFullPath(Path.Combine(matterControlRoot, "..", "MatterControl.sln"));

            Solution solution = workspace.OpenSolutionAsync(solutionPath).Result;

            var translationStrings = new HashSet <string>();

            DiagnosticAnalyzer analyzer = new LocalizeDetector((locstring) =>
            {
                // Add detected Localize() strings to translations list
                translationStrings.AddLocalization(locstring);
            });

            ProjectDependencyGraph projectGraph = solution.GetProjectDependencyGraph();

            // Use Roslyn to find localize calls
            foreach (ProjectId projectId in projectGraph.GetTopologicallySortedProjects())
            {
                var project = solution.GetProject(projectId);
                var compilationWithAnalyzers = project.GetCompilationAsync().Result.WithAnalyzers(ImmutableArray.Create(analyzer));
                var diags = compilationWithAnalyzers.GetAnalyzerDiagnosticsAsync().Result;
            }

            // Push layouts.txt results into newResults
            foreach (var line in File.ReadAllLines(Path.Combine(matterControlRoot, "StaticData", "SliceSettings", "Layouts.txt")).Select(s => s.Trim()))
            {
                var isSliceSettingsKey = line.Contains("_") && !line.Contains(" ");
                if (!isSliceSettingsKey)
                {
                    translationStrings.AddLocalization(line);
                }
            }

            string outputPath = Path.Combine(matterControlRoot, "StaticData", "Translations", "Master.txt");

            using (var outstream = new StreamWriter(outputPath))
            {
                foreach (var line in translationStrings.OrderBy(x => x).ToArray())
                {
                    outstream.WriteLine($"English:{line}");
                    outstream.WriteLine($"Translated:{line}");
                    outstream.WriteLine("");
                }
            }

            System.Diagnostics.Process.Start(outputPath);

            //GenerateComparisonData();
        }