public void TestPreconfigured()
        {
            //The idea here is to simulate a setup where are the
            //resources are pre-declared outside the Unicast messaging
            //framework.
            using (IConnection conn = _builder.CreateConnection()) {
                IModel ch = conn.CreateModel();

                //declare exchanges
                DeclareExchange(ch, "in", "fanout");
                DeclareExchange(ch, "out", "direct");

                //declare queue and binding for relay
                DeclareQueue(ch, "relay");
                BindQueue(ch, "relay", "in", "");

                //declare queue and binding for two participants
                DeclareQueue(ch, "foo");
                BindQueue(ch, "foo", "out", "foo");
                DeclareQueue(ch, "bar");
                BindQueue(ch, "bar", "out", "bar");
            }
            //set up participants, send some messages
            MessagingClosure dummy = delegate(IMessaging m) {
                return(delegate(IModel channel) { });
            };

            TestRelayedHelper(dummy, dummy, _builder);
        }
 protected IConnection Connect() {
     lock (this) {
         if (m_connection != null) {
             ShutdownEventArgs closeReason = m_connection.CloseReason;
             if (closeReason == null) return m_connection;
             if (!IsShutdownRecoverable(closeReason))
                 throw new Client.Exceptions.AlreadyClosedException
                     (closeReason);
         }
         OnStateChange(ConnectorState.Reconnecting);
         Exception e = null;
         for (int i = 0; i < Attempts; i++) {
             e = Try(delegate {
                     m_connection = ConnectionBuilder.CreateConnection();
                 });
             if (e == null){
                 OnStateChange(ConnectorState.Connected);
                 return m_connection;
             }
             if (m_closed.WaitOne(Pause)) break;
         }
         throw (e);
     }
 }
Exemplo n.º 3
0
        static async Task EndToEndTest()
        {
            var httpAddress = $"http://localhost/test";
            var tcpAddress  = $"tcp://localhost:9999/tcpTest";

            var host = new ServiceHostBuilder <Service>(InstanceMode.PerConnection)
                       .WithCallback <ICallback>()
                       //add websocket server
                       .AddWebSocketServer(httpAddress, options => options.ReceiveBufferSize = 1024)
                       //add tcp server
                       .AddTcpServer(tcpAddress, options =>
            {
                options.ReceiveBufferSize = 1024;
            })
                       .WithMessagePackSerializer() //it is the default
                       .WithConsoleLogger()         //default is empty
                       .CreateHost();

            host.ServiceInstanceCreated += service =>
            {
                //configure service instances
                Console.WriteLine("Instance created");
            };

            await host.Open();

            Console.WriteLine("Host is open");

            var clientBuilder1 = new DuplexConnectionBuilder <IService, MyCallback>(InstanceMode.PerConnection)
                                 .WithWebSocketTransport(httpAddress, options =>
            {
                //set connection options
                options.ReceiveBufferSize = 1024;
            })
                                 .WithMessagePackSerializer()
                                 .WithConsoleLogger();

            clientBuilder1.CallbackInstanceCreated += obj =>
            {
                Console.WriteLine($"Created callback of type {obj.GetType()}");
                var callback = (MyCallback)obj;
                //config the callback instance
            };

            var client1 = await clientBuilder1.CreateConnection();

            var client2 = await clientBuilder1.CreateConnection();

            var msg = await client1.Echo("From Client 1");

            Console.WriteLine(msg);

            msg = await client2.Echo("From Client 2");

            Console.WriteLine(msg);

            msg = await client1.CallMeBack();

            Console.WriteLine(msg);

            var client3 = await clientBuilder1.CreateConnection();

            client3.FireAndForget("server is here now");
            Console.WriteLine("client3 is here now"); //this should appear first

            var clientBuilder2 = new ConnectionBuilder <IOtherService>()
                                 .WithWebSocketTransport(httpAddress)
                                 .WithConsoleLogger();

            var client4 = await clientBuilder2.CreateConnection();

            msg = await client4.Echo("It is another Echo"); //another interface same Echo signature

            Console.WriteLine(msg);

            await Task.Delay(6000);

            Console.WriteLine("now with tcp");

            var tcpCient = await new DuplexConnectionBuilder <IService, MyCallback>(InstanceMode.Single)
                           .WithTcpTransport(tcpAddress)
                           .WithConsoleLogger()
                           .CreateConnection();

            msg = await tcpCient.Echo("From TCP Client");

            Console.WriteLine(msg);

            await tcpCient.CallMeBack();

            //how to close connection, the listening will show exception that has no effect
            //await ((IConnection)client4).Close();
        }
Exemplo n.º 4
0
        static void InitDb()
        {
            var    dbConnection = ConnectionBuilder.CreateConnection();
            string sql          = @"CREATE TABLE T_Admin(
	                            ID INTEGER PRIMARY KEY,
	                            UserName VARCHAR(32) NOT NULL,
	                            Password VARCHAR(32) NOT NULL,
	                            Mobile VARCHAR(11),
	                            Email VARCHAR(200),
	                            Realname NVARCHAR(50),
	                            IsDisable INT DEFAULT(0),
	                            CreateTime DATETIME NOT NULL DEFAULT(GETDATE())
                            )";

            dbConnection.Execute(sql);

            sql = @"CREATE TABLE T_AdminLog(
	                            ID INTEGER PRIMARY KEY,
	                            AdminID INT NOT NULL,
	                            Title NVARCHAR(255),
	                            Content Text,
	                            IP VARCHAR(50),
	                            CreateTime DATETIME NOT NULL DEFAULT(GETDATE())
                            )";
            dbConnection.Execute(sql);

            sql = @"CREATE TABLE T_SystemConfig(
	                            ID INTEGER PRIMARY KEY,
	                            Name NVARCHAR(50),
	                            Code VARCHAR(50) NOT NULL,
	                            Value Text,
	                            CreateTime DATETIME NOT NULL DEFAULT(GETDATE())
                            )";
            dbConnection.Execute(sql);

            sql = @"CREATE TABLE T_ImgPlay(
	                            ID INTEGER PRIMARY KEY,
	                            NavigationID INT NOT NULL,
	                            Type INT NOT NULL DEFAULT(0),
	                            Name NVARCHAR(500),
	                            Title NVARCHAR(500),
                                Subhead nVARCHAR(20),
	                            ImgUrl NVARCHAR(500),
	                            LinkUrl NVARCHAR(500),
	                            Target INT NOT NULL DEFAULT(0),
	                            IsDisable INT DEFAULT(0),
	                            Sort INT NOT NULL DEFAULT(0),
	                            CreateTime DATETIME NOT NULL DEFAULT(GETDATE())
                            )";
            dbConnection.Execute(sql);

            sql = @"CREATE TABLE T_FriendlyLink(
	                            ID INTEGER PRIMARY KEY,
	                            Type INT NOT NULL DEFAULT(0),
	                            Name NVARCHAR(500),
	                            Title NVARCHAR(500),
	                            ImgUrl NVARCHAR(500),
	                            LinkUrl NVARCHAR(500),
	                            Target INT NOT NULL DEFAULT(0),
	                            IsDisable INT DEFAULT(0),
	                            Sort INT NOT NULL DEFAULT(0),
	                            CreateTime DATETIME NOT NULL DEFAULT(GETDATE())
                            )";
            dbConnection.Execute(sql);

            sql = @"CREATE TABLE T_Navigation(
	                            ID INTEGER PRIMARY KEY,
	                            Type INT NOT NULL DEFAULT(0),
	                            ParentId INT NOT NULL,
	                            Name NVARCHAR(500),
	                            Url NVARCHAR(500),
	                            Target INT NOT NULL DEFAULT(0),
	                            IsDisable INT DEFAULT(0),
	                            CanDisable INT DEFAULT(0),
	                            Sort INT NOT NULL DEFAULT(0),
	                            CreateTime DATETIME NOT NULL DEFAULT(GETDATE())
                        )";
            dbConnection.Execute(sql);

            sql = @"CREATE TABLE T_Category(
	                            ID INTEGER PRIMARY KEY,
	                            ParentId INT NOT NULL,
	                            ParentIdPath NVARCHAR(255) NOT NULL,
	                            Name NVARCHAR(500),
	                            ImgUrl NVARCHAR(500),
	                            IsDisable INT DEFAULT(0),
	                            Sort INT NOT NULL DEFAULT(0),
	                            CreateTime DATETIME NOT NULL DEFAULT(GETDATE())
                        )";
            dbConnection.Execute(sql);

            sql = @"CREATE TABLE T_News(
	                        ID INTEGER PRIMARY KEY,
	                        CategoryId INT NOT NULL,

	                        Title NVARCHAR(500),
	                        ImgUrl NVARCHAR(500),
	                        Author NVARCHAR(50),
	                        Summary NVARCHAR(500),
	                        Source NVARCHAR(500),
	                        Content Text,
	                        ReleaseTime DATETIME,
	                        ViewCount BIGINT NOT NULL DEFAULT(0),
	                        MetaKeywords NVARCHAR(500),
	                        MetaDescription  NVARCHAR(500),
	 
	                        IsDisable INT DEFAULT(0),
	                        Sort INT NOT NULL DEFAULT(0),
	                        CreateTime DATETIME NOT NULL DEFAULT(GETDATE()),
	                        CreateAdminId INT NOT NULL DEFAULT(0),
	                        UpdateTime DATETIME NOT NULL,
	                        UpdateAdminId  INT NOT NULL DEFAULT(0)
                        )";
            dbConnection.Execute(sql);

            sql = @"CREATE TABLE T_PageContent(
	                        ID INTEGER PRIMARY KEY,
                            ContentType INT NOT NULL DEFAULT(0),
	                        NavigationID INT NOT NULL,
	                        Title nVARCHAR(500),
	                        Content Text,
	                        ImgUrl NVARCHAR(500),
	                        IconCode VARCHAR(100),
                            IsHomePageShows INT NOT NULL DEFAULT(0),
	                        SectionName nVARCHAR(20),
	                        Subhead nVARCHAR(20),
	                        IsDisable INT DEFAULT(0),
	                        Sort INT NOT NULL DEFAULT(0),
	                        CreateTime DATETIME NOT NULL DEFAULT(GETDATE()),
	                        UpdateTime DATETIME NOT NULL
                        )";
            dbConnection.Execute(sql);

            sql = @"CREATE TABLE T_Recruitment(
	                        ID INTEGER PRIMARY KEY,
	                        JobTitle nVARCHAR(100),
	                        Location nVARCHAR(20),
	                        Salary VARCHAR(20),
	                        RecruitingNum INT,
	                        JobDescription Text,

	                        Sort INT NOT NULL DEFAULT(0),

	                        CreateTime DATETIME NOT NULL DEFAULT(GETDATE()),
	                        CreateAdminId INT NOT NULL DEFAULT(0),
	                        UpdateTime DATETIME NOT NULL,
	                        UpdateAdminId  INT NOT NULL DEFAULT(0)
                        )";
            dbConnection.Execute(sql);

            sql = @"CREATE TABLE T_OwnerInfo(
	                        ID INTEGER PRIMARY KEY,
	                        Name NVARCHAR(500),
                            LinkMan VARCHAR(200),
	                        Email VARCHAR(200),
	                        Mobile NVARCHAR(500),
	                        Address  NVARCHAR(500),
	                        MapIFrameUrl Text,
	                        CreateTime DATETIME NOT NULL DEFAULT(GETDATE())
                        )";
            dbConnection.Execute(sql);
        }