本文整理汇总了C#中IGrainState.SetAll方法的典型用法代码示例。如果您正苦于以下问题:C# IGrainState.SetAll方法的具体用法?C# IGrainState.SetAll怎么用?C# IGrainState.SetAll使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IGrainState
的用法示例。
在下文中一共展示了IGrainState.SetAll方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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());
}
}
示例2: 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);
}
}
}
示例3: 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>()));
}
}
}
示例4: 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);
}
}
示例5: 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);
}
}
示例6: ConvertFromStorageFormat
/// <summary>
/// Constructs a grain state instance by deserializing a JSON document.
/// </summary>
/// <param name="grainState">Grain state to be populated for storage.</param>
/// <param name="entityData">JSON storage format representaiton of the grain state.</param>
protected static void ConvertFromStorageFormat(IGrainState grainState, string entityData)
{
object data = JsonConvert.DeserializeObject(entityData, grainState.GetType(), GrainStateMongoDataManager.JsonSetting);
var dict = ((IGrainState)data).AsDictionary();
grainState.SetAll(dict);
}
示例7: ConvertFromStorageFormat
/// <summary>
/// Constructs a grain state instance by deserializing a JSON document.
/// </summary>
/// <param name="grainState">Grain state to be populated for storage.</param>
/// <param name="entityData">JSON storage format representaiton of the grain state.</param>
protected static void ConvertFromStorageFormat(IGrainState grainState, string entityData)
{
var setting = new JsonSerializerSettings();
object data = JsonConvert.DeserializeObject(entityData, grainState.GetType());
var dict = ((IGrainState)data).AsDictionary();
grainState.SetAll(dict);
}
示例8: ConvertFromStorageFormat
/// <summary>
/// Constructs a grain state instance by deserializing a JSON document.
/// </summary>
/// <param name="grainState">Grain state to be populated for storage.</param>
/// <param name="entityData">JSON storage format representaiton of the grain state.</param>
protected static void ConvertFromStorageFormat(IGrainState grainState, string entityData)
{
JavaScriptSerializer deserializer = new JavaScriptSerializer();
object data = deserializer.Deserialize(entityData, grainState.GetType());
var dict = ((IGrainState)data).AsDictionary();
grainState.SetAll(dict);
}