Exemplo n.º 1
0
        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);
            });
        }
Exemplo n.º 2
0
        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(ICompilationProject project, CompileResponse response)
 {
     _project  = project;
     _response = response;
 }
Exemplo n.º 4
0
        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;
            }
        }
Exemplo n.º 5
0
        private void ReceiveMessages()
        {
            try
            {
                while (true)
                {
                    var messageType = _reader.ReadString();
                    if (messageType == "Assembly")
                    {
                        var compileResponse = new CompileResponse();
                        var id = _reader.ReadInt32();
                        var warningsCount = _reader.ReadInt32();
                        compileResponse.Warnings = new string[warningsCount];
                        for (int i = 0; i < warningsCount; i++)
                        {
                            compileResponse.Warnings[i] = _reader.ReadString();
                        }

                        var errorsCount = _reader.ReadInt32();
                        compileResponse.Errors = new string[errorsCount];
                        for (int i = 0; i < errorsCount; i++)
                        {
                            compileResponse.Errors[i] = _reader.ReadString();
                        }
                        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);

                        ProjectCompiled(id, compileResponse);
                    }
                    else if(messageType == "Sources")
                    {
                        int count = _reader.ReadInt32();
                        var files = new List<string>();
                        for (int i = 0; i < count; i++)
                        {
                            files.Add(_reader.ReadString());
                        }

                        ProjectSources(files);
                    }
                    else if (messageType == "ProjectContexts")
                    {
                        int count = _reader.ReadInt32();
                        var projectContexts = new Dictionary<string, int>(StringComparer.OrdinalIgnoreCase);
                        for (int i = 0; i < count; i++)
                        {
                            string key = _reader.ReadString();
                            int id = _reader.ReadInt32();

                            projectContexts[key] = id;
                        }

                        ProjectsInitialized(projectContexts);
                    }
                    else if (messageType == "ProjectChanged")
                    {
                        var id = _reader.ReadInt32();
                        ProjectChanged(id);
                    }
                }
            }
            catch (Exception ex)
            {
                Trace.TraceError("[{0}]: Exception occurred: {1}", GetType().Name, ex);
                Closed();
                return;
            }
        }
Exemplo n.º 6
0
 public DesignTimeProjectReference(Project project, CompileResponse response)
 {
     _project = project;
     _response = response;
 }
Exemplo n.º 7
0
        private void ReceiveMessages()
        {
            try
            {
                while (true)
                {
                    var messageType = _reader.ReadString();
                    if (messageType == "Assembly")
                    {
                        var compileResponse = new CompileResponse();
                        var id            = _reader.ReadInt32();
                        var warningsCount = _reader.ReadInt32();
                        compileResponse.Warnings = new string[warningsCount];
                        for (int i = 0; i < warningsCount; i++)
                        {
                            compileResponse.Warnings[i] = _reader.ReadString();
                        }

                        var errorsCount = _reader.ReadInt32();
                        compileResponse.Errors = new string[errorsCount];
                        for (int i = 0; i < errorsCount; i++)
                        {
                            compileResponse.Errors[i] = _reader.ReadString();
                        }
                        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);

                        ProjectCompiled(id, compileResponse);
                    }
                    else if (messageType == "ProjectContexts")
                    {
                        int count           = _reader.ReadInt32();
                        var projectContexts = new Dictionary <string, int>(StringComparer.OrdinalIgnoreCase);
                        for (int i = 0; i < count; i++)
                        {
                            string key = _reader.ReadString();
                            int    id  = _reader.ReadInt32();

                            projectContexts[key] = id;
                        }

                        ProjectsInitialized(projectContexts);
                    }
                    else if (messageType == "ProjectChanged")
                    {
                        var id = _reader.ReadInt32();
                        ProjectChanged(id);
                    }
                }
            }
            catch (Exception ex)
            {
                Trace.TraceError("[{0}]: Exception occurred: {1}", GetType().Name, ex);
                Closed();
                return;
            }
        }
Exemplo n.º 8
0
        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;
            }
        }