Esempio n. 1
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()}) }}}}");
         }
     }
 }
Esempio n. 2
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);
        }
Esempio n. 3
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);
        }