Exemplo n.º 1
0
        public static void Run(string clientVersion)
        {
            // server
            using (var server = new Server()) {
                server.Run();

                // client
                var assembly = Assembly.GetExecutingAssembly();
                var assemblyLocation = Path.GetDirectoryName(assembly.Location);
                var basePath = Path.Combine(assemblyLocation, clientVersion);

                Extensions.RunInDomain(Client.Run, basePath: basePath);
            }
        }
        protected virtual void Dispose(bool disposing)
        {
            if (!_disposed)
            {
                if (disposing)
                {
                    if (Server != null)
                        Server.ConnectionContext.Disconnect();
                }

                Server = null;
                _disposed = true;

                SqlConnection.ClearAllPools();
            }
        }
 private void createServerInstance()
 {
     Server = new Server();
     Server.ConnectionContext.ConnectionString = string.Format(StringConnection, "master");
 }
Exemplo n.º 4
0
        public void ServerRegisterMsgTest()
        {
            int port = 22222;
            Server srv = new Server(port, new TimeSpan(0, 0, 10));
            Task t = Task.Factory.StartNew(srv.Start);
            byte[] data = new Register(NodeType.ComputationalNode, 1, new List<string>() { "test1", "test2" }).GetXmlData();
            byte[] bytes = null;
            XMLParser parser = null;
            // *** Valid port and address ***
            NetworkClient nc = new NetworkClient("localhost", port);
            NetworkClient nc2 = new NetworkClient("localhost", port);

            Assert.IsNotNull(srv);
            Assert.IsNotNull(nc);
            Assert.IsNotNull(nc2);

            // first cli
            bytes = nc.Work(data);

            Assert.IsNotNull(bytes);

            parser = new XMLParser(bytes);

            Assert.IsNotNull(parser);
            Assert.AreEqual(parser.MessageType, MessageTypes.RegisterResponse);

            // first cli, trying to connect second time
            bytes = nc.Work(data);

            Assert.IsNotNull(bytes);

            parser = new XMLParser(bytes);

            Assert.IsNotNull(parser);
            Assert.AreEqual(parser.MessageType, MessageTypes.RegisterResponse);

            // second cli
            bytes = nc2.Work(data);

            Assert.IsNotNull(bytes);

            parser = new XMLParser(bytes);

            Assert.IsNotNull(parser);
            Assert.AreEqual(parser.MessageType, MessageTypes.RegisterResponse);

            srv.Stop();
            t.Wait();

            // *** Valid port and address (srv is stopped)
            bytes = nc.Work(data);

            Assert.IsNull(bytes);

            // *** invalid port number ***
            srv = new Server(-1, new TimeSpan(0, 0, 10));
            t = Task.Factory.StartNew(srv.Start);

            bytes = nc.Work(data);

            Assert.IsNull(bytes);

            srv.Stop();
            t.Wait();
        }