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


C# Connection.Close方法代码示例

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


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

示例1: 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

示例2: 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

示例3: 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

示例4: btnLoadPI_Click

        private void btnLoadPI_Click(object sender, EventArgs e)
        {
            try
            {
                Connection cnx = new Connection();
                cnx.Open(ConfigurationManager.AppSettings["K2ServerName"]);
                SourceCode.Workflow.Client.ProcessInstance pi = cnx.OpenProcessInstance(int.Parse(txtProcInstanceId.Text));
                txtFolio.Text = pi.Folio;
                lblStatus.Text = pi.Status1.ToString();
                txtProcessFullName.Text = pi.FullName;
                DataTable dt = new DataTable("Datafields");
                dt.Columns.Add("Name");
                dt.Columns.Add("Value");

                foreach (DataField df in pi.DataFields)
                {
                    dt.Rows.Add(new object[] { df.Name, df.Value });
                }

                displayActivity();

                dgvDatafields.DataSource = dt;
                dgvDatafields.Refresh();
                dgvDatafields.AutoResizeColumn(0);
                dgvDatafields.Columns[0].ReadOnly = true;
                dgvDatafields.AutoResizeColumn(1);

                cnx.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "PI Manager eror");
            }
        }
开发者ID:pierrot12,项目名称:K2France.PIManager,代码行数:34,代码来源:Form1.cs

示例5: CloseConnectionWithDetachTest

        public void CloseConnectionWithDetachTest()
        {
            this.testListener.RegisterTarget(TestPoint.Close, (stream, channel, fields) =>
            {
                // send a detach
                TestListener.FRM(stream, 0x16UL, 0, channel, 0u, true);
                return TestOutcome.Continue;
            });

            string testName = "CloseConnectionWithDetachTest";

            Trace.WriteLine(TraceLevel.Information, "sync test");
            {
                Connection connection = new Connection(this.address);
                Session session = new Session(connection);
                SenderLink sender = new SenderLink(session, "sender-" + testName, "any");
                sender.Send(new Message("test") { Properties = new Properties() { MessageId = testName } });
                connection.Close();
                Assert.IsTrue(connection.Error == null, "connection has error!" + connection.Error);
            }

            Trace.WriteLine(TraceLevel.Information, "async test");
            Task.Factory.StartNew(async () =>
            {
                Connection connection = await Connection.Factory.CreateAsync(this.address);
                Session session = new Session(connection);
                SenderLink sender = new SenderLink(session, "sender-" + testName, "any");
                await sender.SendAsync(new Message("test") { Properties = new Properties() { MessageId = testName } });
                await connection.CloseAsync();
                Assert.IsTrue(connection.Error == null, "connection has error!" + connection.Error);

            }).Unwrap().GetAwaiter().GetResult();
        }
开发者ID:ChugR,项目名称:amqpnetlite,代码行数:33,代码来源:ProtocolTests.cs

示例6: 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

示例7: LoadWorkList

        public List<SA4Launcher.Models.WorklistItem> LoadWorkList()
        {
            Connection K2Conn = new Connection();
            SCConnectionStringBuilder K2ConnString = new SCConnectionStringBuilder();
            List<SA4Launcher.Models.WorklistItem> _currentWorkList = new List<SA4Launcher.Models.WorklistItem>();

            //Setup Connection String

            K2ConnString.Host = "Sa4DemoK2wAD";
            K2ConnString.Integrated = false;
            K2ConnString.UserID = "SA4Demo\\Tberry";
            K2ConnString.Password = "Sa42013!";
            K2ConnString.Port = 5252;
            K2ConnString.WindowsDomain = "Sa4Demo";
            K2ConnString.SecurityLabelName = "K2";
            K2ConnString.Authenticate = false;
            K2ConnString.IsPrimaryLogin = true;
            K2Conn.Open("Sa4DemoK2wAD", K2ConnString.ConnectionString.ToString());

            //TODO:  Need to add try loop with true false return
            Worklist K2WorkList = K2Conn.OpenWorklist();
            List<SA4Launcher.Models.Action> CurrentActions = new List<SA4Launcher.Models.Action>();

            if (K2WorkList != null)
            {
                _currentWorkList.Clear();
                foreach (SourceCode.Workflow.Client.WorklistItem K2worklistitem in K2WorkList)
                {
                    //Build Actions First
                    CurrentActions.Clear();
                    foreach (SourceCode.Workflow.Client.Action K2action in K2worklistitem.Actions)
                    {
                        CurrentActions.Add(new SA4Launcher.Models.Action
                        {
                            Name = K2action.Name,
                            Batchable = K2action.Batchable
                        });
                    }

                    //Load worklist items into model
                    _currentWorkList.Add(new SA4Launcher.Models.WorklistItem
                    {
                        ID = K2worklistitem.ID,
                        serialno = K2worklistitem.SerialNumber,
                        Name = K2worklistitem.ProcessInstance.Name,
                        UserName = K2worklistitem.AllocatedUser,
                        Folio = K2worklistitem.ProcessInstance.Folio,
                        StartDate = K2worklistitem.ProcessInstance.StartDate,
                        Status = K2worklistitem.Status.ToString(),
                        ViewFlow = K2worklistitem.ProcessInstance.ViewFlow,
                        Data = K2worklistitem.Data,
                        Priority = K2worklistitem.ProcessInstance.Priority,
                        Actions = CurrentActions.ToList()
                    });
                }
            }
            K2Conn.Close();
            return (_currentWorkList);
        }
开发者ID:jordanberry,项目名称:SA4Launcher,代码行数:59,代码来源:WorkListContext.cs

示例8: 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

示例9: 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

示例10: ConnectionClose

        public void ConnectionClose()
        {
            Dictionary<string, object> options = new Dictionary<string, object>();
            options["id"] = 987654321;
            options["name"] = "Widget";
            options["percent"] = 0.99;

            Connection myConn = new Connection("url", options);
            myConn.Close();

            Assert.IsFalse(myConn.IsOpen);
        }
开发者ID:ncdc,项目名称:qpid,代码行数:12,代码来源:messaging.test.connection.cs

示例11: 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

示例12: CloseConnectionWithDetachTest

        public void CloseConnectionWithDetachTest()
        {
            this.testListener.RegisterTarget(TestPoint.Close, (stream, channel, fields) =>
                {
                    // send a detach
                    TestListener.FRM(stream, 0x16UL, 0, channel, 0u, true);
                    return TestOutcome.Continue;
                });

            string testName = "CloseConnectionWithDetachTest";
            Connection connection = new Connection(new Address("amqp://localhost:" + port));
            Session session = new Session(connection);
            SenderLink sender = new SenderLink(session, "sender-" + testName, "any");
            sender.Send(new Message("test") { Properties = new Properties() { MessageId = testName } });
            connection.Close();
            Assert.IsTrue(connection.Error == null, "connection has error!" + connection.Error);
        }
开发者ID:Eclo,项目名称:amqpnetlite,代码行数:17,代码来源:ProtocolTests.cs

示例13: CloseTest

        public void CloseTest()
        {
            using (var connection = new Connection(CreateClientFactory()))
             {
            Connect(connection);

            _stream.Expect(x => x.Close());
            _tcpClient.Expect(x => x.Close());

            bool statusMessageFired = false;
            connection.StatusMessage += (sender, args) => statusMessageFired = true;
            connection.Close();

            Assert.IsTrue(statusMessageFired);
             }

             _tcpClient.VerifyAllExpectations();
             _stream.VerifyAllExpectations();
        }
开发者ID:kszysiu,项目名称:hfm-net,代码行数:19,代码来源:ConnectionTests.cs

示例14: CloseConnection

 public static void CloseConnection(Connection conn)
 {
     bool isRelease = false;
     try
     {
         if (conn != null)
         {
             conn.Close();
             isRelease = true;
         }
     }
     finally
     {
         if (conn != null && !isRelease)
         {
             conn.Dispose();
             conn = null;
         }
     }
 }
开发者ID:Cloud33,项目名称:K2.Tasks-Service,代码行数:20,代码来源:K2WorkflowUtility.cs

示例15: StartProcess

        /// <summary>
        /// 调用k2的dll,生成流程
        /// <param name="dataFields">开启流程所需数据</param>
        /// <param name="processName">流程名称</param>
        /// </summary>
        public static int StartProcess(string processName, Dictionary<string, string> dataFields, string objectId, string folio, string userName)
        {
            int processInstId = 0;
            Connection k2Connection = new Connection();

            try
            {
                k2Connection.Open(ConfigurationBase.Web.K2Server, ConfigurationBase.Web.K2LoginString);
                k2Connection.ImpersonateUser(userName);

                //创建实例
                ProcessInstance processInst = k2Connection.CreateProcessInstance(processName);
                processInstId = processInst.ID;

                if (!string.IsNullOrEmpty(folio))
                {
                    processInst.Folio = folio;
                }
                #region 赋值datafields
                foreach (string key in dataFields.Keys)
                {
                    if (processInst.DataFields[key] != null)
                    {
                        processInst.DataFields[key].Value = dataFields[key];
                    }
                }
                #endregion
            }
            finally
            {
                if (k2Connection != null)
                {
                    k2Connection.Close();
                }
            }

            return processInstId;
        }
开发者ID:nanin,项目名称:k2-workflowapi,代码行数:43,代码来源:K2Helper.cs


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