private void OnProjectCompiled(int contextId, CompileResponse response) { _compileResponses.AddOrUpdate(contextId, _ => { var tcs = new TaskCompletionSource <CompileResponse>(); tcs.SetResult(response); return(tcs); }, (_, existing) => { if (!existing.TrySetResult(response)) { var tcs = new TaskCompletionSource <CompileResponse>(); tcs.SetResult(response); return(tcs); } return(existing); }); }
private void OnProjectCompiled(int contextId, CompileResponse response) { _compileResponses.AddOrUpdate(contextId, _ => { var tcs = new TaskCompletionSource<CompileResponse>(); tcs.SetResult(response); return tcs; }, (_, existing) => { if (!existing.TrySetResult(response)) { var tcs = new TaskCompletionSource<CompileResponse>(); tcs.SetResult(response); return tcs; } return existing; }); }
public DesignTimeProjectReference(CompilationProjectContext project, CompileResponse response) { _project = project; _response = response; }
private void ReceiveMessages() { try { while (true) { var metadata = _reader.ReadString(); var obj = JsonDeserializer.Deserialize(new StringReader(metadata)) as JsonObject; var messageType = obj.ValueAsString("MessageType"); switch (messageType) { case "Assembly": //{ // "MessageType": "Assembly", // "ContextId": 1, // "AssemblyPath": null, // "Diagnostics": [], // "Blobs": 2 //} // Embedded Refs (special) // Blob 1 // Blob 2 var compileResponse = new CompileResponse(); compileResponse.AssemblyPath = obj.ValueAsString(nameof(CompileResponse.AssemblyPath)); compileResponse.Diagnostics = ValueAsCompilationMessages(obj, (nameof(CompileResponse.Diagnostics))); int contextId = obj.ValueAsInt("ContextId"); int blobs = obj.ValueAsInt("Blobs"); var embeddedReferencesCount = _reader.ReadInt32(); compileResponse.EmbeddedReferences = new Dictionary<string, byte[]>(); for (int i = 0; i < embeddedReferencesCount; i++) { var key = _reader.ReadString(); int valueLength = _reader.ReadInt32(); var value = _reader.ReadBytes(valueLength); compileResponse.EmbeddedReferences[key] = value; } var assemblyBytesLength = _reader.ReadInt32(); compileResponse.AssemblyBytes = _reader.ReadBytes(assemblyBytesLength); var pdbBytesLength = _reader.ReadInt32(); compileResponse.PdbBytes = _reader.ReadBytes(pdbBytesLength); // Skip over blobs that aren't understood for (int i = 0; i < blobs - 2; i++) { int length = _reader.ReadInt32(); _reader.ReadBytes(length); } ProjectCompiled(contextId, compileResponse); break; case "Sources": //{ // "MessageType": "Sources", // "Files": [], //} var files = obj.ValueAsStringArray("Files"); ProjectSources(files); break; case "ProjectContexts": //{ // "MessageType": "ProjectContexts", // "Projects": { "path": id }, //} var projects = obj.ValueAsJsonObject("Projects"); var projectContexts = new Dictionary<string, int>(StringComparer.OrdinalIgnoreCase); foreach (var key in projects.Keys) { projectContexts[key] = projects.ValueAsInt(key); } ProjectsInitialized(projectContexts); break; case "ProjectChanged": { //{ // "MessageType": "ProjectChanged", // "ContextId": id, //} int id = obj.ValueAsInt("ContextId"); ProjectChanged(id); } break; case "Error": //{ // "MessageType": "Error", // "ContextId": id, // "Payload": { // "Message": "", // "Path": "", // "Line": 0, // "Column": 1 // } //} { var id = obj.ValueAsInt("ContextId"); var message = obj.ValueAsJsonObject("Payload"). ValueAsString("Message"); Error(id, message); } break; default: break; } } } catch (Exception ex) { Logger.TraceError("[{0}]: Exception occurred: {1}", GetType().Name, ex); Closed(); return; } }
public DesignTimeProjectReference(CompilationProjectContext project, CompileResponse response) { _project = project; _response = response; }
private void ReceiveMessages() { try { while (true) { var metadata = _reader.ReadString(); var obj = JsonDeserializer.Deserialize(new StringReader(metadata)) as JsonObject; var messageType = obj.ValueAsString("MessageType"); switch (messageType) { case "Assembly": //{ // "MessageType": "Assembly", // "ContextId": 1, // "AssemblyPath": null, // "Diagnostics": [], // "Blobs": 2 //} // Embedded Refs (special) // Blob 1 // Blob 2 var compileResponse = new CompileResponse(); compileResponse.AssemblyPath = obj.ValueAsString(nameof(CompileResponse.AssemblyPath)); compileResponse.Diagnostics = ValueAsCompilationMessages(obj, (nameof(CompileResponse.Diagnostics))); int contextId = obj.ValueAsInt("ContextId"); int blobs = obj.ValueAsInt("Blobs"); var embeddedReferencesCount = _reader.ReadInt32(); compileResponse.EmbeddedReferences = new Dictionary <string, byte[]>(); for (int i = 0; i < embeddedReferencesCount; i++) { var key = _reader.ReadString(); int valueLength = _reader.ReadInt32(); var value = _reader.ReadBytes(valueLength); compileResponse.EmbeddedReferences[key] = value; } var assemblyBytesLength = _reader.ReadInt32(); compileResponse.AssemblyBytes = _reader.ReadBytes(assemblyBytesLength); var pdbBytesLength = _reader.ReadInt32(); compileResponse.PdbBytes = _reader.ReadBytes(pdbBytesLength); // Skip over blobs that aren't understood for (int i = 0; i < blobs - 2; i++) { int length = _reader.ReadInt32(); _reader.ReadBytes(length); } ProjectCompiled(contextId, compileResponse); break; case "Sources": //{ // "MessageType": "Sources", // "Files": [], //} var files = obj.ValueAsStringArray("Files"); ProjectSources(files); break; case "ProjectContexts": //{ // "MessageType": "ProjectContexts", // "Projects": { "path": id }, //} var projects = obj.ValueAsJsonObject("Projects"); var projectContexts = new Dictionary <string, int>(StringComparer.OrdinalIgnoreCase); foreach (var key in projects.Keys) { projectContexts[key] = projects.ValueAsInt(key); } ProjectsInitialized(projectContexts); break; case "ProjectChanged": { //{ // "MessageType": "ProjectChanged", // "ContextId": id, //} int id = obj.ValueAsInt("ContextId"); ProjectChanged(id); } break; case "Error": //{ // "MessageType": "Error", // "ContextId": id, // "Payload": { // "Message": "", // "Path": "", // "Line": 0, // "Column": 1 // } //} { var id = obj.ValueAsInt("ContextId"); var message = obj.ValueAsJsonObject("Payload"). ValueAsString("Message"); Error(id, message); } break; default: break; } } } catch (Exception ex) { Logger.TraceError("[{0}]: Exception occurred: {1}", GetType().Name, ex); Closed(); return; } }