Exemple #1
0
        public async Task <IInstanceHandle> CreateInstance(Type t, WorkerInitOptions options)
        {
            var id = ++sourceId;

            if (!this.simpleInstanceServiceProxy.IsInitialized)
            {
                if (options == null)
                {
                    options = new WorkerInitOptions();
                    options.AddAssemblyOfType(t);
                }

                if (options.UseConventionalServiceAssembly)
                {
                    options.AddAssemblyOfType(t);
                }

                await this.simpleInstanceServiceProxy.InitializeAsync(
                    new WorkerInitOptions
                {
                    InitEndPoint = initEndpointID,
                    EndInvokeCallBackEndpoint = endInvokeCallBackEndpointID
                }.MergeWith(options));;
            }
            var initResult = await this.simpleInstanceServiceProxy.InitInstance(
                new InitInstanceRequest
            {
                Id           = id,
                TypeName     = t.FullName,
                AssemblyName = t.Assembly.GetName().FullName
            });

            if (!initResult.IsSuccess)
            {
                throw new WorkerInstanceInitializeException(initResult.ExceptionMessage, initResult.FullExceptionString);
            }

            return(new CoreInstanceHandle(async() => await OnDispose(id)));
        }