Example #1
0
        private static void RegisterInteractionHandshakeConductor(ContainerBuilder builder)
        {
            builder.Register(
                c =>
            {
                var configuration = c.Resolve <IConfiguration>();
                var sendTimeout   = configuration.HasValueFor(CommunicationConfigurationKeys.WaitForResponseTimeoutInMilliSeconds)
                            ? TimeSpan.FromMilliseconds(
                    configuration.Value <int>(CommunicationConfigurationKeys.WaitForResponseTimeoutInMilliSeconds))
                            : TimeSpan.FromMilliseconds(CommunicationConstants.DefaultWaitForResponseTimeoutInMilliSeconds);

                return(new InteractionHandshakeConductor(
                           EndpointIdExtensions.CreateEndpointIdForCurrentProcess(),
                           c.Resolve <IStoreInformationAboutEndpoints>(),
                           c.Resolve <IStoreInteractionSubjects>(),
                           c.Resolve <IStoreRemoteCommandProxies>(),
                           c.Resolve <IStoreRemoteNotificationProxies>(),
                           c.Resolve <SendMessage>(),
                           c.Resolve <SendMessageAndWaitForResponse>(),
                           sendTimeout,
                           c.Resolve <SystemDiagnostics>()));
            })
            .As <IHandleInteractionHandshakes>()
            .SingleInstance();
        }
        private static void RegisterBootstrapChannel(ContainerBuilder builder)
        {
            builder.Register(
                c =>
            {
                var ctx             = c.Resolve <IComponentContext>();
                var channelTemplate = c.ResolveKeyed <IDiscoveryChannelTemplate>(ChannelTemplate.NamedPipe);
                return(new BootstrapChannel(
                           EndpointIdExtensions.CreateEndpointIdForCurrentProcess(),
                           channelTemplate,
                           c.Resolve <Func <Version, ChannelTemplate, Tuple <Type, IVersionedDiscoveryEndpoint> > >(),
                           () => ctx.Resolve <IHoldServiceConnections>(new TypedParameter(typeof(IChannelTemplate), channelTemplate)),
                           uri => s_BootstrapChannelUri.Add(ChannelTemplate.NamedPipe, uri)));
            })
            .Keyed <IBootstrapChannel>(ChannelTemplate.NamedPipe)
            .As <IDisposable>()
            .SingleInstance();

            builder.Register(
                c =>
            {
                var ctx             = c.Resolve <IComponentContext>();
                var channelTemplate = c.ResolveKeyed <IDiscoveryChannelTemplate>(ChannelTemplate.TcpIP);
                return(new BootstrapChannel(
                           EndpointIdExtensions.CreateEndpointIdForCurrentProcess(),
                           channelTemplate,
                           c.Resolve <Func <Version, ChannelTemplate, Tuple <Type, IVersionedDiscoveryEndpoint> > >(),
                           () => ctx.Resolve <IHoldServiceConnections>(new TypedParameter(typeof(IChannelTemplate), channelTemplate)),
                           uri => s_BootstrapChannelUri.Add(ChannelTemplate.TcpIP, uri)));
            })
            .Keyed <IBootstrapChannel>(ChannelTemplate.TcpIP)
            .As <IDisposable>()
            .SingleInstance();
        }
Example #3
0
        public void OriginatesOnMachine()
        {
            var id          = EndpointIdExtensions.CreateEndpointIdForCurrentProcess();
            var machineName = id.OriginatesOnMachine();

            Assert.AreEqual(Environment.MachineName, machineName);
        }
Example #4
0
        private static void RegisterInteractionMessageProcessingActions(ContainerBuilder builder)
        {
            builder.Register(c => new CommandInvokedProcessAction(
                                 EndpointIdExtensions.CreateEndpointIdForCurrentProcess(),
                                 c.Resolve <SendMessage>(),
                                 c.Resolve <ICommandCollection>(),
                                 c.Resolve <SystemDiagnostics>()))
            .As <IMessageProcessAction>();

            builder.Register(c => new EndpointInteractionInformationProcessAction(
                                 c.Resolve <IHandleInteractionHandshakes>(),
                                 c.Resolve <SystemDiagnostics>()))
            .As <IMessageProcessAction>();

            builder.Register(c => new RegisterForNotificationProcessAction(
                                 c.Resolve <ISendNotifications>()))
            .As <IMessageProcessAction>();

            builder.Register(c => new UnregisterFromNotificationProcessAction(
                                 c.Resolve <ISendNotifications>()))
            .As <IMessageProcessAction>();

            builder.Register(c => new NotificationRaisedProcessAction(
                                 c.Resolve <IRaiseProxyNotifications>(),
                                 c.Resolve <SystemDiagnostics>()))
            .As <IMessageProcessAction>();
        }
 private static void RegisterLocalConnectionInformation(ContainerBuilder builder)
 {
     builder.Register(c => new LocalConnectionInformation(
                          EndpointIdExtensions.CreateEndpointIdForCurrentProcess(),
                          t => s_BootstrapChannelUri[t]))
     .As <IProvideLocalConnectionInformation>();
 }
Example #6
0
        public void IsOnMachine()
        {
            var id = EndpointIdExtensions.CreateEndpointIdForCurrentProcess();

            Assert.IsTrue(id.IsOnMachine(Environment.MachineName));
            Assert.IsFalse(id.IsOnMachine("foobar"));
        }
Example #7
0
 private static void RegisterNotificationCollection(ContainerBuilder builder)
 {
     builder.Register(c => new LocalNotificationCollection(
                          EndpointIdExtensions.CreateEndpointIdForCurrentProcess(),
                          c.Resolve <SendMessage>()))
     .As <INotificationCollection>()
     .As <ISendNotifications>()
     .SingleInstance();
 }
Example #8
0
        public void Deserialize()
        {
            var id   = EndpointIdExtensions.CreateEndpointIdForCurrentProcess();
            var text = id.ToString();

            var otherId = EndpointIdExtensions.Deserialize(text);

            Assert.AreEqual(id, otherId);
        }
Example #9
0
        public void IsConnectionActiveWithIdAndUnresponsiveConnection()
        {
            var endpoint     = EndpointIdExtensions.CreateEndpointIdForCurrentProcess();
            var address      = new Uri("http://localhost/discovery");
            var endpointInfo = new EndpointInformation(
                endpoint,
                new DiscoveryInformation(address),
                new ProtocolInformation(
                    new Version(),
                    new Uri("http://localhost/messages"),
                    new Uri("http://localhost/data")));
            var endpoints = new Mock <IStoreInformationAboutEndpoints>();
            {
                endpoints.Setup(e => e.TryGetConnectionFor(It.IsAny <EndpointId>(), out endpointInfo))
                .Returns(true)
                .Verifiable();
            }

            var commands      = new Mock <ISendCommandsToRemoteEndpoints>();
            var notifications = new Mock <INotifyOfRemoteEndpointEvents>();
            var configuration = new Mock <IConfiguration>();
            {
                configuration.Setup(c => c.HasValueFor(It.IsAny <ConfigurationKey>()))
                .Returns(false);
            }

            var source = new CancellationTokenSource();

            source.Cancel();
            VerifyEndpointConnectionStatus func =
                (id, timeout) =>
            {
                return(Task.Factory.StartNew(
                           () =>
                {
                },
                           source.Token,
                           TaskCreationOptions.None,
                           new CurrentThreadTaskScheduler()));
            };

            var entryPoint = new CommunicationEntryPoint(
                endpoints.Object,
                commands.Object,
                notifications.Object,
                func,
                configuration.Object);

            endpoints.Raise(e => e.OnEndpointConnected     += null, new EndpointEventArgs(endpoint));
            commands.Raise(c => c.OnEndpointConnected      += null, new EndpointEventArgs(endpoint));
            notifications.Raise(n => n.OnEndpointConnected += null, new EndpointEventArgs(endpoint));

            Assert.IsFalse(entryPoint.IsConnectionActive(endpoint));
        }
Example #10
0
        private static void RegisterNotificationHub(ContainerBuilder builder)
        {
            builder.Register(c => new RemoteNotificationHub(
                                 c.Resolve <IStoreInformationAboutEndpoints>(),
                                 c.Resolve <NotificationProxyBuilder>(),
                                 c.Resolve <SystemDiagnostics>()))
            .As <INotifyOfRemoteEndpointEvents>()
            .As <IStoreRemoteNotificationProxies>()
            .As <IRaiseProxyNotifications>()
            .SingleInstance();

            builder.Register(c => new NotificationProxyBuilder(
                                 EndpointIdExtensions.CreateEndpointIdForCurrentProcess(),
                                 c.Resolve <SendMessage>(),
                                 c.Resolve <SystemDiagnostics>()));
        }
Example #11
0
        private static void RegisterCommandHub(ContainerBuilder builder)
        {
            builder.Register(c => new RemoteCommandHub(
                                 c.Resolve <IStoreInformationAboutEndpoints>(),
                                 c.Resolve <CommandProxyBuilder>(),
                                 c.Resolve <SystemDiagnostics>()))
            .As <ISendCommandsToRemoteEndpoints>()
            .As <IStoreRemoteCommandProxies>()
            .SingleInstance();

            builder.Register(c => new CommandProxyBuilder(
                                 EndpointIdExtensions.CreateEndpointIdForCurrentProcess(),
                                 c.Resolve <SendMessageAndWaitForResponse>(),
                                 c.Resolve <IConfiguration>(),
                                 c.Resolve <SystemDiagnostics>()));
        }
Example #12
0
        public void OnEndpointDisconnectedForAnUnknownEndpoint()
        {
            var endpoint      = EndpointIdExtensions.CreateEndpointIdForCurrentProcess();
            var address       = new Uri("http://localhost/discovery");
            var endpoints     = new Mock <IStoreInformationAboutEndpoints>();
            var commands      = new Mock <ISendCommandsToRemoteEndpoints>();
            var notifications = new Mock <INotifyOfRemoteEndpointEvents>();
            var configuration = new Mock <IConfiguration>();
            {
                configuration.Setup(c => c.HasValueFor(It.IsAny <ConfigurationKey>()))
                .Returns(false);
            }

            VerifyEndpointConnectionStatus func = (id, timeout) => null;

            var entryPoint = new CommunicationEntryPoint(
                endpoints.Object,
                commands.Object,
                notifications.Object,
                func,
                configuration.Object);

            EndpointId eventEndpoint = null;

            entryPoint.OnEndpointDisconnected +=
                (s, e) =>
            {
                eventEndpoint = e.Endpoint;
            };

            endpoints.Raise(e => e.OnEndpointDisconnected += null, new EndpointEventArgs(endpoint));
            Assert.IsNull(eventEndpoint);
            Assert.IsFalse(entryPoint.KnownEndpoints().Any());
            Assert.IsNull(entryPoint.FromUri(address));

            commands.Raise(c => c.OnEndpointDisconnected += null, new EndpointEventArgs(endpoint));
            Assert.IsNull(eventEndpoint);
            Assert.IsFalse(entryPoint.KnownEndpoints().Any());
            Assert.IsNull(entryPoint.FromUri(address));

            notifications.Raise(n => n.OnEndpointDisconnected += null, new EndpointEventArgs(endpoint));
            Assert.IsNull(eventEndpoint);
            Assert.IsFalse(entryPoint.KnownEndpoints().Any());
            Assert.IsNull(entryPoint.FromUri(address));
        }
Example #13
0
        private static void RegisterProtocolMessageProcessingActions(ContainerBuilder builder)
        {
            builder.Register(c => new DataDownloadProcessAction(
                                 c.Resolve <IStoreUploads>(),
                                 c.Resolve <IProtocolLayer>(),
                                 c.Resolve <SystemDiagnostics>()))
            .As <IMessageProcessAction>();

            builder.Register(
                c =>
            {
                var ctx = c.Resolve <IComponentContext>();
                return(new EndpointConnectProcessAction(
                           c.Resolve <IHandleProtocolHandshakes>(),
                           from channelType in ctx.Resolve <IEnumerable <IProtocolChannelTemplate> >() select channelType.ChannelTemplate,
                           c.Resolve <SystemDiagnostics>()));
            })
            .As <IMessageProcessAction>();

            builder.Register(c => new EndpointDisconnectProcessAction(
                                 c.Resolve <IStoreEndpointApprovalState>(),
                                 c.Resolve <SystemDiagnostics>()))
            .As <IMessageProcessAction>();

            builder.Register(
                c =>
            {
                KeepAliveResponseCustomDataBuilder keepAliveFunction;
                var success = c.TryResolve(out keepAliveFunction);
                return(new ConnectionVerificationProcessAction(
                           EndpointIdExtensions.CreateEndpointIdForCurrentProcess(),
                           c.Resolve <SendMessage>(),
                           c.Resolve <SystemDiagnostics>(),
                           success ? keepAliveFunction : null));
            })
            .As <IMessageProcessAction>();

            builder.Register(c => new UnknownMessageTypeProcessAction(
                                 EndpointIdExtensions.CreateEndpointIdForCurrentProcess(),
                                 c.Resolve <SendMessage>(),
                                 c.Resolve <SystemDiagnostics>()))
            .As <IMessageProcessAction>();
        }
Example #14
0
        public void IsConnectionActiveWithUrlAndUnknownConnection()
        {
            var endpoint     = EndpointIdExtensions.CreateEndpointIdForCurrentProcess();
            var address      = new Uri("http://localhost/discovery");
            var endpointInfo = new EndpointInformation(
                endpoint,
                new DiscoveryInformation(address),
                new ProtocolInformation(
                    new Version(),
                    new Uri("http://localhost/messages"),
                    new Uri("http://localhost/data")));
            var endpoints = new Mock <IStoreInformationAboutEndpoints>();
            {
                endpoints.Setup(e => e.TryGetConnectionFor(It.IsAny <EndpointId>(), out endpointInfo))
                .Returns(true)
                .Verifiable();
            }

            var commands      = new Mock <ISendCommandsToRemoteEndpoints>();
            var notifications = new Mock <INotifyOfRemoteEndpointEvents>();
            var configuration = new Mock <IConfiguration>();
            {
                configuration.Setup(c => c.HasValueFor(It.IsAny <ConfigurationKey>()))
                .Returns(false);
            }

            VerifyEndpointConnectionStatus func = (id, timeout) => null;

            var entryPoint = new CommunicationEntryPoint(
                endpoints.Object,
                commands.Object,
                notifications.Object,
                func,
                configuration.Object);

            Assert.IsFalse(entryPoint.IsConnectionActive(new Uri("http://localhost/invalid")));
        }
Example #15
0
        public void OnEndpointDisconnected()
        {
            var endpoint     = EndpointIdExtensions.CreateEndpointIdForCurrentProcess();
            var address      = new Uri("http://localhost/discovery");
            var endpointInfo = new EndpointInformation(
                endpoint,
                new DiscoveryInformation(address),
                new ProtocolInformation(
                    new Version(),
                    new Uri("http://localhost/messages"),
                    new Uri("http://localhost/data")));
            var endpoints = new Mock <IStoreInformationAboutEndpoints>();
            {
                endpoints.Setup(e => e.TryGetConnectionFor(It.IsAny <EndpointId>(), out endpointInfo))
                .Returns(true)
                .Verifiable();
            }

            var commands      = new Mock <ISendCommandsToRemoteEndpoints>();
            var notifications = new Mock <INotifyOfRemoteEndpointEvents>();
            var configuration = new Mock <IConfiguration>();
            {
                configuration.Setup(c => c.HasValueFor(It.IsAny <ConfigurationKey>()))
                .Returns(false);
            }

            VerifyEndpointConnectionStatus func = (id, timeout) => null;

            var entryPoint = new CommunicationEntryPoint(
                endpoints.Object,
                commands.Object,
                notifications.Object,
                func,
                configuration.Object);

            EndpointId eventEndpoint = null;

            entryPoint.OnEndpointConnected +=
                (s, e) =>
            {
                eventEndpoint = e.Endpoint;
            };

            entryPoint.OnEndpointDisconnected +=
                (s, e) =>
            {
                eventEndpoint = e.Endpoint;
            };

            endpoints.Raise(e => e.OnEndpointConnected += null, new EndpointEventArgs(endpoint));
            Assert.IsNull(eventEndpoint);
            endpoints.Verify(e => e.TryGetConnectionFor(It.IsAny <EndpointId>(), out endpointInfo), Times.Never());
            Assert.IsFalse(entryPoint.KnownEndpoints().Any());
            Assert.IsNull(entryPoint.FromUri(address));

            commands.Raise(c => c.OnEndpointConnected += null, new EndpointEventArgs(endpoint));
            Assert.IsNull(eventEndpoint);
            endpoints.Verify(e => e.TryGetConnectionFor(It.IsAny <EndpointId>(), out endpointInfo), Times.Never());
            Assert.IsFalse(entryPoint.KnownEndpoints().Any());
            Assert.IsNull(entryPoint.FromUri(address));

            notifications.Raise(n => n.OnEndpointConnected += null, new EndpointEventArgs(endpoint));
            Assert.AreSame(endpoint, eventEndpoint);
            endpoints.Verify(e => e.TryGetConnectionFor(It.IsAny <EndpointId>(), out endpointInfo), Times.Once());
            Assert.IsTrue(entryPoint.KnownEndpoints().Any());
            Assert.AreSame(endpoint, entryPoint.FromUri(address));

            eventEndpoint = null;
            endpoints.Raise(e => e.OnEndpointDisconnected += null, new EndpointEventArgs(endpoint));
            Assert.AreSame(endpoint, eventEndpoint);
            endpoints.Verify(e => e.TryGetConnectionFor(It.IsAny <EndpointId>(), out endpointInfo), Times.Once());
            Assert.IsFalse(entryPoint.KnownEndpoints().Any());
            Assert.IsNull(entryPoint.FromUri(address));

            eventEndpoint = null;
            commands.Raise(c => c.OnEndpointDisconnected += null, new EndpointEventArgs(endpoint));
            Assert.IsNull(eventEndpoint);
            endpoints.Verify(e => e.TryGetConnectionFor(It.IsAny <EndpointId>(), out endpointInfo), Times.Once());
            Assert.IsFalse(entryPoint.KnownEndpoints().Any());
            Assert.IsNull(entryPoint.FromUri(address));

            notifications.Raise(n => n.OnEndpointDisconnected += null, new EndpointEventArgs(endpoint));
            Assert.IsNull(eventEndpoint);
            endpoints.Verify(e => e.TryGetConnectionFor(It.IsAny <EndpointId>(), out endpointInfo), Times.Once());
            Assert.IsFalse(entryPoint.KnownEndpoints().Any());
            Assert.IsNull(entryPoint.FromUri(address));
        }
Example #16
0
        public void IsOnLocalMachine()
        {
            var id = EndpointIdExtensions.CreateEndpointIdForCurrentProcess();

            Assert.IsTrue(id.IsOnLocalMachine());
        }
Example #17
0
 public void DeserializeWithEmptyString()
 {
     Assert.Throws <ArgumentException>(() => EndpointIdExtensions.Deserialize(string.Empty));
 }