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); }
public void LookupResource(FourCC programId, FourCC streamId, FourCC locale, ResourcesAPI.ResourceLookupCallback cb, object userContext) { ContentHandleRequest contentHandleRequest = new ContentHandleRequest(); contentHandleRequest.SetProgramId(programId.GetValue()); contentHandleRequest.SetStreamId(streamId.GetValue()); contentHandleRequest.SetLocale(locale.GetValue()); if (contentHandleRequest == null || !contentHandleRequest.IsInitialized) { base.ApiLog.LogWarning("Unable to create request for RPC call."); return; } RPCContext rPCContext = this.m_rpcConnection.QueueRequest(this.m_resourcesService.Id, 1u, contentHandleRequest, new RPCContextDelegate(this.GetContentHandleCallback), 0u); ResourcesAPIPendingState resourcesAPIPendingState = new ResourcesAPIPendingState(); resourcesAPIPendingState.Callback = cb; resourcesAPIPendingState.UserContext = userContext; this.m_pendingLookups.Add(rPCContext.Header.Token, resourcesAPIPendingState); base.ApiLog.LogDebug("Lookup request sent. PID={0} StreamID={1} Locale={2}", new object[] { programId, streamId, locale }); }