NativeCommon.IFabricAsyncOperationContext NativeRuntime.IFabricStatefulServiceReplica.BeginOpen(
     NativeTypes.FABRIC_REPLICA_OPEN_MODE openMode,
     NativeRuntime.IFabricStatefulServicePartition partition,
     NativeCommon.IFabricAsyncOperationCallback callback)
 {
     return(Utility.WrapNativeAsyncMethodImplementation((cancellationToken) => this.OpenAsync(openMode, partition, cancellationToken), callback, "StatefulServiceReplicaBroker.Open", OpenAsyncApi));
 }
        // internal constructor - used by test code
        internal StatefulServicePartition(
            NativeRuntime.IFabricStatefulServicePartition nativeStatefulPartition,
            ServicePartitionInformation partitionInfo)
            : base()
        {
            Requires.Argument("nativeStatefulPartition", nativeStatefulPartition).NotNull();
            Requires.Argument("partitionInfo", partitionInfo).NotNull();

            this.nativePartition = (NativeRuntime.IFabricStatefulServicePartition3)nativeStatefulPartition;
            this.PartitionInfo   = partitionInfo;
        }
        internal AtomicGroupStatefulServicePartition(
            NativeRuntime.IFabricStatefulServicePartition nativeStatefulPartition,
            NativeRuntime.IFabricServiceGroupPartition nativeServiceGroupPartition,
            ServicePartitionInformation partitionInfo)
            : base(nativeStatefulPartition, partitionInfo)
        {
            Requires.Argument("nativeStatefulPartition", nativeStatefulPartition).NotNull();
            Requires.Argument("nativeServiceGroupPartition", nativeServiceGroupPartition).NotNull();
            Requires.Argument("partitionInfo", partitionInfo).NotNull();

            this.nativeServiceGroupPartition = nativeServiceGroupPartition;
        }
        private StatefulServicePartition CreateStatefulPartition(NativeRuntime.IFabricStatefulServicePartition nativeStatefulPartition)
        {
            //// Calls native code, requires UnmanagedCode permission
            Requires.Argument("nativeStatefulPartition", nativeStatefulPartition).NotNull();

            // Initialize partition information
            ServicePartitionInformation partitionInfo = ServicePartitionInformation.FromNative(nativeStatefulPartition.GetPartitionInfo());

            NativeRuntime.IFabricServiceGroupPartition nativeServiceGroupPartition = nativeStatefulPartition as NativeRuntime.IFabricServiceGroupPartition;

            if (nativeServiceGroupPartition != null)
            {
                return(new AtomicGroupStatefulServicePartition(nativeStatefulPartition, nativeServiceGroupPartition, partitionInfo));
            }

            return(new StatefulServicePartition(nativeStatefulPartition, partitionInfo));
        }
        private Task <IReplicator> OpenAsync(
            NativeTypes.FABRIC_REPLICA_OPEN_MODE openMode,
            NativeRuntime.IFabricStatefulServicePartition partition,
            CancellationToken cancellationToken)
        {
            AppTrace.TraceSource.WriteNoise(
                "StatefulServiceReplicaBroker.OpenAsync",
                "OpenAsync for ServiceName {0}. Uri {1}. ReplicaId {2}. PartitionId {3}, OpenMode {4}",
                this.initializationParameters.ServiceTypeName,
                this.initializationParameters.ServiceName,
                this.replicaId,
                this.initializationParameters.PartitionId,
                openMode);

            this.statefulPartition = this.CreateStatefulPartition(partition);

            return(this.statefulServiceReplica.OpenAsync((ReplicaOpenMode)openMode, this.statefulPartition, cancellationToken));
        }