Exemplo n.º 1
0
        public void Listener_Should_Start_And_Stop_And_Call_EventAgregator_Publish_ReceptionErrorEvent()
        {
            ListenerSettings   listenerSettings = CreateDefaultSettings();
            ConnectionSettings connSettings     = CreateDefaultConnection();

            var moq = new Mock <IMessageReceiver>();

            moq.Setup(x => x.Receive()).Throws <ApplicationException>();
            IMessageReceiver receiver = moq.Object;

            var moq2 = new Mock <IEventPublisher>();

            moq2.Setup(x => x.Publish(It.IsAny <MessageReceivedEvent>()));
            IEventPublisher eventPublisher = moq2.Object;

            Listener target = ListenerFactory.Create(listenerSettings, connSettings, receiver, eventPublisher);

            Assert.AreEqual(ListenerStatus.NotStarted, target.Status);
            target.Start();
            Assert.AreEqual(ListenerStatus.Running, target.Status);
            Thread.Sleep(Constants.ListeningDefaultMilliseconds);
            target.Stop();
            Assert.AreEqual(ListenerStatus.Stopped, target.Status);

            moq2.Verify(x => x.Publish(It.IsAny <ReceptionErrorEvent>()), Times.AtLeastOnce());
        }
Exemplo n.º 2
0
        public void Listener_Should_Start_And_Stop_And_Call_MessagingFactory_CreateMessageReceiver()
        {
            ListenerSettings   listenerSettings = CreateDefaultSettings();
            ConnectionSettings connSettings     = CreateDefaultConnection();
            IMessageReceiver   receiver         = CreateLocalClosedReceiver();
            IMessageReceiver   receiver2        = CreateLocalReceiver();

            var moq1 = new Mock <IMessagingFactory>();

            moq1.Setup(x => x.CreateMessageReceiver(It.IsAny <string>(), It.IsAny <ReceiveMode>())).Returns(receiver2);
            IMessagingFactory messagingFactory = moq1.Object;

            IEventPublisher eventPublisher = new EventPublisher();

            Listener target = ListenerFactory.Create(listenerSettings, connSettings, receiver, eventPublisher, messagingFactory);

            Assert.AreEqual(ListenerStatus.NotStarted, target.Status);
            target.Start();
            Assert.AreEqual(ListenerStatus.Running, target.Status);
            Thread.Sleep(Constants.ListeningDefaultMilliseconds);
            target.Stop();
            Assert.AreEqual(ListenerStatus.Stopped, target.Status);

            moq1.Verify(x => x.CreateMessageReceiver(It.IsAny <string>(), It.IsAny <ReceiveMode>()), Times.Once());
        }
Exemplo n.º 3
0
        /// <summary>
        /// Creates this instance.
        /// </summary>
        /// <returns></returns>
        public IService Create()
        {
            MessageBuilderFactory.CreateDefaultBuilder();
            var listener = ListenerFactory.Create(_input, _handlerRepository);

            return(new MonitorListener(listener));
        }
Exemplo n.º 4
0
        public void GetListener()
        {
            ListenerFactory factory  = new ListenerFactory();
            IListener       listener = factory.CreataListener();

            Assert.IsNotNull(listener);
        }
Exemplo n.º 5
0
 public Server()
 {
     this.listenerFactory   = new ListenerFactory();
     this.Listener          = this.listenerFactory.CreataListener();
     this.messageHandler    = new MessageHandler();
     this.connectionFactory = new ConnectionFactory(this.messageHandler);
     this.ConnectionManager = new ConnectionManager(this.Listener, this.connectionFactory, this.messageHandler);
 }
Exemplo n.º 6
0
 public void Listen(StatusCallback status_callback,
                    ResultCallback result_callback,
                    ErrorCallback error_callback)
 {
     listener_factory = new ListenerFactory(status_callback, result_callback, error_callback, connection.Reconnect);
     // force rebind for existing connection
     rebind(connection.Channel);
 }
Exemplo n.º 7
0
        public void StartStopListener()
        {
            ListenerFactory factory  = new ListenerFactory();
            IListener       listener = factory.CreataListener();

            listener.Start();

            listener.Stop();
        }
Exemplo n.º 8
0
        public void GetSameListener()
        {
            ListenerFactory factory  = new ListenerFactory();
            IListener       listener = factory.CreataListener();

            IListener secondListener = factory.CreataListener();

            Assert.AreEqual(listener, secondListener);
        }
Exemplo n.º 9
0
        public void Listener_Should_Stop()
        {
            ListenerSettings   listenerSettings = CreateDefaultSettings();
            ConnectionSettings connSettings     = CreateDefaultConnection();
            IMessageReceiver   receiver         = CreateLocalReceiver();
            IEventPublisher    eventPublisher   = new EventPublisher();

            Listener target = ListenerFactory.Create(listenerSettings, connSettings, receiver, eventPublisher);

            target.Stop();
        }
Exemplo n.º 10
0
 public static string GetNativeServerURI(string hostName, string instanceName, int overridePortNumber, int overrideListenerPortNumber)
 {
     if (overridePortNumber > 0)
     {
         return(DataphorServiceUtility.BuildNativeInstanceURI(hostName, overridePortNumber, instanceName));
     }
     else
     {
         return(ListenerFactory.GetInstanceURI(hostName, overrideListenerPortNumber, instanceName, true));
     }
 }
Exemplo n.º 11
0
        private static FunctionDefinition CreateTriggeredFunctionDefinitionImpl <TTriggerValue>(
            ITriggerBinding triggerBinding, string parameterName, IFunctionExecutor executor, FunctionDescriptor descriptor,
            IReadOnlyDictionary <string, IBinding> nonTriggerBindings, IFunctionInvoker invoker, SingletonManager singletonManager)
        {
            ITriggeredFunctionBinding <TTriggerValue>         functionBinding = new TriggeredFunctionBinding <TTriggerValue>(descriptor, parameterName, triggerBinding, nonTriggerBindings, singletonManager);
            ITriggeredFunctionInstanceFactory <TTriggerValue> instanceFactory = new TriggeredFunctionInstanceFactory <TTriggerValue>(functionBinding, invoker, descriptor);
            ITriggeredFunctionExecutor triggerExecutor = new TriggeredFunctionExecutor <TTriggerValue>(descriptor, executor, instanceFactory);
            IListenerFactory           listenerFactory = new ListenerFactory(descriptor, triggerExecutor, triggerBinding);

            return(new FunctionDefinition(descriptor, instanceFactory, listenerFactory));
        }
        public EventListenerConfiguratorImpl(Type eventType, ListenerFactory <TListener> listenerFactory,
                                             Expression <Func <EventListeners, TListener[]> > listenerAccessor)
        {
            Guard.IsTrue(x => x.IsGenericTypeDefinition, eventType, "eventType", "Must be a generic type definition");
            Guard.AgainstNull(listenerFactory, "listenerFactory");
            Guard.AgainstNull(listenerAccessor, "listenerAccessor");

            _types            = new HashSet <Type>();
            _eventType        = eventType;
            _listenerFactory  = listenerFactory;
            _listenerAccessor = listenerAccessor;
        }
Exemplo n.º 13
0
        public void Listener_Should_ListenerResume()
        {
            ListenerSettings   listenerSettings = CreateDefaultSettings();
            ConnectionSettings connSettings     = CreateDefaultConnection();
            IMessageReceiver   receiver         = CreateLocalReceiver();
            IEventPublisher    eventPublisher   = new EventPublisher();

            Listener target = ListenerFactory.Create(listenerSettings, connSettings, receiver, eventPublisher);

            target.Resume();
            Assert.AreEqual(ListenerStatus.Running, target.Status);
        }
Exemplo n.º 14
0
        public void ListenerFactory_Create_Test1()
        {
            ListenerSettings   settings       = CreateDefaultSettings();
            ConnectionSettings connSettings   = CreateDefaultConnection();
            IEventPublisher    eventPublisher = new EventPublisher();

            Listener target = ListenerFactory.Create(settings, connSettings, eventPublisher);

            Assert.AreEqual(settings, target.ListenerSettings);
            Assert.AreEqual(connSettings, target.ConnectionSettings);
            Assert.AreEqual(eventPublisher, target.EventPublisher);
        }
Exemplo n.º 15
0
        public void ListenerFactory_Create_Test4()
        {
            string             queueName      = "queueName";
            ConnectionSettings connSettings   = CreateDefaultConnection();
            IEventPublisher    eventPublisher = new EventPublisher();

            Listener target = ListenerFactory.Create(queueName, connSettings, eventPublisher);

            Assert.AreEqual(queueName, target.ListenerSettings.QueueOrTopicPath);
            Assert.AreEqual(connSettings, target.ConnectionSettings);
            Assert.AreEqual(eventPublisher, target.EventPublisher);
        }
Exemplo n.º 16
0
 public Listener StartListener()
 {
     try
     {
         var listener = new ListenerFactory().Create();
         listener.Start();
         return(listener);
     }
     catch (Exception ex)
     {
         this.Logger.WriteException(ex);
         throw;
     }
 }
Exemplo n.º 17
0
        public void ListenerFactory_Create_Test5()
        {
            string             queueName      = "queueName";
            ConnectionSettings connSettings   = CreateDefaultConnection();
            IMessageReceiver   receiver       = new Mock <IMessageReceiver>().Object;
            IEventPublisher    eventPublisher = new EventPublisher();

            Listener target = ListenerFactory.Create(queueName, connSettings, receiver, eventPublisher);

            Assert.AreEqual(queueName, target.ListenerSettings.QueueOrTopicPath);
            Assert.AreEqual(connSettings, target.ConnectionSettings);
            Assert.AreEqual(eventPublisher, target.EventPublisher);
            Assert.AreEqual(receiver, target.MessageReceiver);
        }
Exemplo n.º 18
0
        public void ListenerFactory_Create_Test6()
        {
            string             topicName        = "topicName";
            string             subscriptionName = "subscriptionName";
            ConnectionSettings connSettings     = CreateDefaultConnection();
            IEventPublisher    eventPublisher   = new EventPublisher();

            Listener target = ListenerFactory.Create(topicName, subscriptionName, connSettings, eventPublisher);

            Assert.AreEqual(topicName, target.ListenerSettings.QueueOrTopicPath);
            Assert.AreEqual(subscriptionName, target.ListenerSettings.SubscriptionName);
            Assert.AreEqual(connSettings, target.ConnectionSettings);
            Assert.AreEqual(eventPublisher, target.EventPublisher);
        }
Exemplo n.º 19
0
        public void ListenerFactory_Create_Test2()
        {
            ListenerSettings   settings       = CreateDefaultSettings();
            ConnectionSettings connSettings   = CreateDefaultConnection();
            IEventPublisher    eventPublisher = new EventPublisher();
            IMessageReceiver   receiver       = new Mock <IMessageReceiver>().Object;

            Listener target = ListenerFactory.Create(settings, connSettings, receiver, eventPublisher);

            Assert.AreEqual(settings, target.ListenerSettings);
            Assert.AreEqual(connSettings, target.ConnectionSettings);
            Assert.AreEqual(eventPublisher, target.EventPublisher);
            Assert.AreEqual(receiver, target.MessageReceiver);
        }
Exemplo n.º 20
0
        void InitListeners()
        {
            this.listeners = new List <IListener>(2);
            var listenerRespository = new ListenerFactory();

            foreach (var key in this.ListenerIndexes.Keys)
            {
                var proxy = this.ListenerIndexes[key];
                if (proxy.Enabled)
                {
                    var listener = listenerRespository.GetListener(proxy.Name);
                    this.listeners.Add(listener);
                }
            }
        }
Exemplo n.º 21
0
        private async Task Accept()
        {
            ListenerFactory listenerFactory = new ListenerFactory();

            listenerFactory.Encrypt = true;
            if (CertificateConstructor.TryFindCertificate(out X509Certificate2 x509Certificate2))
            {
                listenerFactory.X509Certificate2 = x509Certificate2;
            }

            using Listener listener       = listenerFactory.Create();
            using Transporter transporter = await listener.Execute(cancellationTokenSource.Token);

            await transporter.Read(this, cancellationTokenSource.Token);
        }
Exemplo n.º 22
0
        private async Task Accept()
        {
            ListenerFactory listenerFactory = new ListenerFactory();

            listenerFactory.Uri = new Uri(webSockets ? "http://localhost:5001/" : "tcp://127.0.0.1:7000");
            Listener listener = listenerFactory.Create();

            for (int i = 0; i < Connections; i++)
            {
                DataPacket  dataPacket  = dataPackets[1][i];
                Transporter transporter = await listener.Execute(cancellationTokenSource.Token);

                tasks.Add(transporter, Receive(transporter, dataPacket));
            }
        }
Exemplo n.º 23
0
        public void ListenerFactory_Create_Test()
        {
            string          queueName           = "queueName";
            string          issuerName          = "issuerName";
            string          issuerKey           = "issuerKey";
            string          serviceBusNamespace = "serviceBusNamespace";
            IEventPublisher eventPublisher      = new EventPublisher();

            Listener target = ListenerFactory.Create(queueName, issuerName, issuerKey, serviceBusNamespace, eventPublisher);

            Assert.AreEqual(queueName, target.ListenerSettings.QueueOrTopicPath);
            Assert.AreEqual(issuerName, target.ConnectionSettings.IssuerName);
            Assert.AreEqual(issuerKey, target.ConnectionSettings.IssuerSecretKey);
            Assert.AreEqual(serviceBusNamespace, target.ConnectionSettings.ServiceBusNamespace);
            Assert.AreEqual(eventPublisher, target.EventPublisher);
        }
Exemplo n.º 24
0
        public void Listener_Should_Start_And_Stop()
        {
            ListenerSettings   listenerSettings = CreateDefaultSettings();
            ConnectionSettings connSettings     = CreateDefaultConnection();
            IMessageReceiver   receiver         = CreateLocalReceiver();
            IEventPublisher    eventPublisher   = new EventPublisher();

            Listener target = ListenerFactory.Create(listenerSettings, connSettings, receiver, eventPublisher);

            Assert.AreEqual(ListenerStatus.NotStarted, target.Status);
            target.Start();
            Assert.AreEqual(ListenerStatus.Running, target.Status);
            Thread.Sleep(Constants.ListeningDefaultMilliseconds);
            target.Stop();
            Assert.AreEqual(ListenerStatus.Stopped, target.Status);
        }
Exemplo n.º 25
0
        private async Task Accept()
        {
            ListenerFactory listenerFactory = new ListenerFactory();

            listenerFactory.Uri = new Uri(webSockets ? "http://localhost:5001/" : "tcp://127.0.0.1:7000");
            Listener listener = listenerFactory.Create();

            for (int i = 0; i < Connections; i++)
            {
                Transporter transporter = await listener.Execute(cancellationTokenSource.Token);

                EchoPacket echoPacket = new EchoPacket(Bytes, Iterations);
                tasks.Add(ExecuteRead(transporter, echoPacket));
                tasks.Add(ExecuteWrite(transporter, echoPacket));
                transporters.Add(transporter);
            }
        }
Exemplo n.º 26
0
 public void BeginLoadInstances()
 {
     Status = ConnectStatus.LoadingInstances;
     Session.Invoke <string[]>
     (
         () => { return(ListenerFactory.EnumerateInstances(_hostName)); },                // TODO: This will need to be changed to use the listener connectivity override overload
         (Exception AException) =>
     {
         Status    = ConnectStatus.SelectHost;
         Exception = AException;
     },
         (string[] AInstances) =>
     {
         Instances = AInstances;
         Status    = ConnectStatus.SelectInstance;
     }
     );
 }
Exemplo n.º 27
0
        /// <summary>
        ///
        /// </summary>
        private LogFactory()
        {
            this.SessionLogIndexs          = new List <string>();
            this.LogSessionEnabledStateMap = new Dictionary <string, bool>();
            this.LogConfigMap        = new Dictionary <string, IConfigNode>();
            this.ListenerRespository = new ListenerFactory();

            AppInstance.RegisterTypeAliasByModule <Logger>(AppConfig.LoggingKey);
            AppInstance.RegisterTypeAliasByModule <SessionLogger>(AppConfig.LoggingKey);
            AppInstance.RegisterTypeAliasByModule <SystemLogger>(AppConfig.LoggingKey);


            AppInstance.RegisterTypeAliasByModule <FileListener>(AppConfig.LoggingKey);
            AppInstance.RegisterTypeAliasByModule <ConsoleListener>(AppConfig.LoggingKey);
            AppInstance.RegisterTypeAliasByModule <QueueListener>(AppConfig.LoggingKey);


            AppInstance.RegisterTypeAliasByModule <TextFormatter>(AppConfig.LoggingKey);
            this.RegisterHandler();
        }
Exemplo n.º 28
0
 private void cbInstanceName_DropDown(object sender, EventArgs e)
 {
     if ((tbHost.Text != String.Empty) && (!_instancesEnumerated))
     {
         try
         {
             _instancesEnumerated = true;
             cbInstanceName.Items.Clear();
             string[] instanceNames = ListenerFactory.EnumerateInstances(tbHost.Text, OverrideListenerPortNumber);
             for (int index = 0; index < instanceNames.Length; index++)
             {
                 cbInstanceName.Items.Add(instanceNames[index]);
             }
         }
         catch (Exception exception)
         {
             _instancesEnumerated = false;
             MessageBox.Show(String.Format("Could not enumerate instances for host \"{0}\".\r\n{1}", tbHost.Text, exception.Message));
         }
     }
 }
Exemplo n.º 29
0
        public void Listener_Should_Start_And_Stop_And_Call_EventAgregator_Publish_StatusChangedEvent()
        {
            ListenerSettings   listenerSettings = CreateDefaultSettings();
            ConnectionSettings connSettings     = CreateDefaultConnection();
            IMessageReceiver   receiver         = CreateLocalReceiver();
            var moq = new Mock <IEventPublisher>();

            moq.Setup(x => x.Publish(It.IsAny <StatusChangedEvent>()));
            IEventPublisher eventPublisher = moq.Object;

            Listener target = ListenerFactory.Create(listenerSettings, connSettings, receiver, eventPublisher);

            Assert.AreEqual(ListenerStatus.NotStarted, target.Status);
            target.Start();
            Assert.AreEqual(ListenerStatus.Running, target.Status);
            Thread.Sleep(Constants.ListeningDefaultMilliseconds);
            target.Stop();
            Assert.AreEqual(ListenerStatus.Stopped, target.Status);

            moq.Verify(x => x.Publish(It.IsAny <StatusChangedEvent>()), Times.Exactly(2));
        }
Exemplo n.º 30
0
        public void Open()
        {
            if (!IsActive)
            {
                if (!String.IsNullOrEmpty(_clientConfigurationName))
                {
                    _channelFactory = new ChannelFactory <IClientDataphorService>(_clientConfigurationName);
                }
                else
                {
                    if (_overridePortNumber == 0)
                    {
                        Uri uri = new Uri(ListenerFactory.GetInstanceURI(_hostName, _overrideListenerPortNumber, _instanceName));
                        _channelFactory =
                            new ChannelFactory <IClientDataphorService>
                            (
                                DataphorServiceUtility.GetBinding(),
                                new EndpointAddress(uri, DataphorServiceUtility.BuildEndpointIdentityCall())
                            );
                    }
                    else
                    {
                        _channelFactory =
                            new ChannelFactory <IClientDataphorService>
                            (
                                DataphorServiceUtility.GetBinding(),
                                new EndpointAddress
                                (
                                    new Uri(DataphorServiceUtility.BuildInstanceURI(_hostName, _overridePortNumber, _instanceName)),
                                    DataphorServiceUtility.BuildEndpointIdentityCall()
                                )
                            );
                    }
                }

                DataphorServiceUtility.ServiceEndpointHook(_channelFactory.Endpoint);
            }
        }
Exemplo n.º 31
0
        public static void Main(string[] args)
        {
            ListenerFactory factory = new ListenerFactory(90, IPAddress.Any, 5);

            Console.ReadLine();
        }