コード例 #1
0
ファイル: BlobReceiver.cs プロジェクト: liweizl/GGTalk
        private Information ConstructBlob()
        {
            if (this.lastFragmentIndex < 0)
            {
                return(null);
            }

            int totalSize = 0;

            for (int i = 0; i <= this.lastFragmentIndex; i++)
            {
                BlobFragmentContract fragment = this.fragmentDictionary.Get(i);
                if (fragment == null)
                {
                    return(null);
                }

                totalSize += fragment.Fragment.Length;
            }

            byte[] blob   = new byte[totalSize];
            int    offset = 0;

            for (int i = 0; i <= this.lastFragmentIndex; i++)
            {
                BlobFragmentContract fragment = this.fragmentDictionary.Get(i);
                Buffer.BlockCopy(fragment.Fragment, 0, blob, offset, fragment.Fragment.Length);
                offset += fragment.Fragment.Length;
            }

            return(new Information(this.sourceID, this.destID, this.informationType, blob));
        }
コード例 #2
0
ファイル: BlobReceiver.cs プロジェクト: liweizl/GGTalk
        public Information Receive(string sourceID, string destID, BlobFragmentContract fragment)
        {
            if (fragment.BlobID == 1 && fragment.FragmentIndex == 0)  //可能是掉线重新登录过
            {
                this.OnUserOffline(sourceID);
            }

            if (fragment.FragmentIndex == 0 && fragment.IsLast)
            {
                return(new Information(sourceID, destID, fragment.InformationType, fragment.Fragment));
            }

            string id   = this.ConstructID(sourceID, fragment.BlobID);
            Blob   blob = this.blobManager.Get(id);

            if (blob == null)
            {
                blob = new Blob(fragment.BlobID, sourceID, destID, fragment.InformationType);
                this.blobManager.Add(id, blob);
            }

            Information info = blob.AddFragment(fragment);

            if (info != null)
            {
                this.blobManager.Remove(id);
            }
            return(info);
        }
コード例 #3
0
ファイル: BlobReceiver.cs プロジェクト: liweizl/GGTalk
        public Information AddFragment(BlobFragmentContract fragment)
        {
            lock (this.locker)
            {
                if (fragment.IsLast)
                {
                    this.lastFragmentIndex = fragment.FragmentIndex;
                }

                this.fragmentDictionary.Add(fragment.FragmentIndex, fragment);
                return(this.ConstructBlob());
            }
        }