예제 #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);
                }
            }
        }
        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));
            ParameterInspectors = EmptyArray <IParameterInspector> .ToArray(operation.ParameterInspectors);

            FaultFormatter      = operation.FaultFormatter;
            _deserializeRequest = operation.DeserializeRequest;
            _serializeReply     = operation.SerializeReply;
            Formatter           = operation.Formatter;
            Invoker             = operation.Invoker;
            IsTerminating       = operation.IsTerminating;
            _isSessionOpenNotificationEnabled = operation.IsSessionOpenNotificationEnabled;
            Action      = operation.Action;
            Name        = operation.Name;
            ReplyAction = operation.ReplyAction;
            IsOneWay    = operation.IsOneWay;

            if (Formatter == null && (_deserializeRequest || _serializeReply))
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.Format(SR.DispatchRuntimeRequiresFormatter0, Name)));
            }
        }
예제 #3
0
        private async Task EnsureBlobExistsAsync()
        {
            if (await m_blob.ExistsAsync())
            {
                return;
            }

            try
            {
                await m_blob.UploadFromByteArrayAsync(
                    EmptyArray.Get <byte>(),
                    0,
                    0,
                    AccessCondition.GenerateIfNoneMatchCondition("*"),
                    null,
                    null);
            }
            catch (StorageException exception)
            {
                // 412 from trying to modify a blob that's leased
                var blobLeased = exception.RequestInformation.HttpStatusCode == (int)HttpStatusCode.PreconditionFailed;

                var blobExists =
                    exception.RequestInformation.HttpStatusCode == (int)HttpStatusCode.Conflict &&
                    exception.RequestInformation.ExtendedErrorInformation.ErrorCode == BlobErrorCodeStrings.BlobAlreadyExists;

                if (!blobExists && !blobLeased)
                {
                    throw;
                }
            }
        }
예제 #4
0
        internal ImmutableClientRuntime(ClientRuntime behavior)
        {
            _channelInitializers = EmptyArray <IChannelInitializer> .ToArray(behavior.ChannelInitializers);

            _interactiveChannelInitializers = EmptyArray <IInteractiveChannelInitializer> .ToArray(behavior.InteractiveChannelInitializers);

            _messageInspectors = EmptyArray <IClientMessageInspector> .ToArray(behavior.MessageInspectors);

            _operationSelector         = behavior.OperationSelector;
            _useSynchronizationContext = behavior.UseSynchronizationContext;
            _validateMustUnderstand    = behavior.ValidateMustUnderstand;

            _unhandled = new ProxyOperationRuntime(behavior.UnhandledClientOperation, this);

            _addTransactionFlowProperties = behavior.AddTransactionFlowProperties;

            _operations = new Dictionary <string, ProxyOperationRuntime>();

            for (int i = 0; i < behavior.Operations.Count; i++)
            {
                ClientOperation       operation        = behavior.Operations[i];
                ProxyOperationRuntime operationRuntime = new ProxyOperationRuntime(operation, this);
                _operations.Add(operation.Name, operationRuntime);
            }

            _correlationCount = _messageInspectors.Length + behavior.MaxParameterInspectors;
        }
예제 #5
0
        public MvdMotion CreateFrom([CanBeNull] CharacterImasMotionAsset bodyMotion, [CanBeNull] Avatar avatar, [CanBeNull] PmxModel mltdPmxModel,
                                    [CanBeNull] CharacterImasMotionAsset cameraMotion,
                                    [CanBeNull] ScenarioObject scenarioObject, int songPosition)
        {
            IReadOnlyList <MvdCameraMotion> cameraFrames;

            if (ProcessCameraFrames && cameraMotion != null)
            {
                cameraFrames = CreateCameraMotions(cameraMotion);
            }
            else
            {
                cameraFrames = EmptyArray.Of <MvdCameraMotion>();
            }

            var mvd = new MvdMotion(cameraFrames);

            if (ConversionConfig.Current.Transform60FpsTo30Fps)
            {
                mvd.Fps = 30;
            }
            else
            {
                mvd.Fps = 60;
            }

            return(mvd);
        }
예제 #6
0
        public static ICloudTableEntityQuery PrepareEntityPointQuery(
            this ICloudTable table,
            string partitionKey)
        {
            Require.NotNull(table, "table");

            return(table.PrepareEntityPointQuery(partitionKey, EmptyArray.Get <string>()));
        }
예제 #7
0
        public async Task IsExistsAsync_WhenBlobDeletedCreated_ReturnsFalse()
        {
            await Blob.UploadAsync(new MemoryStream(EmptyArray.Get <byte>()));

            await Blob.DeleteAsync();

            Assert.False(await Blob.IsExistsAsync());
        }
예제 #8
0
        public ISourceSymbol[] SourceSymbolsFor(IFile file)
        {
            var provider = ProviderFor(file);

            return(provider != null
                                ? provider.SourceSymbolsFor(file)
                                : EmptyArray.Of <ISourceSymbol>());
        }
예제 #9
0
        internal ErrorBehavior(ChannelDispatcher channelDispatcher)
        {
            _handlers = EmptyArray <IErrorHandler> .ToArray(channelDispatcher.ErrorHandlers);

            _debug          = channelDispatcher.IncludeExceptionDetailInFaults;
            _isOnServer     = channelDispatcher.IsOnServer;
            _messageVersion = channelDispatcher.MessageVersion;
        }
예제 #10
0
            public Task <object> InvokeAsync(object instance, object[] inputs, out object[] outputs)
            {
                outputs = EmptyArray <object> .Allocate(0);

                Message message = inputs[0] as Message;

                if (message == null)
                {
                    return(null);
                }

                string action = message.Headers.Action;

                FaultCode code = FaultCode.CreateSenderFaultCode(AddressingStrings.ActionNotSupported,
                                                                 message.Version.Addressing.Namespace);
                string      reasonText = SR.Format(SR.SFxNoEndpointMatchingContract, action);
                FaultReason reason     = new FaultReason(reasonText);

                FaultException exception = new FaultException(reason, code);

                ErrorBehavior.ThrowAndCatch(exception);

                ServiceChannel serviceChannel = OperationContext.Current.InternalServiceChannel;

                OperationContext.Current.OperationCompleted +=
                    delegate(object sender, EventArgs e)
                {
                    ChannelDispatcher channelDispatcher = _dispatchRuntime.ChannelDispatcher;
                    if (!channelDispatcher.HandleError(exception) && serviceChannel.HasSession)
                    {
                        try
                        {
                            serviceChannel.Close(ChannelHandler.CloseAfterFaultTimeout);
                        }
                        catch (Exception ex)
                        {
                            if (Fx.IsFatal(ex))
                            {
                                throw;
                            }
                            channelDispatcher.HandleError(ex);
                        }
                    }
                };

                if (_dispatchRuntime._shared.EnableFaults)
                {
                    MessageFault fault = MessageFault.CreateFault(code, reason, action);
                    return(Task.FromResult((object)Message.CreateMessage(message.Version, fault, message.Version.Addressing.DefaultFaultAction)));
                }
                else
                {
                    OperationContext.Current.RequestContext.Close();
                    OperationContext.Current.RequestContext = null;
                    return(Task.FromResult((object)null));
                }
            }
예제 #11
0
        internal ProxyOperationRuntime(ClientOperation operation, ImmutableClientRuntime parent)
        {
            if (operation == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("operation");
            }
            if (parent == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("parent");
            }

            _parent        = parent;
            _formatter     = operation.Formatter;
            _isInitiating  = operation.IsInitiating;
            _isOneWay      = operation.IsOneWay;
            _isTerminating = operation.IsTerminating;
            _isSessionOpenNotificationEnabled = operation.IsSessionOpenNotificationEnabled;
            _name = operation.Name;
            _parameterInspectors = EmptyArray <IParameterInspector> .ToArray(operation.ParameterInspectors);

            _faultFormatter   = operation.FaultFormatter;
            _serializeRequest = operation.SerializeRequest;
            _deserializeReply = operation.DeserializeReply;
            _action           = operation.Action;
            _replyAction      = operation.ReplyAction;
            _beginMethod      = operation.BeginMethod;
            _syncMethod       = operation.SyncMethod;
            _taskMethod       = operation.TaskMethod;
            this.TaskTResult  = operation.TaskTResult;

            if (_beginMethod != null)
            {
                _inParams = ServiceReflector.GetInputParameters(_beginMethod, true);
                if (_syncMethod != null)
                {
                    _outParams = ServiceReflector.GetOutputParameters(_syncMethod, false);
                }
                else
                {
                    _outParams = Array.Empty <ParameterInfo>();
                }
                _endOutParams = ServiceReflector.GetOutputParameters(operation.EndMethod, true);
                _returnParam  = operation.EndMethod.ReturnParameter;
            }
            else if (_syncMethod != null)
            {
                _inParams    = ServiceReflector.GetInputParameters(_syncMethod, false);
                _outParams   = ServiceReflector.GetOutputParameters(_syncMethod, false);
                _returnParam = _syncMethod.ReturnParameter;
            }

            if (_formatter == null && (_serializeRequest || _deserializeReply))
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.Format(SR.ClientRuntimeRequiresFormatter0, _name)));
            }
        }
예제 #12
0
        internal ImmutableDispatchRuntime(DispatchRuntime dispatch)
        {
            _authenticationBehavior = AuthenticationBehavior.TryCreate(dispatch);
            _authorizationBehavior  = AuthorizationBehavior.TryCreate(dispatch);
            _concurrency            = new ConcurrencyBehavior(dispatch);
            _error        = new ErrorBehavior(dispatch.ChannelDispatcher);
            _enableFaults = dispatch.EnableFaults;
            _inputSessionShutdownHandlers = EmptyArray <IInputSessionShutdown> .ToArray(dispatch.InputSessionShutdownHandlers);

            InstanceBehavior   = new InstanceBehavior(dispatch, this);
            _isOnServer        = dispatch.IsOnServer;
            _manualAddressing  = dispatch.ManualAddressing;
            _messageInspectors = EmptyArray <IDispatchMessageInspector> .ToArray(dispatch.MessageInspectors);

            _securityImpersonation = SecurityImpersonationBehavior.CreateIfNecessary(dispatch);
            RequireClaimsPrincipalOnOperationContext = dispatch.RequireClaimsPrincipalOnOperationContext;
            _impersonateOnSerializingReply           = dispatch.ImpersonateOnSerializingReply;
            _terminate             = TerminatingOperationBehavior.CreateIfNecessary(dispatch);
            _thread                = new ThreadBehavior(dispatch);
            ValidateMustUnderstand = dispatch.ValidateMustUnderstand;
            ParameterInspectorCorrelationOffset = (dispatch.MessageInspectors.Count +
                                                   dispatch.MaxCallContextInitializers);
            _correlationCount = ParameterInspectorCorrelationOffset + dispatch.MaxParameterInspectors;

            DispatchOperationRuntime unhandled = new DispatchOperationRuntime(dispatch.UnhandledDispatchOperation, this);

            if (dispatch.OperationSelector == null)
            {
                ActionDemuxer demuxer = new ActionDemuxer();
                for (int i = 0; i < dispatch.Operations.Count; i++)
                {
                    DispatchOperation        operation        = dispatch.Operations[i];
                    DispatchOperationRuntime operationRuntime = new DispatchOperationRuntime(operation, this);
                    demuxer.Add(operation.Action, operationRuntime);
                }

                demuxer.SetUnhandled(unhandled);
                _demuxer = demuxer;
            }
            else
            {
                CustomDemuxer demuxer = new CustomDemuxer(dispatch.OperationSelector);
                for (int i = 0; i < dispatch.Operations.Count; i++)
                {
                    DispatchOperation        operation        = dispatch.Operations[i];
                    DispatchOperationRuntime operationRuntime = new DispatchOperationRuntime(operation, this);
                    demuxer.Add(operation.Name, operationRuntime);
                }

                demuxer.SetUnhandled(unhandled);
                _demuxer = demuxer;
            }

            _processMessageNonCleanupError = new MessageRpcErrorHandler(ProcessMessageNonCleanupError);
            _processMessageCleanupError    = new MessageRpcErrorHandler(ProcessMessageCleanupError);
        }
        internal ProxyOperationRuntime(ClientOperation operation, ImmutableClientRuntime parent)
        {
            if (operation == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("operation");
            }
            if (parent == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("parent");
            }

            this.parent        = parent;
            this.formatter     = operation.Formatter;
            this.isInitiating  = operation.IsInitiating;
            this.isOneWay      = operation.IsOneWay;
            this.isTerminating = operation.IsTerminating;
            this.isSessionOpenNotificationEnabled = operation.IsSessionOpenNotificationEnabled;
            this.name = operation.Name;
            this.parameterInspectors = EmptyArray <IParameterInspector> .ToArray(operation.ParameterInspectors);

            this.faultFormatter   = operation.FaultFormatter;
            this.serializeRequest = operation.SerializeRequest;
            this.deserializeReply = operation.DeserializeReply;
            this.action           = operation.Action;
            this.replyAction      = operation.ReplyAction;
            this.beginMethod      = operation.BeginMethod;
            this.syncMethod       = operation.SyncMethod;
            this.taskMethod       = operation.TaskMethod;
            this.TaskTResult      = operation.TaskTResult;

            if (this.beginMethod != null)
            {
                this.inParams = ServiceReflector.GetInputParameters(this.beginMethod, true);
                if (this.syncMethod != null)
                {
                    this.outParams = ServiceReflector.GetOutputParameters(this.syncMethod, false);
                }
                else
                {
                    this.outParams = NoParams;
                }
                this.endOutParams = ServiceReflector.GetOutputParameters(operation.EndMethod, true);
                this.returnParam  = operation.EndMethod.ReturnParameter;
            }
            else if (this.syncMethod != null)
            {
                this.inParams    = ServiceReflector.GetInputParameters(this.syncMethod, false);
                this.outParams   = ServiceReflector.GetOutputParameters(this.syncMethod, false);
                this.returnParam = this.syncMethod.ReturnParameter;
            }

            if (this.formatter == null && (serializeRequest || deserializeReply))
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.GetString(SR.ClientRuntimeRequiresFormatter0, this.name)));
            }
        }
예제 #14
0
        public async Task CreateBlockBlob_WithDirectoryPathTest()
        {
            var blob = Container.CreateBlockBlob(
                Guid.NewGuid().ToString("D") +
                "/" +
                Guid.NewGuid().ToString("D"));

            await blob.UploadAsync(new MemoryStream(EmptyArray.Get <byte>()));

            Assert.True(await blob.IsExistsAsync());
        }
예제 #15
0
        public List <Dictionary <string, object> > Execute()
        {
            var result = new List <Dictionary <string, object> >();

            do
            {
                result.AddRange(FetchEntities(m_filter, EmptyArray.Get <byte>()));
            }while (ReadNextSegment);

            return(result);
        }
        private static object[] GetThreadLocalDebugInfo()
        {
            var info = ourThreadLocalDebugInfo;

            if (info == null || info.Count == 0)
            {
                return(EmptyArray.GetInstance <object>());
            }

            return(info.ToArray());
        }
예제 #17
0
 public static ICloudTableEntityRangeQuery PrepareEntityRangeQueryByRows(
     this ICloudTable table,
     string partitionKey,
     string fromRowKey,
     string toRowKey)
 {
     return(table.PrepareEntityRangeQueryByRows(
                partitionKey,
                fromRowKey,
                toRowKey,
                EmptyArray.Get <string>()));
 }
예제 #18
0
        public VmdMotion CreateFrom([CanBeNull] CharacterImasMotionAsset bodyMotion, [CanBeNull] Avatar avatar, [CanBeNull] PmxModel mltdPmxModel,
                                    [CanBeNull] CharacterImasMotionAsset cameraMotion,
                                    [CanBeNull] ScenarioObject scenarioObject, int songPosition)
        {
            IReadOnlyList <VmdBoneFrame>   boneFrames;
            IReadOnlyList <VmdCameraFrame> cameraFrames;
            IReadOnlyList <VmdFacialFrame> facialFrames;
            IReadOnlyList <VmdLightFrame>  lightFrames;

            if (ProcessBoneFrames && (bodyMotion != null && avatar != null && mltdPmxModel != null))
            {
                boneFrames = CreateBoneFrames(bodyMotion, avatar, mltdPmxModel);
            }
            else
            {
                boneFrames = EmptyArray.Of <VmdBoneFrame>();
            }

            if (ProcessCameraFrames && cameraMotion != null)
            {
                cameraFrames = CreateCameraFrames(cameraMotion, FixedFov);
            }
            else
            {
                cameraFrames = EmptyArray.Of <VmdCameraFrame>();
            }

            if (ProcessFacialFrames && scenarioObject != null)
            {
                facialFrames = CreateFacialFrames(scenarioObject, songPosition);
            }
            else
            {
                facialFrames = EmptyArray.Of <VmdFacialFrame>();
            }

            if (ProcessLightFrames && scenarioObject != null)
            {
                lightFrames = CreateLightFrames(scenarioObject);
            }
            else
            {
                lightFrames = EmptyArray.Of <VmdLightFrame>();
            }

            const string modelName = "MODEL_00";

            var vmd = new VmdMotion(modelName, boneFrames, facialFrames, cameraFrames, lightFrames, null);

            return(vmd);
        }
예제 #19
0
        internal InstanceBehavior(DispatchRuntime dispatch, ImmutableDispatchRuntime immutableRuntime)
        {
            this.useSession       = dispatch.ChannelDispatcher.Session;
            this.immutableRuntime = immutableRuntime;
            this.host             = (dispatch.ChannelDispatcher == null) ? null : dispatch.ChannelDispatcher.Host;
            this.initializers     = EmptyArray <IInstanceContextInitializer> .ToArray(dispatch.InstanceContextInitializers);

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

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

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

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

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

            if (this.singleton != null)
            {
                this.singleton.Behavior = this;
            }
        }
        protected byte[] GetContinuationTokenBytes()
        {
            if (m_continuationToken == null)
            {
                return(EmptyArray.Get <byte>());
            }

            return(Encoding.UTF8.GetBytes(
                       "{0} {1} {2} {3}".FormatString(
                           m_continuationToken.NextPartitionKey ?? string.Empty,
                           m_continuationToken.NextRowKey ?? string.Empty,
                           m_continuationToken.NextTableName ?? string.Empty,
                           m_continuationToken.TargetLocation)));
        }
        public NotificationHubDataAttribute(
            bool emptyChannel  = false,
            bool hasSubscriber = true,
            bool startHub      = true)
        {
            Fixture.Customize <INotification>(composer => composer
                                              .FromFactory((EventStreamUpdated notification) => notification));

            Fixture.Customize <IReceivedNotification[]>(composer => composer
                                                        .FromFactory((IReceivedNotification n) => n.YieldArray()));

            Fixture.Customize <Mock <IReceivedNotificationProcessor> >(composer => composer
                                                                       .Do(mock => mock
                                                                           .Setup(self => self.ProcessingCount)
                                                                           .Returns(0)));

            Fixture.Customize <Mock <INotificationsChannel> >(composer => composer
                                                              .Do(mock => mock
                                                                  .Setup(self => self.ReceiveNotificationsAsync())
                                                                  .Returns(() => emptyChannel
                        ? EmptyArray.Get <IReceivedNotification>().YieldTask()
                        : Fixture.Create <IReceivedNotification[]>().YieldTask()))
                                                              .Do(mock => mock
                                                                  .Setup(self => self.SendAsync(It.IsAny <INotification>()))
                                                                  .Returns(TaskDone.Done)));

            Fixture.Customize <IPollingJob>(composer => composer.FromFactory((PollingJobStub stub) => stub));

            Fixture.Customize <Mock <INotificationFormatter> >(composer => composer
                                                               .Do(mock => mock
                                                                   .Setup(self => self.FromBytes(It.IsAny <Stream>()))
                                                                   .Returns(() => Fixture.Create <EventStreamUpdated>()))
                                                               .Do(mock => mock
                                                                   .Setup(self => self.ToBytes(It.IsAny <EventStreamUpdated>()))
                                                                   .ReturnsUsingFixture(Fixture)));

            Fixture.Customize <NotificationHub>(composer => composer
                                                .Do(hub =>
            {
                if (hasSubscriber)
                {
                    hub.Subscribe(Fixture.Create <INotificationListener>());
                }

                if (startHub)
                {
                    hub.StartNotificationProcessing(Fixture.Create <IEventStoreConnection>());
                }
            }));
        }
예제 #22
0
            public object Invoke(object instance, object[] inputs, out object[] outputs)
            {
                FaultException exception;
                ServiceChannel serviceChannel;

                outputs = EmptyArray <object> .Allocate(0);

                Message message = inputs[0] as Message;

                if (message != null)
                {
                    string action = message.Headers.Action;
                    if (DiagnosticUtility.ShouldTraceInformation)
                    {
                        TraceUtility.TraceEvent(TraceEventType.Information, 0x80037, System.ServiceModel.SR.GetString("TraceCodeUnhandledAction"), new StringTraceRecord("Action", action), this, null, message);
                    }
                    FaultCode   code   = FaultCode.CreateSenderFaultCode("ActionNotSupported", message.Version.Addressing.Namespace);
                    FaultReason reason = new FaultReason(System.ServiceModel.SR.GetString("SFxNoEndpointMatchingContract", new object[] { action }));
                    exception = new FaultException(reason, code);
                    System.ServiceModel.Dispatcher.ErrorBehavior.ThrowAndCatch(exception);
                    serviceChannel = OperationContext.Current.InternalServiceChannel;
                    OperationContext.Current.OperationCompleted += delegate(object sender, EventArgs e) {
                        ChannelDispatcher channelDispatcher = this.dispatchRuntime.ChannelDispatcher;
                        if (!channelDispatcher.HandleError(exception) && serviceChannel.HasSession)
                        {
                            try
                            {
                                serviceChannel.Close(ChannelHandler.CloseAfterFaultTimeout);
                            }
                            catch (Exception exception1)
                            {
                                if (Fx.IsFatal(exception1))
                                {
                                    throw;
                                }
                                channelDispatcher.HandleError(exception1);
                            }
                        }
                    };
                    if (this.dispatchRuntime.shared.EnableFaults)
                    {
                        MessageFault fault = MessageFault.CreateFault(code, reason, action);
                        return(Message.CreateMessage(message.Version, fault, message.Version.Addressing.DefaultFaultAction));
                    }
                    OperationContext.Current.RequestContext.Close();
                    OperationContext.Current.RequestContext = null;
                }
                return(null);
            }
예제 #23
0
 internal ErrorBehavior(ChannelDispatcher channelDispatcher)
 {
     if (channelDispatcher?.ErrorHandlers == null)
     {
         Handlers = EmptyArray <IErrorHandler> .Allocate(0);
     }
     else
     {
         Handlers = EmptyArray <IErrorHandler> .ToArray(channelDispatcher.ErrorHandlers);
     }
     _debug = channelDispatcher.IncludeExceptionDetailInFaults;
     //isOnServer = channelDispatcher.IsOnServer;
     _isOnServer     = true;
     _messageVersion = channelDispatcher.MessageVersion;
 }
 internal ProxyRpc(ServiceChannel channel, ProxyOperationRuntime operation, string action, object[] inputs, TimeSpan timeout)
 {
     this.Action           = action;
     this.Activity         = null;
     this.Channel          = channel;
     this.Correlation      = EmptyArray.Allocate(operation.Parent.CorrelationCount);
     this.InputParameters  = inputs;
     this.Operation        = operation;
     this.OutputParameters = null;
     this.Request          = null;
     this.Reply            = null;
     this.ActivityId       = Guid.Empty;
     this.ReturnValue      = null;
     this.MessageVersion   = channel.MessageVersion;
     this.TimeoutHelper    = new System.Runtime.TimeoutHelper(timeout);
 }
예제 #25
0
        private async Task <IReceivedNotification[]> ReceiveNotificationsAsync()
        {
            var notifications = EmptyArray.Get <IReceivedNotification>();

            if (RequestNotificationsRequired())
            {
                notifications = await m_channel.ReceiveNotificationsAsync();

                s_logger.Debug(
                    "Receive {NotificationCount} notifications {NotificationIds}.",
                    notifications.Length,
                    notifications.Select(n => n.Notification.NotificationId));
            }

            return(notifications);
        }
예제 #26
0
        internal InstanceBehavior(DispatchRuntime dispatch, ImmutableDispatchRuntime immutableRuntime)
        {
            this.immutableRuntime = immutableRuntime;
            initializers          = EmptyArray <IInstanceContextInitializer> .ToArray(dispatch.InstanceContextInitializers);

            provider                = dispatch.InstanceProvider;
            singleton               = dispatch.SingletonInstanceContext;
            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;
            }
        }
예제 #27
0
        //EventTraceActivity eventTraceActivity;

        internal ProxyRpc(ServiceChannel channel, ProxyOperationRuntime operation, string action, object[] inputs, CancellationToken token)
        {
            Action = action;
            //this.Activity = null;
            //this.eventTraceActivity = null;
            Channel           = channel;
            Correlation       = EmptyArray.Allocate(operation.Parent.CorrelationCount);
            InputParameters   = inputs;
            Operation         = operation;
            OutputParameters  = null;
            Request           = null;
            Reply             = null;
            ActivityId        = Guid.Empty;
            ReturnValue       = null;
            MessageVersion    = channel.MessageVersion;
            CancellationToken = token;
        }
 public void SendResponse(object returnValue, object[] outputs)
 {
     this.returnValue = returnValue;
     this.outputs     = outputs ?? EmptyArray.Allocate(0);
     if (this.responseWaitHandle != null)
     {
         this.responseWaitHandle.Set();
     }
     else if (this.returnValue is Exception)
     {
         this.context.SendFault((Exception)this.returnValue);
     }
     else
     {
         this.context.SendReply(this.returnValue, this.outputs);
     }
 }
예제 #29
0
        internal ProxyRpc(ServiceChannel channel, ProxyOperationRuntime operation, string action, object[] inputs, TimeSpan timeout)
        {
            Action              = action;
            Activity            = null;
            _eventTraceActivity = null;
            Channel             = channel;
            Correlation         = EmptyArray <object> .Allocate(operation.Parent.CorrelationCount);

            InputParameters  = inputs;
            Operation        = operation;
            OutputParameters = null;
            Request          = null;
            Reply            = null;
            ActivityId       = Guid.Empty;
            ReturnValue      = null;
            MessageVersion   = channel.MessageVersion;
            TimeoutHelper    = new TimeoutHelper(timeout);
        }
예제 #30
0
        public async Task UpdateMessage_UpdatesVisibility()
        {
            // arrange
            await Queue.AddMessageAsync(EmptyArray.Get <byte>());

            var message = await Queue.GetMessageAsync();

            // act
            await Queue.UpdateMessageAsync(
                message.MessageId,
                message.PopReceipt,
                TimeSpan.FromSeconds(5));

            var updatedMessage = await Queue.GetMessageAsync();

            // assert
            Assert.Null(updatedMessage);
        }