Example #1
0
        /// <summary>
        /// 日付別の履歴を取得
        /// </summary>
        /// <param name="iPlayerName">プレイヤー名</param>
        /// <param name="iYmd">日付</param>
        /// <returns></returns>
        public FishHistoryDBModel SelectDayly(string iPlayerName, DateTime iYmd, FishResultStatusKind iResultStatus, string iFishName)
        {
            logger.Trace("Player={0} Ymd={1} ResultStatus={2} Fish={3}", iPlayerName, iYmd, iResultStatus, iFishName);
            FishHistoryDBModel tmpHistory = GetHistoryDB(iPlayerName, iYmd);
            FishHistoryDBModel ret        = GetHistoryDB(iPlayerName, iYmd);

            ret.Fishes.Clear();
            foreach (FishHistoryDBFishModel fish in tmpHistory.Fishes)
            {
                bool addFlg = true;
                if (iResultStatus != FishResultStatusKind.Unknown && fish.Result != iResultStatus)
                {
                    addFlg = false;
                }
                if (iFishName != string.Empty && fish.FishName != iFishName)
                {
                    addFlg = false;
                }
                if (addFlg)
                {
                    ret.Fishes.Add(fish);
                }
            }
            return(ret);
        }
Example #2
0
        /// <summary>
        /// ハラキリを履歴に追加
        /// </summary>
        /// <param name="iPlayername">プレイヤー名</param>
        /// <param name="iFish">FishHistoryDBHarakiriModel</param>
        /// <returns>成功ならTrueを返す</returns>
        public bool AddHarakiri(string iPlayername, FishHistoryDBHarakiriModel iFish)
        {
            FishHistoryDBModel historydb = GetHistoryDB(iPlayername, DateTime.Parse(iFish.EarthTime));

            historydb.Version    = VERSION;
            historydb.PlayerName = iPlayername;
            historydb.EarthDate  = DateTime.Parse(iFish.EarthTime).ToShortDateString();
            historydb.Uploaded   = false;
            historydb.Harakiri.Add(iFish);

            return(PutHistoryDB(iPlayername, historydb));
        }
Example #3
0
        /// <summary>
        /// 日別のサマリーを取得する
        /// </summary>
        /// <param name="iPlayerName">プレイヤー名</param>
        /// <param name="iYmd">日付</param>
        /// <returns>サマリー情報</returns>
        public FishHistoryDBSummaryModel GetSummary(string iPlayerName, DateTime iYmd, FishResultStatusKind iResultStatus, string iFishName)
        {
            logger.Trace("Player={0} Ymd={1} ResultStatus={2} Fish={3}", iPlayerName, iYmd, iResultStatus, iFishName);
            FishHistoryDBModel        history = SelectDayly(iPlayerName, iYmd, iResultStatus, iFishName);
            FishHistoryDBSummaryModel ret     = new FishHistoryDBSummaryModel();

            foreach (FishHistoryDBFishModel fish in history.Fishes)
            {
                ret.Add(fish);
            }
            return(ret);
        }
Example #4
0
        /// <summary>
        /// 魚を履歴に追加
        /// </summary>
        /// <param name="iPlayername">プレイヤー名</param>
        /// <param name="iFish">FishHistoryDBFishModel</param>
        /// <returns>True:成功</returns>
        public bool AddFish(string iPlayername, int iTimeElapsed, FishHistoryDBFishModel iFish)
        {
            FishHistoryDBModel historydb = GetHistoryDB(iPlayername, DateTime.Parse(iFish.EarthTime));

            historydb.Version     = VERSION;
            historydb.PlayerName  = iPlayername;
            historydb.EarthDate   = DateTime.Parse(iFish.EarthTime).ToShortDateString();
            historydb.Uploaded    = false;
            historydb.TimeElapsed = iTimeElapsed;
            historydb.Fishes.Add(iFish);

            return(PutHistoryDB(iPlayername, historydb));
        }
Example #5
0
        private void updateCatchCount(FishHistoryDBModel iFishHistoryDB)
        {
            int cnt = 0;

            foreach (FishHistoryDBFishModel fish in iFishHistoryDB.Fishes)
            {
                if (fish.Result == FishResultStatusKind.Catch &&
                    (fish.FishType == FishDBFishTypeKind.SmallFish || fish.FishType == FishDBFishTypeKind.LargeFish))
                {
                    cnt++;
                }
            }
            this.CatchCount = cnt;
        }
Example #6
0
        /// <summary>
        /// 指定された日付に釣れた魚名を取得する
        /// </summary>
        /// <param name="iPlayerName">プレイヤー名</param>
        /// <param name="iYmd">日付</param>
        /// <returns></returns>
        public List <string> SelectDaylyUniqueFishName(string iPlayerName, DateTime iYmd)
        {
            logger.Trace("Player={0} Ymd={1}", iPlayerName, iYmd);
            FishHistoryDBModel tmpHistory = GetHistoryDB(iPlayerName, iYmd);
            List <string>      ret        = new List <string>();

            foreach (FishHistoryDBFishModel fish in tmpHistory.Fishes)
            {
                if (fish.FishName != string.Empty && !ret.Contains(fish.FishName))
                {
                    ret.Add(fish.FishName);
                }
            }
            return(ret);
        }
Example #7
0
        /// <summary>
        /// xmlへ書き込む
        /// </summary>
        /// <param name="iPlayerName">プレイヤー名</param>
        /// <param name="iHistoryDB">FishHistoryDBModel</param>
        /// <returns>True:成功</returns>
        public bool PutHistoryDB(string iPlayerName, FishHistoryDBModel 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(FishHistoryDBModel));
                            serializer.Serialize(sw, iHistoryDB, ns);
                            //書き込み
                            sw.Flush();
                            sw.Close();
                            sw = null;
                        }
                        break;
                    }
                    catch (IOException)
                    {
                        Thread.Sleep(100);
                        continue;
                    }
                }
                //CatchCountの更新
                updateCatchCount(iHistoryDB);
                return(true);
            }
            catch (Exception e)
            {
                logger.Fatal("{0}の取得中にエラーが発生しました。", xmlFilename);
                throw e;
            }
        }
Example #8
0
        /// <summary>
        /// xmlの内容を全て取得する
        /// </summary>
        /// <returns>FishHistoryDBModel</returns>
        public FishHistoryDBModel GetHistoryDB(string iPlayerName, DateTime iYmd, string iPath = PATH_FISHHISTORYDB)
        {
            string xmlFilename = GetXmlName(iPlayerName, iYmd);

            try
            {
                FishHistoryDBModel history = new FishHistoryDBModel();
                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(FishHistoryDBModel));
                                history = (FishHistoryDBModel)serializer.Deserialize(fs);
                                fs.Close();
                            }
                            break;
                        }
                        catch (IOException)
                        {
                            Thread.Sleep(100);
                            continue;
                        }
                    }
                }
                //CatchCountの更新
                updateCatchCount(history);
                return(history);
            }
            catch (Exception e)
            {
                logger.Fatal("{0}の取得中にエラーが発生しました。", xmlFilename);
                throw e;
            }
        }
Example #9
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);
        }
Example #10
0
 private void updateCatchCount(FishHistoryDBModel iFishHistoryDB)
 {
     int cnt = 0;
     foreach (FishHistoryDBFishModel fish in iFishHistoryDB.Fishes)
     {
         if (fish.Result == FishResultStatusKind.Catch &&
             (fish.FishType == FishDBFishTypeKind.SmallFish || fish.FishType == FishDBFishTypeKind.LargeFish))
         {
             cnt++;
         }
     }
     this.CatchCount = cnt;
 }
Example #11
0
        /// <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);
        }
Example #12
0
        /// <summary>
        /// xmlへ書き込む
        /// </summary>
        /// <param name="iPlayerName">プレイヤー名</param>
        /// <param name="iHistoryDB">FishHistoryDBModel</param>
        /// <returns>True:成功</returns>
        public bool PutHistoryDB(string iPlayerName, FishHistoryDBModel 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(FishHistoryDBModel));
                        serializer.Serialize(sw, iHistoryDB, ns);
                        //書き込み
                        sw.Flush();
                        sw.Close();
                        sw = null;
                    }
                    break;
                }
                catch (IOException)
                {
                    Thread.Sleep(100);
                    continue;
                }
            }
            //CatchCountの更新
            updateCatchCount(iHistoryDB);
            return true;
        }
Example #13
0
 /// <summary>
 /// xmlの内容を全て取得する
 /// </summary>
 /// <returns>FishHistoryDBModel</returns>
 public FishHistoryDBModel GetHistoryDB(string iPlayerName, DateTime iYmd, string iPath = PATH_FISHHISTORYDB)
 {
     string xmlFilename =GetXmlName(iPlayerName,iYmd);
     FishHistoryDBModel history = new FishHistoryDBModel();
     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(FishHistoryDBModel));
                     history = (FishHistoryDBModel)serializer.Deserialize(fs);
                     fs.Close();
                 }
                 break;
             }
             catch (IOException)
             {
                 Thread.Sleep(100);
                 continue;
             }
         }
     }
     //CatchCountの更新
     updateCatchCount(history);
     return history;
 }
Example #14
0
        /// <summary>
        /// コンストラクタ
        /// </summary>
        public FishHistoryDB(string iPlayerName, DateTime iYmd)
        {
            FishHistoryDBModel history = GetHistoryDB(iPlayerName, iYmd);

            updateCatchCount(history);
        }
Example #15
0
        /// <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);
        }