private void ExtractMailAttachment(MailInfo info, ulong userGuid)
        {
            UserProcessScheduler dataProcess = UserServer.Instance.UserProcessScheduler;
            UserThread userThread = dataProcess.GetUserThread(userGuid);
            userThread.QueueAction(userThread.AddAssets, userGuid, info.m_Money, info.m_Gold);

            int itemCt = info.m_Items.Count;
            for (int itemIx = 0; itemIx < itemCt; ++itemIx) {
                MailItem item = info.m_Items[itemIx];
                userThread.QueueAction(userThread.AddItem, userGuid, item.m_ItemId, item.m_ItemNum);
            }
        }
        protected override bool ExecCommand(StoryInstance instance, long delta)
        {
            UserThread userThread = instance.Context as UserThread;
            if (null != userThread) {
                ulong receiver = m_Receiver.Value;
                string title = m_Title.Value;
                string content = m_Content.Value;
                string sender = m_Sender.Value;
                int levelDemand = m_LevelDemand.Value;
                int validPeriod = m_ValidPeriod.Value;
                int money = m_Money.Value;
                int gold = m_Gold.Value;

                MailInfo mailInfo = new MailInfo();
                mailInfo.m_Receiver = receiver;
                mailInfo.m_Title = title;
                mailInfo.m_Text = content;
                mailInfo.m_Sender = sender;
                mailInfo.m_Money = money;
                mailInfo.m_Gold = gold;
                mailInfo.m_LevelDemand = levelDemand;

                for (int i = 0; i < m_MailItems.Count - 1; i += 2) {
                    int itemId = m_MailItems[i].Value;
                    int itemNum = m_MailItems[i + 1].Value;

                    MailItem mailItem = new MailItem();
                    mailItem.m_ItemId = itemId;
                    mailItem.m_ItemNum = itemNum;
                    mailInfo.m_Items.Add(mailItem);
                }
                GlobalProcessThread globalProcess = UserServer.Instance.GlobalProcessThread;
                if (receiver > 0) {
                    globalProcess.QueueAction(globalProcess.SendUserMail, mailInfo, validPeriod);
                } else {
                    globalProcess.QueueAction(globalProcess.SendWholeMail, mailInfo, validPeriod);
                }
            }
            return false;
        }
 private void InitMailData()
 {
     if (m_MailInitStatus == DataInitStatus.Unload)
     {
         if (UserServerConfig.DataStoreAvailable == true)
         {
             m_MailInitStatus = DataInitStatus.Loading;
             Msg_LD_Load msg = new Msg_LD_Load();
             msg.MsgId = (int)DataEnum.TableMailInfo;
             GameFrameworkMessage.Msg_LD_SingleLoadRequest slr = new GameFrameworkMessage.Msg_LD_SingleLoadRequest();
             slr.MsgId    = (int)GameFrameworkData.DataEnum.TableMailInfo;
             slr.LoadType = GameFrameworkMessage.Msg_LD_SingleLoadRequest.LoadTypeEnum.LoadAll;
             slr.Keys.Clear();
             msg.LoadRequests.Add(slr);
             RequestLoad(msg, ((ret) => {
                 if (ret.ErrorNo == Msg_DL_LoadResult.ErrorNoEnum.Success)
                 {
                     List <TableMailInfoWrap> mailList = new List <TableMailInfoWrap>();
                     foreach (var singlerow in ret.Results)
                     {
                         object _msg;
                         if (DbDataSerializer.Decode(singlerow.Data, DataEnum2Type.Query(slr.MsgId), out _msg))
                         {
                             TableMailInfo dataMail = _msg as TableMailInfo;
                             if (null != dataMail)
                             {
                                 TableMailInfoWrap mailInfo = new TableMailInfoWrap();
                                 mailInfo.FromProto(dataMail);
                                 List <int> itemIds = Converter.ConvertNumericList <int>(dataMail.ItemIds);
                                 List <int> itemNums = Converter.ConvertNumericList <int>(dataMail.ItemNumbers);
                                 for (int i = 0; i < itemIds.Count && i < itemNums.Count; ++i)
                                 {
                                     var item = new MailItem();
                                     item.m_ItemId = itemIds[i];
                                     item.m_ItemNum = itemNums[i];
                                     mailInfo.m_Items.Add(item);
                                 }
                                 mailList.Add(mailInfo);
                             }
                         }
                     }
                     UserServer.Instance.GlobalProcessThread.InitMailData(mailList);
                     m_MailInitStatus = DataInitStatus.Done;
                     LogSys.Log(LOG_TYPE.INFO, ConsoleColor.Green, "Load DataCache global data success. Table:TableMailInfo");
                 }
                 else if (ret.ErrorNo == Msg_DL_LoadResult.ErrorNoEnum.NotFound)
                 {
                     //暂时初始化为空列表
                     List <TableMailInfoWrap> mailList = new List <TableMailInfoWrap>();
                     UserServer.Instance.GlobalProcessThread.InitMailData(mailList);
                     m_MailInitStatus = DataInitStatus.Done;
                     LogSys.Log(LOG_TYPE.INFO, ConsoleColor.Green, "Load DataCache global data success. Table:TableMailInfo (empty)");
                 }
                 else
                 {
                     m_MailInitStatus = DataInitStatus.Unload;
                     LogSys.Log(LOG_TYPE.ERROR, ConsoleColor.Red, "Load DataCache global data failed. Table: {0}", "TableMailInfo");
                 }
             }
                               ));
         }
         else
         {
             m_MailInitStatus = DataInitStatus.Done;
             LogSys.Log(LOG_TYPE.INFO, "init mail done!");
         }
     }
 }