本文整理汇总了C#中GrainReference.GetUniformHashCode方法的典型用法代码示例。如果您正苦于以下问题:C# GrainReference.GetUniformHashCode方法的具体用法?C# GrainReference.GetUniformHashCode怎么用?C# GrainReference.GetUniformHashCode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类GrainReference
的用法示例。
在下文中一共展示了GrainReference.GetUniformHashCode方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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()
};
}
示例2: PositiveHash
public static int PositiveHash(GrainReference grainReference, int hashRange)
{
int hash = unchecked((int)grainReference.GetUniformHashCode());
int positiveHash = ((hash % hashRange) + hashRange) % hashRange;
return positiveHash;
}
示例3: MapGrainReferenceToSiloRing
private SiloAddress MapGrainReferenceToSiloRing(GrainReference grainRef)
{
var hashCode = grainRef.GetUniformHashCode();
return ConsistentRingProvider.GetPrimaryTargetSilo(hashCode);
}
示例4: UpsertReminderRowAsync
/// <summary>
/// Either inserts or updates a reminder row.
/// </summary>
/// <param name="storage">The storage to use.</param>
/// <param name="query">The query to use.</param>
/// <param name="serviceId">The service ID.</param>
/// <param name="grainRef">The grain reference (ID).</param>
/// <param name="reminderName">The reminder name to retrieve.</param>
/// <returns>The new etag of the either or updated or inserted reminder row.</returns>
internal static async Task<string> UpsertReminderRowAsync(this IRelationalStorage storage, string query, string serviceId, GrainReference grainRef, string reminderName, DateTime startTime, TimeSpan period)
{
var ret = await storage.ReadAsync(query, command =>
{
var direction = ParameterDirection.Input;
var serviceIdParameter = CreateServiceIdParameter(command, serviceId, direction);
command.Parameters.Add(serviceIdParameter);
var grainIdParameter = CreateGrainIdParameter(command, grainRef.ToKeyString(), direction);
command.Parameters.Add(grainIdParameter);
var reminderNameParameter = CreateReminderName(command, reminderName, direction);
command.Parameters.Add(reminderNameParameter);
var startTimeParameter = CreateStartTimeParameter(command, startTime, direction);
command.Parameters.Add(startTimeParameter);
var periodParameter = CreatePeriodParameter(command, period, direction);
command.Parameters.Add(periodParameter);
var grainIdConsistentHashParameter = CreateGrainIdConsistentHashParameter(command, grainRef.GetUniformHashCode(), direction);
command.Parameters.Add(grainIdConsistentHashParameter);
}, (selector, _) =>
{
return Convert.ToBase64String(selector.GetValueOrDefault<byte[]>("ETag"));
}).ConfigureAwait(continueOnCapturedContext: false);
return ret != null ? ret.FirstOrDefault() : null;
}
示例5: 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;
}
示例6: ReadRow
/// <summary>
/// Reads a reminder for a grain reference by reminder name.
/// Read a row from the remider table
/// </summary>
/// <param name="grainRef"> grain ref to locate the row </param>
/// <param name="reminderName"> remider name to locate the row </param>
/// <returns> Return the RemiderTableData if the rows were read successfully </returns>
public async Task<ReminderEntry> ReadRow(GrainReference grainRef, string reminderName)
{
var reminderId = ConstructReminderId(serviceId, grainRef, reminderName);
var keys = new Dictionary<string, AttributeValue>
{
{ $"{REMINDER_ID_PROPERTY_NAME}", new AttributeValue(reminderId) },
{ $"{GRAIN_HASH_PROPERTY_NAME}", new AttributeValue { N = grainRef.GetUniformHashCode().ToString() } }
};
try
{
return await storage.ReadSingleEntryAsync(TABLE_NAME_DEFAULT_VALUE, keys, Resolve).ConfigureAwait(false);
}
catch (Exception exc)
{
logger.Warn(ErrorCode.ReminderServiceBase,
$"Intermediate error reading reminder entry {Utils.DictionaryToString(keys)} from table {TABLE_NAME_DEFAULT_VALUE}.", exc);
throw;
}
}
示例7: RemoveRow
/// <summary>
/// Remove one row from the reminder table
/// </summary>
/// <param name="grainRef"> specific grain ref to locate the row </param>
/// <param name="reminderName"> remider name to locate the row </param>
/// <param name="eTag"> e tag </param>
/// <returns> Return true if the row was removed </returns>
public async Task<bool> RemoveRow(GrainReference grainRef, string reminderName, string eTag)
{
var reminderId = ConstructReminderId(serviceId, grainRef, reminderName);
var keys = new Dictionary<string, AttributeValue>
{
{ $"{REMINDER_ID_PROPERTY_NAME}", new AttributeValue(reminderId) },
{ $"{GRAIN_HASH_PROPERTY_NAME}", new AttributeValue { N = grainRef.GetUniformHashCode().ToString() } }
};
try
{
var conditionalValues = new Dictionary<string, AttributeValue> { { CURRENT_ETAG_ALIAS, new AttributeValue { N = eTag } } };
var expression = $"{ETAG_PROPERTY_NAME} = {CURRENT_ETAG_ALIAS}";
await storage.DeleteEntryAsync(TABLE_NAME_DEFAULT_VALUE, keys, expression, conditionalValues).ConfigureAwait(false);
return true;
}
catch (ConditionalCheckFailedException)
{
return false;
}
}