Exemplo n.º 1
0
        /// <summary>
        /// Wraps TCP-based bond connection, correspondent proxy and manages their proper disposal
        /// </summary>
        /// <param name="connection">Established bond connection</param>
        /// <param name="proxy">Initialized bond server proxy</param>
        public BondTcpConnection(IOutgoingConnection connection, TProxy proxy)
        {
            Contract.Requires(connection != null);
            Contract.Requires(proxy != null);

            m_connection = connection;
            Proxy        = proxy;
        }
Exemplo n.º 2
0
 public NetMqForwardingClientRqRs(
     IBodyEncoder <TBody> encoder,
     IOutgoingConnection <TPayloadType, TBody> outgoingConnection,
     IConnectionIdGenerator connectionIdGenerator)
 {
     this.connectionId       = connectionIdGenerator.Generate();
     this.encoder            = encoder;
     this.outgoingConnection = outgoingConnection;
 }
Exemplo n.º 3
0
        /// <inheritdoc />
        public void Dispose()
        {
            if (m_connection != null)
            {
                m_connection.Dispose();
                m_connection = null;
            }

            Proxy = null;
        }
 public NetMqClient(
     IBodyEncoder <TBody> encoder,
     IMessageResultMonad <TPayloadType, TBody> messageResultMonad,
     IOutgoingConnection <TPayloadType, TBody> outgoingConnection,
     IConnectionIdGenerator connectionIdGenerator)
 {
     this.encoder            = encoder;
     this.messageResultMonad = messageResultMonad;
     this.outgoingConnection = outgoingConnection;
     this.connectionId       = connectionIdGenerator.Generate();
 }
Exemplo n.º 5
0
 public IncomingMessageProcessor(
     IMessageStore <TPayloadType, TBody, TMsgCtx> messageStore,
     IMessageRouter <TPayloadType, TBody, TMsgCtx> messageRouter,
     IOutgoingConnection <TPayloadType, TBody> outgoingConnection,
     IMessageResultFactory <TBody> messageResultFactory)
 {
     this.buffer               = new MpmcRingBuffer <Message <TPayloadType, TBody> >(0x1000);
     this.outgoingConnection   = outgoingConnection;
     this.messageResultFactory = messageResultFactory;
     this.messageStore         = messageStore;
     this.messageRouter        = messageRouter;
     this.semaphore            = new FastSemaphore(100);
 }
Exemplo n.º 6
0
        public void ApplyInputs_WithValidNetwork_PropogatesNetworkInputs()
        {
            // Arrange
            var network = new DFFNeuralNetwork(1, 1, 2, 2);

            var inputs = new List <INetworkInput>()
            {
                new NetworkInput()
                {
                    ActivationLevel = .75
                }
            };

            network.RandomizeNetwork();

            IInputNeuron        input1            = network.Layers.OfType <IInputLayer>().First().Neurons.First() as IInputNeuron;
            IOutgoingConnection input1Hidden1Conn = input1.Connections.OfType <IOutgoingConnection>().First();
            IOutgoingConnection input1Hidden2Conn = input1.Connections.OfType <IOutgoingConnection>().ToList()[1];

            IHiddenNeuron       hidden1            = input1Hidden1Conn.ToNeuron as IHiddenNeuron;
            IOutgoingConnection hidden1Output1Conn = hidden1.Connections.OfType <IOutgoingConnection>().First();
            IOutgoingConnection hidden1Output2Conn = hidden1.Connections.OfType <IOutgoingConnection>().ToList()[1];

            IHiddenNeuron       hidden2            = input1Hidden2Conn.ToNeuron as IHiddenNeuron;
            IOutgoingConnection hidden2Output1Conn = hidden2.Connections.OfType <IOutgoingConnection>().First();
            IOutgoingConnection hidden2Output2Conn = hidden2.Connections.OfType <IOutgoingConnection>().ToList()[1];

            IOutputNeuron output1 = hidden1Output1Conn.ToNeuron as IOutputNeuron;
            IOutputNeuron output2 = hidden1Output2Conn.ToNeuron as IOutputNeuron;

            // Act
            network.ApplyInputs(inputs);

            var           outputLayer  = network.Layers.OfType <IOutputLayer>().First();
            IOutputNeuron output1After = outputLayer.Neurons.First() as IOutputNeuron;
            IOutputNeuron output2After = outputLayer.Neurons.ToList()[1] as IOutputNeuron;

            // sigmoid function : (1.0 / (1 + Math.Exp(-1.0 * value)));

            var h1Activation = ApplyActivationFunction((.75 * input1Hidden1Conn.Weight) + hidden1.Bias);
            var h2Activation = ApplyActivationFunction((.75 * input1Hidden2Conn.Weight) + hidden2.Bias);
            var o1Activation = ApplyActivationFunction((h1Activation * hidden1Output1Conn.Weight) + (h2Activation * hidden2Output1Conn.Weight) + output1.Bias);
            var o2Activation = ApplyActivationFunction((h1Activation * hidden1Output2Conn.Weight) + (h2Activation * hidden2Output2Conn.Weight) + output2.Bias);

            // Assert
            Assert.IsTrue(o1Activation == output1After.ActivationLevel);
            Assert.IsTrue(o2Activation == output2After.ActivationLevel);
        }
Exemplo n.º 7
0
        private BondTcpConnection <TProxy> OnConnectComplete(
            string server,
            int port,
            CreateProxyCallback createProxyCallback,
            IOutgoingConnection connection,
            SocketError status)
        {
            if (status != SocketError.Success)
            {
                throw new IOException(
                          string.Format(
                              CultureInfo.InvariantCulture,
                              "Failed to connect to {0} ({1})",
                              GetServerDescription(server, port),
                              status));
            }

            var    bondClient = new BondNetlibClient(connection, new BinaryProtocolFactory());
            TProxy proxy      = createProxyCallback(bondClient);

            m_logger.Debug("Connected to {0}", GetServerDescription(server, port));

            return(new BondTcpConnection <TProxy>(connection, proxy));
        }
Exemplo n.º 8
0
        private void SetupUnity()
        {
            try
            {
                var configurationBuilder = new ConfigurationBuilder()
                                           .SetBasePath(Directory.GetCurrentDirectory())
                                           .AddJsonFile("appSettings.json");

                this.container
                .RegisterInstance <
                    IConfigurationRoot>(configurationBuilder.Build())
                .RegisterSingleton <
                    IBodyReconstructorFactory <string>,
                    JsonBodyReconstructorFactory>()
                .RegisterSingleton <
                    IEnvelopFactory <PayloadType, string>,
                    JsonEnvelopeFactory <PayloadType> >()
                .RegisterSingleton <
                    IMessageResultFactory <string>,
                    JsonMessageResultFactory>()
                .RegisterSingleton <
                    IEncoder <PayloadType, string>,
                    StringBodyEncoder <PayloadType> >()
                .RegisterSingleton <
                    IJsonSetting,
                    JsonSettings>()
                .RegisterSingleton <
                    IOutgoingConnection <PayloadType, string>,
                    OutgoingConnection <PayloadType, string> >()
                .RegisterSingleton <
                    IConnectionIdGenerator,
                    ConnectionIdGenerator>()
                .RegisterSingleton <
                    IIncomingMessageBuilder <PayloadType, string>,
                    IncomingMessageBuilder <PayloadType, string> >()
                .RegisterSingleton <
                    IMessageRouter <PayloadType, string, MessageCtx <PayloadType, string> >,
                    MessageRouter <PayloadType, string, MessageCtx <PayloadType, string> > >()
                .RegisterSingleton <
                    IRequestIdGenerator,
                    RequestIdGenerator>()
                .RegisterSingleton <
                    IMessageStore <PayloadType, string, MessageCtx <PayloadType, string> >,
                    InMemoryMessageStore <PayloadType, string, MessageCtx <PayloadType, string> > >()
                .RegisterSingleton <
                    IIncomingMessageHandler <PayloadType, string>,
                    IncomingMessageProcessor <PayloadType, string, MessageCtx <PayloadType, string> > >()
                .RegisterSingleton <IncomingConnection <PayloadType, string, MessageCtx <PayloadType, string> > >()
                .RegisterSingleton <
                    IEncoder <PayloadType, string>,
                    StringBodyEncoder <PayloadType> >()
                .RegisterSingleton <
                    INetMqConfig,
                    NetMqConfig>()
                .RegisterSingleton <
                    IPayloadTypeEncoder <PayloadType, string>,
                    PayloadTypeEncoder>()
                .RegisterSingleton <
                    IMessageSetting,
                    MessagingSetting>()
                ;

                this.outgoingConnection = this.container.Resolve <IOutgoingConnection <PayloadType, string> >();
                this.incomingConnection = this.container
                                          .Resolve <IncomingConnection <PayloadType, string, MessageCtx <PayloadType, string> > >();
                this.incomingMessageHandler = this.container
                                              .Resolve <IIncomingMessageHandler <PayloadType, string> >();
            }
            catch (Exception ex)
            {
                log.Error(ex, ex.Message);
                throw;
            }
        }
 public void Initialize()
 {
     _neuron     = new HiddenNeuron();
     _connection = new OutgoingConnection(_neuron);
 }