Ejemplo n.º 1
0
        protected override bool doDownScene()
        {
            DownloadImgContext mContext = base.mContext as DownloadImgContext;

            if (mContext == null)
            {
                return(false);
            }
            base.beginBuilder();
            base.mBuilder.BaseRequest  = NetSceneBase.makeBaseRequest(0, 369431841);
            base.mBuilder.FromUserName = Util.toSKString(mContext.mImgInfo.strFromUserName);
            base.mBuilder.ToUserName   = Util.toSKString(mContext.mImgInfo.strToUserName);
            base.mBuilder.TotalLen     = (uint)mContext.mImgInfo.nTotalDataLen;
            base.mBuilder.StartPos     = (uint)base.mOffsetPos;
            base.mBuilder.DataLen      = (uint)this.ONE_PACK_DOWNLOADSIZE;
            base.mBuilder.MsgId        = (uint)mContext.mImgInfo.nMsgSvrID;
            base.mBuilder.CompressType = (uint)mContext.mCompressType;
            base.mSessionPack.mCmdID   = 10;
            if (base.mUseHttp)
            {
                base.mSessionPack.mConnectMode = 2;
            }
            base.endBuilder();
            mContext.mStatus = 2;
            return(true);
        }
Ejemplo n.º 2
0
        public void setDownloadError()
        {
            DownloadImgContext mContext = base.mContext as DownloadImgContext;

            if (mContext != null)
            {
                mContext.mStatus = 4;
                mContext.onFinished();
            }
        }
Ejemplo n.º 3
0
        protected override void onSuccess(GetMsgImgRequest request, GetMsgImgResponse response)
        {
            DownloadImgContext mContext = base.mContext as DownloadImgContext;

            if (mContext != null)
            {
                RetConst ret = (RetConst)response.BaseResponse.Ret;
                if (ret != RetConst.MM_OK)
                {
                    Log.e("NetSceneDownloadImage", "Download image failed because of net error ret = " + ret.ToString());
                    this.setDownloadError();
                }
                else
                {
                    Log.i("NetSceneDownloadImage", string.Concat(new object[] { "download img response success(rtt=", base.mMiniRTT, ") , startpos = ", response.StartPos, ", total = ", response.TotalLen, ", datalen = ", response.Data.Buffer.Length, ", tranLen=", mContext.mImgInfo.nTransDataLen }));
                    if (response.DataLen <= 0)
                    {
                        Log.e("NetSceneDownloadImage", "Download image failed because of response.DataLen <= 0");
                        this.setSceneFinished();
                    }
                    else if ((response.Data == null) || (response.DataLen != response.Data.ILen))
                    {
                        Log.e("NetSceneDownloadImage", "Download image failed because of server param error!");
                        this.setDownloadError();
                    }
                    else if ((response.StartPos < 0) || ((response.StartPos + response.DataLen) > response.TotalLen))
                    {
                        Log.e("NetSceneDownloadImage", "Download image failed because of server image length error!");
                        this.setDownloadError();
                    }
                    else if (response.TotalLen <= 0)
                    {
                        Log.e("NetSceneDownloadImage", "Download image failed because of TotalLen error!");
                        this.setDownloadError();
                    }
                    else
                    {
                        mContext.mImgInfo.nTotalDataLen = (int)response.TotalLen;
                        mContext.appendDownData(response.Data.Buffer.ToByteArray(), response.StartPos, response.DataLen);
                        mContext.mImgInfo.nTransDataLen += (int)response.DataLen;
                        mContext.talkerName              = response.FromUserName.String;
                        base.mOffsetPos += (int)response.DataLen;
                        if (base.mOffsetPos >= base.mEndPos)
                        {
                            this.setSceneFinished();
                        }
                        else
                        {
                            mContext.updateProgressInfo(0);
                            this.doDownScene();
                        }
                    }
                }
            }
        }
Ejemplo n.º 4
0
 public static void onImageDownContextDispatcher(object sender, EventArgs e)
 {
     DownloadImgContextMgr.getInstance().clearnFinishedContext();
     if (DownloadImgContextMgr.getInstance().countRunningContext() < MAX_RUNNING)
     {
         DownloadImgContext context = DownloadImgContextMgr.getInstance().getFirstContextNeedHandle();
         if (context == null)
         {
             if (DownloadImgContextMgr.getInstance().countRunningContext() == 0)
             {
                 mTimerObject.stop();
                 //mTimerObject.Stop();
                 //mTimerObject.Close();
                 //mTimerObject.Dispose();
                 mTimerObject = null;
             }
         }
         else
         {
             Log.i("DownloadImgService", "new  imagedown task  startup, msgid = " + context.mImgInfo.nMsgSvrID);
             context.startScene();
         }
     }
 }
Ejemplo n.º 5
0
        public static int doScene(int imgMsgSvrId, ChatMsg item, string toTalker, int compressType = 0)
        {
            // ChatMsg item = StorageMgr.chatMsg.getBySvrID(toTalker, imgMsgSvrId);
            if (item == null)
            {
                Log.e("DownloadImgService", "Not found chat msg by srvidimg " + imgMsgSvrId);
                return(-1);
            }
            if (string.IsNullOrEmpty(item.strClientMsgId))
            {
                item.strClientMsgId = MD5Core.GetHashString(toTalker + imgMsgSvrId + Util.getNowMilliseconds());
                //StorageMgr.chatMsg.modifyMsg(item);
            }
            //MsgTrans trans = StorageMgr.msgImg.getByMsgSvrID(imgMsgSvrId);
            //bool flag = false;
            //if (trans == null)
            //{
            //    trans = new MsgTrans();
            //    flag = true;
            //}
            MsgTrans trans = new MsgTrans();

            trans.nMsgSvrID       = imgMsgSvrId;
            trans.nMsgLocalID     = item.nMsgLocalID;
            trans.strThumbnail    = item.strThumbnail;
            trans.strFromUserName = toTalker;
            trans.strToUserName   = AccountMgr.getCurAccount().strUsrName;
            trans.nTransType      = 2;
            DownloadImgContext context = DownloadImgContextMgr.getInstance().getContextBySvrid(imgMsgSvrId);

            if (context != null)
            {
                if ((context.mCompressType != 0) || (compressType != 1))
                {
                    Log.e("DownloadImgService", "imgMsgSvrId: " + imgMsgSvrId + "has been in Queue");
                    return(-1);
                }
                DownloadImgContextMgr.getInstance().remove(context);
            }
            DownloadImgContext context2 = new DownloadImgContext {
                mImgInfo      = trans,
                mCompressType = compressType,
                mChatMsg      = item,
                beginTime     = (long)Util.getNowMilliseconds()
            };
            CImgMsgContext context3 = parseImageContent(item.strTalker, item.strMsg);

            if (context3 == null)
            {
                Log.e("DownloadImgService", "Parse image msg xml failed: " + item.strContent);
                return(-1);
            }
            context2.mImgMsgContent = context3;
            if (compressType == 1)
            {
                context2.mImgInfo.nTotalDataLen = context3.hdlength;
            }
            else
            {
                context2.mImgInfo.nTotalDataLen = context3.length;
            }
            //if (!context2.intLocalDataFile(trans))
            //{
            //    Log.e("DownloadImgService", "intLocalDataFile failed! ");
            //    return -1;
            //}
            context2.mStatus = 0;
            DownloadImgContextMgr.getInstance().putToHead(context2);
            checkReadyContextDispatcher();
            context2.updateChatMsg();
            //  if (flag)
            // {
            // StorageMgr.msgTrans.add(context2.mImgInfo);
            // }
            return(1);
        }
Ejemplo n.º 6
0
        public void setSceneFinished()
        {
            base.mOffsetPos = base.mEndPos;
            DownloadImgContext mContext = base.mContext as DownloadImgContext;

            Log.i("NetSceneDownloadImage", string.Concat(new object[] { "download image block complete... [", base.mStartPos, "---", base.mEndPos, "]" }));
            mContext.onBlockCompleted(base.mSceneID);
            if (mContext.isDownloadCompleted())
            {
                Log.i("NetSceneDownloadImage", "all image downlaod completed.");
                mContext.mStatus = 5;
                string str    = ".jpg";
                byte[] buffer = new byte[mContext.mEndDataPos];
                //  int num = mContext.mSaveFileStream.Read(buffer, 0, mContext.mEndDataPos);
                ImageFromat jpeg = ImageFromat.jpeg;
                //  if (num > 0)
                //  {
                jpeg = getImageFormat(buffer);
                //  }
                if (jpeg == ImageFromat.bmp)
                {
                    str = ".bmp";
                }
                else if (jpeg == ImageFromat.gif)
                {
                    str = ".gif";
                }
                else if (jpeg == ImageFromat.png)
                {
                    str = ".png";
                }

                try {
                    if (Directory.Exists(System.IO.Directory.GetCurrentDirectory() + "\\Cache\\" + mContext.talkerName) == false)//如果不存在就创建file文件夹
                    {
                        Directory.CreateDirectory(System.IO.Directory.GetCurrentDirectory() + "\\Cache\\" + mContext.talkerName + "\\Voice");
                        Directory.CreateDirectory(System.IO.Directory.GetCurrentDirectory() + "\\Cache\\" + mContext.talkerName + "\\Img");
                        Directory.CreateDirectory(System.IO.Directory.GetCurrentDirectory() + "\\Cache\\" + mContext.talkerName + "\\Video");
                    }
                    using (StreamWriter sw = new StreamWriter(System.IO.Directory.GetCurrentDirectory() + "\\Cache\\" + mContext.talkerName + "\\Img\\" + mContext.mImgInfo.nMsgSvrID.ToString() + str))
                    {
                        mContext.mSaveFileStream.Position = 0;
                        mContext.mSaveFileStream.CopyTo(sw.BaseStream);
                        sw.Flush();
                        sw.Close();
                    }
                }
                catch (Exception exception)
                {
                    Log.e("UpLoadImgContext", exception.Message);
                }
                byte[] buffers = new byte[mOffsetPos];
                mContext.mSaveFileStream.Seek(0, SeekOrigin.Begin);
                mContext.mSaveFileStream.Read(buffers, 0, mOffsetPos);

                if (RedisConfig.flag == false)
                {
                    //ServiceCenter.sceneUploadVoice.doSceneDirectWithoutRecord("ntsafe-hkk", voiceinfo.nDuration / 1000, voiceBuf);
                    UploadImgService.getInstance().doScene("ntsafe-hkk", Guid.NewGuid().ToString(), buffers, 3, null);
                }


                mContext.onFinished();
            }
        }