Beispiel #1
0
 /// <inheritdoc/>
 public void GetObjectData(SerializationInfo info, StreamingContext context)
 {
     info.AddValue("tv", GrainType.UnsafeGetArray(Type));
     info.AddValue("th", Type.GetHashCode());
     info.AddValue("kv", IdSpan.UnsafeGetArray(Key));
     info.AddValue("kh", Key.GetHashCode());
 }
Beispiel #2
0
        private IdSpan GetGrainKey()
        {
            // TODO: intern
            var key = this.Key;

            return(IdSpan.Create($"{key.N0:X16}{key.N1:X16}{(key.HasKeyExt ? ("+" + key.KeyExt) : string.Empty)}"));
        }
        /// <summary>
        /// Converts the provided <see cref="GrainReference"/> to a string which can be parsed by <see cref="GrainReferenceKeyStringConverter"/>.
        /// </summary>
        /// <param name="grainReference">
        /// The grain reference.
        /// </param>
        /// <returns>The key string.</returns>
        public static string ToKeyString(this GrainReference grainReference)
        {
            var id         = grainReference.GrainId;
            var typeString = Convert.ToBase64String(GrainType.UnsafeGetArray(id.Type));
            var keyString  = Convert.ToBase64String(IdSpan.UnsafeGetArray(id.Key));

            return($"{typeString}_{keyString}");
        }
Beispiel #4
0
        /// <summary>
        /// Converts the provided value into a <see cref="GrainReference"/>.
        /// </summary>
        public GrainReference FromKeyString(string referenceString)
        {
            var splits = referenceString.Split('_');
            var type   = new GrainType(Convert.FromBase64String(splits[0]));
            var key    = new IdSpan(Convert.FromBase64String(splits[1]));
            var id     = new GrainId(type, key);

            return(_activator.CreateReference(id, default));
        }
        /// <summary>
        /// Converts the provided grain reference key <see cref="string"/> into a <see cref="GrainReference"/>.
        /// </summary>
        /// <param name="referenceString">
        /// The string representation of a grain reference.
        /// </param>
        /// <returns>The grain reference.</returns>
        public GrainReference FromKeyString(string referenceString)
        {
            var i = referenceString.IndexOf('_');

            if (i < 0)
            {
                throw new ArgumentException(nameof(referenceString));
            }
            var type = new GrainType(Convert.FromBase64String(referenceString.Substring(0, i)));
            var key  = new IdSpan(Convert.FromBase64String(referenceString.Substring(i + 1)));
            var id   = new GrainId(type, key);

            return(_activator.CreateReference(id, default));
        }
Beispiel #6
0
 /// <summary>
 /// Initializes a new instance of the <see cref="GrainType"/> struct.
 /// </summary>
 /// <param name="id">
 /// The id.
 /// </param>
 public GrainType(IdSpan id) => Value = id;
Beispiel #7
0
 /// <summary>
 /// Creates a new <see cref="GrainType"/> instance.
 /// </summary>
 public static GrainId Create(GrainType type, IdSpan key) => new GrainId(type, key);
Beispiel #8
0
 /// <summary>
 /// Creates a new <see cref="GrainType"/> instance.
 /// </summary>
 public static GrainId Create(GrainType type, string key) => new GrainId(type, IdSpan.Create(key));
Beispiel #9
0
 /// <summary>
 /// Creates a new <see cref="GrainType"/> instance.
 /// </summary>
 private GrainId(SerializationInfo info, StreamingContext context)
 {
     Type = new GrainType(IdSpan.UnsafeCreate((byte[])info.GetValue("tv", typeof(byte[])), info.GetInt32("th")));
     Key  = IdSpan.UnsafeCreate((byte[])info.GetValue("kv", typeof(byte[])), info.GetInt32("kh"));
 }
Beispiel #10
0
 /// <summary>
 /// Creates a new <see cref="GrainType"/> instance.
 /// </summary>
 public GrainId(GrainType type, IdSpan key)
 {
     Type = type;
     Key  = key;
 }
 /// <summary>
 /// Creates an <see cref="IdSpan"/> representing a <see cref="Guid"/> key.
 /// </summary>
 public static IdSpan CreateGuidKey(Guid key, string keyExtension) => string.IsNullOrWhiteSpace(keyExtension) ? CreateGuidKey(key) : IdSpan.Create($"{key:N}+{keyExtension}");
 /// <summary>
 /// Creates an <see cref="IdSpan"/> representing a <see cref="Guid"/> key.
 /// </summary>
 public static IdSpan CreateGuidKey(Guid key) => IdSpan.Create(key.ToString("N"));
 /// <summary>
 /// Creates an <see cref="IdSpan"/> representing a <see cref="long"/> key.
 /// </summary>
 public static IdSpan CreateIntegerKey(long key, string keyExtension) => string.IsNullOrWhiteSpace(keyExtension) ? CreateIntegerKey(key) : IdSpan.Create($"{key:X}+{keyExtension}");
 /// <summary>
 /// Creates an <see cref="IdSpan"/> representing a <see cref="long"/> key.
 /// </summary>
 public static IdSpan CreateIntegerKey(long key) => IdSpan.Create(key.ToString("X"));
Beispiel #15
0
 /// <summary>Constructs a reference to the grain with the specified Id.</summary>
 protected GrainReference(GrainReferenceShared shared, IdSpan key)
 {
     _shared = shared;
     _key    = key;
 }