本文整理汇总了C#中GrainReference.ToKeyString方法的典型用法代码示例。如果您正苦于以下问题:C# GrainReference.ToKeyString方法的具体用法?C# GrainReference.ToKeyString怎么用?C# GrainReference.ToKeyString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类GrainReference
的用法示例。
在下文中一共展示了GrainReference.ToKeyString方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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);
}
}
}
示例2: ToElasticValue
public string ToElasticValue(GrainReference gref)
{
///"GrainReference=00000000000000000000000000000000060000006aa96326+abc"
/// to
/// "GrainReference^00000000000000000000000000000000060000006aa96326_abc"
return gref.ToKeyString().Replace("=", "__").Replace("_", "+");
}
示例3: 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);
}
}
示例4: CreateIdFrom
public static string CreateIdFrom(GrainReference grainRef,string reminderName)
{
if (String.IsNullOrEmpty(reminderName))
throw new ArgumentNullException("reminderName");
if (grainRef==null)
throw new ArgumentNullException("grainRef");
return grainRef.ToKeyString() + "," + reminderName;
}
示例5: 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);
}
}
示例6: FromGrainReference
/// <summary>
/// Createa a GrainIdentity from a grain reference and type name
/// </summary>
/// <param name="grainType"></param>
/// <param name="grainReference"></param>
/// <returns></returns>
public static GrainIdentity FromGrainReference(string grainType, GrainReference grainReference)
{
Guard.NotNullOrEmpty(grainType, "grainType");
Guard.NotNull(grainReference, "grainReference");
return new GrainIdentity()
{
GrainType = grainType,
ShardKey = (int)grainReference.GetUniformHashCode(),
GrainKey = grainReference.ToKeyString()
};
}
示例7: WriteStateAsync
public async Task WriteStateAsync(string grainType, GrainReference grainReference, GrainState 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();
}
}
示例8: ReadRows
public async Task<ReminderTableData> ReadRows(GrainReference grainRef)
{
using (var conn = new SqlConnection(connectionString))
{
conn.Open();
var command = new SqlCommand(READ_GRAIN_ROWS);
command.Parameters.Add(new SqlParameter { ParameterName = "@id", DbType = DbType.String, Value = serviceId });
command.Parameters.Add(new SqlParameter { ParameterName = "@grainid", DbType = DbType.String, Value = grainRef.ToKeyString() });
command.Connection = conn;
return await ProcessResults(command);
}
}
示例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>()));
}
}
}
示例10: ClearStateAsync
public async Task ClearStateAsync(string grainType, GrainReference grainReference, GrainState 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())
{
session.Advanced.Defer(new DeleteCommandData
{
Key = id
});
await session.SaveChangesAsync();
}
}
示例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);
}
}
示例12: 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));
}
示例13: ReadReminderRowAsync
/// <summary>
/// Reads one row of reminder data.
/// </summary>
/// <param name="serviceId">Service ID.</param>
/// <param name="grainRef">The grain reference (ID).</param>
/// <param name="reminderName">The reminder name to retrieve.</param>
/// <returns>A remainder entry.</returns>
internal async Task<ReminderEntry> ReadReminderRowAsync( string serviceId, GrainReference grainRef, string reminderName)
{
var ret = await storage.ReadAsync(orleansQueries.ReadReminderRowKey, command =>
{
var serviceIdParameter = CreateServiceIdParameter(command, serviceId);
command.Parameters.Add(serviceIdParameter);
var grainIdParameter = CreateGrainIdParameter(command, grainRef.ToKeyString());
command.Parameters.Add(grainIdParameter);
var reminderNameParameter = CreateReminderName(command, reminderName);
command.Parameters.Add(reminderNameParameter);
}, (selector, _) =>
{
return CreateReminderEntry(selector);
}).ConfigureAwait(continueOnCapturedContext: false);
return ret != null ? ret.FirstOrDefault() : null;
}
示例14: ReadReminderRowsAsync
/// <summary>
/// Reads Orleans reminder data from the tables.
/// </summary>
/// <param name="serviceId">The service ID.</param>
/// <param name="grainRef">The grain reference (ID).</param>
/// <returns>Reminder table data.</returns>
internal async Task<ReminderTableData> ReadReminderRowsAsync(string serviceId, GrainReference grainRef)
{
var ret = await storage.ReadAsync(orleansQueries.ReadReminderRowsKey, command =>
{
var serviceIdParameter = CreateServiceIdParameter(command, serviceId);
command.Parameters.Add(serviceIdParameter);
var grainIdParameter = CreateGrainIdParameter(command, grainRef.ToKeyString());
command.Parameters.Add(grainIdParameter);
}, (selector, _) =>
{
return CreateReminderEntry(selector);
}).ConfigureAwait(continueOnCapturedContext: false);
return new ReminderTableData(ret.Where(i => i != null).ToList());
}
示例15: UpsertReminderRowAsync
/// <summary>
/// Either inserts or updates a reminder row.
/// </summary>
/// <param name="serviceId">The service ID.</param>
/// <param name="grainRef">The grain reference (ID).</param>
/// <param name="reminderName">The reminder name to retrieve.</param>
/// <param name="startTime">Start time of the reminder.</param>
/// <param name="period">Period of the reminder.</param>
/// <returns>The new etag of the either or updated or inserted reminder row.</returns>
internal async Task<string> UpsertReminderRowAsync(string serviceId, GrainReference grainRef, string reminderName, DateTime startTime, TimeSpan period)
{
var ret = await storage.ReadAsync(orleansQueries.UpsertReminderRowKey, command =>
{
var serviceIdParameter = CreateServiceIdParameter(command, serviceId);
command.Parameters.Add(serviceIdParameter);
var grainIdParameter = CreateGrainIdParameter(command, grainRef.ToKeyString());
command.Parameters.Add(grainIdParameter);
var reminderNameParameter = CreateReminderName(command, reminderName);
command.Parameters.Add(reminderNameParameter);
var startTimeParameter = CreateStartTimeParameter(command, startTime);
command.Parameters.Add(startTimeParameter);
var periodParameter = CreatePeriodParameter(command, period);
command.Parameters.Add(periodParameter);
var grainIdConsistentHashParameter = CreateGrainIdConsistentHashParameter(command, grainRef.GetUniformHashCode());
command.Parameters.Add(grainIdConsistentHashParameter);
}, (selector, resultSetCount, cancellationToken) =>
{
return Task.FromResult(Convert.ToBase64String(selector.GetValue<byte[]>("ETag")));
}).ConfigureAwait(continueOnCapturedContext: false);
return ret != null ? ret.FirstOrDefault() : null;
}