public void doSceneToCGI(string msgid, CImgMsgContext imgContext, string toUsername)
        {
            base.beginBuilder();
            base.mBuilder.BaseRequest    = NetSceneBase.makeBaseRequest(0);
            base.mBuilder.FromUserName   = Util.toSKString(AccountMgr.curUserName);
            base.mBuilder.ToUserName     = Util.toSKString(toUsername);
            base.mBuilder.ClientImgId    = Util.toSKString(msgid);
            base.mBuilder.MsgType        = 3;
            base.mBuilder.TotalLen       = (uint)imgContext.length;
            base.mBuilder.StartPos       = 0;
            base.mBuilder.DataLen        = (uint)imgContext.length;
            base.mBuilder.Data           = Util.toSKBuffer(new byte[0]);
            base.mBuilder.EncryVer       = 1;
            base.mBuilder.AESKey         = imgContext.aesKey;
            base.mBuilder.CDNThumbAESKey = imgContext.aesKey;

            base.mBuilder.CompressType  = 0;
            base.mBuilder.CDNBigImgSize = 0;
            base.mBuilder.CDNBigImgUrl  = "";

            if (imgContext.hdlength != 0)
            {
                base.mBuilder.CDNMidImgSize = imgContext.hdlength;
            }
            else
            {
                base.mBuilder.CDNMidImgSize = imgContext.length;
            }

            base.mBuilder.CDNMidImgUrl    = imgContext.midUrlKey;
            base.mBuilder.CDNThumbImgSize = imgContext.thumblength;
            base.mBuilder.CDNThumbImgUrl  = imgContext.thumbUrlKey;

            base.mBuilder.CDNThumbImgWidth  = imgContext.CDNThumbImgWidth;
            base.mBuilder.CDNThumbImgHeight = imgContext.CDNThumbImgHeight;
            base.mSessionPack.mCmdID        = 9;
            base.mSessionPack.mNeedCompress = false;
            base.endBuilder();
        }
Esempio n. 2
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);
        }
Esempio n. 3
0
        public static CImgMsgContext parseImageContent(string strTalker, string xmlContent)
        {
            if (string.IsNullOrEmpty(strTalker))
            {
                return(null);
            }
            CImgMsgContext context = new CImgMsgContext();

            if (string.IsNullOrEmpty(xmlContent))
            {
                context.length   = 0;
                context.hdlength = 0;
                return(context);
            }
            string text = xmlContent;

            if (ContactHelper.isChatRoom(strTalker))
            {
                int index = xmlContent.IndexOf('\n');
                text = xmlContent.Substring(index + 1);
            }
            XElement element = null;

            try
            {
                element = XDocument.Parse(text).Element("msg");
                string name = "img";
                if (element.Element(name) == null)
                {
                    name = "imgmsg";
                }
                XAttribute attribute = element.Element(name).Attribute("length");
                if (attribute != null)
                {
                    context.length = int.Parse(attribute.Value);
                }
                attribute = element.Element(name).Attribute("hdlength");
                if (attribute != null)
                {
                    context.hdlength = int.Parse(attribute.Value);
                }
                attribute = element.Element(name).Attribute("cdnthumblength");
                if (attribute != null)
                {
                    context.thumblength = int.Parse(attribute.Value);
                }
                attribute = element.Element(name).Attribute("encryver");
                if (attribute != null)
                {
                    context.encryVer = int.Parse(attribute.Value);
                }
                attribute = element.Element(name).Attribute("aeskey");
                if (attribute != null)
                {
                    context.aesKey      = attribute.Value;
                    context.thumbaesKey = attribute.Value;
                }
                attribute = element.Element(name).Attribute("cdnthumbaeskey");
                if (attribute != null)
                {
                    context.thumbaesKey = attribute.Value;
                }
                attribute = element.Element(name).Attribute("cdnmidimgurl");
                if (attribute != null)
                {
                    context.midUrlKey = attribute.Value;
                }
                attribute = element.Element(name).Attribute("cdnbigimgurl");
                if (attribute != null)
                {
                    context.bigUrlKey = attribute.Value;
                }
                attribute = element.Element(name).Attribute("cdnthumburl");
                if (attribute != null)
                {
                    context.thumbUrlKey = attribute.Value;
                }

                attribute = element.Element(name).Attribute("cdnthumbheight");
                if (attribute != null)
                {
                    context.CDNThumbImgHeight = int.Parse(attribute.Value);
                }

                attribute = element.Element(name).Attribute("cdnthumbwidth");
                if (attribute != null)
                {
                    context.CDNThumbImgWidth = int.Parse(attribute.Value);
                }
            }
            catch (Exception exception)
            {
                Log.e("DownloadImgService", exception.Message);
                context.length   = 0;
                context.hdlength = 0;
                return(context);
            }
            return(context);
        }