public override bool Execute()
        {
            string outputFileName = String.Format("{0}.area-manifest.xml", AreaName);
            string outputFullPath = Path.Combine(ManifestPath, outputFileName);

            AreaInfo info = new AreaInfo()
            {
                Name         = AreaName,
                Path         = AreaPath,
                Type         = (AreaType)Enum.Parse(typeof(AreaType), AreaType),
                ContentFiles = ContentFiles.Select(o => o.ItemSpec).ToArray()
            };

            // ensure output directory exists before file creation
            string outputDir = Path.GetDirectoryName(outputFullPath);

            FileSystem.CreateDirectory(outputDir);

            XmlSerializer serializer = new XmlSerializer(typeof(AreaInfo));

            using (Stream stream = FileSystem.FileOpen(outputFullPath, FileMode.Create)) {
                serializer.Serialize(stream, info);
            }

            // if we got this far, success!
            return(true);
        }
Exemple #2
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);
        }