public void doScene(UpLoadImgContext imgContext) { if ((imgContext.mStatus != 0) && (imgContext.mStatus != 4)) { Log.e("NetSceneUploadImage", "doScene imgContext.mStatus error, status = " + imgContext.mStatus); } else { imgContext.mStatus = 1; this.mUpImgContext = imgContext; if (((this.mUpImgContext == null) || (this.mUpImgContext.imgInfo == null)) || (this.mUpImgContext.mBigImageMemoryStream == null)) { this.mUpImgContext.mStatus = 4; EventCenter.postEvent(EventConst.ON_NETSCENE_SENDIMG_FAIL, new ParamReturn(-1, this.mUpImgContext.imgInfo.nMsgLocalID, this.mUpImgContext.talkerName), null); this.doSceneFinished(); } else if (((this.mUpImgContext.imgInfo.nTotalDataLen - this.mUpImgContext.imgInfo.nTransDataLen) == 0) || (this.mUpImgContext.imgInfo.nTotalDataLen == 0)) { Log.e("NetSceneUploadImage", "mUpImgContext send dataLen = 0 mUpImgContext.imgInfo.nMsgTransID = " + this.mUpImgContext.imgInfo.nMsgTransID); this.mUpImgContext.mStatus = 4; EventCenter.postEvent(EventConst.ON_NETSCENE_SENDIMG_FAIL, new ParamReturn(-1, this.mUpImgContext.imgInfo.nMsgLocalID, this.mUpImgContext.talkerName, this.mUpImgContext.imgInfo.strImagePath), null); this.doSceneFinished(); } else { Log.i("NetSceneUploadImage", "file size = " + this.mUpImgContext.imgInfo.nTotalDataLen + " byte"); Account account = AccountMgr.getCurAccount(); this.mUpImgContext.imgInfo.strFromUserName = account.strUsrName; int nProgress = (this.mUpImgContext.imgInfo.nTransDataLen * 100) / this.mUpImgContext.imgInfo.nTotalDataLen; if (nProgress <= 5) { nProgress = 5; } Log.i("NetSceneUploadImage", "Progress is: " + nProgress + "%"); EventCenter.postEvent(EventConst.ON_NETSCENE_SENDIMG_PROGRESS, new ParamReturn(nProgress, this.mUpImgContext.imgInfo.nMsgLocalID, this.mUpImgContext.talkerName), null); this.doSceneEx(); } } }
//private void onAccountLoginProc(EventWatcher watcher, BaseEventArgs evtArgs) //{ // List<ChatMsg> msgList = StorageMgr.chatMsg.searhCacheMsg(3, 0, 1); // List<ChatMsg> list2 = StorageMgr.chatMsg.searhCacheMsg(0x27, 0, 1); // if ((list2 != null) && (list2.Count > 0)) // { // if (msgList == null) // { // msgList = new List<ChatMsg>(); // } // foreach (ChatMsg msg in list2) // { // msgList.Add(msg); // } // } // if ((msgList != null) && (msgList.Count > 0)) // { // foreach (ChatMsg msg2 in msgList) // { // msg2.nStatus = 1; // } // //StorageMgr.chatMsg.updateMsgList(msgList); // } //} private void onImageContextDispatcher(object sender, EventArgs e) { UpLoadImgContextMgr.getInstance().clearnFinishedContext(); if (UpLoadImgContextMgr.getInstance().countRunningContext() < MAX_RUNNING) { UpLoadImgContext imgContext = UpLoadImgContextMgr.getInstance().getFirstContextNeedHandle(); if (imgContext == null) { Log.i("UploadImgService", "No more image need send. "); if (UpLoadImgContextMgr.getInstance().countRunningContext() == 0) { //List<ChatMsg> msgList = StorageMgr.chatMsg.searhCacheMsg(3, 0, 1); //if ((msgList != null) && (msgList.Count > 0)) //{ // foreach (ChatMsg msg in msgList) // { // msg.nStatus = 1; // } // // StorageMgr.chatMsg.updateMsgList(msgList); //} Log.i("UploadImgService", "all ready, close dispatcher timer. "); //this.mTimerObject.stop(); mTimerObject.stop(); //mTimerObject.Close(); //mTimerObject.Dispose(); this.mTimerObject = null; } } else if (((imgContext.imgInfo == null) && (imgContext.imgBUf != null)) && !imgContext.fillContextWithOrigStream()) { Log.e("UploadImgService", "fillContext fail!"); imgContext.mStatus = 5; } else { (imgContext.senceHandle as NetSceneUploadImage).doScene(imgContext); } } }
private ChatMsg startDoSence(string talkerName, string filename, byte[] origStream, object sceneInstance, int nImgMsgTranId, int msgType = 3, ParamEx param = null) { if (UpLoadImgContextMgr.getInstance().countRunningContext() >= MAX_RUNNING) { Log.e("UploadImgService", "send Image scene cannot begin ,running task too much. "); return(null); } if ((talkerName == null) || (sceneInstance == null)) { Log.e("UploadImgService", "one of the send Image scene cannot begin, param error."); return(null); } if ((origStream != null) && (filename != null)) { UpLoadImgContext context = new UpLoadImgContext { talkerName = talkerName, filename = filename, // origStream = origStream, //imgBUf=origStream, senceHandle = sceneInstance, mMsgType = msgType, mParamEx = param, beginTime = (long)Util.getNowMilliseconds() }; Log.d("UploadImgService", "begin add chatmsg"); if (context.chatMsgInfo == null) { context.chatMsgInfo = new ChatMsg(); } context.imgBUf = new byte[origStream.Length]; Buffer.BlockCopy(origStream, 0, context.imgBUf, 0, origStream.Length); context.chatMsgInfo.strTalker = talkerName; context.chatMsgInfo.nMsgType = msgType; context.chatMsgInfo.nStatus = 0; context.chatMsgInfo.nIsSender = 1; context.chatMsgInfo.nCreateTime = (long)(Util.getNowMilliseconds() / 1000.0); context.chatMsgInfo.strClientMsgId = MD5Core.GetHashString(talkerName + context.GetHashCode() + Util.getNowMilliseconds()); //StorageMgr.chatMsg.addMsg(context.chatMsgInfo); UpLoadImgContextMgr.getInstance().putToHead(context); this.checkReadyContextDispatcher(); return(context.chatMsgInfo); } if (nImgMsgTranId > 0) { Log.i("UploadImgService", "Resend image nImgMsgTranId = " + nImgMsgTranId); UpLoadImgContext context2 = new UpLoadImgContext(); //context2.loadUploadImgContext(nImgMsgTranId); //if ((context2.imgInfo != null) && (context2.mBigImageMemoryStream != null)) //{ // context2.talkerName = talkerName; // context2.senceHandle = sceneInstance; // context2.beginTime = (long) Util.getNowMilliseconds(); // UpLoadImgContextMgr.getInstance().putToHead(context2); // this.checkReadyContextDispatcher(); // return context2.chatMsgInfo; //} Log.e("UploadImgService", "one of the send Image scene cannot begin, loadUploadImgContext from db error."); return(null); } Log.e("UploadImgService", "one of the send Image scene cannot begin, param error."); return(null); }