本文整理汇总了C#中IGrainState.GetType方法的典型用法代码示例。如果您正苦于以下问题:C# IGrainState.GetType方法的具体用法?C# IGrainState.GetType怎么用?C# IGrainState.GetType使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IGrainState
的用法示例。
在下文中一共展示了IGrainState.GetType方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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);
}
示例2: 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());
}
}
示例3: 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);
}
}
示例4: 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);
}
示例5: 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>()));
}
}
}
示例6: WriteStateAsync
/// <summary>
/// Writes the persisted state from a grain state object into its backing store.
/// </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 holding the persisted state of the grain.</param>
/// <returns>Completion promise for this operation.</returns>
public Task WriteStateAsync(string grainType, GrainReference grainReference, IGrainState grainState)
{
if (DataManager == null) throw new ArgumentException("DataManager property not initialized");
var entityData = ConvertToStorageFormat(grainState);
return DataManager.Write(grainState.GetType().Name, grainReference.ToKeyString(), entityData);
}
示例7: ClearStateAsync
/// <summary>
/// Removes grain state from its backing store, if found.
/// </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">An object holding the persisted state of the grain.</param>
/// <returns></returns>
public Task ClearStateAsync(string grainType, GrainReference grainReference, IGrainState grainState)
{
if (DataManager == null) throw new ArgumentException("DataManager property not initialized");
DataManager.Delete(grainState.GetType().Name, grainReference.ToKeyString());
return TaskDone.Done;
}
示例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)
{
object data = JsonConvert.DeserializeObject(entityData, grainState.GetType(), GrainStateMongoDataManager.JsonSetting);
var dict = ((IGrainState)data).AsDictionary();
grainState.SetAll(dict);
}
示例9: 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);
}
示例10: WriteStateAsync
public async Task WriteStateAsync(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())
{
await session.StoreAsync(grainState, id);
await session.SaveChangesAsync();
}
}
示例11: 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);
}