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; } }
// 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)); }
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); }
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); }
private NativeCommon.IFabricAsyncOperationContext UnregisterInboundSessionCallbackAsyncBeginWrapper( NativeCommon.IFabricAsyncOperationCallback callback) { // AppTrace.TraceSource.WriteNoise("ReliableMessaging.NativeReliableMessaging.FabricCreateReliableSession"); return(this.nativeSessionManager.BeginUnregisterInboundSessionCallback(callback)); }
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)); }
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)); } }
QueryRecordRangeBeginWrapper( NativeCommon.IFabricAsyncOperationCallback Callback) { NativeCommon.IFabricAsyncOperationContext context; this._NativeStream.BeginQueryRecordRange(Callback, out context); return(context); }
private long CreateAtomicGroupBeginWrapper(long atomicGroupId, NativeCommon.IFabricAsyncOperationCallback callback, out NativeCommon.IFabricAsyncOperationContext context) { long atomicGroupIdOut = atomicGroupId; context = this.nativeStateReplicator.BeginCreateAtomicGroup(callback, ref atomicGroupIdOut); return(atomicGroupIdOut); }
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)); } }
DeletePhysicalLogStreamBeginWrapper( Guid PhysicalLogStreamId, NativeCommon.IFabricAsyncOperationCallback Callback) { NativeCommon.IFabricAsyncOperationContext context; this._NativeContainer.BeginDeleteLogStream(PhysicalLogStreamId, Callback, out context); return(context); }
EnumerateLogIdsBeginWrapper( Guid DiskId, NativeCommon.IFabricAsyncOperationCallback Callback) { NativeCommon.IFabricAsyncOperationContext context; this._NativeManager.BeginEnumerateLogContainers(DiskId, Callback, out context); return(context); }
QueryRecordBeginWrapper( KTL_LOG_ASN Asn, NativeCommon.IFabricAsyncOperationCallback Callback) { NativeCommon.IFabricAsyncOperationContext context; this._NativeStream.BeginQueryRecord(Asn, Callback, out context); return(context); }
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); }
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)); }
public virtual void ReleaseComObject(NativeCommon.IFabricAsyncOperationCallback comObject) { try { Marshal.ReleaseComObject(comObject); } catch (Exception) { } }
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; }
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); }
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)); }
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)); } }
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); }