public ActionResult SetUpFolderBackUp() { // Đường dẫn tới file xml. string fileName = HttpContext.Server.MapPath("~/App_Data/config.xml"); if (!System.IO.File.Exists(fileName)) { CrearDocumentoXML(fileName); } // Tạo một đối tượng TextReader mới var xtr = System.Xml.Linq.XDocument.Load(fileName); string path_backup = ""; // string passwordsso = ""; //bool useOtherMailServer = false; var config = xtr.Elements("system.config").FirstOrDefault(); try { if (config.Descendants("path-backup").Any()) { path_backup = config.Element("path-backup").Value.Trim(); } } catch (Exception ex) { return(View()); } var model = new Models.SystemModel() { PathBackupFolder = path_backup }; return(View(model)); }
public MainViewModel() { DisplayName = "Strike! Encounter Builder"; _monsters = new BindableCollection <Models.MonsterModel>(); _traits = new BindableCollection <Models.TraitModel>(); _templates = new BindableCollection <Models.TemplateMonsterModel>(); _dataPath = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "StrikeRPG\\Data\\"); Models.SystemModel sys = null; if (!Directory.Exists(_dataPath)) { Directory.CreateDirectory(_dataPath); } //if (!File.Exists(System.IO.Path.Combine(_dataPath, "monsters.xml"))) //{ // using (StreamWriter ResourceFile = new StreamWriter(new FileStream(System.IO.Path.Combine(_dataPath, "data.xml"), FileMode.Create))) // using (Stream stream = System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream("LastStand.Data.data.xml")) // using (var reader = new StreamReader(stream)) // { // ResourceFile.Write(reader.ReadToEnd()); // ResourceFile.Flush(); // ResourceFile.Close(); // } //} try { TextReader reader = new StreamReader(System.IO.Path.Combine(_dataPath, "data.json")); sys = JsonConvert.DeserializeObject <Models.SystemModel>(reader.ReadToEnd()); reader.Close(); _monsters = new BindableCollection <Models.MonsterModel>(sys.Monsters); _traits = new BindableCollection <Models.TraitModel>(sys.Traits); _templates = new BindableCollection <Models.TemplateMonsterModel>(sys.Templates); } catch (Exception) { } if (_monsters == null) { _monsters = new BindableCollection <Models.MonsterModel>(); } if (_traits == null) { _traits = new BindableCollection <Models.TraitModel>(); } if (_templates == null) { _templates = new BindableCollection <Models.TemplateMonsterModel>(); } if (_monsters.Count > 0) { SelectedMonster = _monsters[0]; } if (_templates.Count > 0) { SelectedTemplate = _templates[0]; } }
//public void ShowTemplateMonsters() //{ // WindowManager wm = new WindowManager(); // Dictionary<string, object> settings = new Dictionary<string, object>(); // settings.Add("Height", 600); // settings.Add("Width", 1000); // settings.Add("SizeToContent", System.Windows.SizeToContent.Manual); // TemplateMonsterListViewModel tmlvm = new TemplateMonsterListViewModel(this); // wm.ShowDialog(tmlvm, null, settings); //} public void Save() { TextWriter writer = new StreamWriter(System.IO.Path.Combine(_dataPath, "data.json")); Models.SystemModel sys = new Models.SystemModel(); sys.Monsters = _monsters.ToList(); sys.Traits = _traits.ToList(); sys.Templates = _templates.ToList(); writer.Write(JsonConvert.SerializeObject(sys)); writer.Flush(); writer.Close(); }
public ActionResult SetUpFolderBackUp(Models.SystemModel model) { if (ModelState.IsValid) { try { // Đường dẫn tới file xml. string fileName = System.Web.Hosting.HostingEnvironment.ApplicationPhysicalPath + "/App_Data/config.xml"; if (!System.IO.File.Exists(fileName)) { CrearDocumentoXML(fileName); } // Tạo một đối tượng TextReader mới var xtr = System.Xml.Linq.XDocument.Load(fileName); if (!xtr.Descendants("system.config").Any()) { XElement EmailElement = new XElement("system.config"); xtr.Add(EmailElement); } var config = xtr.Elements("system.config").FirstOrDefault(); string path_backup = model.PathBackupFolder; if (path_backup.LastIndexOf("\\") != path_backup.Length - 1) { path_backup += "\\"; } if (!string.IsNullOrEmpty(path_backup)) { if (!config.Descendants("path-backup").Any()) { XElement passElement = new XElement("path-backup"); passElement.Value = path_backup; config.Add(passElement); } else { config.SetElementValue("path-backup", path_backup); } } xtr.Save(fileName); try { if (!System.IO.Directory.Exists(model.PathBackupFolder)) { System.IO.Directory.CreateDirectory(model.PathBackupFolder); } } catch { } return(RedirectToAction("Index", "Config")); } catch (Exception ex) { ModelState.AddModelError("", "Error system. Please try again a few minutes."); } } return(View(model)); }