Esempio n. 1
0
        public static NativeCommon.IFabricAsyncOperationContext WrapNativeAsyncMethodImplementation(
            Func <CancellationToken, Task> func,
            NativeCommon.IFabricAsyncOperationCallback callback,
            string functionTag,
            InteropApi interopApi)
        {
            CancellationTokenSource cancellationTokenSource = null;

            try
            {
                AppTrace.TraceSource.WriteNoise(functionTag, "WrapNativeAsyncImpl - Begin");
                cancellationTokenSource = new CancellationTokenSource();
                Task t = func(cancellationTokenSource.Token);
                return(new AsyncTaskCallInAdapter(callback, t, interopApi, cancellationTokenSource, functionTag));
            }
            catch (Exception ex)
            {
                AppTrace.TraceSource.WriteExceptionAsWarning(functionTag, ex, "WrapNativeAsyncImpl - Begin threw exception");
                if (cancellationTokenSource != null)
                {
                    cancellationTokenSource.Dispose();
                }

                interopApi.HandleException(ex);
                TryTranslateManagedExceptionToCOMAndThrow(ex);
                throw;
            }
        }
Esempio n. 2
0
 // The WrapNativeAsyncMethodImplementation functions are meant to be used whenever a native interface implemented in managed
 // has a method that returns an Async Operation
 //
 // This function will take care of tracing, translating exceptions etc and returning the correct type of object
 // It takes in a delegate that should return a Task
 //
 // There are multiple overloads that let you handle passing in multiple arguments
 // Pass in a separate function instead of an actual inline delegate to avoid Partial Trust/Transparency issues
 public static NativeCommon.IFabricAsyncOperationContext WrapNativeAsyncMethodImplementation(
     Func <CancellationToken, Task> func,
     NativeCommon.IFabricAsyncOperationCallback callback,
     string functionTag)
 {
     return(WrapNativeAsyncMethodImplementation(func, callback, functionTag, InteropApi.Default));
 }
        private NativeCommon.IFabricAsyncOperationContext BeginOpen(TimeSpan connectTimeout,
                                                                    NativeCommon.IFabricAsyncOperationCallback callback)
        {
            var timeoutInMilliSeconds = Utility.ToMilliseconds(connectTimeout, "timeout");

            return(this.nativeClient.BeginOpen(timeoutInMilliSeconds, callback));
        }
Esempio n. 4
0
        private long ReplicateBeginWrapper(OperationData operationData, NativeCommon.IFabricAsyncOperationCallback callback, out NativeCommon.IFabricAsyncOperationContext context)
        {
            long sequenceNumber = 0;

            using (var pin = new PinCollection())
            {
                var nativeOperationBuffer = new NativeTypes.FABRIC_OPERATION_DATA_BUFFER_EX1[operationData.Count];

                var buffersAddress = pin.AddBlittable(nativeOperationBuffer);

                for (int i = 0; i < operationData.Count; i++)
                {
                    nativeOperationBuffer[i].Offset = (uint)operationData[i].Offset;
                    nativeOperationBuffer[i].Count  = (uint)operationData[i].Count;
                    nativeOperationBuffer[i].Buffer = pin.AddBlittable(operationData[i].Array);
                }

                context = this.replicatorUsingOperationEx1.BeginReplicate2(
                    operationData.Count,
                    buffersAddress,
                    callback,
                    out sequenceNumber);
            }

            return(sequenceNumber);
        }
Esempio n. 5
0
        CreateContainerBeginWrapper(
            string FullyQualifiedLogFilePath,
            Guid PhysicalLogId,
            Int64 PhysicalLogSize,
            UInt32 MaxAllowedStreams,
            UInt32 MaxRecordSize,
            LogManager.LogCreationFlags CreationFlags,
            NativeCommon.IFabricAsyncOperationCallback Callback)
        {
            NativeCommon.IFabricAsyncOperationContext context;

            using (var pin = new PinCollection())
            {
                this._NativeManager.BeginCreateLogContainer(
                    pin.AddBlittable(FullyQualifiedLogFilePath),
                    PhysicalLogId,
                    pin.AddBlittable(""),
                    PhysicalLogSize,
                    MaxAllowedStreams,
                    MaxRecordSize,
                    CreationFlags,
                    Callback,
                    out context);
            }

            return(context);
        }
Esempio n. 6
0
        private NativeCommon.IFabricAsyncOperationContext UnregisterInboundSessionCallbackAsyncBeginWrapper(
            NativeCommon.IFabricAsyncOperationCallback callback)
        {
            // AppTrace.TraceSource.WriteNoise("ReliableMessaging.NativeReliableMessaging.FabricCreateReliableSession");

            return(this.nativeSessionManager.BeginUnregisterInboundSessionCallback(callback));
        }
Esempio n. 7
0
        CloseBeginWrapper(NativeCommon.IFabricAsyncOperationCallback Callback)
        {
            NativeCommon.IFabricAsyncOperationContext context;

            this._NativeManager.BeginClose(Callback, out context);
            return(context);
        }
 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));
 }
Esempio n. 9
0
        private NativeCommon.IFabricAsyncOperationContext PartitionBackupOperationBeginWrapper(
            Uri serviceName,
            Guid partitionId,
            Guid operationId,
            BackupNowConfiguration configuration,
            TimeSpan timeout,
            NativeCommon.IFabricAsyncOperationCallback callback)
        {
            var timeoutMilliseconds = Utility.ToMilliseconds(timeout, "timeout");
            var partitionInfo       = new BackupPartitionInfo
            {
                PartitionId = partitionId,
                ServiceName = serviceName.ToString(),
            };

            using (var pin = new PinCollection())
            {
                return(this._nativeAgent.BeginPartitionBackupOperation(
                           partitionInfo.ToNative(pin),
                           operationId,
                           configuration.ToNative(pin),
                           timeoutMilliseconds,
                           callback));
            }
        }
Esempio n. 10
0
        QueryRecordRangeBeginWrapper(
            NativeCommon.IFabricAsyncOperationCallback Callback)
        {
            NativeCommon.IFabricAsyncOperationContext context;

            this._NativeStream.BeginQueryRecordRange(Callback, out context);
            return(context);
        }
Esempio n. 11
0
        private long CreateAtomicGroupBeginWrapper(long atomicGroupId, NativeCommon.IFabricAsyncOperationCallback callback, out NativeCommon.IFabricAsyncOperationContext context)
        {
            long atomicGroupIdOut = atomicGroupId;

            context = this.nativeStateReplicator.BeginCreateAtomicGroup(callback, ref atomicGroupIdOut);

            return(atomicGroupIdOut);
        }
Esempio n. 12
0
        ReadContainingBeginWrapper(
            KTL_LOG_ASN Asn,
            NativeCommon.IFabricAsyncOperationCallback Callback)
        {
            NativeCommon.IFabricAsyncOperationContext context;

            this._NativeStream.BeginReadContaining(Asn, Callback, out context);
            return(context);
        }
 private NativeCommon.IFabricAsyncOperationContext BeginClose(TimeSpan connectTimeout,
                                                              NativeCommon.IFabricAsyncOperationCallback callback)
 {
     using (var pin = new PinCollection())
     {
         var timeoutInMilliSeconds = Utility.ToMilliseconds(connectTimeout, "timeout");
         return(this.nativeClient.BeginClose(timeoutInMilliSeconds, callback));
     }
 }
Esempio n. 14
0
        DeletePhysicalLogStreamBeginWrapper(
            Guid PhysicalLogStreamId,
            NativeCommon.IFabricAsyncOperationCallback Callback)
        {
            NativeCommon.IFabricAsyncOperationContext context;

            this._NativeContainer.BeginDeleteLogStream(PhysicalLogStreamId, Callback, out context);
            return(context);
        }
Esempio n. 15
0
        EnumerateLogIdsBeginWrapper(
            Guid DiskId,
            NativeCommon.IFabricAsyncOperationCallback Callback)
        {
            NativeCommon.IFabricAsyncOperationContext context;

            this._NativeManager.BeginEnumerateLogContainers(DiskId, Callback, out context);
            return(context);
        }
Esempio n. 16
0
        QueryRecordBeginWrapper(
            KTL_LOG_ASN Asn,
            NativeCommon.IFabricAsyncOperationCallback Callback)
        {
            NativeCommon.IFabricAsyncOperationContext context;

            this._NativeStream.BeginQueryRecord(Asn, Callback, out context);
            return(context);
        }
Esempio n. 17
0
        WaitForNotificationBeginWrapper(
            NativeLog.KPHYSICAL_LOG_STREAM_NOTIFICATION_TYPE NotificationType,
            UInt64 NotificationValue,
            NativeCommon.IFabricAsyncOperationCallback Callback)
        {
            NativeCommon.IFabricAsyncOperationContext context;

            this._NativeStream.BeginWaitForNotification(NotificationType, NotificationValue, Callback, out context);
            return(context);
        }
Esempio n. 18
0
        private NativeCommon.IFabricAsyncOperationContext OpenBeginWrapper(
            IReliableSessionAbortedCallback sessionClosedCallback, NativeCommon.IFabricAsyncOperationCallback callback)
        {
            // AppTrace.TraceSource.WriteNoise("ReliableMessaging.NativeReliableSession.BeginOpen");
            // TODO: exception handling

            var nativeSessionAbortedCallback = new NativeReliableSessionAbortedCallback(sessionClosedCallback);

            return(this.nativeSessionManager.BeginOpen(nativeSessionAbortedCallback, callback));
        }
Esempio n. 19
0
 public virtual void ReleaseComObject(NativeCommon.IFabricAsyncOperationCallback comObject)
 {
     try
     {
         Marshal.ReleaseComObject(comObject);
     }
     catch (Exception)
     {
     }
 }
Esempio n. 20
0
        MultiRecordReadBeginWrapper(
            KTL_LOG_ASN Asn,
            UInt32 BytesToRead,
            NativeCommon.IFabricAsyncOperationCallback Callback)
        {
            NativeCommon.IFabricAsyncOperationContext context;

            this._NativeStream2.BeginMultiRecordRead(Asn, BytesToRead, Callback, out context);
            return(context);
        }
        internal NativeCommon.IFabricAsyncOperationContext BeginRequest(
            byte[] headers,
            byte[] body,
            TimeSpan timeout,
            NativeCommon.IFabricAsyncOperationCallback callback)
        {
            NativeServiceCommunication.IFabricServiceCommunicationMessage message = new FabricServiceCommunicationMessage(headers, body);
            var nativeTimeout = Utility.ToMilliseconds(timeout, "timeout");

            return(this.nativeClientConnection.BeginRequest(message, nativeTimeout, callback));
        }
            public NativeCommon.IFabricAsyncOperationContext BeginGetOperation(NativeCommon.IFabricAsyncOperationCallback callback)
            {
                throw new NotImplementedException();

                //var asyncAdapter = new AsyncCallInAdapter(callback);
                //var asyncResult = new AsyncResult<NativeRuntime.IFabricOperation>(asyncAdapter.InnerCallback, asyncAdapter.InnerState);
                //asyncAdapter.InnerResult = asyncResult;

                //ThreadPool.QueueUserWorkItem((o) => asyncResult.Complete(this.Operations[this.index++]));
                //return asyncAdapter;
            }
Esempio n. 23
0
        NativeCommon.IFabricAsyncOperationContext NativeGatewayResourceManager.IFabricGatewayResourceManager.BeginDeleteGatewayResource(
            IntPtr resourceName,
            uint timeoutInMilliseconds,
            NativeCommon.IFabricAsyncOperationCallback callback)
        {
            var      gatewayResourceName = NativeTypes.FromNativeString(resourceName);
            TimeSpan managedTimeout      = TimeSpan.FromMilliseconds(timeoutInMilliseconds);

            return(Utility.WrapNativeAsyncMethodImplementation((cancellationToken) =>
                                                               this.DeleteGatewayResourceAsync(gatewayResourceName, managedTimeout, cancellationToken), callback, "GatewayResourceManagerBroker.DeleteGatewayResourceAsync", ThreadErrorMessageSetter));
        }
        private long RollbackBeginWrapper(long atomicGroupId, NativeCommon.IFabricAsyncOperationCallback callback, out NativeCommon.IFabricAsyncOperationContext context)
        {
            long sequenceNumber = 0;

            context = this.nativeAtomicGroupStateReplicator.BeginReplicateAtomicGroupRollback(
                atomicGroupId,
                callback,
                out sequenceNumber);

            return(sequenceNumber);
        }
Esempio n. 25
0
        NativeCommon.IFabricAsyncOperationContext NativeGatewayResourceManager.IFabricGatewayResourceManager.BeginQueryGatewayResources(
            IntPtr queryDescription,
            uint timeoutInMilliseconds,
            NativeCommon.IFabricAsyncOperationCallback callback)
        {
            string   gatewayQueryDescription = NativeTypes.FromNativeString(queryDescription);
            TimeSpan managedTimeout          = TimeSpan.FromMilliseconds(timeoutInMilliseconds);

            return(Utility.WrapNativeAsyncMethodImplementation((cancellationToken) =>
                                                               this.QueryGatewayResourcesAsync(gatewayQueryDescription, managedTimeout, cancellationToken), callback, "GatewayResourceManagerBroker.QueryGatewayResourcesAsync", ThreadErrorMessageSetter));
        }
        private NativeCommon.IFabricAsyncOperationContext BeginRequest(
            FabricTransportMessage message,
            TimeSpan timeout,
            NativeCommon.IFabricAsyncOperationCallback callback)
        {
            var timeoutInMilliSeconds = Utility.ToMilliseconds(timeout, "timeout");

            NativeFabricTransport.IFabricTransportMessage nativeFabricTransportMessage =
                new NativeFabricTransportMessage(message);
            return(this.nativeClient.BeginRequest(nativeFabricTransportMessage, timeoutInMilliSeconds, callback));
        }
Esempio n. 27
0
        IoCtlAsyncBeginWrapper(
            UInt32 ControlCode,
            NativeLog.IKBuffer InBuffer,
            NativeCommon.IFabricAsyncOperationCallback Callback)
        {
            NativeCommon.IFabricAsyncOperationContext context;

            // CONSIDER: does native code need to AddRef InBuffer ?

            this._NativeStream.BeginIoctl(ControlCode, InBuffer, Callback, out context);
            return(context);
        }
 private NativeCommon.IFabricAsyncOperationContext GetRepairTaskListAsyncBeginWrapper(
     RepairTaskQueryDescription queryDescription,
     TimeSpan timeout,
     NativeCommon.IFabricAsyncOperationCallback callback)
 {
     using (var pin = new PinCollection())
     {
         return(this.nativeRepairClient.BeginGetRepairTaskList(
                    queryDescription.ToNative(pin),
                    Utility.ToMilliseconds(timeout, "timeout"),
                    callback));
     }
 }
 private NativeCommon.IFabricAsyncOperationContext UpdateRepairTaskHealthPolicyAsyncBeginWrapper(
     RepairTaskHealthPolicyUpdateDescription requestDescription,
     TimeSpan timeout,
     NativeCommon.IFabricAsyncOperationCallback callback)
 {
     using (var pin = new PinCollection())
     {
         return(this.nativeRepairClient.BeginUpdateRepairTaskHealthPolicy(
                    requestDescription.ToNative(pin),
                    Utility.ToMilliseconds(timeout, "timeout"),
                    callback));
     }
 }
Esempio n. 30
0
        QueryRecordsBeginWrapper(
            KTL_LOG_ASN LowestAsn,
            KTL_LOG_ASN HighestAsn,
            NativeLog.IKArray ResultArray,
            NativeCommon.IFabricAsyncOperationCallback Callback)
        {
            NativeCommon.IFabricAsyncOperationContext context;

            // CONSIDER: Does native code need to AddRef ResultArray ?

            this._NativeStream.BeginQueryRecords(LowestAsn, HighestAsn, ResultArray, Callback, out context);
            return(context);
        }