コード例 #1
0
ファイル: DBManagerClass.cs プロジェクト: nekopanda/EDCB
        public RecFileInfoAppend GetRecFileAppend(RecFileInfo master, bool UpdateDB = false)
        {
            if (master == null)
            {
                return(null);
            }

            if (recFileAppendList == null)
            {
                recFileAppendList = new Dictionary <uint, RecFileInfoAppend>();
            }

            RecFileInfoAppend retv = null;

            if (recFileAppendList.TryGetValue(master.ID, out retv) == false)
            {
                if (UpdateDB == true)
                {
                    var list = recFileInfo.Values.Where(info => info.HasErrPackets == true &&
                                                        recFileAppendList.ContainsKey(info.ID) == false).ToList();

                    try
                    {
                        var extraDatalist = new List <RecFileInfo>();
                        if (cmd.SendGetRecInfoList(list.Select(info => info.ID).ToList(), ref extraDatalist) == ErrCode.CMD_SUCCESS)
                        {
                            extraDatalist.ForEach(item => recFileAppendList.Add(item.ID, new RecFileInfoAppend(item)));
                        }
                    }
                    catch (Exception ex) { MessageBox.Show(ex.Message + "\r\n" + ex.StackTrace); }

                    //何か問題があった場合でも何度もSendGetRecInfoList()しないよう残りも全て登録してしまう。
                    foreach (var item in list.Where(info => recFileAppendList.ContainsKey(info.ID) == false))
                    {
                        recFileAppendList.Add(item.ID, new RecFileInfoAppend(item, false));
                    }

                    recFileAppendList.TryGetValue(master.ID, out retv);
                }
                else
                {
                    var extraRecInfo = new RecFileInfo();
                    if (cmd.SendGetRecInfo(master.ID, ref extraRecInfo) == ErrCode.CMD_SUCCESS)
                    {
                        retv = new RecFileInfoAppend(extraRecInfo);
                        recFileAppendList.Add(master.ID, retv);
                    }
                }
            }
            return(retv ?? new RecFileInfoAppend(master));
        }