Exemplo n.º 1
0
        public void By_default_token_parser_is_the_configured_template_parser(IContainer container)
        {
            "Given we have bootstraped the IoC"
            ._(() => container = BootStrap.Start());

            "Then it should resolve the token template parser"
            ._(() => container.Resolve <ITemplateParser>().Should().BeOfType <TokenTemplateParser>());
        }
 private void Window_Loaded(object sender, RoutedEventArgs e)
 {
     BootStrap.Start();
     worker = new BackgroundWorker();
     worker.WorkerReportsProgress = true;
     worker.DoWork             += worker_DoWork;
     worker.ProgressChanged    += worker_ProgressChanged;
     worker.RunWorkerCompleted += worker_RunWorkerCompleted;
     worker.RunWorkerAsync();
 }
Exemplo n.º 3
0
        private bool TestMaxConnectionNumber(int maxConnectionNumber)
        {
            var configSource = SetupBootstrap(DefaultServerConfig, new Func<IServerConfig, IServerConfig>(c =>
                {
                    var nc = new ServerConfig(c);
                    nc.MaxConnectionNumber = maxConnectionNumber;
                    return nc;
                }));

            BootStrap.Start();

            var config = configSource.Servers.FirstOrDefault();
            EndPoint serverAddress = new IPEndPoint(IPAddress.Parse("127.0.0.1"), config.Port);

            List<Socket> sockets = new List<Socket>();

            var server = BootStrap.AppServers.FirstOrDefault();

            try
            {
                for (int i = 0; i < maxConnectionNumber; i++)
                {
                    Socket socket = CreateClientSocket();
                    socket.Connect(serverAddress);
                    Stream socketStream = GetSocketStream(socket);
                    StreamReader reader = new StreamReader(socketStream, m_Encoding, true);
                    reader.ReadLine();
                    sockets.Add(socket);
                }

                Assert.AreEqual(maxConnectionNumber, server.SessionCount);

                Assert.IsFalse(TryConnect(serverAddress));

                sockets[0].SafeClose();

                Thread.Sleep(500);

                Assert.AreEqual(maxConnectionNumber - 1, server.SessionCount);

                return TryConnect(serverAddress);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message + " " + e.StackTrace);
                throw e;
            }
            finally
            {
                ClearBootstrap();
            }
        }
Exemplo n.º 4
0
        public void command_module_registration(IContainer container)
        {
            "Given we have bootstraped the IoC"
            ._(() => container = BootStrap.Start());

            "Then it should resolve the help command"
            ._(() => container.Resolve <IEnumerable <ICraneCommand> >().Any(item => item.GetType() == typeof(Help)).Should().BeTrue());

            "And it should be a singleton instance" // Is there a better way to verify lifecycle in Autofac?
            ._(
                () =>
                ReferenceEquals(container.Resolve <IEnumerable <ICraneCommand> >().First(item => item.GetType() == typeof(Help)),
                                container.Resolve <IEnumerable <ICraneCommand> >().First(item => item.GetType() == typeof(Help)))
                .Should().BeTrue());
        }
Exemplo n.º 5
0
        public void Xml_help_provider_is_configured_as_the_default_help_provider(IContainer container)
        {
            "Given we have bootstraped the IoC"
            ._(() => container = BootStrap.Start());

            "Then it should resolve the help provider to be an xml help provider"
            ._(() => container.Resolve <IHelpProvider>().Should().BeOfType <XmlHelpProvider>());

            "And it should be a singleton instance" // Is there a better way to verify lifecycle in Autofac?
            ._(
                () =>
                ReferenceEquals(container.Resolve <IHelpProvider>(),
                                container.Resolve <IHelpProvider>())
                .Should().BeTrue());
        }
Exemplo n.º 6
0
        static void Main(string[] args)
        {
            try
            {
                var prop = ApplicationArguments.Parse(args);
                if (prop.PrintHelp)
                {
                    return;
                }

                var bootstrap = new BootStrap(prop);
                bootstrap.Start();

                var program = new Program(bootstrap);
                program.Run();
            }
            catch (Exception ex)
            {
                Console.Error.WriteLine(ex.Message);
                Console.Error.WriteLine(ex.StackTrace);
            }
        }
Exemplo n.º 7
0
        public IHost CreateConsoleHost()
        {
            var container = BootStrap.Start();

            return(container.Resolve <IHost>());
        }
Exemplo n.º 8
0
        public void TestSessionConnectedState()
        {
            byte[] data = new byte[] { 0xff, 0xff, 0xff, 0xf0 };

            Console.WriteLine(BitConverter.ToInt32(data, 0));

            var configSource = SetupBootstrap(DefaultServerConfig);

            if (configSource.Isolation != IsolationMode.None)
                return;

            var serverConfig = configSource.Servers.FirstOrDefault();
            EndPoint serverAddress = new IPEndPoint(IPAddress.Parse("127.0.0.1"), serverConfig.Port);

            BootStrap.Start();

            var server = BootStrap.AppServers.FirstOrDefault() as IAppServer;

            using (Socket socket = CreateClientSocket())
            {
                socket.Connect(serverAddress);
                Stream socketStream = GetSocketStream(socket);
                using (StreamReader reader = new StreamReader(socketStream, m_Encoding, true))
                using (ConsoleWriter writer = new ConsoleWriter(socketStream, m_Encoding, 1024 * 8))
                {
                    reader.ReadLine();
                    writer.WriteLine("SESS");
                    writer.Flush();

                    var sessionID = reader.ReadLine();
                    var session = server.GetSessionByID(sessionID);

                    if (session == null)
                        Assert.Fail("Failed to get session by sessionID");

                    Assert.IsTrue(session.Connected);

                    try
                    {
                        socket.Shutdown(SocketShutdown.Both);
                    }
                    catch { }
                    finally
                    {
                        try
                        {
                            socket.Close();
                        }
                        catch { }
                    }

                    while (true)
                    {
                        Thread.Sleep(5000);

                        if (!session.Connected)
                            break;
                    }
                }
            }
        }