Ejemplo n.º 1
0
        public static void RunDemo()
        {
            var server = new MessagingServer(new MyHttpServiceFactory(),
                                             new MessagingServerConfiguration(new HttpMessageFactory()));

            server.Start(new IPEndPoint(IPAddress.Loopback, 8888));
        }
Ejemplo n.º 2
0
        public void MessagingServer_CerificateStoreIsMockCerificateStore()
        {
            LoggerFactory   loggerFactory   = new LoggerFactory();
            MessagingServer messagingServer = new MessagingServer(Settings, loggerFactory.CreateLogger("Mock"), loggerFactory, CollaborationRegistry, AddressRegistry, new MockCertificateStore());

            Assert.IsInstanceOfType(messagingServer.CertificateStore, typeof(MockCertificateStore));
        }
Ejemplo n.º 3
0
        public void MessagingServer_DefaultCerificateStoreIsWindowsCerificateStore()
        {
            LoggerFactory   loggerFactory   = new LoggerFactory();
            MessagingServer messagingServer = new MessagingServer(Settings, loggerFactory, CollaborationRegistry, AddressRegistry);

            Assert.IsInstanceOfType(messagingServer.CertificateStore, typeof(WindowsCertificateStore));
        }
    public ChatServer()
    {
        var messageFactory = new BasicMessageFactory();
        var configuration  = new MessagingServerConfiguration(messageFactory);

        _server = new MessagingServer(this, configuration);
    }
Ejemplo n.º 5
0
        private static void Main(string[] args)
        {
            // factory that produces our service classes which
            // will handle all incoming messages
            var serviceFactory = new MyServiceFactory();

            // factory used to create the classes that will
            // serialize and build our messages
            var messageFactory = new BasicMessageFactory();

            // server configuration.
            // you can limit the number of clients etc.
            var configuration = new MessagingServerConfiguration(messageFactory);

            // actual server
            var server = new MessagingServer(serviceFactory, configuration);

            server.Start(new IPEndPoint(IPAddress.Any, 7652));

            var client = new MessagingClient(messageFactory);

            client.Connect(new IPEndPoint(IPAddress.Loopback, 7652));

            // Look here! We receive objects!
            client.Received += (sender, eventArgs) => Console.WriteLine("We received: " + eventArgs.Message);

            // And here we are sending one.
            client.Send(new OpenDoor {
                Id = Guid.NewGuid().ToString()
            });

            //to prevent the server from shutting down
            Console.ReadLine();
        }
Ejemplo n.º 6
0
        public void Asynchronous_Receive_CertificateSignError()
        {
            Exception receiveException = null;

            Client = new MessagingClient(Settings, CollaborationRegistry, AddressRegistry)
            {
                DefaultMessageProtection    = new SignThenEncryptMessageProtection(), // disable protection for most tests
                DefaultCertificateValidator = CertificateValidator
            };
            Client.ServiceBus.RegisterAlternateMessagingFactory(MockFactory);

            Server = new MessagingServer(Settings, Logger, LoggerFactory, CollaborationRegistry, AddressRegistry)
            {
                DefaultMessageProtection    = new SignThenEncryptMessageProtection(), // disable protection for most tests
                DefaultCertificateValidator = CertificateValidator
            };
            Server.ServiceBus.RegisterAlternateMessagingFactory(MockFactory);

            CollaborationRegistry.SetupFindAgreementForCounterparty(i =>
            {
                var file = Path.Combine("Files", $"CPA_{i}_ChangedSignedCertificate.xml");
                return(File.Exists(file) == false ? null : File.ReadAllText(file));
            });

            RunAsynchronousReceive(
                postValidation: () => {
                Assert.IsTrue(_startingCalled);
                Assert.IsFalse(_receivedCalled);
                Assert.IsTrue(_completedCalled);
                var error = MockLoggerProvider.FindEntry(EventIds.RemoteCertificate);
                Assert.IsTrue(error.Message
                              .Contains($"{TestCertificates.HelsenorgePrivateSigntature.Thumbprint}"));
                Assert.IsTrue(error.Message
                              .Contains($"{TestCertificates.HelsenorgePrivateSigntature.NotBefore}"));
                var signingException = receiveException as CertificateException;
                Assert.IsNotNull(signingException);
                Assert.IsNotNull(signingException.Payload);
            },
                wait: () => _completedCalled,
                received: (m) => { },
                messageModification: (m) => { },
                handledException: ((m, e) =>
            {
                Server.Stop(TimeSpan.FromSeconds(10));
                _handledExceptionCalled = true;
                _completedCalled = true;
                receiveException = e;
            }),
                messageProtected: true);
        }
Ejemplo n.º 7
0
 /// <summary>
 /// Initializes a new instance of the <see cref="HttpServer" /> class.
 /// </summary>
 /// <param name="moduleManager">The modules are used to process the HTTP requests. You need to specify at least one.</param>
 /// <param name="configuration">You can override the configuration to your likings. We suggest that you using the <see cref="HttpMessageFactory" /> to produce the messages.</param>
 /// <exception cref="System.ArgumentNullException">moduleManager/configuration</exception>
 public HttpServer(IModuleManager moduleManager, MessagingServerConfiguration configuration)
 {
     if (moduleManager == null)
     {
         throw new ArgumentNullException("moduleManager");
     }
     if (configuration == null)
     {
         throw new ArgumentNullException("configuration");
     }
     _moduleManager       = moduleManager;
     _server              = new MessagingServer(this, configuration);
     _bufferSliceStack    = new BufferSliceStack(100, 65535);
     ApplicationInfo      = new MemoryItemStorage();
     _workerConfiguration = new WorkerConfiguration
     {
         Application      = ApplicationInfo,
         BufferSliceStack = _bufferSliceStack,
         ModuleManager    = _moduleManager
     };
 }
Ejemplo n.º 8
0
        internal void SetupInternal(int otherHerId)
        {
            var addressRegistrySettings = new AddressRegistrySettings()
            {
                UserName         = "******",
                Password         = "******",
                EndpointName     = "SomeEndpointName",
                WcfConfiguration = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None),
                CachingInterval  = TimeSpan.FromSeconds(5)
            };
            var collaborationRegistrySettings = new CollaborationProtocolRegistrySettings()
            {
                UserName         = "******",
                Password         = "******",
                EndpointName     = "SomeEndpointName",
                WcfConfiguration = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None),
                CachingInterval  = TimeSpan.FromSeconds(5)
            };

            LoggerFactory = new LoggerFactory();

            MockLoggerProvider = new MockLoggerProvider(null);
            LoggerFactory.AddProvider(MockLoggerProvider);

            //LoggerFactory.AddDebug();
            //Logger = new LoggerMock(LoggerFactory.CreateLogger<BaseTest>());
            Logger = LoggerFactory.CreateLogger <BaseTest>();

            var memoryCache      = new MemoryCache(new MemoryCacheOptions());
            var distributedCache = new MemoryDistributedCache(memoryCache);

            AddressRegistry = new AddressRegistryMock(addressRegistrySettings, distributedCache);
            AddressRegistry.SetupFindCommunicationPartyDetails(i =>
            {
                var file = Path.Combine("Files", $"CommunicationDetails_{i}.xml");
                return(File.Exists(file) == false ? null : XElement.Load(file));
            });
            AddressRegistry.SetupGetCertificateDetailsForEncryption(i =>
            {
                var path = Path.Combine("Files", $"GetCertificateDetailsForEncryption_{i}.xml");
                return(File.Exists(path) == false ? null : XElement.Load(path));
            });
            AddressRegistry.SetupGetCertificateDetailsForValidatingSignature(i =>
            {
                var path = Path.Combine("Files", $"GetCertificateDetailsForValidatingSignature_{i}.xml");
                return(File.Exists(path) == false ? null : XElement.Load(path));
            });

            CollaborationRegistry = new CollaborationProtocolRegistryMock(collaborationRegistrySettings, distributedCache, AddressRegistry);
            CollaborationRegistry.SetupFindProtocolForCounterparty(i =>
            {
                var file = Path.Combine("Files", $"CPP_{i}.xml");
                return(File.Exists(file) == false ? null : File.ReadAllText(file));
            });
            CollaborationRegistry.SetupFindAgreementForCounterparty(i =>
            {
                var file = Path.Combine("Files", $"CPA_{i}.xml");
                return(File.Exists(file) == false ? null : File.ReadAllText(file));
            });
            CollaborationRegistry.SetupFindAgreementById(i =>
            {
                var file = Path.Combine("Files", $"CPA_{i:D}.xml");
                return(File.Exists(file) == false ? null : File.ReadAllText(file));
            });

            Settings = new MessagingSettings()
            {
                MyHerId            = MockFactory.HelsenorgeHerId,
                SigningCertificate = new CertificateSettings()
                {
                    Certificate = TestCertificates.HelsenorgePrivateSigntature
                },
                DecryptionCertificate = new CertificateSettings()
                {
                    Certificate = TestCertificates.HelsenorgePrivateEncryption
                }
            };

            Settings.ServiceBus.ConnectionString = "connection string";
            Settings.ServiceBus.Synchronous.ReplyQueueMapping.Add(Environment.MachineName.ToLower(), "RepliesGoHere");
            // make things easier by only having one processing task per queue
            Settings.ServiceBus.Asynchronous.ProcessingTasks = 1;
            Settings.ServiceBus.Synchronous.ProcessingTasks  = 1;
            Settings.ServiceBus.Error.ProcessingTasks        = 1;

            MockFactory          = new MockFactory(otherHerId);
            CertificateValidator = new MockCertificateValidator();

            Client = new MessagingClient(Settings, CollaborationRegistry, AddressRegistry)
            {
                DefaultMessageProtection    = new NoMessageProtection(), // disable protection for most tests
                DefaultCertificateValidator = CertificateValidator
            };
            Client.ServiceBus.RegisterAlternateMessagingFactory(MockFactory);

            Server = new MessagingServer(Settings, Logger, LoggerFactory, CollaborationRegistry, AddressRegistry)
            {
                DefaultMessageProtection    = new NoMessageProtection(), // disable protection for most tests
                DefaultCertificateValidator = CertificateValidator
            };
            Server.ServiceBus.RegisterAlternateMessagingFactory(MockFactory);
        }