public void Initalize(IConfiguration configuration)
        {
            if (Initialized)
            {
                return;
            }

            _options = new CakeOptions();
            configuration.Bind(_options);

            _logger.LogInformation($"Detecting Cake files in '{_environment.TargetDirectory}'.");

            // Nothing to do if there are no Cake files
            var allCakeFiles = _fileSystemHelper.GetFiles("**/*.cake").ToArray();

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

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

            // Try intialize Cake scripting service
            if (!_scriptService.Initialize(_options))
            {
                _logger.LogWarning("Could not initialize Cake script service. Aborting.");
                return;
            }

            foreach (var cakeFilePath in allCakeFiles)
            {
                AddCakeFile(cakeFilePath);
            }

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

            // Watch .cake files
            _fileSystemWatcher.Watch(".cake", OnCakeFileChanged);

            Initialized = true;
        }
        public void Initalize(IConfiguration configuration)
        {
            _options = new CakeOptions();
            configuration.Bind(_options);

            _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.");

            // Try intialize Cake scripting service
            if (!_scriptService.Initialize(_options))
            {
                _logger.LogWarning("Could not initialize Cake script service. 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;
        }