コード例 #1
0
 public void SetConnectionMeteringContentHandles(ConnectionMeteringContentHandles handles, LocalStorageAPI localStorage)
 {
     if (((handles == null) || !handles.IsInitialized) || (handles.ContentHandleCount == 0))
     {
         this.m_cmLogSource.LogWarning("Invalid connection metering content handle received.");
     }
     else
     {
         if (handles.ContentHandleCount != 1)
         {
             this.m_cmLogSource.LogWarning("More than 1 connection metering content handle specified!");
         }
         bnet.protocol.ContentHandle contentHandle = handles.ContentHandle[0];
         if ((contentHandle == null) || !contentHandle.IsInitialized)
         {
             this.m_cmLogSource.LogWarning("The content handle received is not valid!");
         }
         else
         {
             this.m_cmLogSource.LogDebug("Received request to enable connection metering.");
             ContentHandle ch   = ContentHandle.FromProtocol(contentHandle);
             object[]      args = new object[] { ch };
             this.m_cmLogSource.LogDebug("Requesting file from local storage. ContentHandle={0}", args);
             localStorage.GetFile(ch, new LocalStorageAPI.DownloadCompletedCallback(this.DownloadCompletedCallback));
         }
     }
 }
コード例 #2
0
        public static ContentHandle DeserializeLengthDelimited(Stream stream)
        {
            ContentHandle contentHandle = new ContentHandle();

            ContentHandle.DeserializeLengthDelimited(stream, contentHandle);
            return(contentHandle);
        }
コード例 #3
0
        public static ContentHandle DeserializeLengthDelimited(Stream stream, ContentHandle instance)
        {
            long num = (long)((ulong)ProtocolParser.ReadUInt32(stream));

            num += stream.get_Position();
            return(ContentHandle.Deserialize(stream, instance, num));
        }
コード例 #4
0
        public void SetConnectionMeteringContentHandles(ConnectionMeteringContentHandles handles, LocalStorageAPI localStorage)
        {
            if (handles == null || !handles.IsInitialized || handles.ContentHandleCount == 0)
            {
                this.m_cmLogSource.LogWarning("Invalid connection metering content handle received.");
                return;
            }
            if (handles.ContentHandleCount != 1)
            {
                this.m_cmLogSource.LogWarning("More than 1 connection metering content handle specified!");
            }
            bnet.protocol.ContentHandle contentHandle = handles.ContentHandle.get_Item(0);
            if (contentHandle == null || !contentHandle.IsInitialized)
            {
                this.m_cmLogSource.LogWarning("The content handle received is not valid!");
                return;
            }
            this.m_cmLogSource.LogDebug("Received request to enable connection metering.");
            ContentHandle contentHandle2 = ContentHandle.FromProtocol(contentHandle);

            this.m_cmLogSource.LogDebug("Requesting file from local storage. ContentHandle={0}", new object[]
            {
                contentHandle2
            });
            localStorage.GetFile(contentHandle2, new LocalStorageAPI.DownloadCompletedCallback(this.DownloadCompletedCallback), null);
        }
コード例 #5
0
        private void GetContentHandleCallback(RPCContext context)
        {
            ResourcesAPIPendingState resourcesAPIPendingState = null;

            if (!this.m_pendingLookups.TryGetValue(context.Header.Token, out resourcesAPIPendingState))
            {
                base.ApiLog.LogWarning("Received unmatched lookup response");
                return;
            }
            this.m_pendingLookups.Remove(context.Header.Token);
            bnet.protocol.ContentHandle contentHandle = bnet.protocol.ContentHandle.ParseFrom(context.Payload);
            if (contentHandle == null || !contentHandle.IsInitialized)
            {
                base.ApiLog.LogWarning("Received invalid response");
                resourcesAPIPendingState.Callback(null, resourcesAPIPendingState.UserContext);
                return;
            }
            BattleNetErrors status = (BattleNetErrors)context.Header.Status;

            if (status != BattleNetErrors.ERROR_OK)
            {
                base.ApiLog.LogWarning("Battle.net Resources API C#: Failed lookup. Error={0}", new object[]
                {
                    status
                });
                resourcesAPIPendingState.Callback(null, resourcesAPIPendingState.UserContext);
                return;
            }
            ContentHandle contentHandle2 = ContentHandle.FromProtocol(contentHandle);

            resourcesAPIPendingState.Callback(contentHandle2, resourcesAPIPendingState.UserContext);
        }
コード例 #6
0
        public override bool Equals(object obj)
        {
            ContentHandle contentHandle = obj as ContentHandle;

            if (contentHandle == null)
            {
                return(false);
            }
            if (!this.Region.Equals(contentHandle.Region))
            {
                return(false);
            }
            if (!this.Usage.Equals(contentHandle.Usage))
            {
                return(false);
            }
            if (!this.Hash.Equals(contentHandle.Hash))
            {
                return(false);
            }
            if (this.HasProtoUrl == contentHandle.HasProtoUrl && (!this.HasProtoUrl || this.ProtoUrl.Equals(contentHandle.ProtoUrl)))
            {
                return(true);
            }
            return(false);
        }
コード例 #7
0
        public static ContentHandle DeserializeLengthDelimited(Stream stream, ContentHandle instance)
        {
            long position = (long)ProtocolParser.ReadUInt32(stream);

            position += stream.Position;
            return(ContentHandle.Deserialize(stream, instance, position));
        }
コード例 #8
0
        public static ContentHandle Deserialize(Stream stream, ContentHandle instance, long limit)
        {
            BinaryReader binaryReader = new BinaryReader(stream);

            while (limit < 0L || stream.Position < limit)
            {
                int num = stream.ReadByte();
                if (num == -1)
                {
                    if (limit >= 0L)
                    {
                        throw new EndOfStreamException();
                    }
                    return(instance);
                }
                else if (num != 13)
                {
                    if (num != 21)
                    {
                        if (num != 26)
                        {
                            if (num != 34)
                            {
                                Key  key   = ProtocolParser.ReadKey((byte)num, stream);
                                uint field = key.Field;
                                if (field == 0u)
                                {
                                    throw new ProtocolBufferException("Invalid field id: 0, something went wrong in the stream");
                                }
                                ProtocolParser.SkipKey(stream, key);
                            }
                            else
                            {
                                instance.ProtoUrl = ProtocolParser.ReadString(stream);
                            }
                        }
                        else
                        {
                            instance.Hash = ProtocolParser.ReadBytes(stream);
                        }
                    }
                    else
                    {
                        instance.Usage = binaryReader.ReadUInt32();
                    }
                }
                else
                {
                    instance.Region = binaryReader.ReadUInt32();
                }
            }
            if (stream.Position == limit)
            {
                return(instance);
            }
            throw new ProtocolBufferException("Read past max limit");
        }
コード例 #9
0
 public static ContentHandle FromProtocol(bnet.protocol.ContentHandle contentHandle)
 {
     if ((contentHandle == null) || !contentHandle.IsInitialized)
     {
         return(null);
     }
     return(new ContentHandle {
         Region = new FourCC(contentHandle.Region).ToString(), Usage = new FourCC(contentHandle.Usage).ToString(), Sha256Digest = ByteArrayToString(contentHandle.Hash)
     });
 }
コード例 #10
0
 public static bgs.ContentHandle FromProtocol(bnet.protocol.ContentHandle contentHandle)
 {
     if (contentHandle == null || !contentHandle.IsInitialized)
     {
         return(null);
     }
     bgs.ContentHandle contentHandle1 = new bgs.ContentHandle()
     {
         Region       = (new FourCC(contentHandle.Region)).ToString(),
         Usage        = (new FourCC(contentHandle.Usage)).ToString(),
         Sha256Digest = bgs.ContentHandle.ByteArrayToString(contentHandle.Hash)
     };
     return(contentHandle1);
 }
コード例 #11
0
        public static void Serialize(Stream stream, ContentHandle instance)
        {
            BinaryWriter binaryWriter = new BinaryWriter(stream);

            stream.WriteByte(13);
            binaryWriter.Write(instance.Region);
            stream.WriteByte(21);
            binaryWriter.Write(instance.Usage);
            if (instance.Hash == null)
            {
                throw new ArgumentNullException("Hash", "Required by proto specification.");
            }
            stream.WriteByte(26);
            ProtocolParser.WriteBytes(stream, instance.Hash);
            if (instance.HasProtoUrl)
            {
                stream.WriteByte(34);
                ProtocolParser.WriteBytes(stream, Encoding.get_UTF8().GetBytes(instance.ProtoUrl));
            }
        }
コード例 #12
0
 public void AddContentHandle(bnet.protocol.ContentHandle val)
 {
     this._ContentHandle.Add(val);
 }
コード例 #13
0
 public static ContentHandle Deserialize(Stream stream, ContentHandle instance)
 {
     return(ContentHandle.Deserialize(stream, instance, -1L));
 }
コード例 #14
0
 public void Deserialize(Stream stream)
 {
     ContentHandle.Deserialize(stream, this);
 }
コード例 #15
0
        public override bool Equals(object obj)
        {
            ContentHandle contentHandle = obj as ContentHandle;

            return(contentHandle != null && this.Region.Equals(contentHandle.Region) && this.Usage.Equals(contentHandle.Usage) && this.Hash.Equals(contentHandle.Hash) && this.HasProtoUrl == contentHandle.HasProtoUrl && (!this.HasProtoUrl || this.ProtoUrl.Equals(contentHandle.ProtoUrl)));
        }