static async Task TestClientAsync() { //var workspace = Microsoft.CodeAnalysis.MSBuild.MSBuildWorkspace.Create(); //var solution = await workspace.OpenSolutionAsync(@"C:\Users\lwischik\Documents\Visual Studio 2015\Projects\ConsoleApplicationCS\ConsoleApplicationCS.sln"); //var project = solution.Projects.Single(); var workspace = new Microsoft.DotNet.ProjectModel.Workspaces.ProjectJsonWorkspace(SampleProjectsDirectory + "/ConsoleApp1"); var solution = workspace.CurrentSolution; var project = solution.Projects.Single(); var txt = "int x = 15;\r\nint y = x+2;\r\nSystem.Console.WriteLine(y);\r\n"; project = project.AddDocument("a.csx", txt, null, "c:\\a.csx").WithSourceCodeKind(SourceCodeKind.Script).Project; project = await ReplayHost.InstrumentProjectAsync(project, ImmutableArray <Diagnostic> .Empty, CancellationToken.None); var document = project.Documents.FirstOrDefault(d => Path.GetFileName(d.FilePath) == "a.csx"); if (document != null) { Console.WriteLine($"{document.FilePath}\r\n{await document.GetTextAsync()}"); } var result = await ReplayHost.BuildAsync(project, CancellationToken.None); foreach (var d in result.Diagnostics) { if (d.Severity != DiagnosticSeverity.Error && d.Severity != DiagnosticSeverity.Warning) { continue; } var path = d.Location.IsInSource ? Path.GetFileName(d.Location.SourceTree.FilePath) : ""; var line = d.Location.IsInSource ? d.Location.GetMappedLineSpan().StartLinePosition.Line.ToString() : ""; Console.WriteLine($"{path}({line}):{d.GetMessage()}"); } if (!result.Success) { return; } var process = await ReplayHost.LaunchProcessAsync(result.ReplayOutputFilePath, CancellationToken.None); var cts = new CancellationTokenSource(); var task = Runner(process, cts.Token); var cmd = $"WATCH\t{document.FilePath}\t1\t40\t0"; Console.WriteLine(cmd); await process.PostLineAsync(cmd, CancellationToken.None); while (true) { cmd = await Task.Run(Console.In.ReadLineAsync); if (cmd == null) { break; } await process.PostLineAsync(cmd, CancellationToken.None); } cts.Cancel(); await task.IgnoreCancellation(); }
public static void Main(string[] args) { var solution = new ProjectJsonWorkspace(projectPath).CurrentSolution; solution = RenameNamespace("FastQuant", "SmartQuant", solution); solution = RenameClass("Message", "Message_", solution); solution = RenameClass("Command", "Command_", solution); solution = RenameClass("Response", "Response_", solution); var pids = solution.Projects.Where(p => p.Name.StartsWith("FastQuant")).Select(p => p.Id); foreach (var id in pids) solution = solution.WithProjectAssemblyName(id, NewAssemblyName); foreach (var p in solution.Projects) GenerateDll(p); Console.WriteLine("Succeed!"); }
static async Task TestHostAsync(string projectName) { Project project; if (projectName == "ConsoleApp1") { var workspace = new Microsoft.DotNet.ProjectModel.Workspaces.ProjectJsonWorkspace(SampleProjectsDirectory + "/ConsoleApp1"); var solution = workspace.CurrentSolution; project = solution.Projects.Single(); var txt = "int x = 15;\r\nint y = x+2;\r\nSystem.Console.WriteLine(y);\r\n"; var document = project.AddDocument("a.csx", txt, null, "c:\\a.csx").WithSourceCodeKind(SourceCodeKind.Script); project = document.Project; } else if (projectName == "Methods") { project = await ScriptWorkspace.FromDirectoryScanAsync(SampleProjectsDirectory + "/Methods"); } else { throw new ArgumentException("Projects 'ConsoleApp1' and 'Methods' both work", nameof(projectName)); } var host = new ReplayHost(false); host.DiagnosticChanged += (isAdd, tag, diagnostic, deferrable, cancel) => { if (isAdd) { Console.WriteLine($"+D{tag}: {diagnostic.GetMessage()}"); } else { Console.WriteLine($"-D{tag}"); } }; host.AdornmentChanged += (isAdd, tag, file, line, content, deferrable, cancel) => { if (isAdd) { Console.WriteLine($"+A{tag}: {Path.GetFileName(file)}({line}) {content}"); } else { Console.WriteLine($"-A{tag}"); } }; host.Erred += (error, deferrable, cancel) => { Console.WriteLine(error); }; Console.WriteLine("PROJECT"); await host.ChangeDocumentAsync(project, null, 0, 0, 0); Console.WriteLine("VIEW"); await host.WatchAsync(); if (projectName == "ConsoleApp1") { Console.WriteLine("CHANGE"); var txt = "int x = 15;\r\nint y = x+2;d\r\nSystem.Console.WriteLine(y);\r\n"; var document = project.Documents.First(d => d.Name == "a.csx"); document = document.WithText(SourceText.From(txt)); project = document.Project; await host.ChangeDocumentAsync(project, "a.csx", 1, 1, 1); } else if (projectName == "Methods") { Console.WriteLine("CHANGE MARKDOWN"); var document = project.Documents.First(d => d.Name == "methods.md"); var src = document.GetTextAsync().Result; var txt = src.ToString(); int i = src.Lines.FindIndex(line => txt.Substring(line.Span.Start, line.Span.Length) == "Introductory prose"); txt = txt.Replace("Introductory prose", "Some\nintroduction."); document = document.WithText(SourceText.From(txt)); project = document.Project; // document = project.Documents.First(d => d.Name == "methods.md.csx"); txt = ScriptWorkspace.Md2Csx("methods.md", txt); document = document.WithText(SourceText.From(txt)); project = document.Project; await host.ChangeDocumentAsync(project, "methods.md", i, 1, 2); Console.WriteLine("VIEW"); await host.WatchAsync(); Console.WriteLine("CHANGE CODE"); document = project.Documents.First(d => d.Name == "methods.md"); src = document.GetTextAsync().Result; txt = src.ToString(); i = src.Lines.FindIndex(line => txt.Substring(line.Span.Start, line.Span.Length) == "var txt = GetText();"); txt = txt.Replace("var txt = GetText();", "var txt = GetText();\n"); document = document.WithText(SourceText.From(txt)); project = document.Project; // document = project.Documents.First(d => d.Name == "methods.md.csx"); src = document.GetTextAsync().Result; txt = src.ToString(); txt = txt.Replace("var txt = GetText();", "var txt = GetText();\n"); document = document.WithText(SourceText.From(txt)); project = document.Project; // await host.ChangeDocumentAsync(project, "methods.md", i, 1, 2); } Console.WriteLine("DONE"); }