public IWampRegistrationSubscriptionToken Register(IWampRpcOperation operation, RegisterOptions registerOptions)
        {
            VerifyInvokePoliciesAreCompatible(registerOptions);

            lock (mLock)
            {
                if (RegisterOptions.Invoke != WampInvokePolicy.Single || !mOperations.Any())
                {
                    if (!mOperations.Contains(operation))
                    {
                        RaiseCalleeRegistering(operation);

                        mOperations = mOperations.Add(operation);

                        RaiseCalleeRegistered(operation);
                    }

                    return(new WampRegistrationToken(operation, this));
                }
                else
                {
                    string registerError =
                        $"register for already registered procedure '{operation.Procedure}'";

                    throw new WampException(WampErrors.ProcedureAlreadyExists,
                                            registerError);
                }
            }
        }
Exemplo n.º 2
0
        private void InvocationPattern(long requestId, long registrationId, InvocationDetails details, Func <IWampRpcOperation, IWampRawRpcOperationRouterCallback, InvocationDetails, IWampCancellableInvocation> invocationAction)
        {
            IWampRpcOperation operation = TryGetOperation(registrationId);

            if (operation != null)
            {
                IWampRawRpcOperationRouterCallback callback = GetCallback(requestId);

                InvocationDetails modifiedDetails = new InvocationDetails(details)
                {
                    Procedure = details.Procedure ?? operation.Procedure
                };

                IWampCancellableInvocation invocation = invocationAction(operation, callback, modifiedDetails);

                if (invocation != null)
                {
                    mInvocations[requestId] = new InvocationData(registrationId, invocation);

                    lock (mLock)
                    {
                        mRegistrationsToInvocations.Add(registrationId, requestId);
                    }
                }
            }
        }
        public IWampRegistrationSubscriptionToken Register(IWampRpcOperation operation, RegisterOptions options)
        {
            options = options.WithDefaults();

            MatchRpcOperationCatalog catalog = GetInnerCatalog(options);

            return(catalog.Register(operation, options));
        }
        private void RaiseCalleeUnregistered(IWampRpcOperation operation)
        {
            EventHandler <WampCalleeRemoveEventArgs> handler = CalleeUnregistered;

            if (handler != null)
            {
                handler(this, new WampCalleeRemoveEventArgs(operation));
            }
        }
        private void RaiseCalleeRegistering(IWampRpcOperation operation)
        {
            EventHandler <WampCalleeAddEventArgs> handler = CalleeRegistering;

            if (handler != null)
            {
                handler(this, new WampCalleeAddEventArgs(operation));
            }
        }
        private IWampRpcOperation GetOperation()
        {
            IWampRpcOperation result = mSelector.SelectOperation(mOperations);

            if (result == null)
            {
                WampRpcThrowHelper.NoProcedureRegistered(Procedure);
            }

            return(result);
        }
Exemplo n.º 7
0
        private void InvokePattern(IWampRawRpcOperationRouterCallback caller, Action <IWampRpcOperation> invokeAction)
        {
            lock (mLock)
            {
                IWampRpcOperation operation = GetOperation();

                if (operation != null)
                {
                    invokeAction(operation);
                }
            }
        }
        private IWampCancellableInvocation InvokePattern(string procedure, Func <IWampRpcOperation, IWampCancellableInvocation> invokeAction)
        {
            IWampRpcOperation operation = TryGetOperation(procedure);

            if (operation == null)
            {
                return(null);
            }
            else
            {
                return(invokeAction(operation));
            }
        }
Exemplo n.º 9
0
        public IWampRegistrationSubscriptionToken Register(IWampRpcOperation operation, RegisterOptions registerOptions)
        {
            lock (mLock)
            {
                WampProcedureRegistration registration =
                    mProcedureToRegistration
                    .GetOrAdd
                        (operation.Procedure,
                        procedureUri => CreateRegistration(registerOptions, procedureUri));

                return(registration.Register(operation, registerOptions));
            }
        }
        private IWampCancellableInvocation InvokePattern(Func <IWampRpcOperation, IWampCancellableInvocation> invokeAction)
        {
            lock (mLock)
            {
                IWampRpcOperation operation = GetOperation();

                if (operation != null)
                {
                    return(invokeAction(operation));
                }
            }

            return(null);
        }
        public IWampRpcOperation GetMatchingOperation(string criteria)
        {
            foreach (MatchRpcOperationCatalog innerCatalog in mInnerCatalogs)
            {
                IWampRpcOperation operation = innerCatalog.GetMatchingOperation(criteria);

                if (operation != null)
                {
                    return(operation);
                }
            }

            return(null);
        }
Exemplo n.º 12
0
        private bool InvokePattern(string procedure, Action <IWampRpcOperation> invokeAction)
        {
            IWampRpcOperation operation = TryGetOperation(procedure);

            if (operation == null)
            {
                return(false);
            }
            else
            {
                invokeAction(operation);

                return(true);
            }
        }
Exemplo n.º 13
0
        private void InvocationPattern(long requestId, long registrationId, InvocationDetails details, Action <IWampRpcOperation, IWampRawRpcOperationRouterCallback, InvocationDetails> invocationAction)
        {
            IWampRpcOperation operation = TryGetOperation(registrationId);

            if (operation != null)
            {
                IWampRawRpcOperationRouterCallback callback = GetCallback(requestId);

                InvocationDetails modifiedDetails = new InvocationDetails(details)
                {
                    Procedure = details.Procedure ?? operation.Procedure
                };

                invocationAction(operation, callback, modifiedDetails);
            }
        }
        private void RemoveOperation(IWampRpcOperation operation)
        {
            lock (mLock)
            {
                RaiseCalleeUnregistering(operation);

                mOperations = mOperations.Remove(operation);

                RaiseCalleeUnregistered(operation);

                if (!mOperations.Any())
                {
                    RaiseEmpty();
                }
            }
        }
Exemplo n.º 15
0
        private IEnumerable <OperationToRegister> GetServiceMethodsOfType
            (Func <object> instance,
            Type type,
            ICalleeRegistrationInterceptor interceptor)
        {
            foreach (var method in type.GetPublicInstanceMethods())
            {
                if (interceptor.IsCalleeProcedure(method))
                {
                    IWampRpcOperation operation = CreateRpcMethod(instance, interceptor, method);
                    RegisterOptions   options   = interceptor.GetRegisterOptions(method);

                    yield return(new OperationToRegister(operation, options));
                }
            }
        }
Exemplo n.º 16
0
        public Task <IAsyncDisposable> Register(IWampRpcOperation operation, RegisterOptions options)
        {
            if (!IsConnected)
            {
                throw new WampSessionNotEstablishedException();
            }

            RegisterRequest registerRequest =
                new RegisterRequest(operation, mFormatter);

            long id = mPendingRegistrations.Add(registerRequest);

            registerRequest.RequestId = id;

            mProxy.Register(id, options, operation.Procedure);

            return(registerRequest.Task);
        }
Exemplo n.º 17
0
        private static IWampRpcOperation CreateProgressiveObservableOperation(Func <object> instanceProvider, MethodInfo method, string procedureUri)
        {
            //return new ProgressiveObservableMethodInfoRpcOperation<returnType>
            // (instance, method, procedureUri);

            Type returnType = method.ReturnType.GetGenericArguments()[0];

            Type operationType =
                typeof(ProgressiveObservableMethodInfoRpcOperation <>)
                .MakeGenericType(returnType);

            IWampRpcOperation operation =
                (IWampRpcOperation)Activator.CreateInstance(operationType,
                                                            instanceProvider,
                                                            method,
                                                            procedureUri);

            return(operation);
        }
        public override IWampRpcOperation GetMatchingOperation(string criteria)
        {
            IWampRpcOperation currentOperation = null;
            int currentLength = 0;

            foreach (IWampRpcOperation operation in
                     this.Operations.Where(x => criteria.StartsWith(x.Procedure)))
            {
                string currentProcedure = operation.Procedure;

                if (currentProcedure.Length > currentLength)
                {
                    currentLength    = currentProcedure.Length;
                    currentOperation = operation;
                }
            }

            return(currentOperation);
        }
Exemplo n.º 19
0
        private static IWampRpcOperation CreateProgressiveOperation(Func <object> instanceProvider, MethodInfo method, string procedureUri)
        {
            //return new ProgressiveAsyncMethodInfoRpcOperation<returnType>
            // (instance, method, procedureUri);

            Type returnType =
                TaskExtensions.UnwrapReturnType(method.ReturnType);

            Type operationType =
                typeof(ProgressiveAsyncMethodInfoRpcOperation <>)
                .MakeGenericType(returnType);

            IWampRpcOperation operation =
                (IWampRpcOperation)Activator.CreateInstance(operationType,
                                                            instanceProvider,
                                                            method,
                                                            procedureUri);

            return(operation);
        }
Exemplo n.º 20
0
 public OperationToRegister(IWampRpcOperation operation, RegisterOptions options)
 {
     Operation = operation;
     mOptions  = options;
 }
 private void RaiseCalleeRegistering(IWampRpcOperation operation)
 {
     CalleeRegistering?.Invoke(this, new WampCalleeAddEventArgs(operation));
 }
 private void RaiseCalleeUnregistered(IWampRpcOperation operation)
 {
     CalleeUnregistered?.Invoke(this, new WampCalleeRemoveEventArgs(operation));
 }
 public WampRegistrationToken(IWampRpcOperation operation, WampProcedureRegistration registration)
 {
     mOperation    = operation;
     mRegistration = registration;
 }
Exemplo n.º 24
0
 public RegisterRequest(IWampRpcOperation operation, IWampFormatter <TMessage> formatter) :
     base(formatter)
 {
     mOperation = operation;
 }
Exemplo n.º 25
0
 public WampCalleeAddEventArgs(IWampRpcOperation operation) : base(operation)
 {
 }
 public WampCalleeRemoveEventArgs(IWampRpcOperation operation) : base(operation)
 {
 }
 public Task <IAsyncDisposable> Register(IWampRpcOperation operation, RegisterOptions options)
 {
     return(mCallee.Register(operation, options));
 }
 public WampCalleeChangeEventArgs(IWampRpcOperation operation)
 {
     Operation = operation;
 }
Exemplo n.º 29
0
 public Registration(IWampRpcOperation operation, IAsyncDisposable disposable)
 {
     mOperation  = operation;
     mDisposable = disposable;
 }