private void AddCakeFile(string cakeFilePath)
        {
            try
            {
                var cakeScript = _scriptService.Generate(new FileChange
                {
                    FileName = cakeFilePath,
                    FromDisk = true
                });

                var project = GetProject(cakeScript, cakeFilePath);

                // add Cake project to workspace
                _workspace.AddProject(project);
                var documentId   = DocumentId.CreateNewId(project.Id);
                var loader       = new CakeTextLoader(cakeFilePath, _scriptService);
                var documentInfo = DocumentInfo.Create(
                    documentId,
                    cakeFilePath,
                    filePath: cakeFilePath,
                    loader: loader,
                    sourceCodeKind: SourceCodeKind.Script);

                _workspace.AddDocument(documentInfo);
                _projects[cakeFilePath] = project;
                _logger.LogInformation($"Added Cake project '{cakeFilePath}' to the workspace.");
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, $"{cakeFilePath} will be ignored due to an following error");
            }
        }
Example #2
0
        public void Initalize(IConfiguration configuration)
        {
            _logger.LogInformation($"Detecting Cake files in '{_environment.TargetDirectory}'.");

            // Nothing to do if there are no Cake files
            var allCakeFiles = Directory.GetFiles(_environment.TargetDirectory, "*.cake", SearchOption.AllDirectories);

            if (allCakeFiles.Length == 0)
            {
                _logger.LogInformation("Could not find any Cake files");
                return;
            }

            _logger.LogInformation($"Found {allCakeFiles.Length} Cake files.");

            // Check that script service is connected
            if (!_scriptService.IsConnected)
            {
                _logger.LogWarning("Cake script service not connected. Aborting.");
                return;
            }

            foreach (var cakePath in allCakeFiles)
            {
                try
                {
                    var cakeScript = _scriptService.Generate(new FileChange
                    {
                        FileName = cakePath,
                        FromDisk = true
                    });
                    var project = GetProject(cakeScript, cakePath);

                    // add Cake project to workspace
                    _workspace.AddProject(project);
                    var documentId   = DocumentId.CreateNewId(project.Id);
                    var loader       = new CakeTextLoader(cakePath, _scriptService);
                    var documentInfo = DocumentInfo.Create(
                        documentId,
                        cakePath,
                        filePath: cakePath,
                        loader: loader,
                        sourceCodeKind: SourceCodeKind.Script);

                    _workspace.AddDocument(documentInfo);
                    _projects[cakePath] = project;
                    _logger.LogInformation($"Added Cake project '{cakePath}' to the workspace.");
                }
                catch (Exception ex)
                {
                    _logger.LogError(ex, $"{cakePath} will be ignored due to an following error");
                }
            }

            // Hook up Cake script events
            _scriptService.ReferencesChanged += ScriptReferencesChanged;
            _scriptService.UsingsChanged     += ScriptUsingsChanged;
        }