/// <inheritdoc /> public long RegisterPartitionChangeHandler( Uri serviceName, IResolvedServicePartition servicePartition, FabricPartitionResolutionChangeHandler handler) { var partition = servicePartition as ResolvedServicePartitionWrapper; if (partition == null) { throw new ArgumentException( string.Format( "Only partitions of type {0} are supported. Provided type {1} is not supported.", nameof(ResolvedServicePartitionWrapper), servicePartition.GetType()), nameof(servicePartition)); } // Wrap the provided handler so that it's compatible with Service Fabric. ServicePartitionResolutionChangeHandler actualHandler = (source, id, args) => { ServicePartitionSilos result = null; if (!args.HasException) { result = new ServicePartitionSilos( new ResolvedServicePartitionWrapper(args.Result), args.Result.GetPartitionEndpoints()); } handler( id, new FabricPartitionResolutionChange(result, args.Exception)); }; var sm = this.fabricClient.ServiceManager; switch (servicePartition.Kind) { case ServicePartitionKind.Int64Range: return(sm.RegisterServicePartitionResolutionChangeHandler( serviceName, ((Int64RangePartitionInformation)partition.Partition.Info).LowKey, actualHandler)); case ServicePartitionKind.Named: return(sm.RegisterServicePartitionResolutionChangeHandler( serviceName, ((NamedPartitionInformation)partition.Partition.Info).Name, actualHandler)); case ServicePartitionKind.Singleton: return(sm.RegisterServicePartitionResolutionChangeHandler(serviceName, actualHandler)); default: throw new ArgumentOutOfRangeException( nameof(servicePartition), $"Partition kind {servicePartition.Kind} is not supported"); } }
public static NativeClient.IFabricServicePartitionResolutionChangeHandler ToNative(FabricClient client, ServicePartitionResolutionChangeHandler callback) { ReleaseAssert.AssertIfNot(client != null, "client != null"); if (callback == null) { return(null); } else { var native = new ComFabricServicePartitionResolutionChangeHandler(client, callback); return(native); } }
private ComFabricServicePartitionResolutionChangeHandler(FabricClient client, ServicePartitionResolutionChangeHandler callback) { this.client = client; this.callback = callback; }