/// <summary> /// xmlファイルをコンバートする(1.0.0→1.0.5) /// </summary> /// <returns></returns> private void convert1_0_0to1_0_5(string iXmlFileName, string iPlayerName, DateTime iYmd) { FishHistoryDBModel1_0_0 history1_0_0 = getHistoryDB1_0_0(iPlayerName, iYmd); FishHistoryDBModel1_0_5 history1_0_5 = new FishHistoryDBModel1_0_5(); history1_0_5.Version = "1.0.5"; history1_0_5.PlayerName = history1_0_0.PlayerName; history1_0_5.EarthDate = history1_0_0.EarthDate.ToShortDateString(); foreach (FishHistoryDBFishModel1_0_0 fish1_0_0 in history1_0_0.Fishes) { FishHistoryDBFishModel1_0_5 fish1_0_5 = new FishHistoryDBFishModel1_0_5(); fish1_0_5.FishName = fish1_0_0.FishName; fish1_0_5.ZoneName = fish1_0_0.ZoneName; fish1_0_5.RodName = fish1_0_0.RodName; fish1_0_5.BaitName = fish1_0_0.BaitName; fish1_0_5.ID1 = fish1_0_0.ID1; fish1_0_5.ID2 = fish1_0_0.ID2; fish1_0_5.ID3 = fish1_0_0.ID3; fish1_0_5.ID4 = fish1_0_0.ID4; fish1_0_5.Critical = fish1_0_0.Critical; fish1_0_5.FishCount = fish1_0_0.FishCount; if (fish1_0_0.ID1 == 0 && fish1_0_0.ID2 == 0 && fish1_0_0.ID3 == 0 && fish1_0_0.ID4 == 0) { fish1_0_5.ItemType = FishDBItemTypeKind.Unknown; } else { fish1_0_5.ItemType = FishDBItemTypeKind.Common; } fish1_0_5.FishType = fish1_0_0.FishType; fish1_0_5.Result = fish1_0_0.Result; fish1_0_5.EarthTime = fish1_0_0.EarthTime.ToString(); fish1_0_5.VanaTime = fish1_0_0.VanaTime + ":00"; fish1_0_5.VanaWeekDay = fish1_0_0.VanaWeekDay; fish1_0_5.MoonPhase = fish1_0_0.MoonPhase; fish1_0_5.X = (float)Math.Round(fish1_0_0.X, 1, MidpointRounding.AwayFromZero); fish1_0_5.Y = (float)Math.Round(fish1_0_0.Y, 1, MidpointRounding.AwayFromZero); fish1_0_5.Z = (float)Math.Round(fish1_0_0.Z, 1, MidpointRounding.AwayFromZero); fish1_0_5.H = (float)Math.Round(fish1_0_0.H, 1, MidpointRounding.AwayFromZero); history1_0_5.Fishes.Add(fish1_0_5); } //バックアップ string backupFileName = iXmlFileName + ".bak"; if (File.Exists(backupFileName)) { File.Delete(backupFileName); } File.Copy(iXmlFileName, backupFileName); //xml書き込み PutHistoryDB1_0_5(iPlayerName, history1_0_5); }
private void updateCatchCount1_0_5(FishHistoryDBModel1_0_5 iFishHistoryDB) { int cnt = 0; foreach (FishHistoryDBFishModel1_0_5 fish in iFishHistoryDB.Fishes) { if (fish.Result == FishResultStatusKind.Catch && (fish.FishType == FishDBFishTypeKind.SmallFish || fish.FishType == FishDBFishTypeKind.LargeFish)) { cnt++; } } this.CatchCount = cnt; }
/// <summary> /// xmlへ書き込む(1.0.5) /// </summary> /// <param name="iPlayerName">プレイヤー名</param> /// <param name="iHistoryDB">FishHistoryDBModel</param> /// <returns>True:成功</returns> public bool PutHistoryDB1_0_5(string iPlayerName, FishHistoryDBModel1_0_5 iHistoryDB, string iPath = PATH_FISHHISTORYDB) { string xmlFilename = GetXmlName(iPlayerName, DateTime.Parse(iHistoryDB.EarthDate), iPath); try { if (!Directory.Exists(iPath)) { Directory.CreateDirectory(iPath); } for (int i = 0; i < Constants.FILELOCK_RETRY_COUNT; i++) { try { using (FileStream fs = new FileStream(xmlFilename, FileMode.Create, FileAccess.Write, FileShare.None))//ファイルロック { StreamWriter sw = new StreamWriter(fs, new UTF8Encoding(false)); XmlSerializerNamespaces ns = new XmlSerializerNamespaces(); ns.Add(String.Empty, String.Empty); XmlSerializer serializer = new XmlSerializer(typeof(FishHistoryDBModel1_0_5)); serializer.Serialize(sw, iHistoryDB, ns); //書き込み sw.Flush(); sw.Close(); sw = null; } break; } catch (IOException) { Thread.Sleep(100); continue; } } //CatchCountの更新 updateCatchCount1_0_5(iHistoryDB); return(true); } catch (Exception e) { logger.Fatal("{0}の登録中にエラーが発生しました。", xmlFilename); throw e; } }
/// <summary> /// xmlの内容を全て取得する(1.0.5) /// </summary> /// <returns>FishHistoryDBModel</returns> public FishHistoryDBModel1_0_5 GetHistoryDB1_0_5(string iPlayerName, DateTime iYmd, string iPath = PATH_FISHHISTORYDB) { string xmlFilename = GetXmlName(iPlayerName, iYmd); try { FishHistoryDBModel1_0_5 history = new FishHistoryDBModel1_0_5(); if (!Directory.Exists(iPath)) { Directory.CreateDirectory(iPath); } if (File.Exists(xmlFilename)) { for (int i = 0; i < Constants.FILELOCK_RETRY_COUNT; i++) { try { using (FileStream fs = new FileStream(xmlFilename, FileMode.Open, FileAccess.Read, FileShare.Read)) { XmlSerializer serializer = new XmlSerializer(typeof(FishHistoryDBModel1_0_5)); history = (FishHistoryDBModel1_0_5)serializer.Deserialize(fs); fs.Close(); } break; } catch (IOException) { Thread.Sleep(100); continue; } } } //CatchCountの更新 updateCatchCount1_0_5(history); return(history); } catch (Exception e) { logger.Fatal("{0}の取得中にエラーが発生しました。", xmlFilename); throw e; } }
private void updateCatchCount1_0_5(FishHistoryDBModel1_0_5 iFishHistoryDB) { int cnt = 0; foreach (FishHistoryDBFishModel1_0_5 fish in iFishHistoryDB.Fishes) { if (fish.Result == FishResultStatusKind.Catch && (fish.FishType == FishDBFishTypeKind.SmallFish || fish.FishType == FishDBFishTypeKind.LargeFish)) { cnt++; } } this.CatchCount = cnt; }
/// <summary> /// xmlファイルをコンバートする(1.0.0→1.0.5) /// </summary> /// <returns></returns> private void convert1_0_0to1_0_5(string iXmlFileName, string iPlayerName, DateTime iYmd) { FishHistoryDBModel1_0_0 history1_0_0 = getHistoryDB1_0_0(iPlayerName, iYmd); FishHistoryDBModel1_0_5 history1_0_5 = new FishHistoryDBModel1_0_5(); history1_0_5.Version = "1.0.5"; history1_0_5.PlayerName = history1_0_0.PlayerName; history1_0_5.EarthDate = history1_0_0.EarthDate.ToShortDateString(); foreach (FishHistoryDBFishModel1_0_0 fish1_0_0 in history1_0_0.Fishes) { FishHistoryDBFishModel1_0_5 fish1_0_5 = new FishHistoryDBFishModel1_0_5(); fish1_0_5.FishName = fish1_0_0.FishName; fish1_0_5.ZoneName = fish1_0_0.ZoneName; fish1_0_5.RodName = fish1_0_0.RodName; fish1_0_5.BaitName = fish1_0_0.BaitName; fish1_0_5.ID1 = fish1_0_0.ID1; fish1_0_5.ID2 = fish1_0_0.ID2; fish1_0_5.ID3 = fish1_0_0.ID3; fish1_0_5.ID4 = fish1_0_0.ID4; fish1_0_5.Critical = fish1_0_0.Critical; fish1_0_5.FishCount = fish1_0_0.FishCount; if (fish1_0_0.ID1 == 0 && fish1_0_0.ID2 == 0 && fish1_0_0.ID3 == 0 && fish1_0_0.ID4 == 0) { fish1_0_5.ItemType = FishDBItemTypeKind.Unknown; } else { fish1_0_5.ItemType = FishDBItemTypeKind.Common; } fish1_0_5.FishType = fish1_0_0.FishType; fish1_0_5.Result = fish1_0_0.Result; fish1_0_5.EarthTime = fish1_0_0.EarthTime.ToString(); fish1_0_5.VanaTime = fish1_0_0.VanaTime + ":00"; fish1_0_5.VanaWeekDay = fish1_0_0.VanaWeekDay; fish1_0_5.MoonPhase = fish1_0_0.MoonPhase; fish1_0_5.X = (float)Math.Round(fish1_0_0.X, 1, MidpointRounding.AwayFromZero); fish1_0_5.Y = (float)Math.Round(fish1_0_0.Y, 1, MidpointRounding.AwayFromZero); fish1_0_5.Z = (float)Math.Round(fish1_0_0.Z, 1, MidpointRounding.AwayFromZero); fish1_0_5.H = (float)Math.Round(fish1_0_0.H, 1, MidpointRounding.AwayFromZero); history1_0_5.Fishes.Add(fish1_0_5); } //バックアップ string backupFileName = iXmlFileName + ".bak"; if (File.Exists(backupFileName)) File.Delete(backupFileName); File.Copy(iXmlFileName, backupFileName); //xml書き込み PutHistoryDB1_0_5(iPlayerName, history1_0_5); }
/// <summary> /// xmlへ書き込む(1.0.5) /// </summary> /// <param name="iPlayerName">プレイヤー名</param> /// <param name="iHistoryDB">FishHistoryDBModel</param> /// <returns>True:成功</returns> public bool PutHistoryDB1_0_5(string iPlayerName, FishHistoryDBModel1_0_5 iHistoryDB, string iPath = PATH_FISHHISTORYDB) { string xmlFilename = GetXmlName(iPlayerName, DateTime.Parse(iHistoryDB.EarthDate), iPath); if (!Directory.Exists(iPath)) { Directory.CreateDirectory(iPath); } for (int i = 0; i < Constants.FILELOCK_RETRY_COUNT; i++) { try { using (FileStream fs = new FileStream(xmlFilename, FileMode.Create, FileAccess.Write, FileShare.None))//ファイルロック { StreamWriter sw = new StreamWriter(fs, new UTF8Encoding(false)); XmlSerializerNamespaces ns = new XmlSerializerNamespaces(); ns.Add(String.Empty, String.Empty); XmlSerializer serializer = new XmlSerializer(typeof(FishHistoryDBModel1_0_5)); serializer.Serialize(sw, iHistoryDB, ns); //書き込み sw.Flush(); sw.Close(); sw = null; } break; } catch (IOException) { Thread.Sleep(100); continue; } } //CatchCountの更新 updateCatchCount1_0_5(iHistoryDB); return true; }
/// <summary> /// xmlの内容を全て取得する(1.0.5) /// </summary> /// <returns>FishHistoryDBModel</returns> public FishHistoryDBModel1_0_5 GetHistoryDB1_0_5(string iPlayerName, DateTime iYmd, string iPath = PATH_FISHHISTORYDB) { string xmlFilename = GetXmlName(iPlayerName, iYmd); FishHistoryDBModel1_0_5 history = new FishHistoryDBModel1_0_5(); if (!Directory.Exists(iPath)) { Directory.CreateDirectory(iPath); } if (File.Exists(xmlFilename)) { for (int i = 0; i < Constants.FILELOCK_RETRY_COUNT; i++) { try { using (FileStream fs = new FileStream(xmlFilename, FileMode.Open, FileAccess.Read, FileShare.Read)) { XmlSerializer serializer = new XmlSerializer(typeof(FishHistoryDBModel1_0_5)); history = (FishHistoryDBModel1_0_5)serializer.Deserialize(fs); fs.Close(); } break; } catch (IOException) { Thread.Sleep(100); continue; } } } //CatchCountの更新 updateCatchCount1_0_5(history); return history; }
/// <summary> /// xmlファイルをコンバートする(1.0.5→1.1.0) /// </summary> /// <returns></returns> private void convert1_0_5to1_1_0(string iXmlFileName, string iPlayerName, DateTime iYmd) { FishHistoryDBModel1_0_5 history1_0_5 = GetHistoryDB1_0_5(iPlayerName, iYmd); FishHistoryDBModel history1_1_0 = new FishHistoryDBModel(); history1_1_0.Version = "1.1.0"; history1_1_0.PlayerName = history1_0_5.PlayerName; history1_1_0.EarthDate = history1_0_5.EarthDate; history1_1_0.Uploaded = false; history1_1_0.TimeElapsed = history1_0_5.TimeElapsed; foreach (FishHistoryDBFishModel1_0_5 fish1_0_5 in history1_0_5.Fishes) { FishHistoryDBFishModel fish1_1_0 = new FishHistoryDBFishModel(); fish1_1_0.FishName = fish1_0_5.FishName; fish1_1_0.ZoneName = fish1_0_5.ZoneName; fish1_1_0.RodName = fish1_0_5.RodName; fish1_1_0.BaitName = fish1_0_5.BaitName; fish1_1_0.ID1 = fish1_0_5.ID1; fish1_1_0.ID2 = fish1_0_5.ID2; fish1_1_0.ID3 = fish1_0_5.ID3; fish1_1_0.ID4 = fish1_0_5.ID4; fish1_1_0.Critical = fish1_0_5.Critical; fish1_1_0.FishCount = fish1_0_5.FishCount; fish1_1_0.ItemType = fish1_0_5.ItemType; fish1_1_0.FishType = fish1_0_5.FishType; fish1_1_0.Result = fish1_0_5.Result; fish1_1_0.EarthTime = fish1_0_5.EarthTime; fish1_1_0.VanaTime = fish1_0_5.VanaTime; fish1_1_0.VanaWeekDay = fish1_0_5.VanaWeekDay; fish1_1_0.MoonPhase = fish1_0_5.MoonPhase; fish1_1_0.X = fish1_0_5.X; fish1_1_0.Y = fish1_0_5.Y; fish1_1_0.Z = fish1_0_5.Z; fish1_1_0.H = fish1_0_5.H; fish1_1_0.Skill = fish1_0_5.Skill; fish1_1_0.SerpentRumors = fish1_0_5.SerpentRumors; fish1_1_0.AnglersAlmanac = fish1_0_5.AnglersAlmanac; fish1_1_0.FrogFishing = fish1_0_5.FrogFishing; fish1_1_0.Mooching = fish1_0_5.Mooching; history1_1_0.Fishes.Add(fish1_1_0); } foreach (FishHistoryDBHarakiriModel1_0_5 harakiri1_0_5 in history1_0_5.Harakiri) { FishHistoryDBHarakiriModel harakiri1_1_0 = new FishHistoryDBHarakiriModel(); harakiri1_1_0.EarthTime = harakiri1_0_5.EarthTime; harakiri1_1_0.VanaTime = harakiri1_0_5.VanaTime; harakiri1_1_0.FishName = harakiri1_0_5.FishName; harakiri1_1_0.ItemName = harakiri1_0_5.ItemName; history1_1_0.Harakiri.Add(harakiri1_1_0); } //バックアップ string backupFileName = iXmlFileName + ".bak"; if (File.Exists(backupFileName)) { File.Delete(backupFileName); } File.Copy(iXmlFileName, backupFileName); //xml書き込み PutHistoryDB(iPlayerName, history1_1_0); }