private void WriteAssembly(ProjectWorld project, BinaryWriter writer)
 {
     writer.Write("Assembly");
     writer.Write(Id);
     writer.Write(project.Diagnostics.Warnings.Count);
     foreach (var warning in project.Diagnostics.Warnings)
     {
         writer.Write(warning);
     }
     writer.Write(project.Diagnostics.Errors.Count);
     foreach (var error in project.Diagnostics.Errors)
     {
         writer.Write(error);
     }
     writer.Write(project.Outputs.EmbeddedReferences.Count);
     foreach (var pair in project.Outputs.EmbeddedReferences)
     {
         writer.Write(pair.Key);
         writer.Write(pair.Value.Length);
         writer.Write(pair.Value);
     }
     writer.Write(project.Outputs.AssemblyBytes.Length);
     writer.Write(project.Outputs.AssemblyBytes);
     writer.Write(project.Outputs.PdbBytes.Length);
     writer.Write(project.Outputs.PdbBytes);
 }
Beispiel #2
0
        private void WriteAssembly(int version, ProjectWorld project, BinaryWriter writer)
        {
            if (version == 0)
            {
                writer.Write("Assembly");
                writer.Write(Id);

                writer.Write(project.CompilationDiagnostics.Warnings.Count);
                foreach (var warning in project.CompilationDiagnostics.Warnings)
                {
                    writer.Write(warning.FormattedMessage);
                }

                writer.Write(project.CompilationDiagnostics.Errors.Count);
                foreach (var error in project.CompilationDiagnostics.Errors)
                {
                    writer.Write(error.FormattedMessage);
                }

                WriteAssembly(project, writer);
            }
            else
            {
                var obj = new JObject();
                obj["MessageType"] = "Assembly";
                obj["ContextId"]   = Id;
                obj[nameof(CompileResponse.Diagnostics)]  = ConvertToJArray(project.CompilationDiagnostics.Diagnostics);
                obj[nameof(CompileResponse.AssemblyPath)] = project.Outputs.AssemblyPath;
                obj["Blobs"] = 2;
                writer.Write(obj.ToString(Formatting.None));

                WriteAssembly(project, writer);
            }
        }
Beispiel #3
0
        private void SendCompiledAssemblies(ProjectWorld localProject)
        {
            if (localProject.Outputs == null)
            {
                return;
            }

            List <CompiledAssemblyState> waitingForCompiledAssemblies;

            if (_waitingForCompiledAssemblies.TryGetValue(localProject.TargetFramework, out waitingForCompiledAssemblies))
            {
                foreach (var waitingForCompiledAssembly in waitingForCompiledAssemblies)
                {
                    if (!waitingForCompiledAssembly.AssemblySent)
                    {
                        Trace.TraceInformation("[ApplicationContext]: OnTransmit(Assembly)");

                        waitingForCompiledAssembly.Connection.Transmit(writer =>
                        {
                            WriteProjectSources(localProject, writer);
                            WriteAssembly(localProject, writer);
                        });

                        waitingForCompiledAssembly.AssemblySent = true;
                    }
                }
            }
        }
Beispiel #4
0
 private void WriteProjectSources(ProjectWorld project, BinaryWriter writer)
 {
     writer.Write("Sources");
     writer.Write(project.Sources.Files.Count);
     foreach (var file in project.Sources.Files)
     {
         writer.Write(file);
     }
 }
Beispiel #5
0
        public override bool PreDraw(SpriteBatch s, Color lightColor)
        {
            Player  owner          = Main.player[projectile.owner];
            Vector2 OwnerPos       = new Vector2(owner.position.X + owner.width / 2, owner.position.Y + owner.height / 2);
            Vector2 ProjPos        = new Vector2(projectile.position.X + projectile.width / 2, projectile.position.Y + projectile.height / 2);
            float   targetrotation = (float)Math.Atan2((ProjPos.Y - OwnerPos.Y), (ProjPos.X - OwnerPos.X));

            ProjectWorld.DrawChain(OwnerPos, ProjPos, texture, s);

            return(true);
        }
Beispiel #6
0
 private static void WriteAssembly(ProjectWorld project, BinaryWriter writer)
 {
     writer.Write(project.Outputs.EmbeddedReferences.Count);
     foreach (var pair in project.Outputs.EmbeddedReferences)
     {
         writer.Write(pair.Key);
         writer.Write(pair.Value.Length);
         writer.Write(pair.Value);
     }
     writer.Write(project.Outputs.AssemblyBytes.Length);
     writer.Write(project.Outputs.AssemblyBytes);
     writer.Write(project.Outputs.PdbBytes.Length);
     writer.Write(project.Outputs.PdbBytes);
 }
Beispiel #7
0
 private void WriteProjectSources(int version, ProjectWorld project, BinaryWriter writer)
 {
     if (version == 0)
     {
         writer.Write("Sources");
         writer.Write(project.Sources.Files.Count);
         foreach (var file in project.Sources.Files)
         {
             writer.Write(file);
         }
     }
     else
     {
         var obj = new JObject();
         obj["MessageType"] = "Sources";
         obj["Files"]       = new JArray(project.Sources.Files);
         writer.Write(obj.ToString(Formatting.None));
     }
 }
        private void SendCompiledAssemblies(ProjectWorld localProject)
        {
            List <CompiledAssemblyState> waitingForCompiledAssemblies;

            if (_waitingForCompiledAssemblies.TryGetValue(localProject.TargetFramework, out waitingForCompiledAssemblies))
            {
                for (int i = waitingForCompiledAssemblies.Count - 1; i >= 0; i--)
                {
                    var waitingForCompiledAssembly = waitingForCompiledAssemblies[i];

                    if (!waitingForCompiledAssembly.AssemblySent)
                    {
                        Trace.TraceInformation("[ApplicationContext]: OnTransmit(Assembly)");

                        waitingForCompiledAssembly.Connection.Transmit(writer =>
                        {
                            WriteAssembly(localProject, writer);
                        });

                        waitingForCompiledAssembly.AssemblySent = true;
                    }

                    if (waitingForCompiledAssembly.ProjectChanged && !waitingForCompiledAssembly.ProjectChangedSent)
                    {
                        Trace.TraceInformation("[ApplicationContext]: OnTransmit(ProjectChanged)");

                        waitingForCompiledAssembly.Connection.Transmit(writer =>
                        {
                            writer.Write("ProjectChanged");
                            writer.Write(Id);
                        });

                        waitingForCompiledAssembly.ProjectChangedSent = true;

                        waitingForCompiledAssemblies.Remove(waitingForCompiledAssembly);
                    }
                }
            }
        }
Beispiel #9
0
        private bool UpdateProjectCompilation(ProjectWorld project, out ProjectCompilation compilation)
        {
            var export = project.ApplicationHostContext.LibraryManager.GetLibraryExport(_local.ProjectInformation.Name);

            ProjectCompilation oldCompilation;

            if (!_compilations.TryGetValue(project.TargetFramework, out oldCompilation) ||
                export != oldCompilation?.Export)
            {
                compilation                    = new ProjectCompilation();
                compilation.Export             = export;
                compilation.EmbeddedReferences = new Dictionary <string, byte[]>();
                foreach (var reference in compilation.Export.MetadataReferences)
                {
                    if (compilation.ProjectReference == null)
                    {
                        compilation.ProjectReference = reference as IMetadataProjectReference;
                    }

                    var embedded = reference as IMetadataEmbeddedReference;
                    if (embedded != null)
                    {
                        compilation.EmbeddedReferences[embedded.Name] = embedded.Contents;
                    }
                }

                var diagnostics = compilation.ProjectReference.GetDiagnostics();
                compilation.Errors   = diagnostics.Errors.ToList();
                compilation.Warnings = diagnostics.Warnings.ToList();

                _compilations[project.TargetFramework] = compilation;

                return(true);
            }

            compilation = oldCompilation;
            return(false);
        }
Beispiel #10
0
        private bool UpdateProjectCompilation(ProjectWorld project, out ProjectCompilation compilation)
        {
            var exporter = _compilationEngine.CreateProjectExporter(_local.Project, project.TargetFramework, _configuration.Value);
            var export   = exporter.GetExport(_local.ProjectInformation.Name);

            ProjectCompilation oldCompilation;

            if (!_compilations.TryGetValue(project.TargetFramework, out oldCompilation) ||
                export != oldCompilation?.Export)
            {
                compilation                    = new ProjectCompilation();
                compilation.Export             = export;
                compilation.EmbeddedReferences = new Dictionary <string, byte[]>();
                foreach (var reference in compilation.Export.MetadataReferences)
                {
                    if (compilation.ProjectReference == null)
                    {
                        compilation.ProjectReference = reference as IMetadataProjectReference;
                    }

                    var embedded = reference as IMetadataEmbeddedReference;
                    if (embedded != null)
                    {
                        compilation.EmbeddedReferences[embedded.Name] = embedded.Contents;
                    }
                }

                var diagnostics = compilation.ProjectReference.GetDiagnostics();
                compilation.Diagnostics = diagnostics.Diagnostics.ToList();

                _compilations[project.TargetFramework] = compilation;

                return(true);
            }

            compilation = oldCompilation;
            return(false);
        }
        private void Reconcile()
        {
            if (IsDifferent(_local.ProjectInformation, _remote.ProjectInformation))
            {
                Trace.TraceInformation("[ApplicationContext]: OnTransmit(ProjectInformation)");

                _initializedContext.Transmit(new Message
                {
                    ContextId   = Id,
                    MessageType = "ProjectInformation",
                    Payload     = JToken.FromObject(_local.ProjectInformation)
                });

                _remote.ProjectInformation = _local.ProjectInformation;
            }

            var unprocessedFrameworks = new HashSet <FrameworkName>(_remote.Projects.Keys);

            foreach (var pair in _local.Projects)
            {
                ProjectWorld localProject = pair.Value;
                ProjectWorld remoteProject;

                if (!_remote.Projects.TryGetValue(pair.Key, out remoteProject))
                {
                    remoteProject = new ProjectWorld();
                    _remote.Projects[pair.Key] = remoteProject;
                }

                unprocessedFrameworks.Remove(pair.Key);

                if (IsDifferent(localProject.Dependencies, remoteProject.Dependencies))
                {
                    Trace.TraceInformation("[ApplicationContext]: OnTransmit(Dependencies)");

                    _initializedContext.Transmit(new Message
                    {
                        ContextId   = Id,
                        MessageType = "Dependencies",
                        Payload     = JToken.FromObject(localProject.Dependencies)
                    });

                    remoteProject.Dependencies = localProject.Dependencies;
                }

                if (IsDifferent(localProject.CompilerOptions, remoteProject.CompilerOptions))
                {
                    Trace.TraceInformation("[ApplicationContext]: OnTransmit(CompilerOptions)");

                    _initializedContext.Transmit(new Message
                    {
                        ContextId   = Id,
                        MessageType = "CompilerOptions",
                        Payload     = JToken.FromObject(localProject.CompilerOptions)
                    });

                    remoteProject.CompilerOptions = localProject.CompilerOptions;
                }

                if (IsDifferent(localProject.References, remoteProject.References))
                {
                    Trace.TraceInformation("[ApplicationContext]: OnTransmit(References)");

                    _initializedContext.Transmit(new Message
                    {
                        ContextId   = Id,
                        MessageType = "References",
                        Payload     = JToken.FromObject(localProject.References)
                    });

                    remoteProject.References = localProject.References;
                }

                if (IsDifferent(localProject.Diagnostics, remoteProject.Diagnostics))
                {
                    Trace.TraceInformation("[ApplicationContext]: OnTransmit(Diagnostics)");

                    _initializedContext.Transmit(new Message
                    {
                        ContextId   = Id,
                        MessageType = "Diagnostics",
                        Payload     = JToken.FromObject(localProject.Diagnostics)
                    });

                    remoteProject.Diagnostics = localProject.Diagnostics;
                }

                if (IsDifferent(localProject.Sources, remoteProject.Sources))
                {
                    Trace.TraceInformation("[ApplicationContext]: OnTransmit(Sources)");

                    _initializedContext.Transmit(new Message
                    {
                        ContextId   = Id,
                        MessageType = "Sources",
                        Payload     = JToken.FromObject(localProject.Sources)
                    });

                    remoteProject.Sources = localProject.Sources;
                }

                SendCompiledAssemblies(localProject);
            }

            SendDiagnostics();

            // Remove all processed frameworks from the remote view
            foreach (var framework in unprocessedFrameworks)
            {
                _remote.Projects.Remove(framework);
            }
        }
        private void Calculate()
        {
            if (_appPath.WasAssigned ||
                _configuration.WasAssigned ||
                _filesChanged.WasAssigned ||
                _rebuild.WasAssigned)
            {
                bool triggerBuildOutputs = _rebuild.WasAssigned;

                _appPath.ClearAssigned();
                _configuration.ClearAssigned();
                _filesChanged.ClearAssigned();
                _rebuild.ClearAssigned();

                _state.Value = Initialize(_appPath.Value, _configuration.Value, triggerBuildOutputs);
            }

            var state = _state.Value;

            if (_state.WasAssigned && state != null)
            {
                _state.ClearAssigned();

                _local = new World();
                _local.ProjectInformation = new ProjectMessage
                {
                    Name = state.Name,

                    // All target framework information
                    Frameworks = state.Frameworks,

                    // debug/release etc
                    Configurations = state.Configurations,

                    Commands = state.Commands,

                    ProjectSearchPaths = state.ProjectSearchPaths,

                    GlobalJsonPath = state.GlobalJsonPath
                };

                for (int i = 0; i < state.Projects.Count; i++)
                {
                    var project       = state.Projects[i];
                    var frameworkData = project.TargetFramework;

                    var projectWorld = new ProjectWorld
                    {
                        TargetFramework = project.FrameworkName,
                        Sources         = new SourcesMessage
                        {
                            Framework = frameworkData,
                            Files     = project.Metadata.SourceFiles
                        },
                        CompilerOptions = new CompilationOptionsMessage
                        {
                            Framework          = frameworkData,
                            CompilationOptions = project.CompilationSettings
                        },
                        Dependencies = new DependenciesMessage
                        {
                            Framework      = frameworkData,
                            RootDependency = state.Name,
                            Dependencies   = project.Dependencies
                        },
                        References = new ReferencesMessage
                        {
                            Framework         = frameworkData,
                            ProjectReferences = project.ProjectReferences,
                            FileReferences    = project.Metadata.References,
                            RawReferences     = project.Metadata.RawReferences
                        },
                        Diagnostics = new DiagnosticsMessage
                        {
                            Framework = frameworkData,
                            Errors    = project.Metadata.Errors,
                            Warnings  = project.Metadata.Warnings
                        },
                        Outputs = new OutputsMessage
                        {
                            FrameworkData      = frameworkData,
                            AssemblyBytes      = project.Output.AssemblyBytes,
                            PdbBytes           = project.Output.PdbBytes,
                            AssemblyPath       = project.Output.AssemblyPath,
                            EmbeddedReferences = project.Output.EmbeddedReferences
                        }
                    };

                    _local.Projects[project.FrameworkName] = projectWorld;

                    List <CompiledAssemblyState> waitingForCompiledAssemblies;
                    if (_waitingForCompiledAssemblies.TryGetValue(project.FrameworkName, out waitingForCompiledAssemblies))
                    {
                        foreach (var waitingForCompiledAssembly in waitingForCompiledAssemblies)
                        {
                            if (waitingForCompiledAssembly.AssemblySent)
                            {
                                waitingForCompiledAssembly.ProjectChanged = true;
                            }
                        }
                    }
                }
            }
        }
Beispiel #13
0
        private bool DoStageOne()
        {
            State state = null;

            if (_appPath.WasAssigned ||
                _configuration.WasAssigned ||
                _filesChanged.WasAssigned ||
                _rebuild.WasAssigned ||
                _restoreComplete.WasAssigned ||
                _sourceTextChanged.WasAssigned)
            {
                bool triggerBuildOutputs    = _rebuild.WasAssigned || _filesChanged.WasAssigned;
                bool triggerRestoreComplete = _restoreComplete.WasAssigned;

                _appPath.ClearAssigned();
                _configuration.ClearAssigned();
                _filesChanged.ClearAssigned();
                _rebuild.ClearAssigned();
                _sourceTextChanged.ClearAssigned();
                _restoreComplete.ClearAssigned();

                // Trigger that the project outputs changes in case the runtime process
                // hasn't died yet
                TriggerProjectOutputsChanged();

                state = DoInitialWork(_appPath.Value, _configuration.Value, triggerBuildOutputs, triggerRestoreComplete);
            }

            if (state == null)
            {
                return(false);
            }

            _local = new World();
            _local.ProjectInformation = new ProjectMessage
            {
                Name = state.Name,

                // All target framework information
                Frameworks = state.Frameworks,

                // debug/release etc
                Configurations = state.Configurations,

                Commands = state.Commands,

                ProjectSearchPaths = state.ProjectSearchPaths,

                GlobalJsonPath = state.GlobalJsonPath
            };

            foreach (var project in state.Projects)
            {
                var frameworkData = project.TargetFramework;

                var projectWorld = new ProjectWorld
                {
                    ApplicationHostContext = project.DependencyInfo.HostContext,
                    TargetFramework        = project.FrameworkName,
                    Sources = new SourcesMessage
                    {
                        Framework = frameworkData,
                        Files     = project.SourceFiles
                    },
                    CompilerOptions = new CompilationOptionsMessage
                    {
                        Framework          = frameworkData,
                        CompilationOptions = project.CompilationSettings
                    },
                    Dependencies = new DependenciesMessage
                    {
                        Framework      = frameworkData,
                        RootDependency = state.Name,
                        Dependencies   = project.DependencyInfo.Dependencies
                    },
                    References = new ReferencesMessage
                    {
                        Framework         = frameworkData,
                        ProjectReferences = project.DependencyInfo.ProjectReferences,
                        FileReferences    = project.DependencyInfo.References,
                        RawReferences     = project.DependencyInfo.RawReferences
                    }
                };

                _local.Projects[project.FrameworkName] = projectWorld;
            }

            return(true);
        }
Beispiel #14
0
        private bool ResolveDependencies()
        {
            ProjectState state = null;

            if (_appPath.WasAssigned ||
                _configuration.WasAssigned ||
                _filesChanged.WasAssigned ||
                _rebuild.WasAssigned ||
                _refreshDependencies.WasAssigned)
            {
                bool triggerBuildOutputs = _rebuild.WasAssigned || _filesChanged.WasAssigned;
                bool triggerDependencies = _refreshDependencies.WasAssigned || _rebuild.WasAssigned;

                _appPath.ClearAssigned();
                _configuration.ClearAssigned();
                _filesChanged.ClearAssigned();
                _rebuild.ClearAssigned();
                _refreshDependencies.ClearAssigned();

                // Trigger that the project outputs changes in case the runtime process
                // hasn't died yet
                TriggerProjectOutputsChanged();

                state = _projectStateResolver.Resolve(_appPath.Value,
                                                      _configuration.Value,
                                                      triggerBuildOutputs,
                                                      triggerDependencies,
                                                      ProtocolVersion,
                                                      _remote.ProjectInformation?.ProjectSearchPaths);
            }

            if (state == null)
            {
                return(false);
            }

            _local                    = new World();
            _local.Project            = state.Project;
            _local.ProjectInformation = new ProjectMessage
            {
                Name = state.Name,

                // All target framework information
                Frameworks = state.Frameworks,

                // debug/release etc
                Configurations = state.Configurations,

                Commands = state.Commands,

                ProjectSearchPaths = state.ProjectSearchPaths,

                GlobalJsonPath = state.GlobalJsonPath
            };

            _local.ProjectDiagnostics = new DiagnosticsListMessage(state.Diagnostics);

            foreach (var project in state.Projects)
            {
                var frameworkData = project.TargetFramework;

                var projectWorld = new ProjectWorld
                {
                    TargetFramework = project.FrameworkName,
                    Sources         = new SourcesMessage
                    {
                        Framework = frameworkData,
                        Files     = project.SourceFiles
                    },
                    CompilerOptions = new CompilationOptionsMessage
                    {
                        Framework          = frameworkData,
                        CompilationOptions = project.CompilationSettings
                    },
                    Dependencies = new DependenciesMessage
                    {
                        Framework      = frameworkData,
                        RootDependency = state.Name,
                        Dependencies   = project.DependencyInfo.Dependencies
                    },
                    References = new ReferencesMessage
                    {
                        Framework         = frameworkData,
                        ProjectReferences = project.DependencyInfo.ProjectReferences,
                        FileReferences    = project.DependencyInfo.References,
                        RawReferences     = project.DependencyInfo.RawReferences
                    },
                    DependencyDiagnostics = new DiagnosticsListMessage(project.DependencyInfo.Diagnostics, frameworkData)
                };

                _local.Projects[project.FrameworkName] = projectWorld;
            }

            if (_pluginHandler.FaultedPluginRegistrations)
            {
                var assemblyLoadContext = GetAppRuntimeLoadContext();

                _pluginHandler.TryRegisterFaultedPlugins(assemblyLoadContext);
            }

            return(true);
        }