Пример #1
0
        private void BuildGlobalConfig(ConfigurationBuilder configurationBuilder)
        {
            // TODO: handle this directory already existing - but from another tool or
            // component etc. Offer the user the ability to set their own value for this?
            const string configDirectoryName = "sculptor-cli";

            string rootConfigPath = _fileSystem.Path.Combine(
                Environment.GetFolderPath(
                    Environment.SpecialFolder.LocalApplicationData), configDirectoryName);

            string configFilePath = _fileSystem.Path.Combine(
                rootConfigPath,
                FilePathHelper.GlobalConfigFileName);

            _fileSystem.Directory.CreateDirectory(rootConfigPath);

            configurationBuilder
            .SetBasePath(rootConfigPath)
            .AddJsonFile(
                FilePathHelper.GlobalConfigFileName,
                optional: false,
                reloadOnChange: false);

            if (_fileSystem.File.Exists(configFilePath))
            {
                return;
            }

            using (var file = _fileSystem.File.Create(configFilePath))
            {
                string globalTemplatePath = FilePathHelper
                                            .GetTemplatePath(FilePathHelper.GlobalConfigTemplateFileName);

                string fileText = _fileSystem.File.ReadAllText(
                    globalTemplatePath,
                    Encoding.UTF8);

                string defaultLogPath = _fileSystem.Path.Combine(rootConfigPath, "log");

                _fileSystem.Directory.CreateDirectory(defaultLogPath);

                string processedText = fileText.Replace(
                    "<<PATH_FORMAT>>",
                    FilePathHelper.BuildPlatformIndependentPath(
                        _fileSystem.Path.Combine(
                            defaultLogPath,
                            "{Date}-sculptor-cli.log")));

                byte[] configFileBytes = Encoding.UTF8.GetBytes(processedText);
                file.Write(configFileBytes);
            }
        }