public async Task <Tuple <List <T>, CMPStorageError> > FetchAllAsync <T>(string tableNameString, FetchProgressCallback <T> fetchProgressCallback) where T : CMPTableStorageModel, new() { if (_tableStorageService == null) { return(null); } var fetchedResults = await _tableStorageService.FetchAllAsync <T>(tableNameString, fetchProgressCallback); return(fetchedResults); }
public async Task <Tuple <List <T>, CMPStorageError> > FetchAsync <T>(string tableNameString, string partitionKeyString, FetchProgressCallback <T> fetchProgressCallback) where T : CMPTableStorageModel, new() { if (_cloudTableClient == null) { return(new Tuple <List <T>, CMPStorageError>(null, null)); } if (string.IsNullOrEmpty(tableNameString) == true) { return(new Tuple <List <T>, CMPStorageError>(null, null)); } try { var tableReference = _cloudTableClient.GetTableReference(tableNameString); if (tableReference == null) { return(new Tuple <List <T>, CMPStorageError>(null, null)); } string filterConditionString = TableQuery.GenerateFilterCondition(KPartitionKeystring, QueryComparisons.Equal, partitionKeyString); var fetchedResultsInfo = await FetchForFilterAsync <T>(tableReference, filterConditionString, fetchProgressCallback); return(fetchedResultsInfo); } catch (StorageException exception) { var error = CMPStorageError.CreateErrorFromException(exception); return(new Tuple <List <T>, CMPStorageError>(null, error)); } }
public void FetchFormatFiles(PolyAsset asset, PolyFormatType formatType, PolyApi.FetchFormatFilesCallback completionCallback, FetchProgressCallback progressCallback = null) { PolyUtils.AssertNotNull(asset, "Asset can't be null."); PolyUtils.AssertNotNull(formatType, "formatType can't be null."); PolyFormat packageToFetch = asset.GetFormatIfExists(formatType); if (packageToFetch == null) { if (completionCallback != null) { completionCallback(asset, PolyStatus.Error("Format type not present in asset")); } return; } PolyUtils.AssertNotNull(packageToFetch.root, "packageToFetch.root can't be null."); PolyUtils.AssertNotNull(packageToFetch.root.url, "packageToFetch.root.url can't be null."); PolyUtils.AssertNotNull(packageToFetch.resources, "packageToFetch.resources can't be null."); string accessToken = GetAccessToken(); FetchOperationState state = new FetchOperationState(); state.asset = asset; state.completionCallback = completionCallback; state.progressCallback = progressCallback; state.packageBeingFetched = packageToFetch; // Indicates how many files are pending download (1 for main file + 1 for each resource). state.totalFiles = state.pendingFiles = 1 + packageToFetch.resources.Count; // Note that the callbacks are asynchronous so they may complete in any order. What we do know is that they // will all be called on the main thread, so they won't be called concurrently. long maxCacheAge = asset.IsMutable ? MUTABLE_ASSET_MAX_CACHE_AGE : IMMUTABLE_ASSET_MAX_CACHE_AGE; PolyClientUtils.GetRawFileBytes(packageToFetch.root.url, accessToken, maxCacheAge, (PolyStatus status, byte[] data) => { ProcessFileFetchResult(state, ROOT_FILE_INDEX, status, data); }); for (int i = 0; i < packageToFetch.resources.Count; i++) { int thisIndex = i; // copy of variable, for closure below. PolyClientUtils.GetRawFileBytes(packageToFetch.resources[i].url, accessToken, maxCacheAge, (status, data) => { ProcessFileFetchResult(state, thisIndex, status, data); }); } }
private async Task <Tuple <List <T>, CMPStorageError> > FetchForFilterAsync <T>(CloudTable tableReference, string filterConditionString, FetchProgressCallback <T> fetchProgressCallback = null) where T : CMPTableStorageModel, new() { if ((tableReference == null) || (string.IsNullOrEmpty(filterConditionString) == true)) { return(new Tuple <List <T>, CMPStorageError>(null, null)); } var tableQuery = new TableQuery <T>().Where(filterConditionString); TableContinuationToken token = null; var fetchedResultsList = new List <T>(); do { var tableQuerySegment = await tableReference.ExecuteQuerySegmentedAsync(tableQuery, token); var currentResultsList = tableQuerySegment?.Results?.Cast <T>().ToList(); if (fetchProgressCallback != null) { fetchProgressCallback.Invoke(currentResultsList); } fetchedResultsList.AddRange(currentResultsList); token = tableQuerySegment.ContinuationToken; } while (token != null); return(new Tuple <List <T>, CMPStorageError>(fetchedResultsList, null)); }