Exemple #1
0
        /// <summary>
        /// xmlファイルをコンバートする(1.0.0→1.0.5)
        /// </summary>
        private void convert1_0_0to1_0_5(string iXmlFileName, string iRodName)
        {
            FishDBModel1_0_0 fishdb1_0_0 = getFishDB1_0_0(iRodName);
            FishDBModel      fishdb1_0_5 = new FishDBModel();

            fishdb1_0_5.Version = "1.0.5";
            fishdb1_0_5.RodName = fishdb1_0_0.RodName;
            foreach (FishDBFishModel1_0_0 fish1_0_0 in fishdb1_0_0.Fishes)
            {
                FishDBFishModel fish1_0_5 = new FishDBFishModel();
                //FishDBFishTypeKind.Monster→FishDBFishTypeKind.UnknownMonster
                if (fish1_0_0.FishType == FishDBFishTypeKind.Monster)
                {
                    fish1_0_0.FishType = FishDBFishTypeKind.UnknownMonster;
                }
                fish1_0_5.FishType = fish1_0_0.FishType;
                //FishName
                if (fish1_0_0.FishType == FishDBFishTypeKind.UnknownSmallFish ||
                    fish1_0_0.FishType == FishDBFishTypeKind.UnknownLargeFish ||
                    fish1_0_0.FishType == FishDBFishTypeKind.UnknownItem ||
                    fish1_0_0.FishType == FishDBFishTypeKind.UnknownMonster ||
                    fish1_0_0.FishType == FishDBFishTypeKind.Unknown)
                {
                    if (fish1_0_0.IDs.Count > 0)
                    {
                        fish1_0_5.FishName = FishDB.GetTmpFishNameFromFishType(fish1_0_0.FishType, fish1_0_0.IDs[0].ID1, fish1_0_0.IDs[0].ID2, fish1_0_0.IDs[0].ID3, fish1_0_0.IDs[0].ID4);
                    }
                    else
                    {
                        fish1_0_5.FishName = fish1_0_0.FishName;
                    }
                }
                else
                {
                    fish1_0_5.FishName = fish1_0_0.FishName;
                }
                //ID
                foreach (FishDBIdModel1_0_0 id1_0_0 in fish1_0_0.IDs)
                {
                    FishDBIdModel id1_0_5 = new FishDBIdModel();
                    id1_0_5.ID1      = id1_0_0.ID1;
                    id1_0_5.ID2      = id1_0_0.ID2;
                    id1_0_5.ID3      = id1_0_0.ID3;
                    id1_0_5.ID4      = id1_0_0.ID4;
                    id1_0_5.Count    = id1_0_0.Count;
                    id1_0_5.Critical = id1_0_0.Critical;
                    id1_0_5.ItemType = FishDBItemTypeKind.Common;
                    fish1_0_5.IDs.Add(id1_0_5);
                }
                //エリア 初期化する
                fish1_0_5.ZoneNames = new List <string>();
                //エサ
                fish1_0_5.BaitNames = fish1_0_0.BaitNames;

                fishdb1_0_5.Fishes.Add(fish1_0_5);
            }

            //バックアップ
            string backupFileName = iXmlFileName + ".bak";

            if (File.Exists(backupFileName))
            {
                File.Delete(backupFileName);
            }
            File.Copy(iXmlFileName, backupFileName);
            //xml書き込み
            putFishDB(iRodName, fishdb1_0_5);
        }
Exemple #2
0
        /// <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);
        }
Exemple #3
0
        public bool AddFish(string iRodName, string iFishName, FishDBFishTypeKind iFishType, FishDBIdModel iID, string iZoneName, string iBaitName)
        {
            logger.Trace("RodName={0} Fish={1} Type={2} ID={3} Zone={4} Bait={5}", iRodName, iFishName, iFishType, iID, iZoneName, iBaitName);
            FishDBModel fishDB = getFishDB(iRodName);

            fishDB.Version = VERSION;
            fishDB.RodName = iRodName;

            //不明魚として登録されている場合、削除する
            for (int fishIdx = 0; fishIdx < fishDB.Fishes.Count; fishIdx++)
            {
                if (fishDB.Fishes[fishIdx].IDs.Contains(iID) &&
                    fishDB.Fishes[fishIdx].ZoneNames.Contains(iZoneName) &&
                    (fishDB.Fishes[fishIdx].FishType == FishDBFishTypeKind.UnknownSmallFish ||
                     fishDB.Fishes[fishIdx].FishType == FishDBFishTypeKind.UnknownLargeFish ||
                     fishDB.Fishes[fishIdx].FishType == FishDBFishTypeKind.UnknownItem ||
                     fishDB.Fishes[fishIdx].FishType == FishDBFishTypeKind.UnknownMonster ||
                     fishDB.Fishes[fishIdx].FishType == FishDBFishTypeKind.Unknown))
                {
                    fishDB.Fishes[fishIdx].ZoneNames.Remove(iZoneName);
                    //エリア情報が無くなっった場合、魚情報を削除する
                    if (fishDB.Fishes[fishIdx].ZoneNames.Count == 0)
                    {
                        fishDB.Fishes.RemoveAt(fishIdx);
                    }
                    break;
                }
            }

            //更新処理
            bool foundFlg = false;

            for (int fishIdx = 0; fishIdx < fishDB.Fishes.Count; fishIdx++)
            {
                if (fishDB.Fishes[fishIdx].FishName == iFishName)
                {
                    foundFlg = true;
                    fishDB.Fishes[fishIdx].FishName = iFishName;
                    fishDB.Fishes[fishIdx].FishType = iFishType;
                    if (!fishDB.Fishes[fishIdx].IDs.Contains(iID))
                    {
                        logger.Info("IDの追加 竿={0} 魚={1} ID={2}", iRodName, iFishName, iID);
                        fishDB.Fishes[fishIdx].IDs.Add(iID);
                    }
                    if (!fishDB.Fishes[fishIdx].ZoneNames.Contains(iZoneName))
                    {
                        logger.Info("エリアの追加 竿={0} 魚={1} エリア={2}", iRodName, iFishName, iZoneName);
                        fishDB.Fishes[fishIdx].ZoneNames.Add(iZoneName);
                    }
                    if (!fishDB.Fishes[fishIdx].BaitNames.Contains(iBaitName))
                    {
                        logger.Info("エサの追加 竿={0} 魚={1} エサ={2}", iRodName, iFishName, iBaitName);
                        fishDB.Fishes[fishIdx].BaitNames.Add(iBaitName);
                    }
                }
            }
            //新規追加処理
            if (!foundFlg)
            {
                logger.Info("魚の追加 竿={0} 魚={1} 魚タイプ={2} ID={3} エリア={4} エサ={5}", iRodName, iFishName, iFishType, iID, iZoneName, iBaitName);
                FishDBFishModel fish = new FishDBFishModel();
                fish.FishName = iFishName;
                fish.FishType = iFishType;
                fish.IDs.Add(iID);
                fish.ZoneNames.Add(iZoneName);
                fish.BaitNames.Add(iBaitName);
                fishDB.Fishes.Add(fish);
            }
            //ソート
            fishDB.Fishes.Sort(FishDBFishModel.SortTypeName);
            for (int i = 0; i < fishDB.Fishes.Count; i++)
            {
                fishDB.Fishes[i].IDs.Sort(FishDBIdModel.SortCountCritical);
            }
            //Rod.xmlへ出力する
            if (!putFishDB(iRodName, fishDB))
            {
                return(false);
            }
            return(true);
        }