/// <summary> /// <para>Asynchronously registers the specified <see cref="System.Fabric.ServiceGroupFactory" /> for the specified service group type with the /// specified <paramref name="timeout" /> and <paramref name="cancellationToken" />.</para> /// </summary> /// <param name="serviceGroupTypeName"> /// <para>The type name of the ServiceGroup service type (as a string). This should match the type of the service group type as specified in /// the manifests and/or the CreateServiceGroup command.</para> /// </param> /// <param name="factory"> /// <para>The <see cref="System.Fabric.ServiceGroupFactory" /> which can create the specified service group type.</para> /// </param> /// <param name="timeout"> /// <para>The maximum amount of time Service Fabric will allow this operation to continue before returning a TimeoutException.</para> /// </param> /// <param name="cancellationToken"> /// <para>The <see cref="System.Threading.CancellationToken" /> that the operation is observing. It can be used to send a notification that the /// operation should be canceled. Note that cancellation is advisory and that the operation may still be completed even if it is canceled.</para> /// </param> /// <returns> /// <para>The task representing the asynchronous operation.</para> /// </returns> public Task RegisterServiceGroupFactoryAsync(string serviceGroupTypeName, ServiceGroupFactory factory, TimeSpan timeout, CancellationToken cancellationToken) { this.ThrowIfDisposed(); FabricRuntime.ValidateParametersForRegisterServiceGroupFactory(serviceGroupTypeName, factory); return(this.RegisterServiceGroupFactoryAsyncHelper(serviceGroupTypeName, factory, (uint)timeout.TotalMilliseconds, cancellationToken)); }
/// <summary> /// <para>Registers the specified <see cref="System.Fabric.ServiceGroupFactory" /> for the specified type.</para> /// </summary> /// <param name="serviceGroupTypeName"> /// <para>The type name of the ServiceGroup service type (as a string). This should match the type of the service group type as specified in the /// manifests and/or the CreateServiceGroup command.</para> /// </param> /// <param name="factory"> /// <para>The <see cref="System.Fabric.ServiceGroupFactory" /> which can create the specified service group type.</para> /// </param> public void RegisterServiceGroupFactory(string serviceGroupTypeName, ServiceGroupFactory factory) { this.ThrowIfDisposed(); FabricRuntime.ValidateParametersForRegisterServiceGroupFactory(serviceGroupTypeName, factory); Utility.WrapNativeSyncInvokeInMTA(() => this.InternalRegisterServiceGroupFactory(serviceGroupTypeName, factory), "FabricRuntime.RegisterServiceGroupFactory"); }
private void InternalRegisterServiceGroupFactory(string serviceGroupType, ServiceGroupFactory serviceGroupFactory) { //// Calls native code, requires UnmanagedCode permission NativeRuntime.IFabricServiceGroupFactory nativeFactory = this.CreateServiceGroupFactoryHelper(serviceGroupFactory); using (var pin = new PinBlittable(serviceGroupType)) { this.NativeRuntimeObject.RegisterServiceGroupFactory(pin.AddrOfPinnedObject(), nativeFactory); } }
private NativeRuntime.IFabricServiceGroupFactory CreateServiceGroupFactoryHelper(ServiceGroupFactory factory) { NativeRuntime.IFabricServiceGroupFactoryBuilder nativeBuilder = this.NativeRuntimeObject.CreateServiceGroupFactoryBuilder(); foreach (var namedFactory in factory.StatefulServiceFactories) { ServiceFactoryBroker broker = new ServiceFactoryBroker(namedFactory.Item2, this.codePackageActivationContext); using (var pin = new PinBlittable(namedFactory.Item1)) { nativeBuilder.AddStatefulServiceFactory(pin.AddrOfPinnedObject(), broker as NativeRuntime.IFabricStatefulServiceFactory); } } foreach (var namedFactory in factory.StatelessServiceFactories) { ServiceFactoryBroker broker = new ServiceFactoryBroker(namedFactory.Item2, this.codePackageActivationContext); using (var pin = new PinBlittable(namedFactory.Item1)) { nativeBuilder.AddStatelessServiceFactory(pin.AddrOfPinnedObject(), broker as NativeRuntime.IFabricStatelessServiceFactory); } } NativeRuntime.IFabricServiceGroupFactory serviceGroupFactory = nativeBuilder.ToServiceGroupFactory(); return(serviceGroupFactory); }
private Task RegisterServiceGroupFactoryAsyncHelper(string serviceGroupTypeName, ServiceGroupFactory factory, uint timeoutMs, CancellationToken cancellationToken) { NativeRuntime.IFabricServiceGroupFactory serviceGroupFactory = this.CreateServiceGroupFactoryHelper(factory); return(Utility.WrapNativeAsyncInvokeInMTA( (callback) => this.RegisterServiceGroupFactoryBeginWrapper(serviceGroupTypeName, serviceGroupFactory, timeoutMs, callback), this.RegisterServiceGroupFactoryEndWrapper, cancellationToken, "FabricRuntime.RegisterServiceGroupFactory")); }
private static void ValidateParametersForRegisterServiceGroupFactory(string serviceGroupTypeName, ServiceGroupFactory serviceGroupFactory) { Requires.Argument <string>("serviceGroupTypeName", serviceGroupTypeName).NotNullOrWhiteSpace(); Requires.Argument <ServiceGroupFactory>("serviceGroupFactory", serviceGroupFactory).NotNull(); }