/// <summary> /// Returns the long representation of a grain primary key. /// </summary> /// <param name="grain">The grain to find the primary key for.</param> /// <returns>A long representing the primary key for this grain.</returns> public static long GetPrimaryKeyLong(this IAddressable grain) { var grainId = GetGrainId(grain); if (GrainIdKeyExtensions.TryGetIntegerKey(grainId, out var primaryKey, out _)) { return(primaryKey); } if (LegacyGrainId.TryConvertFromGrainId(grainId, out var legacyId)) { return(legacyId.GetPrimaryKeyLong()); } throw new InvalidOperationException($"Unable to extract integer key from grain id {grainId}"); }
/// <summary> /// Returns the Guid representation of a grain primary key. /// </summary> /// <param name="grain">The grain to find the primary key for.</param> /// <returns>A Guid representing the primary key for this grain.</returns> public static Guid GetPrimaryKey(this IAddressable grain) { var grainId = GetGrainId(grain); if (GrainIdKeyExtensions.TryGetGuidKey(grainId, out var guid)) { return(guid); } if (LegacyGrainId.TryConvertFromGrainId(grainId, out var legacyId)) { return(legacyId.GetPrimaryKey()); } if (GrainIdKeyExtensions.TryGetIntegerKey(grainId, out var integerKey)) { var N1 = integerKey; return(new Guid(0, 0, 0, (byte)N1, (byte)(N1 >> 8), (byte)(N1 >> 16), (byte)(N1 >> 24), (byte)(N1 >> 32), (byte)(N1 >> 40), (byte)(N1 >> 48), (byte)(N1 >> 56))); } throw new InvalidOperationException($"Unable to extract GUID key from grain id {grainId}"); }