public bool RestoreDb() { bool result = false; string exePath = ReflectHelper.GetExePath(); string path = Path.Combine(exePath, "dbbak\\db.bak"); string bakpath = FileDialogHelper.OpenBakDb(path); if (bakpath != null && bakpath != string.Empty) { if (DialogResult.Yes == MessageBox.Show("确定要还原吗?请在还原前进行备份!", "窗口提示", MessageBoxButtons.YesNo)) { try { File.Copy(bakpath, ReflectHelper.GetExePath() + @"\db\db.mdb", true); result = true; MessageBoxHelper.Show("还原成功,请退出系统重进!"); } catch (Exception ex) { //LogFactoryWrapper.Debug(ex.ToString()); MessageBoxHelper.Show("还原失败!"); } } } return(result); }
/// <summary> /// 删除配置文件 /// </summary> /// <typeparam name="T"></typeparam> public static void RemoveConfig <T>() { string path = ReflectHelper.GetExePath() + "/config/" + typeof(T).Name + ".cfg"; if (File.Exists(path)) { File.Delete(path); caches.Remove(typeof(T).FullName); } }
/// <summary> /// 保存某一个对象的配置 /// </summary> /// <typeparam name="T">泛型对象</typeparam> /// <returns>如果不存在会怎么样?</returns> public static void SaveToCaches(object config, string file) { string dir = ReflectHelper.GetExePath() + "/Caches"; if (!Directory.Exists(dir)) { Directory.CreateDirectory(dir); } string path = ReflectHelper.GetExePath() + "/Caches/" + file + ".txt"; if (SerializeHelper.SerializeToFile(config, path)) { } }
/// <summary> /// 获取配置信息 /// </summary> /// <returns>配置信息</returns> public static ClientConfig GetConfig() { string path = ReflectHelper.GetExePath() + "\\" + Config_File_Name; if (File.Exists(path)) { ClientConfig config = (ClientConfig)SerializeHelper.DeserializeFromFile(path); return(config); } else { return(null); } }
/// <summary> /// 获取某一个对象Config的cache的泛型方法 /// </summary> /// <typeparam name="T">泛型对象</typeparam> /// <returns>如果不存在会怎么样?</returns> public static T GetConfig <T>() { string typename = typeof(T).FullName; if (!caches.Contains(typename)) { string path = ReflectHelper.GetExePath() + "/config/" + typeof(T).Name + ".cfg"; if (File.Exists(path)) { object config = SerializeHelper.DeserializeFromFile(path); caches.Add(typename, config); } } return((T)Get <T>()); }
/// <summary> /// 保存某一个对象的配置 /// </summary> /// <typeparam name="T">泛型对象</typeparam> /// <returns>如果不存在会怎么样?</returns> public static void SaveConfig <T>(T config) { string dir = ReflectHelper.GetExePath() + "/config"; if (!Directory.Exists(dir)) { Directory.CreateDirectory(dir); } string typename = typeof(T).FullName; string path = ReflectHelper.GetExePath() + "/config/" + typeof(T).Name + ".cfg"; if (SerializeHelper.SerializeToFile(config, path)) { Add(typename, config); } }
public static void BackUp() { string path = FileDialogHelper.SaveConfig(); if (path != null && path != string.Empty) { try { File.Copy(ReflectHelper.GetExePath() + @"\config\" + FileName, path, true); MessageBoxHelper.Show(" 备份成功!"); } catch (Exception ex) { MessageBoxHelper.Show(" 备份失败!异常:" + ex.Message); } } }
void dbbak_Click(object sender, EventArgs e) { string path = FileDialogHelper.SaveBakDb(); if (path != null && path != string.Empty) { try { File.Copy(ReflectHelper.GetExePath() + @"\db\db.mdb", path, true); MessageBoxHelper.Show(" 备份成功!"); } catch (Exception ex) { //LogFactoryWrapper.Debug(ex.ToString()); MessageBoxHelper.Show(" 备份失败!"); } } }
void bak_Click(object sender, EventArgs e) { string file = FileDialogHelper.SaveZip(string.Empty); if (file.Length > 0) { string path = ReflectHelper.GetExePath(); string dir = Path.Combine(path, "config"); if (FileHelper.ZipDir(dir, file)) { MessageBoxHelper.Show("备份成功!"); } else { MessageBoxHelper.Show("备份失败!"); } } }
/// <summary> /// 保存某一个对象的配置 /// </summary> /// <typeparam name="T">泛型对象</typeparam> /// <returns>如果不存在会怎么样?</returns> public static object GetFromCaches(string file) { string dir = ReflectHelper.GetExePath() + "/Caches"; if (!Directory.Exists(dir)) { Directory.CreateDirectory(dir); } string path = ReflectHelper.GetExePath() + "/Caches/" + file + ".txt"; if (File.Exists(path)) { return(SerializeHelper.DeserializeFromFile(path)); } else { return(null); } }
void restore_Click(object sender, EventArgs e) { string file = FileDialogHelper.OpenZip(string.Empty); if (file.Length > 0) { string path = ReflectHelper.GetExePath(); string dir = Path.Combine(path, "config"); if (FileHelper.UnZipDir(file, dir)) { MessageBoxHelper.Show("还原成功!请退出重进使配置生效!"); //FT.Commons.Cache.StaticCacheManager.Caches.Clear(); } else { MessageBoxHelper.Show("还原失败!"); } } }
public static void Restore() { string path = FileDialogHelper.OpenConfig(); if (path != null && path != string.Empty) { if (DialogResult.Yes == MessageBox.Show("确定要还原吗?请在还原前进行备份!", "窗口提示", MessageBoxButtons.YesNo)) { try { File.Copy(path, ReflectHelper.GetExePath() + @"\config\" + FileName, true); MessageBoxHelper.Show("还原成功!"); Load(); } catch (Exception ex) { MessageBoxHelper.Show("还原失败!异常:" + ex.Message); } } } }
void dbrestore_Click(object sender, EventArgs e) { string path = FileDialogHelper.OpenAccessDb(); if (path != null && path != string.Empty) { if (DialogResult.Yes == MessageBox.Show("确定要还原吗?请在还原前进行备份!", "窗口提示", MessageBoxButtons.YesNo)) { try { File.Copy(path, ReflectHelper.GetExePath() + @"\db\db.mdb", true); MessageBoxHelper.Show("还原成功!"); } catch (Exception ex) { //LogFactoryWrapper.Debug(ex.ToString()); MessageBoxHelper.Show("还原失败!"); } } } }
//public int Days = 1; public bool BakDb() { bool result = false; try { string exePath = ReflectHelper.GetExePath(); string path = Path.Combine(exePath, "dbbak"); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } DirectoryInfo dir = new DirectoryInfo(path); FileInfo[] files = dir.GetFiles(); if (files.Length >= BakCount) { DateTime first = files[0].CreationTime; int index = 0; for (int i = 1; i < files.Length; i++) { if (files[i].CreationTime < first) { first = files[i].CreationTime; index = i; } } files[index].Delete(); File.Copy("db\\db.mdb", "dbbak\\dbbak" + System.DateTime.Now.ToString("yyyyMMddHHmmss") + ".bak"); } else { File.Copy("db\\db.mdb", "dbbak\\dbbak" + System.DateTime.Now.ToString("yyyyMMddHHmmss") + ".bak"); } result = true; } catch (Exception ex) { } return(result); }
/// <summary> /// 保存客户端配置 /// </summary> /// <param name="config">配置信息</param> public static void SaveConfig(ClientConfig config) { string path = ReflectHelper.GetExePath() + "\\" + Config_File_Name; SerializeHelper.SerializeToFile(config, path); }