Esempio n. 1
0
        private PartitionInformation GetBackupServicePartitionInformationFromServicePartitionInformation(ServicePartitionInformation servicePartitionInformation)
        {
            PartitionInformation backupServicePartitionInformation = null;

            switch (servicePartitionInformation.Kind)
            {
            case ServicePartitionKind.Singleton:
                backupServicePartitionInformation = new SingletonPartitionInformation();
                break;

            case ServicePartitionKind.Int64Range:
                var int64RangePartitionInformation = servicePartitionInformation as Fabric.Int64RangePartitionInformation;
                ThrowIf.Null(int64RangePartitionInformation, "int64RangePartitionInformation");
                backupServicePartitionInformation = new Int64RangePartitionInformation()
                {
                    HighKey = int64RangePartitionInformation.HighKey,
                    LowKey  = int64RangePartitionInformation.LowKey
                };
                break;

            case ServicePartitionKind.Named:
                var namedPartitionInformation = servicePartitionInformation as Fabric.NamedPartitionInformation;
                ThrowIf.Null(namedPartitionInformation, "namedPartitionInformation");
                backupServicePartitionInformation = new NamedPartitionInformation()
                {
                    Name = namedPartitionInformation.Name
                };
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            return(backupServicePartitionInformation);
        }
Esempio n. 2
0
        /// <summary>
        /// Creates an <see cref="SingletonPartitionInformation"/> with the provided values.
        /// Can be used as argument to call <see cref="CreateStatelessPartition"/>.
        /// Can be used as argument to call <see cref="CreateStatefulPartition"/>.
        /// </summary>
        /// <returns></returns>
        public static SingletonPartitionInformation CreateSingletonPartitonInfo(Guid id = default(Guid))
        {
            var partition = new SingletonPartitionInformation();

            typeof(ServicePartitionInformation)
            .GetProperty(nameof(ServicePartitionInformation.Id))
            .SetValue(partition, id, BindingFlags.Instance | BindingFlags.NonPublic, null, null, CultureInfo.CurrentCulture);

            return(partition);
        }
        /// <summary>
        /// Serializes the object to JSON.
        /// </summary>
        /// <param name="writer">The <see cref="T: Newtonsoft.Json.JsonWriter" /> to write to.</param>
        /// <param name="obj">The object to serialize to JSON.</param>
        internal static void Serialize(JsonWriter writer, SingletonPartitionInformation obj)
        {
            // Required properties are always serialized, optional properties are serialized when not null.
            writer.WriteStartObject();
            writer.WriteProperty(obj.ServicePartitionKind, "ServicePartitionKind", ServicePartitionKindConverter.Serialize);
            if (obj.Id != null)
            {
                writer.WriteProperty(obj.Id, "Id", PartitionIdConverter.Serialize);
            }

            writer.WriteEndObject();
        }
Esempio n. 4
0
        private static async Task <string> GetPartitionEndpointAsync(StatefulServiceContext serviceContext, SingletonPartitionInformation partition)
        {
            var resolvedPartition = await FabricClient.ServiceManager.ResolveServicePartitionAsync(serviceContext.ServiceName).ConfigureAwait(false);

            return(resolvedPartition?.GetEndpoint()?.Address);
        }