示例#1
0
        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>
        /// Adds the value to the <see cref="IncludePatterns"/> collection property and
        /// returns this instance.
        /// </summary>
        /// <param name="value">
        /// The value to add to the <see cref="IncludePatterns"/> collection property.
        /// </param>
        /// <returns>
        /// This instance.
        /// </returns>
        /// <remarks>
        /// This method is part of the fluent interface.
        /// </remarks>
        /// <exception cref="System.ArgumentNullException">
        /// <para><paramref name="value"/> is <c>null</c> or empty.</para>
        /// </exception>
        public T WithIncludePattern(string value)
        {
            if (StringEx.IsNullOrWhiteSpace(value))
            {
                throw new ArgumentNullException("value");
            }

            IncludePatterns.Add(value);
            return((T)this);
        }
示例#3
0
        public CompositeGlob(IEnumerable <string> includePatterns, IEnumerable <string> excludePatterns)
        {
            if (excludePatterns == null)
            {
                excludePatterns = new List <string>();
            }

            IncludePatterns = includePatterns.ToArray();
            ExcludePatterns = excludePatterns.ToArray();

            includeGlobs = IncludePatterns.Select(pattern => new GLOB(pattern)).ToArray();
            excludeGlobs = ExcludePatterns.Select(pattern => new GLOB(pattern)).ToArray();
        }
示例#4
0
 public override void Write(CustomFileWriter writer)
 {
     writer.WriteLine($"- name: Cache {IncludePatterns.JoinComma()}");
     using (writer.Indent())
     {
         writer.WriteLine("uses: actions/cache@v2");
         writer.WriteLine("with:");
         using (writer.Indent())
         {
             writer.WriteLine("path: |");
             IncludePatterns.ForEach(x => writer.WriteLine($"  {x}"));
             ExcludePatterns.ForEach(x => writer.WriteLine($"  !{x}"));
             writer.WriteLine($"key: ${{{{ runner.os }}}}-${{{{ hashFiles({KeyFiles.Select(x => x.SingleQuote()).JoinComma()}) }}}}");
         }
     }
 }
示例#5
0
        /// <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);
        }
示例#6
0
        /// <summary>
        /// Reads the config file
        /// </summary>
        /// <returns>an empty string if no exception occurs</returns>
        public bool Read()
        {
            Log.Trace(@"ConfigFileHelper.Read() ...");

            try
            {
                if (!ConfigFileExists)
                {
                    return(false);
                }

                bool isConfigRead = true;

                ParityFile1 = string.Empty;
                ParityFile2 = string.Empty;
                ZParityFile = string.Empty;
                ParityFile3 = string.Empty;
                ParityFile4 = string.Empty;
                ParityFile5 = string.Empty;
                ParityFile6 = string.Empty;

                ConfigErrors.Clear();

                ConfigWarnings.Clear();

                ContentFiles.Clear();

                SnapShotSources.Clear();

                ExcludePatterns.Clear();

                IncludePatterns.Clear();

                BlockSizeKB = Constants.DefaultBlockSize;

                AutoSaveGB = Constants.DefaultAutoSave;

                foreach (string line in File.ReadLines(ConfigPath))
                {
                    string lineStart = line.Trim();

                    if (string.IsNullOrWhiteSpace(lineStart) || lineStart.StartsWith(@"#"))
                    {
                        continue;
                    }

                    // Not a comment so process the line

                    // split the line by the first space encountered
                    string[] configItem = lineStart.Split(new[] { ' ' }, 2);
                    Log.Trace(@"configItem [{0}]", string.Join(" ", configItem));
                    string configItemName = configItem[0] ?? string.Empty;
                    Log.Trace(@"configItemName [{0}]", configItemName);
                    string configItemValue = (configItem.Length > 1) ? configItem[1] : string.Empty;
                    Log.Trace(@"configItemValue [{0}]", configItemValue);

                    // ignore the line if it is not an a recognized setting
                    if (!validConfigNames.Contains(configItemName))
                    {
                        continue;
                    }
                    Log.Trace(@"configItemName found in validConfigNames");

                    switch (configItemName)
                    {
                    case @"parity":
                        ParityFile1 = configItemValue;
                        break;

                    case @"q-parity":
                        Log.Warn(@"'q-parity' entry in config file will be changed to '2-parity' when config is saved");
                        ParityFile2 = configItemValue;
                        break;

                    case @"2-parity":
                        // handle legacy 'q-parity' entry by giving it priority over any '2-parity' entry; saving config will rename 'q-parity' to '2-parity' and leave the path unchanged
                        if (string.IsNullOrEmpty(ParityFile2))
                        {
                            ParityFile2 = configItemValue;
                        }
                        break;

                    case @"z-parity":
                        // #WARNING! Your CPU doesn't have a fast implementation for triple parity.
                        // #WARNING! It's recommended to switch to 'z-parity' instead than '3-parity'.
                        ZParityFile = configItemValue;
                        ParityFile3 = string.Empty;
                        break;

                    case @"3-parity":
                        if (string.IsNullOrWhiteSpace(ZParityFile))
                        {
                            ParityFile3 = configItemValue;
                        }
                        break;

                    case @"4-parity":
                        ParityFile4 = configItemValue;
                        break;

                    case @"5-parity":
                        ParityFile5 = configItemValue;
                        break;

                    case @"6-parity":
                        ParityFile6 = configItemValue;
                        break;

                    case @"content":
                        ContentFiles.Add(configItemValue);
                        break;

                    case @"disk":
                    case @"data":     // Handle older configs
                    {
                        // get the data name, d1,d2,d3 etc
                        string diskName = configItemValue.Split(' ')[0];

                        // get the path
                        int diskSplitIndex = configItemValue.IndexOf(' ');

                        string diskPath = configItemValue.Substring(diskSplitIndex + 1);

                        // special handling of data sources since order preservation is extremely important
                        if (!string.IsNullOrEmpty(diskName) && !string.IsNullOrEmpty(diskPath))
                        {
                            SnapShotSources.Add(new SnapShotSource {
                                    Name = diskName, DirSource = diskPath
                                });
                        }
                    }
                    break;

                    case @"exclude":
                        ExcludePatterns.Add(configItemValue);
                        break;

                    case @"include":
                        IncludePatterns.Add(configItemValue);
                        break;

                    case @"block_size":
                        BlockSizeKB = uint.Parse(configItemValue);
                        if (BlockSizeKB < Constants.MinBlockSize || BlockSizeKB > Constants.MaxBlockSize)
                        {
                            isConfigRead = false;
                        }
                        break;

                    case @"autosave":
                        AutoSaveGB = uint.Parse(configItemValue);
                        // ReSharper disable once ConditionIsAlwaysTrueOrFalse
                        if (AutoSaveGB < Constants.MinAutoSave || AutoSaveGB > Constants.MaxAutoSave)
                        {
                            isConfigRead = false;
                        }
                        break;

                    case @"nohidden":
                        Nohidden = true;
                        break;
                    }
                }

                return(isConfigRead);
            }
            catch (Exception ex)
            {
                Log.Error(ex);
                return(false);
            }
        }
示例#7
0
        /// <summary>
        /// Reads the config file
        /// </summary>
        /// <returns>an empty string if no exception occurrs</returns>
        public string Read()
        {
            try
            {
                ParityFile  = string.Empty;
                QParityFile = string.Empty;
                ContentFiles.Clear();
                SnapShotSources.Clear();
                ExcludePatterns.Clear();
                IncludePatterns.Clear();
                BlockSizeKB = 256;
                AutoSaveGB  = 250;

                foreach (string line in File.ReadLines(ConfigPath))
                {
                    string lineStart = line.TrimStart();
                    if (!string.IsNullOrWhiteSpace(lineStart) &&
                        !lineStart.StartsWith("#")
                        )
                    {
                        // Not a comment, so off we go.
                        int    splitIndex = lineStart.IndexOf(' ');
                        string value      = lineStart.Substring(splitIndex + 1);
                        if (string.IsNullOrWhiteSpace(value))
                        {
                            continue;
                        }
                        switch (lineStart.Substring(0, splitIndex).ToLower())
                        {
                        case "parity":
                            ParityFile = value;
                            break;

                        case "q-parity":
                            QParityFile = value;
                            break;

                        case "content":
                            ContentFiles.Add(value);
                            break;

                        case "disk":
                        {
                            // Step over the disk name
                            int diskSplitIndex = value.IndexOf(' ');
                            SnapShotSources.Add(value.Substring(diskSplitIndex + 1));
                        }
                        break;

                        case "exclude":
                            ExcludePatterns.Add(value);
                            break;

                        case "include":
                            IncludePatterns.Add(value);
                            break;

                        case "block_size":
                            BlockSizeKB = uint.Parse(value);
                            break;

                        case "nohidden":
                            Nohidden = true;
                            break;

                        case "autosave":
                            AutoSaveGB = uint.Parse(value);
                            break;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                return(ex.Message);
            }
            return(string.Empty);
        }
示例#8
0
        /// <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);
        }
示例#9
0
        /// <summary>
        /// Reads the config file
        /// </summary>
        /// <returns>an empty string if no exception occurrs</returns>
        public bool Read()
        {
            try
            {
                if (!ConfigFileExists)
                {
                    return(false);
                }

                ParityFile1 = string.Empty;
                ParityFile2 = string.Empty;
                ParityFile3 = string.Empty;
                ParityFile4 = string.Empty;
                ParityFile5 = string.Empty;
                ParityFile6 = string.Empty;
                ContentFiles.Clear();
                SnapShotSources.Clear();
                ExcludePatterns.Clear();
                IncludePatterns.Clear();
                BlockSizeKB = 256;
                AutoSaveGB  = 250;

                foreach (string line in File.ReadLines(ConfigPath))
                {
                    string lineStart = line.Trim();
                    if (string.IsNullOrWhiteSpace(lineStart) || lineStart.StartsWith("#"))
                    {
                        continue;
                    }

                    // Not a comment so process the line

                    // split the line by the first space encountered
                    string[] configItem      = lineStart.Split(new[] { ' ' }, 2);
                    string   configItemName  = configItem[0] ?? string.Empty;
                    string   configItemValue = (configItem.Length > 1) ? configItem[1] : string.Empty;

                    // ignore the line if it is not an a recognized setting
                    if (!_validConfigNames.Contains(configItemName))
                    {
                        continue;
                    }

                    switch (configItemName)
                    {
                    case "parity":
                        ParityFile1 = configItemValue;
                        break;

                    case "q-parity":
                        Log.Instance.Warn("'q-parity' entry in config file should be changed to '2-parity'");
                        ParityFile2 = configItemValue;
                        break;

                    case "2-parity":
                        // handle legacy 'q-parity' entry by giving it priority over any '2-parity' entry; saving config will rename 'q-parity' to '2-parity' and leave the path unchanged
                        if (string.IsNullOrEmpty(ParityFile2))
                        {
                            ParityFile2 = configItemValue;
                        }
                        break;

                    case "3-parity":
                        ParityFile3 = configItemValue;
                        break;

                    case "4-parity":
                        ParityFile4 = configItemValue;
                        break;

                    case "5-parity":
                        ParityFile5 = configItemValue;
                        break;

                    case "6-parity":
                        ParityFile6 = configItemValue;
                        break;

                    case "content":
                        ContentFiles.Add(configItemValue);
                        break;

                    case "disk":
                        // Step over the disk name
                        int diskSplitIndex = configItemValue.IndexOf(' ');
                        SnapShotSources.Add(configItemValue.Substring(diskSplitIndex + 1));
                        break;

                    case "exclude":
                        ExcludePatterns.Add(configItemValue);
                        break;

                    case "include":
                        IncludePatterns.Add(configItemValue);
                        break;

                    case "block_size":
                        BlockSizeKB = uint.Parse(configItemValue);
                        break;

                    case "nohidden":
                        Nohidden = true;
                        break;

                    case "autosave":
                        AutoSaveGB = uint.Parse(configItemValue);
                        break;
                    }
                }
            }
            catch (Exception ex)
            {
                Log.Instance.Error(ex);
                return(false);
            }
            return(true);
        }
示例#10
0
        /// <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);
        }