Exemplo n.º 1
0
        public void Start()
        {
            _layerFactory                 = new OwinHandlerFactory(_parameters.OwinApp, _parameters.OwinCapabilities);
            _ipIsLocalChecker             = new IpIsLocalChecker();
            _connectionAllocationStrategy = _parameters.ConnectionAllocationStrategy;
            var isSsl = _parameters.Certificate != null;

            _layerFactory = new Transport2HttpFactory(_parameters.BufferSize, isSsl, _parameters.ServerHeader, _ipIsLocalChecker, _layerFactory);
            if (isSsl)
            {
                _layerFactory = new SslTransportFactory(_parameters, _layerFactory);
            }
            ListenSocket = new Socket(_parameters.EndPoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
            var start = DateTime.UtcNow;

            while (true)
            {
                try
                {
                    ListenSocket.Bind(_parameters.EndPoint);
                    break;
                }
                catch when(start + _parameters.RetrySocketBindingTime > DateTime.UtcNow)
                {
                }
                Thread.Sleep(50);
            }
            ListenSocket.Listen(100);
            var initialConnectionCount = _connectionAllocationStrategy.CalculateNewConnectionCount(0, 0);

            AllocatedConnections = initialConnectionCount;
            _blocks.Add(new ConnectionBlock(this, _layerFactory, initialConnectionCount));
        }
Exemplo n.º 2
0
 public SslTransportFactory(X509Certificate certificate, SslProtocols protocols, ILayerFactory next, bool clientCertificateRequired)
 {
     _certificate = certificate;
     _protocols = protocols;
     _clientCertificateRequired = clientCertificateRequired;
     _next = next;
 }
Exemplo n.º 3
0
 public void Start()
 {
     _layerFactory = new OwinHandlerFactory(_parameters.OwinApp, _parameters.OwinCapabilities);
     _ipIsLocalChecker = new IpIsLocalChecker();
     _connectionAllocationStrategy = _parameters.ConnectionAllocationStrategy;
     var isSsl = _parameters.Certificate != null;
     _layerFactory = new Transport2HttpFactory(_parameters.BufferSize, isSsl, _parameters.ServerHeader, _ipIsLocalChecker, _layerFactory);
     if (isSsl)
     {
         _layerFactory = new SslTransportFactory(_parameters, _layerFactory);
     }
     ListenSocket = new Socket(_parameters.EndPoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
     var start = DateTime.UtcNow;
     while (true)
     {
         try
         {
             ListenSocket.Bind(_parameters.EndPoint);
             break;
         }
         catch when(start + _parameters.RetrySocketBindingTime > DateTime.UtcNow)
         {
         }
         Thread.Sleep(50);
     }
     ListenSocket.Listen(100);
     var initialConnectionCount = _connectionAllocationStrategy.CalculateNewConnectionCount(0, 0);
     AllocatedConnections = initialConnectionCount;
     _blocks.Add(new ConnectionBlock(this, _layerFactory, initialConnectionCount));
 }
Exemplo n.º 4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="DrawingContextImpl"/> class.
        /// </summary>
        /// <param name="visualBrushRenderer">The visual brush renderer.</param>
        /// <param name="renderTarget">The render target to draw to.</param>
        /// <param name="layerFactory">
        /// An object to use to create layers. May be null, in which case a
        /// <see cref="WicRenderTargetBitmapImpl"/> will created when a new layer is requested.
        /// </param>
        /// <param name="swapChain">An optional swap chain associated with this drawing context.</param>
        /// <param name="finishedCallback">An optional delegate to be called when context is disposed.</param>
        public DrawingContextImpl(
            IVisualBrushRenderer visualBrushRenderer,
            ILayerFactory layerFactory,
            SharpDX.Direct2D1.RenderTarget renderTarget,
            SharpDX.DXGI.SwapChain1 swapChain = null,
            Action finishedCallback           = null)
        {
            _visualBrushRenderer = visualBrushRenderer;
            _layerFactory        = layerFactory;
            _renderTarget        = renderTarget;
            _swapChain           = swapChain;
            _finishedCallback    = finishedCallback;

            if (_renderTarget is DeviceContext deviceContext)
            {
                _deviceContext     = deviceContext;
                _ownsDeviceContext = false;
            }
            else
            {
                _deviceContext     = _renderTarget.QueryInterface <DeviceContext>();
                _ownsDeviceContext = true;
            }

            _deviceContext.BeginDraw();
        }
Exemplo n.º 5
0
        private void loadLayer()
        {
            DialogResult result = AddLayerDialog.ShowDialog(this);

            if (result == DialogResult.OK)
            {
                foreach (string fileName in AddLayerDialog.FileNames)
                {
                    string        extension    = Path.GetExtension(fileName);
                    ILayerFactory layerFactory = null;

                    if (!_layerFactoryCatalog.TryGetValue(extension, out layerFactory))
                    {
                        continue;
                    }

                    ILayer layer = layerFactory.Create(Path.GetFileNameWithoutExtension(fileName), fileName);

                    addLayer(layer);
                }

                changeUIOnLayerSelectionChange();

                MainMapImage.Refresh();
            }
        }
Exemplo n.º 6
0
 public Transport2HttpFactory(int receiveBufferSize, bool isSsl, IIpIsLocalChecker ipIsLocalChecker, ILayerFactory next)
 {
     _receiveBufferSize = receiveBufferSize;
     _isSsl = isSsl;
     _ipIsLocalChecker = ipIsLocalChecker;
     _next = next;
     _charBuffer = new ThreadLocal<char[]>(()=>new char[receiveBufferSize]);
     PerConnectionBufferSize = MyPerConnectionBufferSize() + _next.PerConnectionBufferSize;
 }
Exemplo n.º 7
0
        public Engine(ILogger logger, ILayerFactory layerFactory, ILayerDetailsService layerDetailsService, ILayerNameInfoService layerNameInfoService)
        {
            _logger               = logger;
            _layerFactory         = layerFactory;
            _layerDetailsService  = layerDetailsService;
            _layerNameInfoService = layerNameInfoService;

            _layers = new Dictionary <string, Layer>();
        }
Exemplo n.º 8
0
 public Transport2HttpFactory(int receiveBufferSize, bool isSsl, string serverName, IIpIsLocalChecker ipIsLocalChecker, ILayerFactory next)
 {
     _receiveBufferSize = receiveBufferSize;
     _isSsl             = isSsl;
     _serverName        = serverName;
     _ipIsLocalChecker  = ipIsLocalChecker;
     _next                   = next;
     _charBuffer             = new ThreadLocal <char[]>(() => new char[receiveBufferSize]);
     PerConnectionBufferSize = MyPerConnectionBufferSize() + _next.PerConnectionBufferSize;
 }
Exemplo n.º 9
0
 internal ConnectionBlock(Server server, ILayerFactory layerFactory, int connectionCount)
 {
     _connections = new SaeaLayerCallback[connectionCount];
     var perConnectionBufferSize = layerFactory.PerConnectionBufferSize;
     var reserveAtEnd = layerFactory.CommonBufferSize;
     var constantsOffset = checked(connectionCount * perConnectionBufferSize);
     var buffer = new byte[checked(constantsOffset + reserveAtEnd)];
     layerFactory.InitCommonBuffer(buffer, constantsOffset);
     for (var i = 0; i < connectionCount; i++)
     {
         var handler = (ITransportLayerHandler)layerFactory.Create(buffer, i * perConnectionBufferSize, constantsOffset, i);
         var callback = new SaeaLayerCallback(handler, server.ListenSocket, server, i, server.ContextFlow);
         _connections[i] = callback;
         handler.PrepareAccept();
     }
 }
Exemplo n.º 10
0
        internal ConnectionBlock(Server server, ILayerFactory layerFactory, int connectionCount)
        {
            _connections = new SaeaLayerCallback[connectionCount];
            var perConnectionBufferSize = layerFactory.PerConnectionBufferSize;
            var reserveAtEnd            = layerFactory.CommonBufferSize;
            var constantsOffset         = checked (connectionCount * perConnectionBufferSize);
            var buffer = new byte[checked (constantsOffset + reserveAtEnd)];

            layerFactory.InitCommonBuffer(buffer, constantsOffset);
            for (var i = 0; i < connectionCount; i++)
            {
                var handler  = (ITransportLayerHandler)layerFactory.Create(buffer, i * perConnectionBufferSize, constantsOffset, i);
                var callback = new SaeaLayerCallback(handler, server.ListenSocket, server, i, server.ContextFlow);
                _connections[i] = callback;
                handler.PrepareAccept();
            }
        }
Exemplo n.º 11
0
        public static ILayer LoadLayer(string filename)
        {
            Logger.Debug("Attempting to load Map Layer from file '{0}'", filename);

            string        extension    = System.IO.Path.GetExtension(filename);
            ILayerFactory layerFactory = null;

            if (!_layerFactoryCatalog.TryGetValue(extension.ToLower(), out layerFactory))
            {
                Logger.Debug("No appropriate layer factory could be found for file '{0}'", filename);
                return(null);
            }

            ILayer layer = layerFactory.Create(System.IO.Path.GetFileNameWithoutExtension(filename), filename);

            return(layer);
        }
Exemplo n.º 12
0
 public void Start()
 {
     _layerFactory = new OwinHandlerFactory(_parameters.OwinApp, _parameters.OwinCapabilities);
     _ipIsLocalChecker = new IpIsLocalChecker();
     _connectionAllocationStrategy = _parameters.ConnectionAllocationStrategy;
     var isSsl = _parameters.Certificate != null;
     _layerFactory = new Transport2HttpFactory(_parameters.BufferSize, isSsl, _ipIsLocalChecker, _layerFactory);
     if (isSsl)
     {
         _layerFactory = new SslTransportFactory(_parameters.Certificate, _layerFactory);
     }
     ListenSocket = new Socket(_parameters.EndPoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
     ListenSocket.Bind(_parameters.EndPoint);
     ListenSocket.Listen(100);
     var initialConnectionCount = _connectionAllocationStrategy.CalculateNewConnectionCount(0, 0);
     AllocatedConnections = initialConnectionCount;
     _blocks.Add(new ConnectionBlock(this, _layerFactory, initialConnectionCount));
 }
Exemplo n.º 13
0
 /// <summary>
 /// Initializes a new instance of the <see cref="DrawingContextImpl"/> class.
 /// </summary>
 /// <param name="visualBrushRenderer">The visual brush renderer.</param>
 /// <param name="renderTarget">The render target to draw to.</param>
 /// <param name="layerFactory">
 /// An object to use to create layers. May be null, in which case a
 /// <see cref="WicRenderTargetBitmapImpl"/> will created when a new layer is requested.
 /// </param>
 /// <param name="directWriteFactory">The DirectWrite factory.</param>
 /// <param name="imagingFactory">The WIC imaging factory.</param>
 /// <param name="swapChain">An optional swap chain associated with this drawing context.</param>
 /// <param name="finishedCallback">An optional delegate to be called when context is disposed.</param>
 public DrawingContextImpl(
     IVisualBrushRenderer visualBrushRenderer,
     ILayerFactory layerFactory,
     SharpDX.Direct2D1.RenderTarget renderTarget,
     SharpDX.DirectWrite.Factory directWriteFactory,
     SharpDX.WIC.ImagingFactory imagingFactory,
     SharpDX.DXGI.SwapChain1 swapChain = null,
     Action finishedCallback           = null)
 {
     _visualBrushRenderer = visualBrushRenderer;
     _layerFactory        = layerFactory;
     _renderTarget        = renderTarget;
     _swapChain           = swapChain;
     _finishedCallback    = finishedCallback;
     _directWriteFactory  = directWriteFactory;
     _imagingFactory      = imagingFactory;
     _renderTarget.BeginDraw();
 }
Exemplo n.º 14
0
        private void OpenToolStripButton_Click(object sender, EventArgs e)
        {
            DialogResult result = OpenProjectFileDialog.ShowDialog(this);

            if (result == DialogResult.OK)
            {
                prj = osgGISProjects.XmlSerializer.loadProject(OpenProjectFileDialog.FileName);

                foreach (osgGISProjects.Source source in prj.getSources())
                {
                    string filename = source.getURI();

                    ILayerFactory layerFactory = null;
                    if (!_layerFactoryCatalog.TryGetValue(Path.GetExtension(filename), out layerFactory))
                    {
                        continue;
                    }
                    ILayer layer = layerFactory.Create(Path.GetFileNameWithoutExtension(filename), filename);
                    addLayer(layer);
                }
            }
        }
        public void NetworkConstructorTest()
        {
            //given
            ILayer        firstLayer   = MockRepository.GenerateMock <ILayer>();
            ILayer        secondLayer  = MockRepository.GenerateMock <ILayer>();
            ILayerFactory layerFactory = MockRepository.GenerateMock <ILayerFactory>();

            layerFactory.Stub(lf => lf.ConstructLayer(
                                  Arg <double> .Is.Anything, Arg <int> .Is.Anything, Arg <int> .Is.Anything,
                                  Arg <string> .Is.Equal("First"))
                              ).Return(firstLayer);
            layerFactory.Stub(lf => lf.ConstructLayer(
                                  Arg <double> .Is.Anything, Arg <int> .Is.Anything, Arg <int> .Is.Anything,
                                  Arg <string> .Is.Equal("Second"))
                              ).Return(secondLayer);
            List <LayerDescription> layersDescriptions = new List <LayerDescription>
            {
                new LayerDescription {
                    Bias = 1.0, LayerFactory = layerFactory, Name = "First", NeuronNumber = 4
                },
                new LayerDescription {
                    Bias = 1.0, LayerFactory = layerFactory, Name = "Second", NeuronNumber = 6
                }
            };
            List <ILayer> expectedLayers = new List <ILayer> {
                firstLayer, secondLayer
            };

            //when
            Network network = new Network(2, layersDescriptions);

            //then
            CollectionAssert.AreEqual(expectedLayers, network.Layers);
            layerFactory.AssertWasCalled(lf => lf.ConstructLayer(Arg <double> .Is.Equal(1.0), Arg <int> .Is.Equal(2), Arg <int> .Is.Equal(4), Arg <string> .Is.Equal("First")));
            layerFactory.AssertWasCalled(lf => lf.ConstructLayer(Arg <double> .Is.Equal(1.0), Arg <int> .Is.Equal(4), Arg <int> .Is.Equal(6), Arg <string> .Is.Equal("Second")));
        }
Exemplo n.º 16
0
 internal SslTransportFactory(IServerParameters serverParameters, ILayerFactory next)
 {
     _serverParameters = serverParameters;
     _next = next;
 }
        public void NetworkComputeTest()
        {
            //given
            ILayer firstLayer = MockRepository.GenerateMock <ILayer>();
            List <List <double> > firstLayerResults = new List <List <double> >
            {
                new List <double> {
                    1.0, 2.0, 3.0, 4.0
                },
                new List <double> {
                    1.0, 2.0, 3.0, 4.0
                },
                new List <double> {
                    1.0, 2.0, 3.0, 4.0
                },
                new List <double> {
                    1.0, 2.0, 3.0, 4.0
                },
            };

            firstLayer.Stub(layer => layer.Compute(Arg <IEnumerable <IEnumerable <double> > > .Is.Anything, Arg <int> .Is.Anything)).Return(firstLayerResults);
            firstLayer.Stub(layer => layer.Neurons).Return(new List <INeuron>
            {
                MockRepository.GenerateMock <INeuron>(),
                MockRepository.GenerateMock <INeuron>(),
                MockRepository.GenerateMock <INeuron>(),
                MockRepository.GenerateMock <INeuron>()
            });
            List <double> secondLayerResults = new List <double> {
                1.0, 2.0, 3.0, 4.0, 5.0, 6.0
            };
            ILayer secondLayer = MockRepository.GenerateMock <ILayer>();

            secondLayer.Stub(layer => layer.Compute(Arg <IEnumerable <IEnumerable <double> > > .Is.Anything)).Return(secondLayerResults);
            secondLayer.Stub(layer => layer.Neurons).Return(new List <INeuron>
            {
                MockRepository.GenerateMock <INeuron>(),
                MockRepository.GenerateMock <INeuron>(),
                MockRepository.GenerateMock <INeuron>(),
                MockRepository.GenerateMock <INeuron>(),
                MockRepository.GenerateMock <INeuron>(),
                MockRepository.GenerateMock <INeuron>(),
            });
            int           expectedNeuronNumber = secondLayer.Neurons.Count();
            ILayerFactory layerFactory         = MockRepository.GenerateMock <ILayerFactory>();

            layerFactory.Stub(lf => lf.ConstructLayer(
                                  Arg <double> .Is.Anything, Arg <int> .Is.Anything, Arg <int> .Is.Anything,
                                  Arg <string> .Is.Equal("First"))
                              ).Return(firstLayer);
            layerFactory.Stub(lf => lf.ConstructLayer(
                                  Arg <double> .Is.Anything, Arg <int> .Is.Anything, Arg <int> .Is.Anything,
                                  Arg <string> .Is.Equal("Second"))
                              ).Return(secondLayer);
            List <List <double> > inputs = new List <List <double> > {
                new List <double> {
                    1.0, 2.0
                }, new List <double> {
                    1.0, 2.0
                }
            };
            List <LayerDescription> layersDescriptions = new List <LayerDescription>
            {
                new LayerDescription {
                    Bias = 1.0, LayerFactory = layerFactory, Name = "First", NeuronNumber = 4
                },
                new LayerDescription {
                    Bias = 1.0, LayerFactory = layerFactory, Name = "Second", NeuronNumber = 6
                }
            };
            Network network = new Network(2, layersDescriptions);

            //when
            List <double> results = network.Compute(inputs).ToList();

            //then
            CollectionAssert.AreEqual(secondLayerResults, results);
            firstLayer.AssertWasCalled(layer => layer.Compute(Arg <IEnumerable <IEnumerable <double> > > .Is.Equal(inputs), Arg <int> .Is.Equal(expectedNeuronNumber)));
            secondLayer.AssertWasCalled(layer => layer.Compute(Arg <IEnumerable <IEnumerable <double> > > .Is.Equal(firstLayerResults)));
        }
Exemplo n.º 18
0
 public SslTransportFactory(X509Certificate certificate, SslProtocols protocols, ILayerFactory next)
 {
     _certificate = certificate;
     _protocols = protocols;
     _next = next;
 }
Exemplo n.º 19
0
 public SslTransportFactory(X509Certificate certificate, ILayerFactory next)
 {
     _certificate = certificate;
     _next        = next;
 }
Exemplo n.º 20
0
 public SslTransportFactory(X509Certificate certificate, ILayerFactory next)
 {
     _certificate = certificate;
     _next = next;
 }
Exemplo n.º 21
0
 public SslTransportFactory(X509Certificate certificate, SslProtocols protocols, ILayerFactory next)
 {
     _certificate = certificate;
     _protocols   = protocols;
     _next        = next;
 }
Exemplo n.º 22
0
 internal SslTransportFactory(IServerParameters serverParameters, ILayerFactory next)
 {
     _serverParameters = serverParameters;
     _next             = next;
 }