本文整理汇总了C#中IGrainState.AsDictionary方法的典型用法代码示例。如果您正苦于以下问题:C# IGrainState.AsDictionary方法的具体用法?C# IGrainState.AsDictionary怎么用?C# IGrainState.AsDictionary使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IGrainState
的用法示例。
在下文中一共展示了IGrainState.AsDictionary方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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);
}
}
示例2: 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());
}
}
示例3: ConvertToStorageFormat
/// <summary>
/// Serialize to Azure storage format in either binary or JSON format.
/// </summary>
/// <param name="grainState">The grain state data to be serialized</param>
/// <param name="entity">The Azure table entity the data should be stored in</param>
/// <remarks>
/// See:
/// http://msdn.microsoft.com/en-us/library/system.web.script.serialization.javascriptserializer.aspx
/// for more on the JSON serializer.
/// </remarks>
internal void ConvertToStorageFormat(IGrainState grainState, GrainStateEntity entity)
{
// Dehydrate
var dataValues = grainState.AsDictionary();
int dataSize;
if (useJsonFormat)
{
// http://james.newtonking.com/json/help/index.html?topic=html/T_Newtonsoft_Json_JsonConvert.htm
string data = Newtonsoft.Json.JsonConvert.SerializeObject(dataValues, jsonSettings);
if (Log.IsVerbose3) Log.Verbose3("Writing JSON data size = {0} for grain id = Partition={1} / Row={2}",
data.Length, entity.PartitionKey, entity.RowKey);
dataSize = data.Length;
entity.StringData = data;
}
else
{
// Convert to binary format
byte[] data = SerializationManager.SerializeToByteArray(dataValues);
if (Log.IsVerbose3) Log.Verbose3("Writing binary data size = {0} for grain id = Partition={1} / Row={2}",
data.Length, entity.PartitionKey, entity.RowKey);
dataSize = data.Length;
entity.Data = data;
}
if (dataSize > MAX_DATA_SIZE)
{
var msg = string.Format("Data too large to write to Azure table. Size={0} MaxSize={1}", dataSize, MAX_DATA_SIZE);
Log.Error(0, msg);
throw new ArgumentOutOfRangeException("GrainState.Size", msg);
}
}
示例4: 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));
}
示例5: ConvertToStorageFormat
/// <summary>
/// Serializes from a grain instance to a JSON document.
/// </summary>
/// <param name="grainState">Grain state to be converted into JSON storage format.</param>
/// <remarks>
/// </remarks>
protected static string ConvertToStorageFormat(string grainType, IGrainState grainState)
{
IDictionary<string, object> dataValues = grainState.AsDictionary();
//store _Type into couchbase
dataValues["_Type"] = grainType;
return JsonConvert.SerializeObject(dataValues);
}
示例6: ConvertToStorageFormat
/// <summary>
/// Serializes from a grain instance to a JSON document.
/// </summary>
/// <param name="grainState">Grain state to be converted into JSON storage format.</param>
/// <remarks>
/// See:
/// http://msdn.microsoft.com/en-us/library/system.web.script.serialization.javascriptserializer.aspx
/// for more on the JSON serializer.
/// </remarks>
protected static string ConvertToStorageFormat(IGrainState grainState)
{
IDictionary<string, object> dataValues = grainState.AsDictionary();
JavaScriptSerializer serializer = new JavaScriptSerializer();
return serializer.Serialize(dataValues);
}