本文整理汇总了C#中IGrainState类的典型用法代码示例。如果您正苦于以下问题:C# IGrainState类的具体用法?C# IGrainState怎么用?C# IGrainState使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
IGrainState类属于命名空间,在下文中一共展示了IGrainState类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: ReadStateAsync
public async Task ReadStateAsync(string grainType, GrainReference grainReference, IGrainState grainState)
{
var tableResult = await _table.ExecuteAsync(TableOperation.Retrieve<DynamicTableEntity>(grainReference.ToKeyString(), grainType));
if (tableResult.Result == null)
{
return;
}
var entity = tableResult.Result as DynamicTableEntity;
var serializer = new JsonSerializer();
using (var memoryStream = new MemoryStream())
{
foreach (var propertyName in entity.Properties.Keys.Where(p => p.StartsWith("d")).OrderBy(p => p))
{
var dataPart = entity.Properties[propertyName];
await memoryStream.WriteAsync(dataPart.BinaryValue, 0, dataPart.BinaryValue.Length);
}
memoryStream.Position = 0;
using (var bsonReader = new BsonReader(memoryStream))
{
var data = serializer.Deserialize<Dictionary<string, object>>(bsonReader);
grainState.SetAll(data);
}
}
}
开发者ID:justinliew,项目名称:Orleans.StorageEx,代码行数:26,代码来源:AzureTableStorageEx.cs
示例2: ReadStateAsync
public async Task ReadStateAsync(string grainType, GrainReference grainReference, IGrainState grainState)
{
if (!(grainState is IAggregateState))
throw new NotAggregateStateException(grainState.GetType());
var stream = this.GetStreamName(grainType, grainReference);
var sliceStart = 0;
StreamEventsSlice currentSlice;
do
{
var sliceCount = sliceStart + ReadPageSize;
currentSlice = await this.Connection.ReadStreamEventsForwardAsync(stream, sliceStart, sliceCount, true);
if (currentSlice.Status == SliceReadStatus.StreamNotFound)
return;
if (currentSlice.Status == SliceReadStatus.StreamDeleted)
throw new StreamDeletedException();
sliceStart = currentSlice.NextEventNumber;
foreach (var @event in currentSlice.Events)
{
dynamic deserialisedEvent = DeserializeEvent(@event.Event);
StateTransformer.ApplyEvent(deserialisedEvent, grainState as IAggregateState);
}
} while (!currentSlice.IsEndOfStream);
}
开发者ID:timfun,项目名称:orleans.eventsourcing,代码行数:32,代码来源:EventStoreProvider.cs
示例3: ReadStateAsync
public async Task ReadStateAsync(string grainType, GrainReference grainId, IGrainState grainState)
{
try
{
var blobName = BlobStorageProvider.GetBlobName(grainType, grainId);
var blob = container.GetBlockBlobReference(blobName);
var text = await blob.DownloadTextAsync();
if (string.IsNullOrWhiteSpace(text))
{
return;
}
var data = JsonConvert.DeserializeObject(text, grainState.GetType());
var dict = ((IGrainState)data).AsDictionary();
grainState.SetAll(dict);
}
catch (StorageException ex)
{
;
}
catch (Exception ex)
{
Log.Error(0, ex.ToString());
}
}
开发者ID:justinliew,项目名称:OrleansBlobStorageProvider,代码行数:25,代码来源:BlobStorageProvider.cs
示例4: WriteStateAsync
public async Task WriteStateAsync(string grainType, GrainReference grainReference, IGrainState grainState)
{
try
{
var collection = await this.EnsureCollection(grainType);
var documents = await this.Client.ReadDocumentFeedAsync(collection.DocumentsLink);
var documentId = grainReference.ToKeyString();
var document = documents.Where(d => d.Id == documentId).FirstOrDefault();
if(document != null)
{
document.State = grainState.AsDictionary();
await this.Client.ReplaceDocumentAsync(document);
}
else
{
await this.Client.CreateDocumentAsync(collection.DocumentsLink,
new GrainStateDocument { Id = documentId, State = grainState.AsDictionary() });
}
}
catch (Exception ex)
{
Log.Error(0, "Error in WriteStateAsync", ex);
}
}
开发者ID:SmartFire,项目名称:orleans.storageprovider.documentdb,代码行数:26,代码来源:DocumentDBStorageProvider.cs
示例5: WriteStateAsync
public Task<string> WriteStateAsync(string stateStore, string grainStoreKey, IGrainState grainState)
{
if (logger.IsVerbose) logger.Verbose("WriteStateAsync for {0} grain: {1} eTag: {2}", stateStore, grainStoreKey, grainState.ETag);
GrainStateStore storage = GetStoreForGrain(stateStore);
storage.UpdateGrainState(grainStoreKey, grainState);
if (logger.IsVerbose) logger.Verbose("Done WriteStateAsync for {0} grain: {1} eTag: {2}", stateStore, grainStoreKey, grainState.ETag);
return Task.FromResult(grainState.ETag);
}
开发者ID:sbambach,项目名称:orleans,代码行数:8,代码来源:MemoryStorageGrain.cs
示例6: ReadStateAsync
/// <summary>
/// Reads persisted state from the backing store and deserializes it into the the target
/// grain state object.
/// </summary>
/// <param name="grainType">A string holding the name of the grain class.</param>
/// <param name="grainReference">Represents the long-lived identity of the grain.</param>
/// <param name="grainState">A reference to an object to hold the persisted state of the grain.</param>
/// <returns>Completion promise for this operation.</returns>
public async Task ReadStateAsync(string grainType, GrainReference grainReference, IGrainState grainState)
{
if (DataManager == null) throw new ArgumentException("DataManager property not initialized");
var entityData = await DataManager.Read(grainState.GetType().Name, grainReference.ToKeyString());
if (entityData != null)
{
ConvertFromStorageFormat(grainState, entityData);
}
}
开发者ID:Joshua-Ferguson,项目名称:orleans,代码行数:17,代码来源:BaseJSONStorageProvider.cs
示例7: ClearStateAsync
public Task ClearStateAsync(string grainType, GrainReference grainReference, IGrainState grainState)
{
if (!(grainState is IAggregateState))
throw new NotAggregateStateException(grainState.GetType());
var state = grainState as IAggregateState;
var stream = this.GetStreamName(grainType, grainReference);
return this.Connection.DeleteStreamAsync(stream, state.Version);
}
开发者ID:timfun,项目名称:orleans.eventsourcing,代码行数:10,代码来源:EventStoreProvider.cs
示例8: WriteStateAsync
public async Task WriteStateAsync(string grainType, GrainReference grainId, IGrainState grainState)
{
try
{
var blobName = BlobStorageProvider.GetBlobName(grainType, grainId);
var storedData = JsonConvert.SerializeObject(grainState.AsDictionary());
var blob = container.GetBlockBlobReference(blobName);
await blob.UploadTextAsync(storedData);
}
catch (Exception ex)
{
Log.Error(0, ex.ToString());
}
}
开发者ID:justinliew,项目名称:OrleansBlobStorageProvider,代码行数:14,代码来源:BlobStorageProvider.cs
示例9: ReadStateAsync
public async Task ReadStateAsync(string grainType, GrainReference grainReference, IGrainState grainState)
{
var stateName = grainState.GetType().Name;
var key = grainReference.ToKeyString();
var id = string.Format(CultureInfo.InvariantCulture, "{0}/{1}", stateName, key);
using (IAsyncDocumentSession session = this.documentStore.OpenAsyncSession())
{
var state = await session.LoadAsync<RavenJObject>(id);
if (state != null)
{
grainState.SetAll(state.ToDictionary(x => x.Key, x => x.Value.Value<object>()));
}
}
}
开发者ID:ReubenBond,项目名称:orleans.storageprovider.ravendb,代码行数:15,代码来源:RavenDBStorageProvider.cs
示例10: WriteStateAsync
public Task WriteStateAsync(string grainType, GrainReference grainReference, IGrainState grainState)
{
var entity = new DynamicTableEntity(grainReference.ToKeyString(), grainType) { ETag = "*" };
var serializer = new JsonSerializer();
using (var memoryStream = new MemoryStream())
{
using (var bsonWriter = new BsonWriter(memoryStream))
{
serializer.Serialize(bsonWriter, grainState.AsDictionary());
SplitBinaryData(entity, memoryStream.ToArray());
}
}
return _table.ExecuteAsync(TableOperation.InsertOrReplace(entity));
}
开发者ID:justinliew,项目名称:Orleans.StorageEx,代码行数:17,代码来源:AzureTableStorageEx.cs
示例11: ReadStateAsync
public async Task ReadStateAsync(string grainType, GrainReference grainReference, IGrainState grainState)
{
try
{
var collection = await this.EnsureCollection(grainType);
var documents = await this.Client.ReadDocumentFeedAsync(collection.DocumentsLink);
var documentId = grainReference.ToKeyString();
GrainStateDocument document = documents.Where(d => d.Id == documentId).FirstOrDefault();
if(document != null)
grainState.SetAll(document.State);
}
catch (Exception ex)
{
Log.Error(0, "Error in ReadStateAsync", ex);
}
}
开发者ID:SmartFire,项目名称:orleans.storageprovider.documentdb,代码行数:17,代码来源:DocumentDBStorageProvider.cs
示例12: WriteStateAsync
/// <summary> Write state data function for this storage provider. </summary>
/// <see cref="IStorageProvider.WriteStateAsync"/>
public async Task WriteStateAsync(string grainType, GrainReference grainId, IGrainState grainState)
{
var blobName = GetBlobName(grainType, grainId);
try
{
if (this.Log.IsVerbose3) this.Log.Verbose3((int)AzureProviderErrorCode.AzureBlobProvider_Storage_Writing, "Writing: GrainType={0} Grainid={1} ETag={2} to BlobName={3} in Container={4}", grainType, grainId, grainState.ETag, blobName, container.Name);
var json = JsonConvert.SerializeObject(grainState.State, settings);
var blob = container.GetBlockBlobReference(blobName);
blob.Properties.ContentType = "application/json";
var containerNotFound = false;
try
{
await blob.UploadTextAsync(
json,
Encoding.UTF8,
AccessCondition.GenerateIfMatchCondition(grainState.ETag),
null,
null).ConfigureAwait(false);
}
catch (StorageException exception)
{
var errorCode = exception.RequestInformation.ExtendedErrorInformation.ErrorCode;
containerNotFound = errorCode == BlobErrorCodeStrings.ContainerNotFound;
}
if (containerNotFound)
{
// if the container does not exist, create it, and make another attempt
if (this.Log.IsVerbose3) this.Log.Verbose3((int)AzureProviderErrorCode.AzureBlobProvider_ContainerNotFound, "Creating container: GrainType={0} Grainid={1} ETag={2} to BlobName={3} in Container={4}", grainType, grainId, grainState.ETag, blobName, container.Name);
await container.CreateIfNotExistsAsync().ConfigureAwait(false);
await blob.UploadTextAsync(
json,
Encoding.UTF8,
AccessCondition.GenerateIfMatchCondition(grainState.ETag),
null,
null).ConfigureAwait(false);
}
grainState.ETag = blob.Properties.ETag;
if (this.Log.IsVerbose3) this.Log.Verbose3((int)AzureProviderErrorCode.AzureBlobProvider_Storage_DataRead, "Written: GrainType={0} Grainid={1} ETag={2} to BlobName={3} in Container={4}", grainType, grainId, grainState.ETag, blobName, container.Name);
}
catch (Exception ex)
{
Log.Error((int)AzureProviderErrorCode.AzureBlobProvider_WriteError,
string.Format("Error writing: GrainType={0} Grainid={1} ETag={2} to BlobName={3} in Container={4} Exception={5}", grainType, grainId, grainState.ETag, blobName, container.Name, ex.Message),
ex);
}
}
开发者ID:pedroreys,项目名称:orleans,代码行数:54,代码来源:AzureBlobStorage.cs
示例13: ClearStateAsync
/// <summary> Clear / Delete state data function for this storage provider. </summary>
/// <see cref="IStorageProvider.ClearStateAsync"/>
public async Task ClearStateAsync(string grainType, GrainReference grainId, IGrainState grainState)
{
var blobName = GetBlobName(grainType, grainId);
try
{
if (this.Log.IsVerbose3) this.Log.Verbose3((int)AzureProviderErrorCode.AzureBlobProvider_ClearingData, "Clearing: GrainType={0} Grainid={1} ETag={2} BlobName={3} in Container={4}", grainType, grainId, grainState.ETag, blobName, container.Name);
var blob = container.GetBlockBlobReference(blobName);
await blob.DeleteIfExistsAsync(
DeleteSnapshotsOption.None,
AccessCondition.GenerateIfMatchCondition(grainState.ETag),
null,
null).ConfigureAwait(false);
grainState.ETag = blob.Properties.ETag;
if (this.Log.IsVerbose3) this.Log.Verbose3((int)AzureProviderErrorCode.AzureBlobProvider_Cleared, "Cleared: GrainType={0} Grainid={1} ETag={2} BlobName={3} in Container={4}", grainType, grainId, grainState.ETag, blobName, container.Name);
}
catch (Exception ex)
{
Log.Error((int)AzureProviderErrorCode.AzureBlobProvider_ClearError,
string.Format("Error clearing: GrainType={0} Grainid={1} ETag={2} BlobName={3} in Container={4} Exception={5}", grainType, grainId, grainState.ETag, blobName, container.Name, ex.Message),
ex);
}
}
开发者ID:pedroreys,项目名称:orleans,代码行数:26,代码来源:AzureBlobStorage.cs
示例14: ConvertFromStorageFormat
/// <summary>
/// Deserialize from Azure storage format
/// </summary>
/// <param name="grainState">The grain state data to be deserialized in to</param>
/// <param name="entity">The Azure table entity the stored data</param>
internal void ConvertFromStorageFormat(IGrainState grainState, GrainStateEntity entity)
{
Dictionary<string, object> dataValues = null;
try
{
if (entity.Data != null)
{
// Rehydrate
dataValues = SerializationManager.DeserializeFromByteArray<Dictionary<string, object>>(entity.Data);
}
else if (entity.StringData != null)
{
dataValues = Newtonsoft.Json.JsonConvert.DeserializeObject<Dictionary<string, object>>(entity.StringData, jsonSettings);
}
if (dataValues != null)
{
grainState.SetAll(dataValues);
}
// Else, no data found
}
catch (Exception exc)
{
var sb = new StringBuilder();
if (entity.Data != null)
{
sb.AppendFormat("Unable to convert from storage format GrainStateEntity.Data={0}", entity.Data);
}
else if (entity.StringData != null)
{
sb.AppendFormat("Unable to convert from storage format GrainStateEntity.StringData={0}", entity.StringData);
}
if (dataValues != null)
{
int i = 1;
foreach (var dvKey in dataValues.Keys)
{
object dvValue = dataValues[dvKey];
sb.AppendLine();
sb.AppendFormat("Data #{0} Key={1} Value={2} Type={3}", i, dvKey, dvValue, dvValue.GetType());
i++;
}
}
Log.Error(0, sb.ToString(), exc);
throw new AggregateException(sb.ToString(), exc);
}
}
开发者ID:stanroze,项目名称:orleans,代码行数:51,代码来源:AzureTableStorage.cs
示例15: ReadStateAsync
/// <summary> Read state data function for this storage provider. </summary>
/// <see cref="IStorageProvider.ReadStateAsync"/>
public async Task ReadStateAsync(string grainType, GrainReference grainId, IGrainState grainState)
{
var blobName = GetBlobName(grainType, grainId);
if (this.Log.IsVerbose3) this.Log.Verbose3((int)AzureProviderErrorCode.AzureBlobProvider_Storage_Reading, "Reading: GrainType={0} Grainid={1} ETag={2} from BlobName={3} in Container={4}", grainType, grainId, grainState.ETag, blobName, container.Name);
try
{
var blob = container.GetBlockBlobReference(blobName);
string json;
try
{
json = await blob.DownloadTextAsync().ConfigureAwait(false);
}
catch (StorageException exception)
{
var errorCode = exception.RequestInformation.ExtendedErrorInformation.ErrorCode;
if (errorCode == BlobErrorCodeStrings.BlobNotFound)
{
if (this.Log.IsVerbose2) this.Log.Verbose2((int)AzureProviderErrorCode.AzureBlobProvider_BlobNotFound, "BlobNotFound reading: GrainType={0} Grainid={1} ETag={2} from BlobName={3} in Container={4}", grainType, grainId, grainState.ETag, blobName, container.Name);
return;
}
if (errorCode == BlobErrorCodeStrings.ContainerNotFound)
{
if (this.Log.IsVerbose2) this.Log.Verbose2((int)AzureProviderErrorCode.AzureBlobProvider_ContainerNotFound, "ContainerNotFound reading: GrainType={0} Grainid={1} ETag={2} from BlobName={3} in Container={4}", grainType, grainId, grainState.ETag, blobName, container.Name);
return;
}
throw;
}
if (string.IsNullOrWhiteSpace(json))
{
if (this.Log.IsVerbose2) this.Log.Verbose2((int)AzureProviderErrorCode.AzureBlobProvider_BlobEmpty, "BlobEmpty reading: GrainType={0} Grainid={1} ETag={2} from BlobName={3} in Container={4}", grainType, grainId, grainState.ETag, blobName, container.Name);
return;
}
grainState.State = JsonConvert.DeserializeObject(json, grainState.State.GetType(), settings);
grainState.ETag = blob.Properties.ETag;
if (this.Log.IsVerbose3) this.Log.Verbose3((int)AzureProviderErrorCode.AzureBlobProvider_Storage_DataRead, "Read: GrainType={0} Grainid={1} ETag={2} from BlobName={3} in Container={4}", grainType, grainId, grainState.ETag, blobName, container.Name);
}
catch (Exception ex)
{
Log.Error((int)AzureProviderErrorCode.AzureBlobProvider_ReadError,
string.Format("Error reading: GrainType={0} Grainid={1} ETag={2} from BlobName={3} in Container={4} Exception={5}", grainType, grainId, grainState.ETag, blobName, container.Name, ex.Message),
ex);
}
}
开发者ID:pedroreys,项目名称:orleans,代码行数:52,代码来源:AzureBlobStorage.cs
示例16: WriteStateAsync
/// <summary> Write state data function for this storage provider. </summary>
/// <see cref="IStorageProvider#WriteStateAsync"/>
public async Task WriteStateAsync(string grainType, GrainReference grainReference, IGrainState grainState)
{
if(grainState.State is GrainState) //WARN: HACK, such a hack
grainState.ETag = ((GrainState)grainState.State).Etag;
var primaryKey = grainReference.ToKeyString();
if (Log.IsVerbose3)
{
Log.Verbose3((int) SimpleSQLServerProviderErrorCodes.SimpleSQLServerProvider_WritingData,
$"Writing: GrainType={grainType} PrimaryKey={primaryKey} GrainId={grainReference} ETag={grainState.ETag} to DataSource={this.sqlconnBuilder.DataSource + "." + this.sqlconnBuilder.InitialCatalog}");
}
try
{
var data = grainState.State;
byte[] payload = null;
string jsonpayload = string.Empty;
if (this.useJsonOrBinaryFormat != StorageFormatEnum.Json)
{
payload = SerializationManager.SerializeToByteArray(data);
}
if (this.useJsonOrBinaryFormat == StorageFormatEnum.Json || this.useJsonOrBinaryFormat == StorageFormatEnum.Both)
{
jsonpayload = JsonConvert.SerializeObject(data, jsonSettings);
}
var kvb = new KeyValueStore()
{
JsonContext = jsonpayload,
BinaryContent = payload,
GrainKeyId = primaryKey,
ETag = Guid.NewGuid().ToString()
};
using (var db = new KeyValueDbContext(this.sqlconnBuilder.ConnectionString))
{
if(grainState.ETag != null)
{
var value = await db.KeyValues.Where(s => s.GrainKeyId.Equals(primaryKey)).Select(s => s.ETag).SingleOrDefaultAsync();
if(value != null && value != grainState.ETag)
{
string error = $"Etag mismatch during WriteStateAsync for grain {primaryKey}: Expected = {value ?? "null"} Received = {grainState.ETag}";
Log.Error(0, error);
throw new InconsistentStateException(error);
}
}
db.Set<KeyValueStore>().AddOrUpdate(kvb);
grainState.ETag = kvb.ETag;
if(grainState.State is GrainState)
((GrainState)grainState.State).Etag = kvb.ETag;
await db.SaveChangesAsync();
}
}
catch (Exception ex)
{
Log.Error((int) SimpleSQLServerProviderErrorCodes.SimpleSQLServerProvider_WriteError,
$"Error writing: GrainType={grainType} GrainId={grainReference} ETag={grainState.ETag} to DataSource={this.sqlconnBuilder.DataSource + "." + this.sqlconnBuilder.InitialCatalog}",
ex);
throw;
}
}
开发者ID:OrleansContrib,项目名称:Orleans.StorageProviders.SimpleSQLServerStorage,代码行数:69,代码来源:SimpleSQLServerStorage.cs
示例17: WriteStateInternal
private async Task WriteStateInternal(IGrainState grainState, GrainStateRecord record, bool clear = false)
{
var fields = new Dictionary<string, AttributeValue>();
if (record.BinaryState != null && record.BinaryState.Length > 0)
{
fields.Add(BINARY_STATE_PROPERTY_NAME, new AttributeValue { B = new MemoryStream(record.BinaryState) });
}
else if (!string.IsNullOrWhiteSpace(record.StringState))
{
fields.Add(STRING_STATE_PROPERTY_NAME, new AttributeValue(record.StringState));
}
int newEtag = 0;
if (clear)
{
fields.Add(GRAIN_REFERENCE_PROPERTY_NAME, new AttributeValue(record.GrainReference));
fields.Add(GRAIN_TYPE_PROPERTY_NAME, new AttributeValue(record.GrainType));
int currentEtag = 0;
int.TryParse(grainState.ETag, out currentEtag);
newEtag = currentEtag;
fields.Add(ETAG_PROPERTY_NAME, new AttributeValue { N = newEtag++.ToString() });
await storage.PutEntryAsync(tableName, fields).ConfigureAwait(false);
}
else if (string.IsNullOrWhiteSpace(grainState.ETag))
{
fields.Add(GRAIN_REFERENCE_PROPERTY_NAME, new AttributeValue(record.GrainReference));
fields.Add(GRAIN_TYPE_PROPERTY_NAME, new AttributeValue(record.GrainType));
fields.Add(ETAG_PROPERTY_NAME, new AttributeValue { N = "0" });
var expression = $"attribute_not_exists({GRAIN_REFERENCE_PROPERTY_NAME}) AND attribute_not_exists({GRAIN_TYPE_PROPERTY_NAME})";
await storage.PutEntryAsync(tableName, fields, expression).ConfigureAwait(false);
}
else
{
var keys = new Dictionary<string, AttributeValue>();
keys.Add(GRAIN_REFERENCE_PROPERTY_NAME, new AttributeValue(record.GrainReference));
keys.Add(GRAIN_TYPE_PROPERTY_NAME, new AttributeValue(record.GrainType));
int currentEtag = 0;
int.TryParse(grainState.ETag, out currentEtag);
newEtag = currentEtag;
newEtag++;
fields.Add(ETAG_PROPERTY_NAME, new AttributeValue { N = newEtag.ToString() });
var conditionalValues = new Dictionary<string, AttributeValue> { { CURRENT_ETAG_ALIAS, new AttributeValue { N = currentEtag.ToString() } } };
var expression = $"{ETAG_PROPERTY_NAME} = {CURRENT_ETAG_ALIAS}";
await storage.UpsertEntryAsync(tableName, keys, fields, expression, conditionalValues).ConfigureAwait(false);
}
grainState.ETag = newEtag.ToString();
}
开发者ID:ticup,项目名称:orleans,代码行数:54,代码来源:DynamoDBStorageProvider.cs
示例18: ReadStateAsync
/// <summary> Read state data function for this storage provider. </summary>
/// <see cref="IStorageProvider.ReadStateAsync"/>
public async Task ReadStateAsync(string grainType, GrainReference grainReference, IGrainState grainState)
{
if (storage == null) throw new ArgumentException("GrainState-Table property not initialized");
string partitionKey = GetKeyString(grainReference);
if (Log.IsVerbose3) Log.Verbose3(ErrorCode.StorageProviderBase, "Reading: GrainType={0} Pk={1} Grainid={2} from Table={3}", grainType, partitionKey, grainReference, tableName);
string rowKey = AWSUtils.ValidateDynamoDBRowKey(grainType);
var record = await storage.ReadSingleEntryAsync(tableName,
new Dictionary<string, AttributeValue>
{
{ GRAIN_REFERENCE_PROPERTY_NAME, new AttributeValue(partitionKey) },
{ GRAIN_TYPE_PROPERTY_NAME, new AttributeValue(rowKey) }
},
(fields) =>
{
return new GrainStateRecord
{
GrainType = fields[GRAIN_TYPE_PROPERTY_NAME].S,
GrainReference = fields[GRAIN_REFERENCE_PROPERTY_NAME].S,
ETag = int.Parse(fields[ETAG_PROPERTY_NAME].N),
BinaryState = fields.ContainsKey(BINARY_STATE_PROPERTY_NAME) ? fields[BINARY_STATE_PROPERTY_NAME].B.ToArray() : null,
StringState = fields.ContainsKey(STRING_STATE_PROPERTY_NAME) ? fields[STRING_STATE_PROPERTY_NAME].S : string.Empty
};
}).ConfigureAwait(false);
if (record != null)
{
var loadedState = ConvertFromStorageFormat(record);
grainState.State = loadedState ?? Activator.CreateInstance(grainState.State.GetType());
grainState.ETag = record.ETag.ToString();
}
// Else leave grainState in previous default condition
}
开发者ID:ticup,项目名称:orleans,代码行数:37,代码来源:DynamoDBStorageProvider.cs
示例19: ClearStateAsync
public Task ClearStateAsync(string grainType, GrainReference grainReference, IGrainState grainState) => TaskDone.Done;
开发者ID:AntyaDev,项目名称:Orleankka,代码行数:1,代码来源:StreamSubscriptionBootstrapper.cs
示例20: ReadStateAsync
/// <summary> Read state data function for this storage provider. </summary>
/// <see cref="IStorageProvider#ReadStateAsync"/>
public async Task ReadStateAsync(string grainType, GrainReference grainReference, IGrainState grainState)
{
var primaryKey = grainReference.ToKeyString();
if (Log.IsVerbose3)
{
Log.Verbose3((int) SimpleSQLServerProviderErrorCodes.SimpleSQLServerProvider_ReadingData,
$"Reading: GrainType={grainType} Pk={primaryKey} Grainid={grainReference} from DataSource={this.sqlconnBuilder.DataSource + "." + this.sqlconnBuilder.InitialCatalog}");
}
try
{
using (var db = new KeyValueDbContext(this.sqlconnBuilder.ConnectionString))
{
switch (this.useJsonOrBinaryFormat)
{
case StorageFormatEnum.Binary:
case StorageFormatEnum.Both:
{
var value = await db.KeyValues.Where(s => s.GrainKeyId.Equals(primaryKey)).Select(s => new { s.BinaryContent, s.ETag } ).SingleOrDefaultAsync();
if (value != null)
{
//data = SerializationManager.DeserializeFromByteArray<Dictionary<string, object>>(value);
grainState.State = SerializationManager.DeserializeFromByteArray<object>(value.BinaryContent);
grainState.ETag = value.ETag;
if(grainState.State is GrainState)
((GrainState)grainState.State).Etag = value.ETag;
}
}
break;
case StorageFormatEnum.Json:
{
var value = await db.KeyValues.Where(s => s.GrainKeyId.Equals(primaryKey)).Select(s => new { s.JsonContext, s.ETag }).SingleOrDefaultAsync();
if (value != null && !string.IsNullOrEmpty(value.JsonContext))
{
//data = JsonConvert.DeserializeObject<Dictionary<string, object>>(value, jsonSettings);
grainState.State = JsonConvert.DeserializeObject(value.JsonContext, grainState.State.GetType(), jsonSettings);
grainState.ETag = value.ETag;
if(grainState.State is GrainState)
((GrainState)grainState.State).Etag = value.ETag;
}
}
break;
default:
break;
}
}
}
catch (Exception ex)
{
Log.Error((int) SimpleSQLServerProviderErrorCodes.SimpleSQLServerProvider_ReadError,
$"Error reading: GrainType={grainType} Grainid={grainReference} ETag={grainState.ETag} from DataSource={this.sqlconnBuilder.DataSource + "." + this.sqlconnBuilder.InitialCatalog}",
ex);
throw;
}
}
开发者ID:OrleansContrib,项目名称:Orleans.StorageProviders.SimpleSQLServerStorage,代码行数:59,代码来源:SimpleSQLServerStorage.cs
注:本文中的IGrainState类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论