当前位置: 首页>>代码示例>>C#>>正文


C# Connection.CreateSession方法代码示例

本文整理汇总了C#中Connection.CreateSession方法的典型用法代码示例。如果您正苦于以下问题:C# Connection.CreateSession方法的具体用法?C# Connection.CreateSession怎么用?C# Connection.CreateSession使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Connection的用法示例。


在下文中一共展示了Connection.CreateSession方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: FixtureSetup

        public void FixtureSetup()
        {
            _cx = ConnectionTests.CreateConnection();
            if (_cx.ListDatabases().Contains("relax-reference-tests"))
            {
                _cx.DeleteDatabase("relax-reference-tests");
            }
            _cx.CreateDatabase("relax-reference-tests");
            _sx = _cx.CreateSession("relax-reference-tests");
            _sx2 = _cx.CreateSession("relax-reference-tests");

            _sx.Save(new Widget { Id = "w1", Name = "Widget", Cost = 30 });
            _sx.Save(new Widget { Id = "w2", Name = "Gadget", Cost = 30 });
            _sx.Save(new Widget { Id = "w3", Name = "Foo",    Cost = 35 });
            _sx.Save(new Widget { Id = "w4", Name = "Bar",    Cost = 35 });
            _sx.Save(new Widget { Id = "w5", Name = "Biz",    Cost = 45 });
            _sx.Save(new Widget { Id = "w6", Name = "Bang",   Cost = 55 });
            
            _sx.SaveRaw(JObject.Parse(
            @"{
                _id: 'g1',
                Name: 'Gadget #1',
                Primary: 'w1'
            }"));
            
            _sx.SaveRaw(JObject.Parse(
            @"{
                _id: 'g2',
                Name: 'Gadget #1',
                Secondary: ['w1', 'w2', 'w3']
            }"));

        }
开发者ID:nicknystrom,项目名称:RedBranch.Hammock,代码行数:33,代码来源:ReferenceTests.cs

示例2: FixtureSetup

        public void FixtureSetup()
        {
            _cx = ConnectionTests.CreateConnection();
            if (_cx.ListDatabases().Contains("relax-session-tests"))
            {
                _cx.DeleteDatabase("relax-session-tests");
            }
            _cx.CreateDatabase("relax-session-tests");
            _sx = _cx.CreateSession("relax-session-tests");

            // create an initial document on a seperate session
            var x = _cx.CreateSession(_sx.Database);
            var w = new Widget {Name = "gizmo", Tags = new[] {"whizbang", "geegollie"}};
            _doc = x.Save(w);
        }
开发者ID:nicknystrom,项目名称:RedBranch.Hammock,代码行数:15,代码来源:SessionTests.cs

示例3: Main

        static void Main(string[] args) {
            String broker = args.Length > 0 ? args[0] : "localhost:5672";
            String address = args.Length > 1 ? args[1] : "amq.topic";

            Connection connection = null;
            try {
                connection = new Connection(broker);
                connection.Open();
                Session session = connection.CreateSession();

                Receiver receiver = session.CreateReceiver(address);
                Sender sender = session.CreateSender(address);

                sender.Send(new Message("Hello world!"));

                Message message = new Message();
                message = receiver.Fetch(DurationConstants.SECOND * 1);
                Console.WriteLine("{0}", message.GetContent());
                session.Acknowledge();

                connection.Close();
            } catch (Exception e) {
                Console.WriteLine("Exception {0}.", e);
                if (null != connection)
                    connection.Close();
            }
        }
开发者ID:irinabov,项目名称:debian-qpid-cpp,代码行数:27,代码来源:csharp.example.helloworld.cs

示例4: Page_Load

 protected void Page_Load( object sender, EventArgs e )
 {
     var url = ConfigurationManager.AppSettings.Get( "CLOUDANT_URL" );
     var connection = new Connection( new Uri( url ) );
     if ( !connection.ListDatabases().Contains( "gmkreports" ) )
     {
         connection.CreateDatabase( "gmkreports" );
     }
     var repository = new Repository<Report>( connection.CreateSession( "gmkreports" ) );
     var report = new Report { ID = Guid.NewGuid(), Type = 1, AccessionNumber = "123", Contents = "abcd" };
     System.Diagnostics.Stopwatch watch = new System.Diagnostics.Stopwatch();
     watch.Reset();
     watch.Start();
     var id = repository.Save( report ).Id;
     var retrievedReport = repository.Get( id );
     watch.Stop();
     if ( retrievedReport.ID == report.ID && retrievedReport.Type == report.Type && retrievedReport.AccessionNumber == report.AccessionNumber && retrievedReport.Contents == report.Contents )
     {
         _label.Text = watch.ElapsedMilliseconds.ToString();
     }
     else
     {
         _label.Text = "Error";
     }
 }
开发者ID:saintarian,项目名称:AppHarborTest,代码行数:25,代码来源:Default.aspx.cs

示例5: InitDb

        private void InitDb()
        {
            Connection connection = new Connection(new Uri(Config.HOST));

            connection.DeleteDatabase(Config.CLOTHES_DB_NAME);

            //if (!connection.ListDatabases().Any(db => db == Config.CLOTHES_DB_NAME))
            //{
            connection.CreateDatabase(Config.CLOTHES_DB_NAME);

            Session session = connection.CreateSession(Config.CLOTHES_DB_NAME);

            string allClothesScript =
                File.ReadAllText(HttpContext.Current.Server.MapPath("~/App_Data/all-clothes-map.js"));

            string colorsMap =
                File.ReadAllText(HttpContext.Current.Server.MapPath("~/App_Data/colors-map.js"));

            string colorsReduce =
                File.ReadAllText(HttpContext.Current.Server.MapPath("~/App_Data/colors-reduce.js"));

            DesignDocument designDocument = new DesignDocument();
            designDocument.Language = "javascript";
            designDocument.Views = new Dictionary<string, View>();

            designDocument.Views.Add("all-clothes", new View { Map = allClothesScript });
            designDocument.Views.Add("colors-breakdown", new View { Map = colorsMap, Reduce = colorsReduce });

            session.Save(designDocument, "_design/clothes-queries");
            //}
        }
开发者ID:mondok,项目名称:CouchDB-MVC-Sample,代码行数:31,代码来源:Global.asax.cs

示例6: FixtureSetup

        public void FixtureSetup()
        {
            _cx = ConnectionTests.CreateConnection();
            if (_cx.ListDatabases().Contains("relax-query-tests"))
            {
                _cx.DeleteDatabase("relax-query-tests");
            }
            _cx.CreateDatabase("relax-query-tests");
            _sx = _cx.CreateSession("relax-query-tests");
        
            // populate a few widgets & a simple design doc
            _sx.Save(new Widget { Name = "widget", Manufacturer = "acme" });
            _sx.Save(new Widget { Name = "sprocket", Manufacturer = "acme" });
            _sx.Save(new Widget { Name = "doodad", Manufacturer = "widgetco" });

            _sx.Save(
                new DesignDocument {
                         Language = "javascript",
                         Views = new Dictionary<string, View>
                         {
                            { "all-widgets", new View {
                                Map = @"function(doc) { emit(null, null); }"
                            }},
                            { "all-manufacturers", new View() {
                                Map = @"function(doc) { emit(doc.Manufacturer, 1); }",
                                Reduce = @"function(keys, values, rereduce) { return sum(values); }"
                            }}
                         }
                 },
                 "_design/widgets"
            );      
        }
开发者ID:nicknystrom,项目名称:RedBranch.Hammock,代码行数:32,代码来源:QueryTests.cs

示例7: Main

        //
        // Sample invocation: csharp.example.declare_queues.exe localhost:5672 my-queue
        //
        static int Main(string[] args) {
            string addr = "localhost:5672";
            string queue = "my-queue";

            if (args.Length > 0)
                addr = args[0];
            if (args.Length > 1)
                queue = args[1];

            Connection connection = null;
            try
            {
                connection = new Connection(addr);
                connection.Open();
                Session session = connection.CreateSession();
                String queueName = queue + "; {create: always}";
                Sender sender = session.CreateSender(queueName);
                session.Close();
                connection.Close();
                return 0;
            }
            catch (Exception e)
            {
                Console.WriteLine("Exception {0}.", e);
                if (null != connection)
                    connection.Close();
            }
            return 1;
        }
开发者ID:irinabov,项目名称:debian-qpid-cpp,代码行数:32,代码来源:csharp.example.declare_queues.cs

示例8: CloudantDataService

 public CloudantDataService()
 {
     var url = ConfigurationManager.AppSettings.Get( "CLOUDANT_URL" );
     var connection = new Connection( new Uri( url ) );
     if ( !connection.ListDatabases().Contains( "reports" ) )
     {
         connection.CreateDatabase( "reports" );
     }
     _repository = new Repository<Report>( connection.CreateSession( "reports" ) );
 }
开发者ID:saintarian,项目名称:AppHarborTest,代码行数:10,代码来源:CloudantDataService.svc.cs

示例9: FixtureSetup

 public void FixtureSetup()
 {
     _cx = ConnectionTests.CreateConnection();
     if (_cx.ListDatabases().Contains("relax-session-tests"))
     {
         _cx.DeleteDatabase("relax-session-tests");
     }
     _cx.CreateDatabase("relax-session-tests");
     _sx = _cx.CreateSession("relax-session-tests");
 }
开发者ID:nicknystrom,项目名称:RedBranch.Hammock,代码行数:10,代码来源:AttachmentTests.cs

示例10: Main

        //
        // Sample invocation: csharp.example.drain.exe --broker localhost:5672 --timeout 30 my-queue
        //
        static int Main(string[] args) {
            Options options = new Options(args);

            Connection connection = null;
            try
            {
                connection = new Connection(options.Url, options.ConnectionOptions);
                connection.Open();
                Session session = connection.CreateSession();
                Receiver receiver = session.CreateReceiver(options.Address);
                Duration timeout = options.Forever ? 
                                   DurationConstants.FORVER : 
                                   DurationConstants.SECOND * options.Timeout;
                Message message = new Message();

                while (receiver.Fetch(ref message, timeout))
                {
                    Dictionary<string, object> properties = new Dictionary<string, object>();
                    properties = message.Properties;
                    Console.Write("Message(properties={0}, content='", 
                                  message.MapAsString(properties));

                    if ("amqp/map" == message.ContentType)
                    {
                        Dictionary<string, object> content = new Dictionary<string, object>();
                        message.GetContent(content);
                        Console.Write(message.MapAsString(content));
                    }
                    else if ("amqp/list" == message.ContentType)
                    {
                        Collection<object> content = new Collection<object>();
                        message.GetContent(content);
                        Console.Write(message.ListAsString(content));
                    }
                    else
                    {
                        Console.Write(message.GetContent());
                    }
                    Console.WriteLine("')");
                    session.Acknowledge();
                }
                receiver.Close();
                session.Close();
                connection.Close();
                return 0;
            }
            catch (Exception e)
            {
                Console.WriteLine("Exception {0}.", e);
                if (null != connection)
                    connection.Close();
            }
            return 1;
        }
开发者ID:irinabov,项目名称:debian-qpid-cpp,代码行数:57,代码来源:csharp.example.drain.cs

示例11: Main

        static int Main(string[] args) {
            Options options = new Options(args);

            Connection connection = null;
            try
            {
                connection = new Connection(options.Url, options.ConnectionOptions);
                connection.Open();
                Session session = connection.CreateSession();
                Sender sender = session.CreateSender(options.Address);
                Message message;
                if (options.Entries.Count > 0)
                {
                    Dictionary<string, object> content = new Dictionary<string, object>();
                    SetEntries(options.Entries, content);
                    message = new Message(content);
                }
                else
                {
                    message = new Message(options.Content);
                    message.ContentType = "text/plain";
                }
                Address replyToAddr = new Address(options.ReplyTo);

                Stopwatch stopwatch = new Stopwatch();
                TimeSpan timespan = new TimeSpan(0,0,options.Timeout);
                stopwatch.Start();
                for (int count = 0;
                    (0 == options.Count || count < options.Count) &&
                    (0 == options.Timeout || stopwatch.Elapsed <= timespan);
                    count++) 
                {
                    if ("" != options.ReplyTo) message.ReplyTo = replyToAddr;
                    string id = options.Id ;
                    if ("" == id) {
                        Guid g = Guid.NewGuid();
                        id = g.ToString();
                    }
                    string spoutid = id + ":" + count;
                    message.SetProperty("spout-id", spoutid);
                    sender.Send(message);
                }
                session.Sync();
                connection.Close();
                return 0;
            } catch (Exception e) {
                Console.WriteLine("Exception {0}.", e);
                if (null != connection)
                    connection.Close();
            }
            return 1;
        }
开发者ID:irinabov,项目名称:debian-qpid-cpp,代码行数:52,代码来源:csharp.example.spout.cs

示例12: Main

        // csharp.map.receiver example
        //
        // Send an amqp/map message to amqp:tcp:localhost:5672 amq.direct/map_example
        // The map message 
        //
        static int Main(string[] args)
        {
            string url = "amqp:tcp:localhost:5672";
            string address = "message_queue; {create: always}";
            string connectionOptions = "";

            if (args.Length > 0)
                url = args[0];
            if (args.Length > 1)
                address = args[1];
            if (args.Length > 2)
                connectionOptions = args[2];

            //
            // Create and open an AMQP connection to the broker URL
            //
            Connection connection = new Connection(url);
            connection.Open();

            //
            // Create a session and a receiver fir the direct exchange using the
            // routing key "map_example".
            //
            Session session = connection.CreateSession();
            Receiver receiver = session.CreateReceiver(address);

            //
            // Fetch the message from the broker
            //
            Message message = receiver.Fetch(DurationConstants.MINUTE);

            //
            // Extract the structured content from the message.
            //
            Dictionary<string, object> content = new Dictionary<string, object>();
            message.GetContent(content);
            Console.WriteLine("{0}", message.AsString(content));

            //
            // Acknowledge the receipt of all received messages.
            //
            session.Acknowledge();

            //
            // Close the receiver and the connection.
            //
            receiver.Close();
            connection.Close();
            return 0;
        }
开发者ID:irinabov,项目名称:debian-qpid-cpp,代码行数:55,代码来源:csharp.map.receiver.cs

示例13: Main

        static int Main(string[] args) {
            String url = "amqp:tcp:127.0.0.1:5672";
            String connectionOptions = "";

            if (args.Length > 0)
                url = args[0];
            if (args.Length > 1)
                connectionOptions = args[1];

            Connection connection = new Connection(url, connectionOptions);
            try
            {
                connection.Open();

                Session session = connection.CreateSession();

                Sender sender = session.CreateSender("service_queue");

                Address responseQueue = new Address("#response-queue; {create:always, delete:always}");
                Receiver receiver = session.CreateReceiver(responseQueue);

                String[] s = new String[] {
                    "Twas brillig, and the slithy toves",
                    "Did gire and gymble in the wabe.",
                    "All mimsy were the borogroves,",
                    "And the mome raths outgrabe."
                };

                Message request = new Message("");
                request.ReplyTo = responseQueue;

                for (int i = 0; i < s.Length; i++) {
                    request.SetContent(s[i]);
                    sender.Send(request);
                    Message response = receiver.Fetch();
                    Console.WriteLine("{0} -> {1}", request.GetContent(), response.GetContent());
                }
                connection.Close();
                return 0;
            }
            catch (Exception e)
            {
                Console.WriteLine("Exception {0}.", e);
                connection.Close();
            }
            return 1;
        }
开发者ID:irinabov,项目名称:debian-qpid-cpp,代码行数:47,代码来源:csharp.example.client.cs

示例14: Main

        // Direct sender example
        //
        // Send 10 messages from localhost:5672, amq.direct/key
        // Messages are assumed to be printable strings.
        //
        static int Main(string[] args)
        {
            String host = "localhost:5672";
            String addr = "amq.direct/key";
            Int32 nMsg = 10;

            if (args.Length > 0)
                host = args[0];
            if (args.Length > 1)
                addr = args[1];
            if (args.Length > 2)
                nMsg = Convert.ToInt32(args[2]);

            Console.WriteLine("csharp.direct.sender");
            Console.WriteLine("host : {0}", host);
            Console.WriteLine("addr : {0}", addr);
            Console.WriteLine("nMsg : {0}", nMsg);
            Console.WriteLine();

            Connection connection = null;
            try
            {
                connection = new Connection(host);
                connection.Open();

                if (!connection.IsOpen) {
                    Console.WriteLine("Failed to open connection to host : {0}", host);
                } else {
                    Session session = connection.CreateSession();
                    Sender sender = session.CreateSender(addr);
                    for (int i = 0; i < nMsg; i++) {
                        Message message = new Message(String.Format("Test Message {0}", i));
                        sender.Send(message);
                    }
                    session.Sync();
                    connection.Close();
                    return 0;
                }
            } catch (Exception e) {
                Console.WriteLine("Exception {0}.", e);
                if (null != connection)
                    connection.Close();
            }
            return 1;
        }
开发者ID:irinabov,项目名称:debian-qpid-cpp,代码行数:50,代码来源:csharp.direct.sender.cs

示例15: Main

        // Direct receiver example
        //
        // Receive 10 messages from localhost:5672, amq.direct/key
        // Messages are assumed to be printable strings.
        //
        static int Main(string[] args)
        {
            String host = "localhost:5672";
            String addr = "amq.direct/key";
            Int32 nMsg = 10;

            if (args.Length > 0)
                host = args[0];
            if (args.Length > 1)
                addr = args[1];
            if (args.Length > 2)
                nMsg = Convert.ToInt32(args[2]);

            Console.WriteLine("csharp.direct.receiver");
            Console.WriteLine("host : {0}", host);
            Console.WriteLine("addr : {0}", addr);
            Console.WriteLine("nMsg : {0}", nMsg);
            Console.WriteLine();

            Connection connection = null;
            try
            {
                connection = new Connection(host);
                connection.Open();
                if (!connection.IsOpen) {
                    Console.WriteLine("Failed to open connection to host : {0}", host);
                } else {
                    Session session = connection.CreateSession();
                    Receiver receiver = session.CreateReceiver(addr);
                    Message message = new Message("");
                    for (int i = 0; i < nMsg; i++) {
                        Message msg2 = receiver.Fetch(DurationConstants.FORVER);
                        Console.WriteLine("Rcvd msg {0} : {1}", i, msg2.GetContent());
                    }
                    connection.Close();
                    return 0;
                }
            } catch (Exception e) {
                Console.WriteLine("Exception {0}.", e);
                if (null != connection)
                    connection.Close();
            }
            return 1;
        }
开发者ID:irinabov,项目名称:debian-qpid-cpp,代码行数:49,代码来源:csharp.direct.receiver.cs


注:本文中的Connection.CreateSession方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。