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); }
public bool GetFile(ContentHandle ch, LocalStorageAPI.DownloadCompletedCallback cb, object userContext = null) { bool flag; try { LocalStorageFileState localStorageFileState = new LocalStorageFileState(LocalStorageAPI.m_downloadId) { CH = ch, Callback = cb, UserContext = userContext }; LocalStorageAPI.s_log.LogDebug("Starting GetFile State={0}", new object[] { localStorageFileState }); if (!this.LoadStateFromDrive(localStorageFileState)) { LocalStorageAPI.s_log.LogDebug("Unable to load file from disk, starting a download. State={0}", new object[] { localStorageFileState }); this.DownloadFromDepot(localStorageFileState); } return(true); } catch (Exception exception1) { Exception exception = exception1; LocalStorageAPI.s_log.LogWarning("EXCEPTION (GetFile): {0}", new object[] { exception.Message }); flag = false; } return(flag); }
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 bool GetFile(ContentHandle ch, LocalStorageAPI.DownloadCompletedCallback cb, object userContext = null) { try { LocalStorageFileState localStorageFileState = new LocalStorageFileState(LocalStorageAPI.m_downloadId); localStorageFileState.CH = ch; localStorageFileState.Callback = cb; localStorageFileState.UserContext = userContext; LocalStorageAPI.s_log.LogDebug("Starting GetFile State={0}", new object[] { localStorageFileState }); if (!this.LoadStateFromDrive(localStorageFileState)) { LocalStorageAPI.s_log.LogDebug("Unable to load file from disk, starting a download. State={0}", new object[] { localStorageFileState }); this.DownloadFromDepot(localStorageFileState); } } catch (Exception ex) { LocalStorageAPI.s_log.LogWarning("EXCEPTION (GetFile): {0}", new object[] { ex.get_Message() }); return(false); } return(true); }
private void ResouceLookupCallback(ContentHandle contentHandle, object userContext) { if (contentHandle == null) { base.ApiLog.LogWarning("BN resource look up failed unable to proceed"); return; } base.ApiLog.LogDebug("Lookup done Region={0} Usage={1} SHA256={2}", new object[] { contentHandle.Region, contentHandle.Usage, contentHandle.Sha256Digest }); this.m_battleNet.LocalStorage.GetFile(contentHandle, new LocalStorageAPI.DownloadCompletedCallback(this.DownloadCompletedCallback), null); }
public static ContentHandle FromProtocol(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 = ContentHandle.ByteArrayToString(contentHandle.Hash) }); }
private void ResouceLookupTestCallback(ContentHandle contentHandle, object userContext) { if (contentHandle == null) { base.ApiLog.LogWarning("Lookup failed"); return; } int num = (int)userContext; base.ApiLog.LogDebug("Lookup done i={0} Region={1} Usage={2} SHA256={3}", new object[] { num, contentHandle.Region, contentHandle.Usage, contentHandle.Sha256Digest }); }