public bool CanRename(string oldName, string newName)
 {
     return((oldName != AutoGenerateTemplateName) &&
            (!string.IsNullOrWhiteSpace(newName)) &&
            SettingsList.Contains(oldName) &&
            !SettingsList.Contains(newName));
 }
Exemple #2
0
        private string GenerateCsvConfig(string targetFilePath, GenerateConfigSettings newSettings)
        {
            if (!File.Exists(targetFilePath))
            {
                throw new FileNotFoundException("Target CSV file not exist.", targetFilePath);
            }

            var targetFileDir  = Path.GetDirectoryName(targetFilePath);
            var targetFileName = Path.GetFileNameWithoutExtension(targetFilePath);
            var configFilePath = Path.Combine(targetFileDir, targetFileName + ".config.csx");

            if (File.Exists(configFilePath))
            {
                throw new InvalidOperationException($"Config File \"{configFilePath}\" already exists.");
            }

            //Generate a CSV config template.
            var configText = GenerateCsvConfigText(targetFilePath, newSettings.TargetFileEncoding, newSettings.HasHeaderRecord);
            //Save to template file.
            var templateFilePath = Path.Combine(ConfigFileDirectory, newSettings.TemplateName + ".config.csx");

            File.WriteAllText(templateFilePath, configText);

            CurrentConfigFilePath = templateFilePath;

            if (!SettingsList.Contains(newSettings.TemplateName))
            {
                SettingsList.Add(newSettings.TemplateName);
            }

            return(configText);
        }
Exemple #3
0
 public void SaveConfigFile(string configText, string templateName = null)
 {
     File.WriteAllText(CurrentConfigFilePath, configText);
     if (templateName != null && !SettingsList.Contains(templateName))
     {
         SettingsList.Add(templateName);
     }
 }
Exemple #4
0
        public void GetConfigFiles()
        {
            Directory.CreateDirectory(ConfigFileDirectory);
            var files = Directory.GetFiles(ConfigFileDirectory, "*.config.csx");

            SettingsList.Clear();

            var items = new[] { AutoGenerateTemplateName }
            .Concat(files.Select(x => Path.GetFileNameWithoutExtension(Path.GetFileNameWithoutExtension(x))));

            foreach (var item in items)
            {
                if (!SettingsList.Contains(item))
                {
                    SettingsList.Add(item);
                }
            }
        }
 public bool CanRemove(string name)
 {
     return((name != AutoGenerateTemplateName) && SettingsList.Contains(name));
 }