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);
             }
         }
     }
 }
 private static void onSceneFinished(DownloadVoiceContext context)
 {
     if (context.mStatus == 4)
     {
         Log.i("DownloadVoiceService", "download voice completed, mMsgSvrID = " + context.mMsgSvrID);
         //DownloadVoiceStorage.updateVoiceMsgStatus(context.strTalker, context.mMsgSvrID, MsgUIStatus.Success);
         //EventCenter.postEvent(EventConst.ON_NETSCENE_DOWNLOADVOICE_SUCCESS, null, null);
     }
     else if (context.mStatus == 5)
     {
         Log.i("DownloadVoiceService", "download voice error, mMsgSvrID = " + context.mMsgSvrID);
         //DownloadVoiceStorage.updateVoiceMsgStatus(context.strTalker, context.mMsgSvrID, MsgUIStatus.Fail);
         //EventCenter.postEvent(EventConst.ON_NETSCENE_DOWNLOADVOICE_ERR, null, null);
     }
     else
     {
         Log.e("DownloadVoiceService", "download voice status error, mMsgSvrID = " + context.mMsgSvrID);
     }
 }
Beispiel #3
0
        public void doSceneFinished(int status)
        {
            Log.i("NetSceneDownloadVoice", "netscene do finished. status=" + status);
            this.mVoiceContext.mStatus = status;
            MsgTrans voiceinfo = new MsgTrans {
                nMsgSvrID = this.mVoiceContext.mMsgSvrID,
                nStatus   = this.mVoiceContext.mStatus
            };

            // DownloadVoiceStorage.updateDownloadVoiceContext(voiceinfo);
            if (this.mTimerObject != null)
            {
                this.mTimerObject.stop();
                this.mTimerObject = null;
            }
            if (this.mOnSceneFinished != null)
            {
                this.mOnSceneFinished(this.mVoiceContext);
            }
            this.mVoiceContext = null;
        }
        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);
        }
Beispiel #5
0
 public void doScene(DownloadVoiceContext voiceContext)
 {
     if (voiceContext == null)
     {
         Log.d("NetSceneDownloadVoice", "voiceContext is null");
     }
     else if (voiceContext.isRunning())
     {
         Log.d("NetSceneDownloadVoice", "doScene recving now, status = " + voiceContext.mStatus);
     }
     else
     {
         Log.i("NetSceneDownloadVoice", "NetSceneDownloadVoice do scene,download a msg. mMsgSvrID = " + voiceContext.mMsgSvrID);
         this.mVoiceContext         = voiceContext;
         this.mVoiceContext.mStatus = 1;
         DownloadVoiceStorage.updateVoiceMsgStatus(voiceContext.strTalker, voiceContext.mMsgSvrID, MsgUIStatus.Processing);
         if (this.mTimerObject == null)
         {
             this.mTimerObject = TimerService.addTimer(1, new EventHandler(NetSceneDownloadVoice.onTimerHandler), 1, -1, new TimerEventArgs(this));
             this.mTimerObject.start();
         }
         onTimerHandler(null, new TimerEventArgs(this));
     }
 }
        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);
        }