private async IAsyncEnumerable <ConversionResult> ConvertProjectUnhandled <TLanguageConversion>(IReadOnlyCollection <Project> selectedProjects, [EnumeratorCancellation] CancellationToken cancellationToken) where TLanguageConversion : ILanguageConversion, new() { await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); if (selectedProjects.Count > 1) { await _outputWindow.WriteToOutputWindowAsync($"Converting {selectedProjects.Count} projects...", true, true); } var projectsByPath = _visualStudioWorkspace.CurrentSolution.Projects.ToLookup(p => p.FilePath, p => p); #pragma warning disable VSTHRD010 // Invoke single-threaded types on Main thread - ToList ensures this happens within the same thread just switched to above var projects = selectedProjects.Select(p => projectsByPath[p.FullName].First()).ToList(); #pragma warning restore VSTHRD010 // Invoke single-threaded types on Main thread await TaskScheduler.Default; var solutionConverter = SolutionConverter.CreateFor <TLanguageConversion>(projects, progress: CreateOutputWindowProgress(), cancellationToken: cancellationToken); var results = solutionConverter.Convert(); await foreach (var result in results) { yield return(result); } }
public async IAsyncEnumerable <ConversionResult> ConvertProjectsWhereAsync(Func <Project, bool> shouldConvertProject, Language?targetLanguage, IProgress <ConversionProgress> progress, [EnumeratorCancellation] CancellationToken token) { var strProgress = new Progress <string>(s => progress.Report(new ConversionProgress(s))); #pragma warning disable VSTHRD012 // Provide JoinableTaskFactory where allowed - Shouldn't need main thread, and I can't access ThreadHelper without referencing VS shell. _cachedSolution ??= new AsyncLazy <Solution>(async() => await GetSolutionAsync(_solutionFilePath, strProgress)); #pragma warning restore VSTHRD012 // Provide JoinableTaskFactory where allowed var solution = await _cachedSolution.GetValueAsync(); if (!targetLanguage.HasValue) { targetLanguage = solution.Projects.Any(p => p.Language == LanguageNames.VisualBasic) ? Language.CS : Language.VB; } var languageConversion = targetLanguage == Language.CS ? (ILanguageConversion) new VBToCSConversion() : new CSToVBConversion(); var languageNameToConvert = targetLanguage == Language.CS ? LanguageNames.VisualBasic : LanguageNames.CSharp; var projectsToConvert = solution.Projects.Where(p => p.Language == languageNameToConvert && shouldConvertProject(p)).ToArray(); var results = SolutionConverter.CreateFor(languageConversion, projectsToConvert, progress, token).Convert(); await foreach (var r in results) { yield return(r); } }
private async Task <IEnumerable <ConversionResult> > ConvertProjectUnhandledAsync <TLanguageConversion>(IReadOnlyCollection <Project> selectedProjects) where TLanguageConversion : ILanguageConversion, new() { await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); var projectDesc = selectedProjects.Count == 1 ? selectedProjects.Single().Name : selectedProjects.Count + " projects"; await _outputWindow.WriteToOutputWindowAsync($"Converting {projectDesc}...", true, true); var projectsByPath = _visualStudioWorkspace.CurrentSolution.Projects.ToLookup(p => p.FilePath, p => p); #pragma warning disable VSTHRD010 // Invoke single-threaded types on Main thread - ToList ensures this happens within the same thread just switched to above var projects = selectedProjects.Select(p => projectsByPath[p.FullName].First()).ToList(); #pragma warning restore VSTHRD010 // Invoke single-threaded types on Main thread await TaskScheduler.Default; var solutionConverter = SolutionConverter.CreateFor <TLanguageConversion>(projects, new Progress <ConversionProgress>(s => { _outputWindow.WriteToOutputWindowAsync(FormatForOutputWindow(s)).ForgetNoThrow(); })); return(await solutionConverter.Convert()); }
public async Task ConvertProjectsWhere<TLanguageConversion>(Func<Project, bool> shouldConvertProject, [CallerMemberName] string expectedResultsDirectory = "") where TLanguageConversion : ILanguageConversion, new() { bool recharacterizeByWritingExpectedOverActual = TestConstants.RecharacterizeByWritingExpectedOverActual; var languageNameToConvert = typeof(TLanguageConversion) == typeof(VBToCSConversion) ? LanguageNames.VisualBasic : LanguageNames.CSharp; var projectsToConvert = (await _solution.GetValueAsync()).Projects.Where(p => p.Language == languageNameToConvert && shouldConvertProject(p)).ToArray(); var conversionResults = (await SolutionConverter.CreateFor<TLanguageConversion>(projectsToConvert).Convert()).ToDictionary(c => c.TargetPathOrNull, StringComparer.OrdinalIgnoreCase); var expectedResultDirectory = GetExpectedResultDirectory<TLanguageConversion>(expectedResultsDirectory); try { if (!expectedResultDirectory.Exists) expectedResultDirectory.Create(); var expectedFiles = expectedResultDirectory.GetFiles("*", SearchOption.AllDirectories) .Where(f => !f.FullName.Contains(@"\obj\") && !f.FullName.Contains(@"\bin\")).ToArray(); AssertAllExpectedFilesAreEqual(expectedFiles, conversionResults, expectedResultDirectory, OriginalSolutionDir); AssertAllConvertedFilesWereExpected(expectedFiles, conversionResults, expectedResultDirectory, OriginalSolutionDir); AssertNoConversionErrors(conversionResults); } finally { if (recharacterizeByWritingExpectedOverActual) { if (expectedResultDirectory.Exists) expectedResultDirectory.Delete(true); if (_writeAllFilesForManualTesting) FileSystem.CopyDirectory(OriginalSolutionDir, expectedResultDirectory.FullName); foreach (var conversionResult in conversionResults) { var expectedFilePath = conversionResult.Key.Replace(OriginalSolutionDir, expectedResultDirectory.FullName); Directory.CreateDirectory(Path.GetDirectoryName(expectedFilePath)); File.WriteAllText(expectedFilePath, conversionResult.Value.ConvertedCode); } } } Assert.False(recharacterizeByWritingExpectedOverActual, $"Test setup issue: Set {nameof(recharacterizeByWritingExpectedOverActual)} to false after using it"); }
/// <summary> /// 一个新实例初始化<see cref="FrmMain"/> 类。 /// </summary> public FrmMain() { this.InitializeComponent(); this.solutionConverter = null; this.solutionPath = null; this.ResetForm(); }
internal UpgradeWizard(ISolutionManagement solution, IEnumerable <IProjectStore> projectStoreContext, IProjectStore targetProjectStore, Action solutionUpgradedAction, IServiceProvider serviceProvider) { this.solution = solution; this.serviceProvider = serviceProvider; this.converter = new SolutionConverter(solution, projectStoreContext, targetProjectStore, this.serviceProvider); this.solutionUpgradedAction = solutionUpgradedAction; }
/// <summary> /// Initializes a new instance of the <see cref="Form1"/> class. /// </summary> public Form1() { this.InitializeComponent(); this.solutionConverter = null; this.solutionPath = null; this.ResetForm(); // ProjectConverter a = new ProjectConverter(@"E:\F\BackUp\My Projects\HIT\Year2\C-Sharp\SolutionConverter\SolutionConverter\bin\Debug\TotalLineAccumulator.csproj"); // a.ConvertTo(VisualStudioVersion.VisualStudio2010); }
private IEnumerable <ConversionResult> ConvertProjectUnhandled <TLanguageConversion>(IReadOnlyCollection <Project> selectedProjects) where TLanguageConversion : ILanguageConversion, new() { var projectsByPath = _visualStudioWorkspace.CurrentSolution.Projects.ToLookup(p => p.FilePath, p => p); var projects = selectedProjects.Select(p => projectsByPath[p.FullName].First()).ToList(); var convertedFiles = SolutionConverter.CreateFor <TLanguageConversion>(projects, new Progress <string>(s => _outputWindow.WriteToOutputWindow(Environment.NewLine + s))).Convert(); return(convertedFiles); }
private IEnumerable <ConversionResult> ConvertProjectUnhandled <TLanguageConversion>(IReadOnlyCollection <Project> selectedProjects) where TLanguageConversion : ILanguageConversion, new() { var projectsByPath = _visualStudioWorkspace.CurrentSolution.Projects.ToLookup(p => p.FilePath, p => p); var projects = selectedProjects.Select(p => projectsByPath[p.FullName].First()).ToList(); var convertedFiles = SolutionConverter.CreateFor <TLanguageConversion>(projects).Convert(); return(convertedFiles); }
/// <summary> /// Loads the solution. /// </summary> /// <param name="solutionPath">The solution path.</param> private void LoadSolution(string solutionPath) { if (solutionPath != null) { this.solutionConverter = new SolutionConverter(solutionPath); if (this.solutionConverter.IsReady) { this.Text = "Solution Converter - " + this.solutionConverter.Name; this.SolutionPathLbl.Text = this.solutionConverter.Name + " (" + solutionPath + ")"; this.SolutionPathLbl.Enabled = true; this.CurrentSolutionLbl.Enabled = true; switch (this.solutionConverter.VisualStudioVersion) { case VisualStudioVersion.VisualStudio2002: this.chkVS2002.Checked = true; break; case VisualStudioVersion.VisualStudio2003: this.chkVS2003.Checked = true; break; case VisualStudioVersion.VisualStudio2005: this.chkVS2005.Checked = true; this.ConvertBtn.Enabled = true; break; case VisualStudioVersion.VisualStudio2008: this.chkVS2008.Checked = true; this.ConvertBtn.Enabled = true; break; case VisualStudioVersion.VisualStudio2010: this.chkVS2010.Checked = true; this.ConvertBtn.Enabled = true; break; } switch (this.solutionConverter.IdeVersion) { case IdeVersion.VisualStudio: this.chkVS.Checked = true; break; case IdeVersion.CSExpress: this.chkCsExp.Checked = true; break; case IdeVersion.VBExpress: this.chkVbExp.Checked = true; break; } } } }
static void Main(string[] args) { Logger.Init(); var converter = new SolutionConverter(); converter.Convert(@"C:\TTL\web\source\WebTestComponents\src\Test.Common"); //File convert Logger.Log("End ..."); System.Console.ReadLine(); }
public async Task ConvertProjectsWhere <TLanguageConversion>(Func <Project, bool> shouldConvertProject, [CallerMemberName] string testName = "") where TLanguageConversion : ILanguageConversion, new() { using (var workspace = MSBuildWorkspace.Create(new Dictionary <string, string>() { { "Configuration", "Debug" }, { "Platform", "AnyCPU" } })) { var originalSolutionDir = Path.Combine(GetTestDataDirectory(), "CharacterizationTestSolution"); var solutionFile = Path.Combine(originalSolutionDir, "CharacterizationTestSolution.sln"); var solution = await workspace.OpenSolutionAsync(solutionFile); var languageNameToConvert = typeof(TLanguageConversion) == typeof(VBToCSConversion) ? LanguageNames.VisualBasic : LanguageNames.CSharp; var projectsToConvert = solution.Projects.Where(p => p.Language == languageNameToConvert && shouldConvertProject(p)).ToArray(); var conversionResults = SolutionConverter.CreateFor <TLanguageConversion>(projectsToConvert).Convert().GetAwaiter().GetResult().ToDictionary(c => c.TargetPathOrNull, StringComparer.OrdinalIgnoreCase); var expectedResultDirectory = GetExpectedResultDirectory <TLanguageConversion>(testName); try { if (!expectedResultDirectory.Exists) { expectedResultDirectory.Create(); } var expectedFiles = expectedResultDirectory.GetFiles("*", SearchOption.AllDirectories); AssertAllExpectedFilesAreEqual(expectedFiles, conversionResults, expectedResultDirectory, originalSolutionDir); AssertAllConvertedFilesWereExpected(expectedFiles, conversionResults, expectedResultDirectory, originalSolutionDir); AssertNoConversionErrors(conversionResults); } finally { if (_writeNewCharacterization) { if (expectedResultDirectory.Exists) { expectedResultDirectory.Delete(true); } //FileSystem.CopyDirectory(originalSolutionDir, expectedResultDirectory.FullName); //Uncomment to copy all source files too so the sln is runnable foreach (var conversionResult in conversionResults) { var expectedFilePath = conversionResult.Key.Replace(originalSolutionDir, expectedResultDirectory.FullName); Directory.CreateDirectory(Path.GetDirectoryName(expectedFilePath)); File.WriteAllText(expectedFilePath, conversionResult.Value.ConvertedCode); } } } } Assert.False(_writeNewCharacterization, $"Test setup issue: Set {nameof(_writeNewCharacterization)} to false after using it"); }
/// <summary> /// Resets the form. /// </summary> private void ResetForm() { this.Text = "Solution Converter"; foreach (Control chkBox in this.panel1.Controls) { (chkBox as CheckBox).Checked = false; } this.SolutionPathLbl.Text = "N/A"; this.SolutionPathLbl.Enabled = false; this.CurrentSolutionLbl.Enabled = false; this.ConvertBtn.Enabled = false; this.solutionPath = null; this.solutionConverter = null; }
private async Task <IEnumerable <ConversionResult> > ConvertProjectUnhandledAsync <TLanguageConversion>(IReadOnlyCollection <Project> selectedProjects) where TLanguageConversion : ILanguageConversion, new() { await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); var projectsByPath = _visualStudioWorkspace.CurrentSolution.Projects.ToLookup(p => p.FilePath, p => p); #pragma warning disable VSTHRD010 // Invoke single-threaded types on Main thread - ToList ensures this happens within the same thread just switched to above var projects = selectedProjects.Select(p => projectsByPath[p.FullName].First()).ToList(); #pragma warning restore VSTHRD010 // Invoke single-threaded types on Main thread var solutionConverter = SolutionConverter.CreateFor <TLanguageConversion>(projects, new Progress <string>(s => { var unusedFireAndForget = LogProgressAsync(s); })); return(await ThreadHelper.JoinableTaskFactory.RunAsync(() => solutionConverter.Convert())); }
public void ConvertProjectsWhere <TLanguageConversion>(Func <Project, bool> shouldConvertProject, [CallerMemberName] string testName = "") where TLanguageConversion : ILanguageConversion, new() { using (var workspace = MSBuildWorkspace.Create()) { var solutionDir = Path.Combine(GetTestDataDirectory(), "CharacterizationTestSolution"); var solutionFile = Path.Combine(solutionDir, "CharacterizationTestSolution.sln"); var solution = workspace.OpenSolutionAsync(solutionFile).GetAwaiter().GetResult(); var languageNameToConvert = typeof(TLanguageConversion) == typeof(VBToCSConversion) ? LanguageNames.VisualBasic : LanguageNames.CSharp; var projectsToConvert = solution.Projects.Where(p => p.Language == languageNameToConvert && shouldConvertProject(p)).ToArray(); var conversionResults = SolutionConverter.CreateFor <TLanguageConversion>(projectsToConvert).Convert().ToDictionary(c => c.TargetPathOrNull); var expectedResultDirectory = GetExpectedResultDirectory <TLanguageConversion>(testName); try { var expectedFiles = expectedResultDirectory.GetFiles("*", SearchOption.AllDirectories); foreach (var expectedFile in expectedFiles) { AssertFileEqual(conversionResults, expectedResultDirectory, expectedFile, solutionDir); } } catch (Exception e) when(_writeNewCharacterization) { Console.Error.WriteLine(e); if (expectedResultDirectory.Exists) { expectedResultDirectory.Delete(true); } FileSystem.CopyDirectory(solutionDir, expectedResultDirectory.FullName); foreach (var conversionResult in conversionResults) { var expectedFilePath = conversionResult.Key.Replace(solutionDir, expectedResultDirectory.FullName); Directory.CreateDirectory(Path.GetDirectoryName(expectedFilePath)); File.WriteAllText(expectedFilePath, conversionResult.Value.ConvertedCode); } } } }
/// <summary> /// 加载方案。 /// </summary> /// <param name="solutionPath">解决的路径。</param> private void LoadSolution(string solutionPath) { if (solutionPath != null) { foreach (Control chkBox in this.panel1.Controls) { (chkBox as CheckBox).Checked = false; } this.solutionConverter = new SolutionConverter(solutionPath); if (this.solutionConverter.IsReady) { this.Text = "VS版本转换器 - " + this.solutionConverter.Name; this.SolutionPathLbl.Text = this.solutionConverter.Name + " (" + solutionPath + ")"; this.SolutionPathLbl.Enabled = true; this.CurrentSolutionLbl.Enabled = true; switch (this.solutionConverter.VisualStudioVersion) { case VisualStudioVersion.VisualStudio2002: this.chkVS2002.Checked = true; break; case VisualStudioVersion.VisualStudio2003: this.chkVS2003.Checked = true; break; case VisualStudioVersion.VisualStudio2005: this.chkVS2005.Checked = true; this.ConvertBtn.Enabled = true; break; case VisualStudioVersion.VisualStudio2008: this.chkVS2008.Checked = true; this.ConvertBtn.Enabled = true; break; case VisualStudioVersion.VisualStudio2010: this.chkVS2010.Checked = true; this.ConvertBtn.Enabled = true; break; case VisualStudioVersion.VisualStudio2012: this.chkVS2012.Checked = true; this.ConvertBtn.Enabled = true; break; case VisualStudioVersion.VisualStudio2013: this.chkVS2013.Checked = true; this.ConvertBtn.Enabled = true; break; case VisualStudioVersion.VisualStudio2015: this.chkVS2015.Checked = true; this.ConvertBtn.Enabled = true; break; } switch (this.solutionConverter.IdeVersion) { case IdeVersion.VisualStudio: this.chkVS.Checked = true; break; case IdeVersion.CSExpress: this.chkCsExp.Checked = true; break; case IdeVersion.VBExpress: this.chkVbExp.Checked = true; break; } } } }
/// <summary> /// 将重置表单。 /// </summary> private void ResetForm() { this.Text = "VS版本转换器"; foreach (Control chkBox in this.panel1.Controls) { (chkBox as CheckBox).Checked = false; } this.SolutionPathLbl.Text = "不可用/不适用"; this.SolutionPathLbl.Enabled = false; this.CurrentSolutionLbl.Enabled = false; this.ConvertBtn.Enabled = false; this.solutionPath = null; this.solutionConverter = null; }