public async Task ReadStateAsync(string grainType, GrainReference grainId, IGrainState grainState) { try { var blobName = BlobStorageProvider.GetBlobName(grainType, grainId); var blob = container.GetBlockBlobReference(blobName); var exists = await blob.ExistsAsync(); if (!exists) { return; } var text = await blob.DownloadTextAsync(); if (string.IsNullOrWhiteSpace(text)) { return; } var data = JsonConvert.DeserializeObject(text, grainState.GetType(), settings); var dict = ((IGrainState)data).AsDictionary(); grainState.SetAll(dict); grainState.Etag = blob.Properties.ETag; } catch (Exception ex) { Log.Error(0, ex.ToString()); } }
public async Task ClearStateAsync(string grainType, GrainReference grainId, IGrainState grainState) { try { var blobName = BlobStorageProvider.GetBlobName(grainType, grainId); var blob = container.GetBlockBlobReference(blobName); await blob.DeleteIfExistsAsync(); } catch (Exception ex) { Log.Error(0, ex.ToString()); } }
public async Task WriteStateAsync(string grainType, GrainReference grainId, IGrainState grainState) { try { var blobName = BlobStorageProvider.GetBlobName(grainType, grainId); var storedData = JsonConvert.SerializeObject(grainState.AsDictionary(), settings); var blob = container.GetBlockBlobReference(blobName); await blob.UploadTextAsync(storedData); } catch (Exception ex) { Log.Error(0, ex.ToString()); } }
public async Task ClearStateAsync(string grainType, GrainReference grainId, IGrainState grainState) { try { var blobName = BlobStorageProvider.GetBlobName(grainType, grainId); var blob = container.GetBlockBlobReference(blobName); await blob.DeleteIfExistsAsync( DeleteSnapshotsOption.None, AccessCondition.GenerateIfMatchCondition(grainState.Etag), null, null); grainState.Etag = blob.Properties.ETag; } catch (Exception ex) { Log.Error(0, ex.ToString()); } }
public async Task WriteStateAsync(string grainType, GrainReference grainId, IGrainState grainState) { try { var blobName = BlobStorageProvider.GetBlobName(grainType, grainId); var storedData = JsonConvert.SerializeObject(grainState.AsDictionary(), settings); var blob = container.GetBlockBlobReference(blobName); await blob.UploadTextAsync( storedData, Encoding.UTF8, AccessCondition.GenerateIfMatchCondition(grainState.Etag), null, null); grainState.Etag = blob.Properties.ETag; } catch (Exception ex) { Log.Error(0, ex.ToString()); } }