private IEnumerable <FieldDescriptor> BuildListWithFieldsToShow(string fieldString) { var fieldList = new List <FieldDescriptor>(); var fieldNames = new ListString(fieldString).ToArray(); if (fieldNames.Any()) { IncludePatterns = fieldNames .Where(name => !name.StartsWith("-")) .Select( name => new WildcardPattern(name, WildcardOptions.IgnoreCase | WildcardOptions.CultureInvariant)) .ToList(); ExcludePatterns = fieldNames .Where(name => name.StartsWith("-")) .Select( name => new WildcardPattern(name.Substring(1), WildcardOptions.IgnoreCase | WildcardOptions.CultureInvariant)) .ToList(); } var currentItem = CurrentItem; currentItem.Fields.ReadAll(); var template = TemplateManager.GetTemplate(Settings.DefaultBaseTemplate, currentItem.Database); FieldCollection fields = new FieldCollection(CurrentItem); fields.ReadAll(); fields.Sort(); foreach (Field field in fields) { //if not including standard field and it's standard, skip it. if (!IncludeStandardFields && template.ContainsField(field.ID)) { continue; } var name = field.Name; var wildcardMatch = IncludePatterns.Any(pattern => pattern.IsMatch(name)); if (!wildcardMatch) { continue; } if (ExcludePatterns.Any(pattern => pattern.IsMatch(name))) { wildcardMatch = false; } if (wildcardMatch) { fieldList.Add(new FieldDescriptor(currentItem, field.Name)); } } return(fieldList); }
/// <summary> /// Writes the config file /// </summary> /// <returns>an empty string if no exception occurs</returns> public string Write(string trgtFileName) { try { StringBuilder fileContents = new StringBuilder(); fileContents.Append(Section1); // parity fileContents.Append(Section2); AddParityToConfig(fileContents, ParityFile1, char.MinValue); // #-parity fileContents.Append(Section3); AddParityToConfig(fileContents, ParityFile2, '2'); AddParityToConfig(fileContents, ZParityFile, 'z'); AddParityToConfig(fileContents, ParityFile3, '3'); AddParityToConfig(fileContents, ParityFile4, '4'); AddParityToConfig(fileContents, ParityFile5, '5'); AddParityToConfig(fileContents, ParityFile6, '6'); // content fileContents.Append(Section4); ContentFiles.ForEach(item => fileContents.AppendLine($"content {(Directory.Exists(item) ? Path.Combine(item, @"snapraid.content") : item)}")); // data sources fileContents.Append(Section5); foreach (SnapShotSource shotSource in SnapShotSources) { fileContents.Append(@"disk ").Append(shotSource.Name).Append(@" ").AppendLine(shotSource.DirSource); } // exclude hidden files fileContents.Append(Section6); fileContents.AppendLine(Nohidden ? @"nohidden" : @"#nohidden"); // exclude files and directories fileContents.Append(Section7); if (ExcludePatterns.Any()) { ExcludePatterns.ForEach(item => fileContents.Append(@"exclude ").AppendLine(item)); } // include files and directories if (IncludePatterns.Any()) { IncludePatterns.ForEach(item => fileContents.Append(@"include ").AppendLine(item)); } // blocksize fileContents.Append(Section8); BlockSizeKB = BlockSizeKB >= Constants.MinBlockSize && BlockSizeKB <= Constants.MaxBlockSize ? BlockSizeKB : Constants.DefaultBlockSize; fileContents.Append("block_size ").Append(BlockSizeKB).AppendLine(); // hashsize fileContents.Append(Section9); // autosave fileContents.Append(Section10); // ReSharper disable once ConditionIsAlwaysTrueOrFalse AutoSaveGB = AutoSaveGB >= Constants.MinAutoSave && AutoSaveGB <= Constants.MaxAutoSave ? AutoSaveGB : Constants.DefaultAutoSave; fileContents.Append(@"autosave ").Append(AutoSaveGB).AppendLine(); // pool fileContents.Append(Section11); // windows share // smartctl Directory.CreateDirectory(Path.GetDirectoryName(trgtFileName)); File.WriteAllText(trgtFileName, fileContents.ToString()); } catch (Exception ex) { Log.Fatal(ex); return(ex.Message); } return(string.Empty); }
/// <summary> /// Writes the config file /// </summary> /// <returns>an empty string if no exception occurrs</returns> public string Write() { try { List <string> fileContents = new List <string> { "# Configuration for snapraid via Elucidate", string.Empty, "# Defines the file to use as Parity storage", "# It must NOT be in a data disk", "parity " + (Directory.Exists(ParityFile)? Path.Combine(ParityFile, "SnapRAID.parity"):ParityFile), string.Empty, "# Defines the file to use as Q-Parity storage", "# If specified, it enables a double failures protection like RAID6", "# It must NOT be in a data disk" }; if (string.IsNullOrEmpty(QParityFile)) { fileContents.Add(@"#q-parity F:\qar\q-parity\SnapRAID.Q.parity"); } else { fileContents.Add("q-parity " + (Directory.Exists(QParityFile) ? Path.Combine(QParityFile, "SnapRAID.Q.parity") : QParityFile)); } fileContents.Add(string.Empty); fileContents.Add("# Defines the file to use as content list"); fileContents.Add("# You can use multiple specification to store more copies of the file"); fileContents.Add("# It's suggested to have at least N+1 copies of the file, where N is the number of parity files."); fileContents.Add("# It can be in a data disk"); fileContents.Add("# It can be in the disks used for parity storage"); fileContents.AddRange(ContentFiles.Select(contentFile => "content " + (Directory.Exists(contentFile) ? Path.Combine(contentFile, "SnapRAID.content") : contentFile))); fileContents.Add(string.Empty); fileContents.Add("# Defines the data disks to use"); fileContents.Add("# The order is relevant for parity, do not change it"); fileContents.AddRange(SnapShotSources.Select((t, index) => string.Concat("disk d", index, ' ', t))); fileContents.Add(string.Empty); fileContents.Add("# Excludes hidden files and directories (uncomment to enable)."); fileContents.Add(Nohidden ? "nohidden" : "# nohidden"); fileContents.Add(string.Empty); fileContents.Add("# Defines files and directories to exclude"); fileContents.Add("# Remember that all the paths are relative at the mount points"); fileContents.Add("# Format: \"exclude FILE\""); fileContents.Add("# Format: \"exclude DIR\\\""); fileContents.Add("# Format: \"exclude \\PATH\\FILE\""); fileContents.Add("# Format: \"exclude \\PATH\\DIR\\\""); if (ExcludePatterns.Any()) { fileContents.AddRange(ExcludePatterns.Select(pattern => "exclude " + pattern)); } if (IncludePatterns.Any()) { fileContents.AddRange(IncludePatterns.Select(pattern => "include " + pattern)); } fileContents.Add(string.Empty); fileContents.Add("# Defines the block size in kibi bytes (1024 bytes)."); fileContents.Add("# Default value is 256 -> 256 kibi bytes -> 262144 bytes"); fileContents.Add("block_size " + BlockSizeKB); fileContents.Add(string.Empty); fileContents.Add("# Automatically save the state when synching after the specied amount of GiB processed."); fileContents.Add("# This option is useful to avoid to restart from scratch long 'sync'"); fileContents.Add("# commands interrupted by a machine crash."); fileContents.Add("# The SIZE argument is specified in gibi bytes -> 1073741824 bytes"); fileContents.Add("# Default value is 0, meaning disabled."); fileContents.Add("# Format: \"autosave SIZE_IN_GiB\""); fileContents.Add("autosave " + AutoSaveGB); fileContents.Add(string.Empty); File.WriteAllLines(ConfigPath, fileContents); } catch (Exception ex) { return(ex.Message); } return(string.Empty); }
/// <summary> /// Writes the config file /// </summary> /// <returns>an empty string if no exception occurs</returns> public string Write() { try { StringBuilder fileContents = new StringBuilder(); fileContents.Append(Section1); // parity fileContents.Append(Section2); fileContents.AppendLine($"parity {(Directory.Exists(ParityFile1) ? Path.Combine(ParityFile1, "SnapRAID.parity") : ParityFile1)}"); // X-parity fileContents.Append(Section3); if (!string.IsNullOrEmpty(ParityFile2)) { fileContents.AppendLine($"2-parity {(Directory.Exists(ParityFile2) ? Path.Combine(ParityFile2, "SnapRAID.2-parity") : ParityFile2)}"); } if (!string.IsNullOrEmpty(ParityFile3)) { fileContents.AppendLine($"3-parity {(Directory.Exists(ParityFile3) ? Path.Combine(ParityFile3, "SnapRAID.3-parity") : ParityFile3)}"); } if (!string.IsNullOrEmpty(ParityFile4)) { fileContents.AppendLine($"4-parity {(Directory.Exists(ParityFile4) ? Path.Combine(ParityFile4, "SnapRAID.4-parity") : ParityFile4)}"); } if (!string.IsNullOrEmpty(ParityFile5)) { fileContents.AppendLine($"5-parity {(Directory.Exists(ParityFile5) ? Path.Combine(ParityFile5, "SnapRAID.5-parity") : ParityFile5)}"); } if (!string.IsNullOrEmpty(ParityFile6)) { fileContents.AppendLine($"6-parity {(Directory.Exists(ParityFile6) ? Path.Combine(ParityFile6, "SnapRAID.6-parity") : ParityFile6)}"); } // content fileContents.Append(Section4); ContentFiles.ForEach(item => fileContents.AppendLine($"content {(Directory.Exists(item) ? Path.Combine(item, "SnapRAID.content") : item)}")); // data sources fileContents.Append(Section5); List <string> strSnapShotSources = new List <string>(); strSnapShotSources.AddRange(SnapShotSources.Select((t, index) => string.Concat("disk d", index + 1, ' ', t))); strSnapShotSources.ForEach(item => fileContents.AppendLine(item)); // exclude hidden files fileContents.Append(Section6); fileContents.AppendLine(Nohidden ? "nohidden" : "#nohidden"); // exclude files and directories fileContents.Append(Section7); if (ExcludePatterns.Any()) { ExcludePatterns.ForEach(item => fileContents.AppendLine("exclude " + item)); } // include files and directories if (IncludePatterns.Any()) { IncludePatterns.ForEach(item => fileContents.AppendLine("include " + item)); } // blocksize fileContents.Append(Section8); fileContents.AppendLine("block_size " + BlockSizeKB); // hashsize fileContents.Append(Section9); // autosave fileContents.Append(Section10); fileContents.AppendLine("autosave " + AutoSaveGB); // pool fileContents.Append(Section11); // windows share // smartctl File.WriteAllText(ConfigPath, fileContents.ToString()); } catch (Exception ex) { ExceptionHandler.ReportException(ex); return(ex.Message); } return(string.Empty); }