protected async Task <CompilationResult> Compile(IFileSystem fileSystem) { var compiler = new CSharpCompiler( fileSystem.GetFiles("GeneratedCode", "*.cs", SearchOption.AllDirectories) .Select(each => new KeyValuePair <string, string>(each, fileSystem.ReadFileAsText(each))).ToArray(), ManagedAssets.FrameworkAssemblies.Concat( AppDomain.CurrentDomain.GetAssemblies() .Where(each => !each.IsDynamic && !string.IsNullOrEmpty(each.Location)) .Select(each => each.Location) .Concat(new[] { Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "Microsoft.Rest.ClientRuntime.dll"), Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "Microsoft.Rest.ClientRuntime.Azure.dll") }) )); var result = await compiler.Compile(OutputKind.DynamicallyLinkedLibrary); // if it failed compiling and we're in an interactive session if (!result.Succeeded && System.Environment.OSVersion.Platform == PlatformID.Win32NT && System.Environment.UserInteractive) { var error = result.Messages.FirstOrDefault(each => each.Severity == DiagnosticSeverity.Error); if (error != null) { // use this to dump the files to disk for examination // open in Favorite Code Editor InspectWithFavoriteCodeEditor(fileSystem.SaveFilesToTemp(GetType().Name), error.Location.GetMappedLineSpan()); } } return(result); }
internal static string SaveFilesToTemp(this IFileSystem fileSystem, string folderName = null) { folderName = string.IsNullOrWhiteSpace(folderName) ? Guid.NewGuid().ToString() : folderName; var outputFolder = Path.Combine(Path.GetTempPath(), folderName); if (Directory.Exists(outputFolder)) { try { fileSystem.EmptyDirectory(outputFolder); fileSystem.DeleteDirectory(outputFolder); } catch { // who cares... } } Directory.CreateDirectory(outputFolder); foreach (var file in fileSystem.GetFiles("", "*", SearchOption.AllDirectories)) { var target = Path.Combine(outputFolder, file.Substring(file.IndexOf(":", StringComparison.Ordinal) + 1)); Directory.CreateDirectory(Path.GetDirectoryName(target)); File.WriteAllText(target, fileSystem.ReadFileAsText(file)); } return(outputFolder); }
public static ServiceDefinition Load(string path, IFileSystem fileSystem) { if (fileSystem == null) { throw new ArgumentNullException("fileSystem"); } return SwaggerParser.Parse(fileSystem.ReadFileAsText(path)); }
public static ServiceDefinition Load(string path, IFileSystem fileSystem) { if (fileSystem == null) { throw new ArgumentNullException("fileSystem"); } return(SwaggerParser.Parse(fileSystem.ReadFileAsText(path))); }
public static ServiceDefinition Load(string path, IFileSystem fileSystem) { if (fileSystem == null) { throw new ArgumentNullException("fileSystem"); } var swaggerDocument = fileSystem.ReadFileAsText(path); return(Parse(path, swaggerDocument)); }
protected async Task <CompilationResult> Compile(IFileSystem fileSystem) { var compiler = new CSharpCompiler( fileSystem.GetFiles("GeneratedCode", "*.cs", SearchOption.AllDirectories) .Select(each => new KeyValuePair <string, string>(each, fileSystem.ReadFileAsText(each))).ToArray(), ManagedAssets.FrameworkAssemblies.Concat( AppDomain.CurrentDomain.GetAssemblies() .Where(each => !each.IsDynamic && !string.IsNullOrEmpty(each.Location)) .Select(each => each.Location) .Concat(new[] { Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "Microsoft.Rest.ClientRuntime.dll") }) )); return(await compiler.Compile(OutputKind.DynamicallyLinkedLibrary)); }
private static async Task<CompilationResult> Compile(IFileSystem fileSystem) { var compiler = new CSharpCompiler( fileSystem.GetFiles("GeneratedCode", "*.cs", SearchOption.AllDirectories) .Select(each => new KeyValuePair<string, string>(each, fileSystem.ReadFileAsText(each))).ToArray(), ManagedAssets.FrameworkAssemblies.Concat( AppDomain.CurrentDomain.GetAssemblies() .Where(each => !each.IsDynamic && !string.IsNullOrEmpty(each.Location)) .Select(each => each.Location) .Concat(new[] { Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "Microsoft.Rest.ClientRuntime.dll"), Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "Microsoft.Rest.ClientRuntime.Azure.dll") }) )); return await compiler.Compile(Microsoft.Rest.CSharp.Compiler.Compilation.OutputKind.DynamicallyLinkedLibrary); }
protected async Task <Microsoft.Rest.CSharp.Compiler.Compilation.CompilationResult> Compile(IFileSystem fileSystem) { var compiler = new CSharpCompiler(fileSystem.GetFiles("GeneratedCode", "*.cs", SearchOption.AllDirectories) .Select(each => new KeyValuePair <string, string>(each, fileSystem.ReadFileAsText(each))).ToArray(), _assemblies); var result = await compiler.Compile(OutputKind.DynamicallyLinkedLibrary); #if false // if it failed compiling and we're in an interactive session if (!result.Succeeded && Environment.OSVersion.Platform == PlatformID.Win32NT && Environment.UserInteractive) { var error = result.Messages.FirstOrDefault(each => each.Severity == DiagnosticSeverity.Error); if (error != null) { // use this to dump the files to disk for examination // open in Favorite Code Editor InspectWithFavoriteCodeEditor(fileSystem.SaveFilesToTemp(GetType().Name), error.Location.GetMappedLineSpan()); } } #endif return(result); }
protected async Task<CompilationResult> Compile(IFileSystem fileSystem) { var compiler = new CSharpCompiler( fileSystem.GetFiles("GeneratedCode", "*.cs", SearchOption.AllDirectories) .Select(each => new KeyValuePair<string, string>(each, fileSystem.ReadFileAsText(each))).ToArray(), ManagedAssets.FrameworkAssemblies.Concat( AppDomain.CurrentDomain.GetAssemblies() .Where(each => !each.IsDynamic && !string.IsNullOrEmpty(each.Location) ) .Select(each => each.Location) .Concat(new[] { Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "Microsoft.Rest.ClientRuntime.dll"), Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "Microsoft.Rest.ClientRuntime.Azure.dll") }) )); var result = await compiler.Compile(OutputKind.DynamicallyLinkedLibrary); // if it failed compiling and we're in an interactive session if (!result.Succeeded && System.Environment.OSVersion.Platform == PlatformID.Win32NT && System.Environment.UserInteractive) { var error = result.Messages.FirstOrDefault(each => each.Severity == DiagnosticSeverity.Error); if (error != null) { // use this to dump the files to disk for examination // open in Favorite Code Editor InspectWithFavoriteCodeEditor(fileSystem.SaveFilesToTemp(GetType().Name), error.Location.GetMappedLineSpan()); } } return result; }
public virtual TCodeModel Load(IFileSystem fileSystem, string path) { return(Load(fileSystem.ReadFileAsText(path))); }