//*** Local cache ***// public override async Task <C8oLocalCacheResponse> GetResponseFromLocalCache(string c8oCallRequestIdentifier) { C8oFullSyncDatabase fullSyncDatabase = await GetOrCreateFullSyncDatabase(C8o.LOCAL_CACHE_DATABASE_NAME); Document localCacheDocument = fullSyncDatabase.Database.GetExistingDocument(c8oCallRequestIdentifier); if (localCacheDocument == null) { throw new C8oUnavailableLocalCacheException(C8oExceptionMessage.MissingLocalCacheResponseDocument()); } IDictionary <string, object> properties = localCacheDocument.Properties; string response; string responseType; long expirationDate; if (!C8oUtils.TryGetParameterObjectValue <String>(properties, C8o.LOCAL_CACHE_DOCUMENT_KEY_RESPONSE, out response) || !C8oUtils.TryGetParameterObjectValue <String>(properties, C8o.LOCAL_CACHE_DOCUMENT_KEY_RESPONSE_TYPE, out responseType)) { throw new C8oUnavailableLocalCacheException(C8oExceptionMessage.InvalidLocalCacheResponseInformation()); } if (!C8oUtils.TryGetParameterObjectValue <long>(properties, C8o.LOCAL_CACHE_DOCUMENT_KEY_EXPIRATION_DATE, out expirationDate)) { expirationDate = -1; } return(new C8oLocalCacheResponse(response, responseType, expirationDate)); }
public Task <C8oFullSyncDatabase> GetOrCreateFullSyncDatabase(string databaseName) { string localDatabaseName = databaseName + localSuffix; if (!fullSyncDatabases.ContainsKey(localDatabaseName)) { fullSyncDatabases[localDatabaseName] = new C8oFullSyncDatabase(c8o, manager, databaseName, fullSyncDatabaseUrlBase, localSuffix); if (cblChangeListeners.ContainsKey(databaseName)) { fullSyncDatabases[localDatabaseName].Database.Changed += cblChangeListeners[databaseName]; } } return(Task.FromResult <C8oFullSyncDatabase>(fullSyncDatabases[localDatabaseName])); }
public override async Task SaveResponseToLocalCache(string c8oCallRequestIdentifier, C8oLocalCacheResponse localCacheResponse) { C8oFullSyncDatabase fullSyncDatabase = await GetOrCreateFullSyncDatabase(C8o.LOCAL_CACHE_DATABASE_NAME); Document localCacheDocument = fullSyncDatabase.Database.GetDocument(c8oCallRequestIdentifier); IDictionary <string, object> properties = new Dictionary <string, object>(); properties[C8o.LOCAL_CACHE_DOCUMENT_KEY_RESPONSE] = localCacheResponse.Response; properties[C8o.LOCAL_CACHE_DOCUMENT_KEY_RESPONSE_TYPE] = localCacheResponse.ResponseType; if (localCacheResponse.ExpirationDate > 0) { properties[C8o.LOCAL_CACHE_DOCUMENT_KEY_EXPIRATION_DATE] = localCacheResponse.ExpirationDate; } SavedRevision currentRevision = localCacheDocument.CurrentRevision; if (currentRevision != null) { properties[FULL_SYNC__REV] = currentRevision.Id; } localCacheDocument.PutProperties(properties); }