/// <summary> /// ファイルコンバーター /// </summary> /// <returns></returns> public void Converter() { string[] xmlFileNames = Directory.GetFiles(PATH_FISHDB); foreach (string xmlFileName in xmlFileNames) { List <string> regGroupStr = new List <string>(); if (MiscTool.GetRegexString(xmlFileName, PATH_FISHDB + "\\\\(.*)\\.xml$", out regGroupStr)) { string rodName = regGroupStr[0]; if (!_Rods.Contains(rodName)) { continue; } //最新版までコンバート for (int i = 0; i < Constants.MAX_LOOP_COUNT; i++) { string version = getXmlVersion(xmlFileName); if (string.IsNullOrEmpty(version) || version == VERSION) { break; } if (version == "1.0.0")////1.0.0→1.0.5 { logger.Info("FishDBのコンバート 1.0.0→1.0.5 {0}", xmlFileName); convert1_0_0to1_0_5(xmlFileName, rodName); } } } } }
/// <summary> /// ファイルコンバーター /// </summary> /// <returns></returns> public void Converter() { string[] xmlFileNames = Directory.GetFiles(PATH_FISHHISTORYDB); foreach (string xmlFileName in xmlFileNames) { //string filename = Path.GetFileName(xmlFileName); List <string> regGroupStr = new List <string>(); if (MiscTool.GetRegexString(xmlFileName, PATH_FISHHISTORYDB + "\\\\(.*)_([0-9][0-9][0-9][0-9])([0-9][0-9])([0-9][0-9])\\.xml$", out regGroupStr)) { string playerName = regGroupStr[0]; DateTime ymd = DateTime.Parse(string.Format("{0}/{1}/{2}", regGroupStr[1], regGroupStr[2], regGroupStr[3])); //最新版までコンバート for (int i = 0; i < Constants.MAX_LOOP_COUNT; i++) { string version = GetXmlVersion(xmlFileName); if (version == VERSION) { break; } else if (version == "1.0.0")////1.0.0→1.0.5 { logger.Info("FishHistoryDBのコンバート 1.0.0→1.0.5 {0}", xmlFileName); convert1_0_0to1_0_5(xmlFileName, playerName, ymd); } else if (version == "1.0.5")////1.0.5→1.1.0 { logger.Info("FishHistoryDBのコンバート 1.0.5→1.1.0 {0}", xmlFileName); convert1_0_5to1_1_0(xmlFileName, playerName, ymd); } } } } }
/// <summary> /// チャット内容からChatKbnKindを取得する /// </summary> /// <param name="iCl">チャットライン</param> /// <returns>チャット区分</returns> private ChatKbnKind getChatKbnFromChatline(EliteAPI.ChatEntry iCl, out List <string> oArgs) { oArgs = new List <string>(); foreach (KeyValuePair <ChatKbnKind, string> v in dictionaryChat) { string searchStr = v.Value; if (MiscTool.IsRegexString(iCl.Text, searchStr)) { oArgs = MiscTool.GetRegexString(iCl.Text, searchStr); return(v.Key); } } return(ChatKbnKind.Unknown); }
/// <summary> /// データベース更新処理 /// </summary> public bool UpdateDB() { logger.Debug("DB更新開始"); string response = string.Empty; bool httpRet = false; //アプリケーションバージョンチェック EventReceiveMessage("== クライアントのバージョンチェック ==", 0xFFFFFFFF, true); NameValueCollection postCheckVersion = new NameValueCollection(); postCheckVersion.Add("version", MiscTool.GetAppVersion()); string responseCheckVersion = string.Empty; bool retCheckVersion = HttpPost(serverName + URL_API_CHECK_VERSION, postCheckVersion, out responseCheckVersion); if (!retCheckVersion) { EventReceiveMessage(responseCheckVersion, 0xFFFF0000); return(false); } XmlSerializer seriApiCheckVersion = new XmlSerializer(typeof(UpdateDBApiCheckVersionModel)); MemoryStream msApiCheckVersion = new MemoryStream(Encoding.UTF8.GetBytes(responseCheckVersion)); var resCheckVersion = (UpdateDBApiCheckVersionModel)seriApiCheckVersion.Deserialize(msApiCheckVersion); if (resCheckVersion.Result.Success == "true") { //有効バージョンか? if (resCheckVersion.VersionEnable == "true") { //新しいバージョンがリリースされているか? if (resCheckVersion.NewVersionExists != "true") { //最新バージョンを使用 EventReceiveMessage(resCheckVersion.Message); } else { //新しいバージョンがある EventReceiveMessage(resCheckVersion.Message, 0xFFFF0000); //イベント発生 EventNewerVersion(resCheckVersion.Message, resCheckVersion.NewVersionUrl); } } else { //無効なバージョン EventReceiveMessage(resCheckVersion.Message, 0xFFFF0000); //イベント発生 EventNewerVersion(resCheckVersion.Message, resCheckVersion.NewVersionUrl); return(false); } } else { EventReceiveMessage(resCheckVersion.Result.Message, 0xFFFF0000); return(false); } //有効名称データの取得 EventReceiveMessage("== チェックデータを取得 ==", 0xFFFFFFFF, true); //有効名称データの受信 response = string.Empty; httpRet = Http(serverName + URL_API_ENABLE_NAME, out response); UpdateDBApiEnableNameModel enablename = new UpdateDBApiEnableNameModel(); if (httpRet) { XmlSerializer serializer = new XmlSerializer(typeof(UpdateDBApiEnableNameModel)); MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes(response)); enablename = (UpdateDBApiEnableNameModel)serializer.Deserialize(ms); if (enablename.Result.Success != "true") { //イベント発生 EventReceiveMessage(string.Format("{0}", enablename.Result.Message), 0xFFFF0000); return(false); } } else { //イベント発生 EventReceiveMessage(string.Format("{0}", response), 0xFFFF0000); return(false); } //履歴データの送信 EventReceiveMessage("== 履歴データの送信 ==", 0xFFFFFFFF, true); string[] xmlFileNames = Directory.GetFiles(FishHistoryDB.PATH_FISHHISTORYDB); foreach (string xmlFileName in xmlFileNames) { string filename = Path.GetFileName(xmlFileName); List <string> regGroupStr = new List <string>(); if (MiscTool.GetRegexString(xmlFileName, FishHistoryDB.PATH_FISHHISTORYDB + "\\\\(.*)_([0-9][0-9][0-9][0-9])([0-9][0-9])([0-9][0-9])\\.xml$", out regGroupStr)) { string playerName = regGroupStr[0]; DateTime ymd = DateTime.Parse(string.Format("{0}/{1}/{2}", regGroupStr[1], regGroupStr[2], regGroupStr[3])); //アップロード対象か? FishHistoryDBModel history = historyDB.GetHistoryDB(playerName, ymd); if (!history.Uploaded) { //XMLからプレイヤー情報を消去する history = historyDB.GetHistoryDB(playerName, ymd); history.PlayerName = DUMMY_PLAYER_NAME; //名称チェック 魚 var uploadFishes = new List <FishHistoryDBFishModel>(); foreach (var fish in history.Fishes) { if (fish.Result == FishResultStatusKind.Catch) { if ( enablename.Rods.Contains(new UpdateDBApiEnableNameRodModel(fish.RodName)) && (fish.FishName.Length == 0 | enablename.Fishes.Contains(new UpdateDBApiEnableNameFishModel(fish.FishName))) && enablename.Zones.Contains(new UpdateDBApiEnableNameZoneModel(fish.ZoneName)) && enablename.Baits.Contains(new UpdateDBApiEnableNameBaitModel(fish.BaitName))) { uploadFishes.Add(fish); } } else { uploadFishes.Add(fish); } } history.Fishes = uploadFishes; //名称チェック ハラキリ var uploadHarakiri = new List <FishHistoryDBHarakiriModel>(); foreach (var harakiri in history.Harakiri) { if (enablename.Fishes.Contains(new UpdateDBApiEnableNameFishModel(harakiri.FishName)) && (harakiri.ItemName.Length == 0 | enablename.HarakiriItems.Contains(new UpdateDBApiEnableNameHarakiriItemModel(harakiri.ItemName)))) { uploadHarakiri.Add(harakiri); } } history.Harakiri = uploadHarakiri; //一時ディレクトリにXMLファイルを保存 historyDB.PutHistoryDB(DUMMY_PLAYER_NAME, history, Constants.PATH_TEMP); string uploadFileName = historyDB.GetXmlName(DUMMY_PLAYER_NAME, ymd, Constants.PATH_TEMP); logger.Debug("コピー {0}→{1}", filename, uploadFileName); //ファイルアップロード logger.Debug("{0}を送信中", uploadFileName); EventReceiveMessage(string.Format("{0}をアップロード", filename)); NameValueCollection nvc = new NameValueCollection(); response = string.Empty; httpRet = HttpUploadFile(serverName + URL_API_UPLOAD_HISTORY, uploadFileName, "upfile", "application/xml", nvc, out response); logger.Trace("Response:\r{0}", response); if (httpRet) { //レスポンスを取得 XmlSerializer serializer = new XmlSerializer(typeof(UpdateDBApiUploadHistoryModel)); //byte[] bres = Encoding.UTF8.GetBytes(response); MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes(response)); var res = (UpdateDBApiUploadHistoryModel)serializer.Deserialize(ms); //HistoryDBを送信済みにする FishHistoryDBModel history2 = historyDB.GetHistoryDB(playerName, ymd); history2.Uploaded = true; historyDB.PutHistoryDB(playerName, history2); //エラー発生 if (res.Result.Success != "true") { //イベント発生 EventReceiveMessage(string.Format("{0}", res.Result.Message), 0xFFFF0000); } } else { //イベント発生 EventReceiveMessage(string.Format("{0}", response), 0xFFFF0000); } //テンポラリファイル削除 if (File.Exists(uploadFileName)) { File.Delete(uploadFileName); } } } } //魚情報を取得 EventReceiveMessage("== 魚情報を取得 ==", 0xFFFFFFFF, true); //ステータスの受信 response = string.Empty; httpRet = Http(serverName + URL_API_STATUS, out response); UpdateDBApiStatusModel status = new UpdateDBApiStatusModel(); if (httpRet) { XmlSerializer serializer = new XmlSerializer(typeof(UpdateDBApiStatusModel)); MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes(response)); status = (UpdateDBApiStatusModel)serializer.Deserialize(ms); if (status.Result.Success == "true") { foreach (UpdateDBApiStatusStatusModel rod in status.Status) { logger.Info("竿:{0} 更新日:{1}", rod.RodName, rod.LastUpdate); if (!File.Exists(Path.Combine(FishDB.PATH_FISHDB, rod.RodName + ".xml")) || DateTime.Parse(rod.LastUpdate) > DateTime.Parse(settings.Global.UpdateDB.LastUpdate)) { //竿魚情報取得 EventReceiveMessage(string.Format("{0}のダウンロード", rod.RodName)); string url = serverName + URL_API_ROD + "/" + WebUtility.HtmlEncode(rod.RodName); string response2 = string.Empty; bool httpRet2 = Http(url, out response2); //登録処理 if (httpRet2) { XmlSerializer serializer2 = new XmlSerializer(typeof(UpdateDBApiRodModel)); MemoryStream ms2 = new MemoryStream(Encoding.UTF8.GetBytes(response2)); var res2 = (UpdateDBApiRodModel)serializer2.Deserialize(ms2); if (res2.Result.Success == "true") { foreach (FishDBFishModel fish in res2.Rod.Fishes) { //IDの追加 foreach (var id in fish.IDs) { FishDBIdModel idm = new FishDBIdModel(id.ID1, id.ID2, id.ID3, id.ID4, id.Count, id.Critical, id.ItemType); fishDB.AddFish(res2.Rod.RodName, fish.FishName, fish.FishType, idm, fish.ZoneNames[0], fish.BaitNames[0]); } //エリアの追加 foreach (var zone in fish.ZoneNames) { FishDBIdModel idm = new FishDBIdModel(fish.IDs[0].ID1, fish.IDs[0].ID2, fish.IDs[0].ID3, fish.IDs[0].ID4, fish.IDs[0].Count, fish.IDs[0].Critical, fish.IDs[0].ItemType); fishDB.AddFish(res2.Rod.RodName, fish.FishName, fish.FishType, idm, zone, fish.BaitNames[0]); } //エサの追加 foreach (var bait in fish.BaitNames) { FishDBIdModel idm = new FishDBIdModel(fish.IDs[0].ID1, fish.IDs[0].ID2, fish.IDs[0].ID3, fish.IDs[0].ID4, fish.IDs[0].Count, fish.IDs[0].Critical, fish.IDs[0].ItemType); fishDB.AddFish(res2.Rod.RodName, fish.FishName, fish.FishType, idm, fish.ZoneNames[0], bait); } } } else { //イベント発生 EventReceiveMessage(string.Format("{0}", res2.Result.Message), 0xFFFF0000); } } else { //イベント発生 EventReceiveMessage(string.Format("{0}", response2), 0xFFFF0000); } } Thread.Sleep(1); } } } else { //イベント発生 EventReceiveMessage(string.Format("{0}", response), 0xFFFF0000); return(false); } //最終更新日の設定 settings.Global.UpdateDB.LastUpdate = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"); EventReceiveMessage("データベースの更新が完了しました", 0xFFFFFFFF, true); logger.Debug("DB更新終了"); return(true); }