Example #1
0
        //readonly bool isInsideTransactedReceiveScope;

        internal DispatchOperationRuntime(DispatchOperation operation, ImmutableDispatchRuntime parent)
        {
            if (operation == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(operation));
            }

            if (operation.Invoker == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.RuntimeRequiresInvoker0));
            }

            DisposeParameters       = ((operation.AutoDisposeParameters) && (!operation.HasNoDisposableParameters));
            Parent                  = parent ?? throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(parent));
            CallContextInitializers = EmptyArray <ICallContextInitializer> .ToArray(operation.CallContextInitializers);

            ParameterInspectors = EmptyArray <IParameterInspector> .ToArray(operation.ParameterInspectors);

            FaultFormatter      = operation.FaultFormatter;
            Impersonation       = operation.Impersonation;
            AuthorizeClaims     = operation.AuthorizeClaims;
            _deserializeRequest = operation.DeserializeRequest;
            SerializeReply      = operation.SerializeReply;
            Formatter           = operation.Formatter;
            Invoker             = operation.Invoker;
            IsTerminating       = operation.IsTerminating;
            _isSessionOpenNotificationEnabled = operation.IsSessionOpenNotificationEnabled;
            Action = operation.Action;
            Name   = operation.Name;
            ReleaseInstanceAfterCall  = operation.ReleaseInstanceAfterCall;
            ReleaseInstanceBeforeCall = operation.ReleaseInstanceBeforeCall;
            ReplyAction = operation.ReplyAction;
            IsOneWay    = operation.IsOneWay;
            ReceiveContextAcknowledgementMode = operation.ReceiveContextAcknowledgementMode;

            if (Formatter == null && (_deserializeRequest || SerializeReply))
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.Format(SR.DispatchRuntimeRequiresFormatter0, Name)));
            }

            if ((operation.Parent.InstanceProvider == null) && (operation.Parent.Type != null))
            {
                if (Invoker is SyncMethodInvoker sync)
                {
                    ValidateInstanceType(operation.Parent.Type, sync.Method);
                }

                //AsyncMethodInvoker async = this.invoker as AsyncMethodInvoker;
                //if (async != null)
                //{
                //    this.ValidateInstanceType(operation.Parent.Type, async.BeginMethod);
                //    this.ValidateInstanceType(operation.Parent.Type, async.EndMethod);
                //}

                if (Invoker is TaskMethodInvoker task)
                {
                    ValidateInstanceType(operation.Parent.Type, task.TaskMethod);
                }
            }
        }
Example #2
0
 internal void InvalidateRuntime()
 {
     lock (ThisLock)
     {
         shared.ThrowIfImmutable();
         runtime = null;
     }
 }
Example #3
0
        ImmutableDispatchRuntime GetRuntimeCore()
        {
            lock (ThisLock)
            {
                if (runtime == null)
                {
                    runtime = new ImmutableDispatchRuntime(this);
                }

                return(runtime);
            }
        }
Example #4
0
        internal ImmutableDispatchRuntime GetRuntime()
        {
            ImmutableDispatchRuntime runtime = this.runtime;

            if (runtime != null)
            {
                return(runtime);
            }
            else
            {
                return(GetRuntimeCore());
            }
        }
Example #5
0
        internal InstanceBehavior(DispatchRuntime dispatch, ImmutableDispatchRuntime immutableRuntime)
        {
            this.immutableRuntime = immutableRuntime;
            initializers          = EmptyArray <IInstanceContextInitializer> .ToArray(dispatch.InstanceContextInitializers);

            provider  = dispatch.InstanceProvider;
            singleton = dispatch.SingletonInstanceContext;
            //    this.transactionAutoCompleteOnSessionClose = dispatch.TransactionAutoCompleteOnSessionClose;
            //    this.releaseServiceInstanceOnTransactionComplete = dispatch.ReleaseServiceInstanceOnTransactionComplete;
            isSynchronized          = (dispatch.ConcurrencyMode != ConcurrencyMode.Multiple);
            instanceContextProvider = dispatch.InstanceContextProvider;

            if (provider == null)
            {
                ConstructorInfo constructor = null;
                if (dispatch.Type != null)
                {
                    constructor = InstanceBehavior.GetConstructor(dispatch.Type);
                }

                if (singleton == null)
                {
                    if (dispatch.Type != null && (dispatch.Type.GetTypeInfo().IsAbstract || dispatch.Type.GetTypeInfo().IsInterface))
                    {
                        throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.SFxServiceTypeNotCreatable));
                    }

                    if (constructor == null)
                    {
                        throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.SFxNoDefaultConstructor));
                    }
                }

                if (constructor != null)
                {
                    if (singleton == null || !singleton.IsWellKnown)
                    {
                        InvokerUtil            util    = new InvokerUtil();
                        CreateInstanceDelegate creator = util.GenerateCreateInstanceDelegate(dispatch.Type, constructor);
                        provider = new InstanceProvider(creator);
                    }
                }
            }

            if (singleton != null)
            {
                singleton.Behavior = this;
            }
        }
Example #6
0
        internal InstanceBehavior(DispatchRuntime dispatch, ImmutableDispatchRuntime immutableRuntime)
        {
            _immutableRuntime = immutableRuntime;
            _initializers     = EmptyArray <IInstanceContextInitializer> .ToArray(dispatch.InstanceContextInitializers);

            _provider  = dispatch.InstanceProvider;
            _singleton = dispatch.SingletonInstanceContext;
            InstanceContextProvider = dispatch.InstanceContextProvider;

            if (_provider == null)
            {
                ConstructorInfo constructor = null;
                if (dispatch.Type != null)
                {
                    constructor = GetConstructor(dispatch.Type);
                }

                if (_singleton == null)
                {
                    if (dispatch.Type != null && (dispatch.Type.GetTypeInfo().IsAbstract || dispatch.Type.GetTypeInfo().IsInterface))
                    {
                        throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.SFxServiceTypeNotCreatable));
                    }

                    if (constructor == null)
                    {
                        throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.SFxNoDefaultConstructor));
                    }
                }

                if (constructor != null)
                {
                    if (_singleton == null || !_singleton.IsWellKnown)
                    {
                        InvokerUtil            util    = new InvokerUtil();
                        CreateInstanceDelegate creator = util.GenerateCreateInstanceDelegate(dispatch.Type, constructor);
                        _provider = new InstanceProvider(creator);
                    }
                }
            }

            if (_singleton != null)
            {
                _singleton.Behavior = this;
            }
        }
        //readonly bool isInsideTransactedReceiveScope;

        internal DispatchOperationRuntime(DispatchOperation operation, ImmutableDispatchRuntime parent)
        {
            if (operation == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(operation));
            }
            if (parent == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(parent));
            }
            if (operation.Invoker == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.RuntimeRequiresInvoker0));
            }

            disposeParameters       = ((operation.AutoDisposeParameters) && (!operation.HasNoDisposableParameters));
            this.parent             = parent;
            callContextInitializers = EmptyArray <ICallContextInitializer> .ToArray(operation.CallContextInitializers);

            inspectors = EmptyArray <IParameterInspector> .ToArray(operation.ParameterInspectors);

            faultFormatter     = operation.FaultFormatter;
            impersonation      = operation.Impersonation;
            deserializeRequest = operation.DeserializeRequest;
            serializeReply     = operation.SerializeReply;
            formatter          = operation.Formatter;
            invoker            = operation.Invoker;

            try
            {
                isSynchronous = operation.Invoker.IsSynchronous;
            }
            catch (Exception e)
            {
                if (Fx.IsFatal(e))
                {
                    throw;
                }
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperCallback(e);
            }
            isTerminating = operation.IsTerminating;
            isSessionOpenNotificationEnabled = operation.IsSessionOpenNotificationEnabled;
            action = operation.Action;
            name   = operation.Name;
            releaseInstanceAfterCall  = operation.ReleaseInstanceAfterCall;
            releaseInstanceBeforeCall = operation.ReleaseInstanceBeforeCall;
            replyAction = operation.ReplyAction;
            isOneWay    = operation.IsOneWay;
            receiveContextAcknowledgementMode = operation.ReceiveContextAcknowledgementMode;
            bufferedReceiveEnabled            = operation.BufferedReceiveEnabled;

            if (formatter == null && (deserializeRequest || serializeReply))
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.Format(SR.DispatchRuntimeRequiresFormatter0, name)));
            }

            if ((operation.Parent.InstanceProvider == null) && (operation.Parent.Type != null))
            {
                SyncMethodInvoker sync = invoker as SyncMethodInvoker;
                if (sync != null)
                {
                    ValidateInstanceType(operation.Parent.Type, sync.Method);
                }

                //AsyncMethodInvoker async = this.invoker as AsyncMethodInvoker;
                //if (async != null)
                //{
                //    this.ValidateInstanceType(operation.Parent.Type, async.BeginMethod);
                //    this.ValidateInstanceType(operation.Parent.Type, async.EndMethod);
                //}

                TaskMethodInvoker task = invoker as TaskMethodInvoker;
                if (task != null)
                {
                    ValidateInstanceType(operation.Parent.Type, task.TaskMethod);
                }
            }
        }
Example #8
0
        //internal bool IsRoleProviderSet
        //{
        //    get { return this.roleProvider != null; }
        //}

        internal DispatchOperationRuntime GetOperation(ref Message message)
        {
            ImmutableDispatchRuntime runtime = GetRuntime();

            return(runtime.GetOperation(ref message));
        }