/// <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 FabricPartitionResolutionChange(ServicePartitionSilos result, Exception exception) { this.result = result; this.Exception = exception; }