/// <summary> /// Bait.xmlの内容を全て取得する /// </summary> /// <returns>BaitDBModel</returns> private BaitDBModel getBaitDB() { try { string xmlFilename = PATH_FISHDB + @"\" + FILENAME_BAITDB; BaitDBModel Baitdb = new BaitDBModel(); if (File.Exists(xmlFilename)) { FileStream fs = new FileStream(xmlFilename, System.IO.FileMode.Open); XmlSerializer serializer = new XmlSerializer(typeof(BaitDBModel)); Baitdb = (BaitDBModel)serializer.Deserialize(fs); fs.Close(); } return(Baitdb); } catch (Exception e) { logger.Fatal("{0}の取得中にエラーが発生しました。", FILENAME_BAITDB); throw e; } }
/// <summary> /// Bait.xmlに登録内容を書き出す /// </summary> /// <param name="iBaitDB">BaitDBModel</param> /// <returns>True:成功</returns> private bool putBaitDB(BaitDBModel iBaitDB) { try { string xmlFilename = PATH_FISHDB + @"\" + FILENAME_BAITDB; StreamWriter sw = new StreamWriter(xmlFilename, false, new UTF8Encoding(false)); XmlSerializerNamespaces ns = new XmlSerializerNamespaces(); ns.Add(String.Empty, String.Empty); XmlSerializer serializer = new XmlSerializer(typeof(BaitDBModel)); serializer.Serialize(sw, iBaitDB, ns); //書き込み sw.Flush(); sw.Close(); sw = null; return(true); } catch (Exception e) { logger.Fatal("{0}の登録中にエラーが発生しました。", FILENAME_BAITDB); throw e; } }
/// <summary> /// 餌を取得する /// </summary> /// <param name="iSearchString">餌名称(正規表現)</param> /// <returns>餌の一覧</returns> public List <BaitDBBaitModel> SelectBait(string iSearchString) { logger.Trace("SearchString={0}", iSearchString); List <BaitDBBaitModel> ret = new List <BaitDBBaitModel>(); BaitDBModel Baitdb = getBaitDB(); if (iSearchString == string.Empty) { ret = Baitdb.Bait; } else { foreach (BaitDBBaitModel Bait in Baitdb.Bait) { if (MiscTool.IsRegexString(Bait.BaitName, iSearchString)) { ret.Add(Bait); } } } ret.Sort(BaitDBModel.SortTypeName); return(ret); }