static void InitializeProjects()
        {
            int projectContextId = 0;

            foreach (string projectFile in Directory.EnumerateFiles(solutionPath, "project.json", SearchOption.AllDirectories))
            {
                projectContextId++;

                string projectFolder = Path.GetDirectoryName(projectFile);

                var initializeMessage = new InitializeMessage
                {
                    ProjectFolder = projectFolder
                };

                queue.Post(Message.FromPayload(
                               "Initialize",
                               projectContextId,
                               JToken.FromObject(initializeMessage)));

                var changeConfigMessage = new ChangeConfigurationMessage
                {
                    Configuration = "Release"
                };

                queue.Post(Message.FromPayload(
                               "ChangeConfiguration",
                               projectContextId,
                               JToken.FromObject(changeConfigMessage)));
            }
        }
Beispiel #2
0
        public void ShouldChangeConfiguration()
        {
            IConfigManager configManagerMock          = Substitute.For <IConfigManager>();
            var            changeConfigurationMessage = new ChangeConfigurationMessage(configManagerMock);

            mainWindowViewModelMock.DidNotReceive().Configure(configManagerMock);
            controller.Trigger(changeConfigurationMessage);
            mainWindowViewModelMock.Received().Configure(configManagerMock);
        }
 public void ChangeConfiguration(string config)
 {
     foreach (int contextId in _context.ProjectContextMapping.Values)
     {
         var message = new Message();
         message.HostId      = _context.HostId;
         message.ContextId   = contextId;
         message.MessageType = "ChangeConfiguration";
         var configMessage = new ChangeConfigurationMessage();
         configMessage.Configuration = config;
         message.Payload             = JToken.FromObject(configMessage);
         try
         {
             _context.Connection.Post(message);
         }
         catch (IOException ex)
         {
             _logger.LogError("Post failed", ex);
         }
     }
 }
Beispiel #4
0
        private bool ProcessMessage()
        {
            Message message;

            lock (_inbox)
            {
                if (!_inbox.Any())
                {
                    return(false);
                }

                message = _inbox.Dequeue();

                // REVIEW: Can this ever happen?
                if (message == null)
                {
                    return(false);
                }
            }

            Logger.TraceInformation("[ApplicationContext]: Received {0}", message.MessageType);

            switch (message.MessageType)
            {
            case "Initialize":
            {
                // This should only be sent once
                if (_initializedContext == null)
                {
                    _initializedContext = message.Sender;

                    var data = new InitializeMessage
                    {
                        Version       = GetValue <int>(message.Payload, "Version"),
                        Configuration = GetValue(message.Payload, "Configuration"),
                        ProjectFolder = GetValue(message.Payload, "ProjectFolder")
                    };

                    _appPath.Value       = data.ProjectFolder;
                    _configuration.Value = data.Configuration ?? "Debug";

                    // Therefore context protocol version is set only when the version is not 0 (meaning 'Version'
                    // protocol is not missing) and protocol version is not overridden by environment variable.
                    if (data.Version != 0 && !_protocolManager.EnvironmentOverridden)
                    {
                        _contextProtocolVersion = Math.Min(data.Version, _protocolManager.MaxVersion);
                        Logger.TraceInformation($"[{nameof(ApplicationContext)}]: Set context protocol version to {_contextProtocolVersion.Value}");
                    }
                }
                else
                {
                    Logger.TraceInformation("[ApplicationContext]: Received Initialize message more than once for {0}", _appPath.Value);
                }
            }
            break;

            case "Teardown":
            {
                // TODO: Implement
            }
            break;

            case "ChangeConfiguration":
            {
                var data = new ChangeConfigurationMessage
                {
                    Configuration = GetValue(message.Payload, "Configuration")
                };
                _configuration.Value = data.Configuration;
            }
            break;

            case "RefreshDependencies":
            case "RestoreComplete":
            {
                _refreshDependencies.Value = default(Void);
            }
            break;

            case "Rebuild":
            {
                _rebuild.Value = default(Void);
            }
            break;

            case "FilesChanged":
            {
                _filesChanged.Value = default(Void);
            }
            break;

            case "GetCompiledAssembly":
            {
                var libraryKey = new RemoteLibraryKey
                {
                    Name            = GetValue(message.Payload, "Name"),
                    TargetFramework = GetValue(message.Payload, "TargetFramework"),
                    Configuration   = GetValue(message.Payload, "Configuration"),
                    Aspect          = GetValue(message.Payload, "Aspect"),
                    Version         = GetValue <int>(message.Payload, nameof(RemoteLibraryKey.Version)),
                };

                var targetFramework = new FrameworkName(libraryKey.TargetFramework);

                // Only set this the first time for the project
                if (!_requiresAssemblies.ContainsKey(targetFramework))
                {
                    _requiresAssemblies[targetFramework] = new Trigger <Void>();
                }

                _requiresAssemblies[targetFramework].Value = default(Void);

                List <CompiledAssemblyState> waitingForCompiledAssemblies;
                if (!_waitingForCompiledAssemblies.TryGetValue(targetFramework, out waitingForCompiledAssemblies))
                {
                    waitingForCompiledAssemblies = new List <CompiledAssemblyState>();
                    _waitingForCompiledAssemblies[targetFramework] = waitingForCompiledAssemblies;
                }

                waitingForCompiledAssemblies.Add(new CompiledAssemblyState
                    {
                        Connection = message.Sender,
                        Version    = libraryKey.Version
                    });
            }
            break;

            case "GetDiagnostics":
            {
                _requiresCompilation.Value = default(Void);

                _waitingForDiagnostics.Add(message.Sender);
            }
            break;

            case "Plugin":
            {
                var pluginMessage = message.Payload.ToObject <PluginMessage>();
                var result        = _pluginHandler.OnReceive(pluginMessage);

                _refreshDependencies.Value = default(Void);
                _pluginWorkNeeded.Value    = default(Void);

                if (result == PluginHandlerOnReceiveResult.RefreshDependencies)
                {
                    _refreshDependencies.Value = default(Void);
                }
            }
            break;
            }

            return(true);
        }