/// <summary> /// Open bat file /// </summary> private void FileOpenBat(String filename) { XmlDocument doc = new XmlDocument(); IXmlFormatter formatter = FepXmlableFactory.CreateXmlFormatter(); IXmlContext cnt; XmlElement _eleBat; // Deserialize object from xml format doc.Load(filename); cnt = FepXmlableFactory.CreateXmlContext(formatter, doc); doc = cnt.Document; _eleBat = doc.DocumentElement; _batManager = cnt.FromXml(_eleBat) as MkaBatManager; _batManager.BatInfo.BatDirectory = Path.GetDirectoryName(filename); for (int i = 0; i < _batManager.ImageFileNames.Count; i++) { _batManager.ImageFilePaths.Add(_batManager.BatInfo.BatDirectory + "\\" + _batManager.ImageFileNames[i]); _batManager.GlassFilePaths.Add(_batManager.BatInfo.BatDirectory + "\\" + Path.GetFileNameWithoutExtension(_batManager.ImageFileNames[i]) + MkaDefine.MkaFileExt); } }
/// <summary> /// Load glass information from xml file /// </summary> private MkaDocument FileLoadGlass(String filename) { XmlDocument doc = new XmlDocument(); doc.Load(filename); // Deserialize object from xml format IXmlFormatter formatter = FepXmlableFactory.CreateXmlFormatter(); IXmlContext cnt = FepXmlableFactory.CreateXmlContext(formatter, doc); XmlElement _eleBat = cnt.Document.DocumentElement; XmlNode _eleGlass = _eleBat.FirstChild; XmlNode _eleMk = _eleGlass.FirstChild; MkaDocument mkaDoc = new MkaDocument(null); mkaDoc.GlassInfo = cnt.FromXml(_eleGlass as XmlElement) as MkaGlassInfo; mkaDoc.BatInfo = cnt.FromXml(_eleBat as XmlElement) as MkaBatInfo; mkaDoc.MokkanList = cnt.FromXml(_eleMk as XmlElement) as MokkanList; mkaDoc.BatInfo.BatDirectory = Path.GetDirectoryName(filename); mkaDoc.GlassInfo.GlassFilePath = filename; mkaDoc.GlassInfo.MokkanKazu = mkaDoc.MokkanList.Count; mkaDoc.GlassImage = Path.GetDirectoryName(filename) + "\\" + mkaDoc.GlassInfo.ImageFileName; int maxRid = mkaDoc.MokkanList.GetMaxRBangou() + 1; if (maxRid == 1) { MkaMokkanInfo.LastRBangou = mkaDoc.GlassInfo.KaishiRBangou; } else { MkaMokkanInfo.LastRBangou = maxRid; } mkaDoc.MokkanList.KaishiRBangou = MkaMokkanInfo.LastRBangou; return(mkaDoc); }
public void Save() { try { // Serialize object to xml format XmlDocument doc = new XmlDocument(); IXmlFormatter formatter = FepXmlableFactory.CreateXmlFormatter(); IXmlContext cnt = FepXmlableFactory.CreateXmlContext(formatter, doc); doc = cnt.Document; XmlDeclaration xmldecl = doc.CreateXmlDeclaration("1.0", null, null); XmlElement _eleBat = cnt.ToXml(this); doc.AppendChild(_eleBat); doc.InsertBefore(xmldecl, doc.DocumentElement); doc.Save(BatFilePath); } catch (System.Exception ex) { MessageBox.Show(Owner, MkaMessage.ErrSaveFile); _log.Error(MkaMessage.ErrSaveFile, ex); } }