Example #1
0
        /// <summary>
        ///      Load
        /// </summary>
        /// <param name="yourPath"></param>
        /// <returns></returns>
        public static AutoCopySetting Load(string yourPath)
        {
            var table = new DataTable(StaticString.SettingTableName);

            try
            {
                var lstNode = new DataSet();
                lstNode.ReadXml(yourPath);
                table = lstNode.Tables[StaticString.SettingTableName];
                var setting =
                    new AutoCopySetting
                {
                    SourcePath      = table.Rows[0][StaticString.SourcePath].ToString(),
                    DestinationPath = table.Rows[0][StaticString.DestinationPath].ToString(),
                    ArchivePath     = table.Rows[0][StaticString.ArchivePath].ToString(),
                    RepeatEach      = table.Rows[0][StaticString.RepeatEach].ToString(),
                    TransferType    = table.Rows[0][StaticString.TransferType].ToString(),
                    ArchiveType     = table.Rows[0][StaticString.ArchiveType].ToString(),
                };
                return(setting);
            }
            catch (Exception ex)
            {
                return(new AutoCopySetting());
            }
        }
        /// <summary>
        ///      Save
        /// </summary>
        /// <param name="settings"></param>
        /// <param name="path">    </param>
        public static void Save(AutoCopySetting settings, string path)
        {
            if (File.Exists(path))
            {
                File.Delete(path);
            }
            var dtSettings = SettingTable.FillAutoCopyTable(settings, StaticString.SettingTableName);

            using (Stream stream = new FileStream(path, FileMode.Create, FileAccess.ReadWrite))
            {
                dtSettings.WriteXml(stream);
            }
        }
 /// <summary>
 ///      FillAutoCopyTable
 /// </summary>
 /// <param name="setting"></param>
 /// <param name="name">   </param>
 /// <returns></returns>
 public static DataTable FillAutoCopyTable(AutoCopySetting setting, string name)
 {
     using (var tble = CreateAutoCopyTable(name))
     {
         tble.Rows.Add(
             setting.SourcePath,
             setting.DestinationPath,
             setting.ArchivePath,
             setting.RepeatEach,
             setting.TransferType,
             setting.ArchiveType);
         ;
         return(tble);
     }
 }