Example #1
0
 public static DownloadVoiceContextMgr getInstance()
 {
     if (gDownloadVoiceContextMgr == null)
     {
         gDownloadVoiceContextMgr = new DownloadVoiceContextMgr();
     }
     return(gDownloadVoiceContextMgr);
 }
 public static void onVoiceContextDispatcher(object sender, EventArgs e)
 {
     DownloadVoiceContextMgr.getInstance().clearnFinishedContext();
     //if (DownloadVoiceContextMgr.getInstance().getCount() <= 0)
     //{
     //    DownloadVoiceStorage.loadDownloadVoiceContextList();
     //}
     if (DownloadVoiceContextMgr.getInstance().getCount() <= 0)
     {
         Log.i("DownloadVoiceService", "all ready, close dispatcher timer. ");
         if (isFirstSync)
         {
             ServiceCenter.sceneNewSync.unsetRecvMsgStatus(RecvMsgStatus.isRecvVoice);
             //EventCenter.postEvent(EventConst.ON_NETSCENE_DOWNLOADVOICE_SERVICE_FINISH, null, null);
             isFirstSync = false;
         }
         //if (isAppActive)
         //{
         //    ServiceCenter.sceneNewSync.unsetRecvMsgStatus(RecvMsgStatus.isRecvVoice);
         //    EventCenter.postEvent(EventConst.ON_NETSCENE_DOWNLOADVOICE_SERVICE_FINISH, null, null);
         //    isAppActive = false;
         //}
         if (mTimerObject != null)
         {
             mTimerObject.stop();
             mTimerObject = null;
         }
     }
     else
     {
         int num  = DownloadVoiceContextMgr.getInstance().countRunningContext();
         int num2 = (int)getDownloadPackNum();
         if (num >= num2)
         {
             Log.i("DownloadVoiceService", "return request, because reach MaxRunningNum = " + num2);
         }
         else
         {
             for (int i = 0; i < (num2 - num); i++)
             {
                 DownloadVoiceContext voiceContext = DownloadVoiceContextMgr.getInstance().getFirstContextNeedHandle();
                 if (voiceContext == null)
                 {
                     return;
                 }
                 Log.i("DownloadVoiceService", "new task startup, mMsgSvrID = " + voiceContext.mMsgSvrID);
                 NetSceneDownloadVoice voice = new NetSceneDownloadVoice();
                 voice.mOnSceneFinished += new onSceneDownloadFinishedDelegate(DownloadVoiceService.onSceneFinished);
                 voice.doScene(voiceContext);
             }
         }
     }
 }
        public static bool reDownloadVoiceInfo(ChatMsg msg)
        {
            MsgTrans voiceinfo = new MsgTrans
            {
                nTransType      = 4,
                nStatus         = 0,
                strToUserName   = AccountMgr.getCurAccount().strUsrName,
                strFromUserName = msg.strTalker
            };
            string strMsg = msg.strMsg;

            if (ContactMgr.getUserType(msg.strTalker) == ContactMgr.UserType.UserTypeChatRoom)
            {
                strMsg = strMsg.Substring(strMsg.IndexOf('\n') + 1);
            }
            if (!parseVoiceMsgXML(strMsg, voiceinfo))
            {
                Log.d("DownloadVoiceService", "parseVoiceMsgXML failed");
                return(false);
            }
            voiceinfo.nMsgSvrID = msg.nMsgSvrID;
            if (AccountMgr.getCurAccount().strUsrName == voiceinfo.strFromUserName)
            {
                Log.d("DownloadVoiceService", "the mVoiceinfo.strFromUserName is yourself");
                return(false);
            }
            if (DownloadVoiceContextMgr.getInstance().GetBySvrID(msg.nMsgSvrID) == null)
            {
                DownloadVoiceContext context = new DownloadVoiceContext(msg.nMsgSvrID, msg.strTalker)
                {
                    mStatus = 0
                };
                context.Enqueue(voiceinfo);
                DownloadVoiceContextMgr.getInstance().putToTail(context);
                //DownloadVoiceStorage.updateDownloadVoiceContext(voiceinfo);
                doSceneBegin();
            }
            return(true);
        }
        public static bool downloadVoiceInfo(AddMsg cmdAM)
        {
            MsgTrans voiceinfo = new MsgTrans
            {
                nTransType      = 4,
                nStatus         = 0,
                strToUserName   = cmdAM.ToUserName.String,
                strFromUserName = cmdAM.FromUserName.String
            };
            string xmlStr = cmdAM.Content.String;

            if (ContactMgr.getUserType(cmdAM.FromUserName.String) == ContactMgr.UserType.UserTypeChatRoom)
            {
                xmlStr = xmlStr.Substring(xmlStr.IndexOf('\n') + 1);
            }
            if (!parseVoiceMsgXML(xmlStr, voiceinfo))
            {
                Log.d("DownloadVoiceService", "parseVoiceMsgXML failed");
                return(false);
            }
            voiceinfo.nMsgSvrID = cmdAM.MsgId;
            if (AccountMgr.getCurAccount().strUsrName == voiceinfo.strFromUserName)
            {
                Log.d("DownloadVoiceService", "the mVoiceinfo.strFromUserName is yourself");
                return(false);
            }
            if (isCancelVoiceMsg(xmlStr))
            {
                Log.d("DownloadVoiceService", "the msg has been canceled");
                //StorageMgr.chatMsg.delMsg(ChatMsgHelper.getTalker(voiceinfo.strToUserName, voiceinfo.strFromUserName), voiceinfo.nMsgSvrID);
                voiceinfo.nStatus = 5;
                //DownloadVoiceStorage.updateDownloadVoiceContext(voiceinfo);
                DownloadVoiceContext context = DownloadVoiceContextMgr.getInstance().GetBySvrID(cmdAM.MsgId);
                if (context != null)
                {
                    context.mStatus = 5;
                }
                return(false);
            }
            if ((cmdAM.ImgBuf != null) && (cmdAM.ImgBuf.Buffer.Length != 0))
            {
                return(saveShortVoiceInfo(voiceinfo, cmdAM.ImgBuf.Buffer.ToByteArray()));
            }
            DownloadVoiceContext bySvrID = DownloadVoiceContextMgr.getInstance().GetBySvrID(cmdAM.MsgId);

            if (bySvrID == null)
            {
                bySvrID = new DownloadVoiceContext(cmdAM.MsgId, ChatMsgHelper.getTalker(cmdAM.ToUserName.String, cmdAM.FromUserName.String))
                {
                    mStatus = 0
                };
                bySvrID.Enqueue(voiceinfo);
                DownloadVoiceContextMgr.getInstance().putToTail(bySvrID);
            }
            else
            {
                bySvrID.Enqueue(voiceinfo);
            }
            //DownloadVoiceStorage.updateDownloadVoiceContext(voiceinfo);
            doSceneBegin();
            return(true);
        }