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


C# Bus.Dispose方法代码示例

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


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

示例1: ClosesOpenConnectionOnDispose

        public void ClosesOpenConnectionOnDispose()
        {
            var mockRepository = new MockRepository();
            var config = mockRepository.DynamicMock<IBrokerConfiguration>();
            var connFactory = mockRepository.DynamicMock<IBrokerConnectionFactory>();
            var conn = mockRepository.DynamicMock<IBrokerConnection>();
            var consumer = mockRepository.DynamicMock<IRegisteredConsumer>();

            using (mockRepository.Record())
            {
                SetupResult.For(consumer.MessageType).Return(typeof (TestMessage));
                SetupResult.For(connFactory.CreateConnection()).Return(conn);
                SetupResult.For(config.ConnectionFactory).Return(connFactory);
                SetupResult.For(config.RegisteredConsumers).Return(new Dictionary<Type, IList<IRegisteredConsumer>> { { typeof(TestMessage), new List<IRegisteredConsumer> { consumer } } });
                SetupResult.For(conn.IsOpen).Return(true);

                Expect.Call(conn.Close);
            }

            using (mockRepository.Playback())
            {
                var bus = new Bus(config);
                bus.GetLiveConnection();
                bus.Dispose();
            }
        }
开发者ID:nordbergm,项目名称:NSimpleBus,代码行数:26,代码来源:BusTests.cs

示例2: WithManualWireUp

        public void WithManualWireUp()
        {
            var configuration = new PaymentServiceConfiguration();
            var bus = new Bus(configuration);
            var accountRepository = new AccountRepository(configuration);
            var paymentService = new PaymentService(accountRepository, bus, () => DateTime.Now);

            paymentService.Start();

            // pretend something is publishing to me
            PretendToPublish();

            // wait for some shutdown event here
            bus.Dispose();
            accountRepository.Dispose();
        }
开发者ID:mikehadlow,项目名称:Mike.Spikes,代码行数:16,代码来源:Program.cs

示例3: switchON


//.........这里部分代码省略.........
                    {
                        SqlDataReader _dt = sqlComm.ExecuteReader();

                        while (_dt.Read())
                        {
                            GroupAddressON.Add(_dt["On/Off Address"].ToString());
                            GroupAddressMeter.Add(_dt["MeasureCurrent Address"].ToString());
                        }

                        _dt.Close();
                    }
                }

                conn.Close();
            }

            Ping pingOrder = new Ping();
            for (var i=0; i<4; i++)
            {
                try
                {
                    pingOrder.Send(AddressIP);
                }
                catch (PingException ex)
                {

                }
            }
            pingOrder = null;

            using (Bus _bus = new Bus(new KnxIpTunnelingConnectorParameters(AddressIP, ushort.Parse(AddressPort), AddressNat)))
            {
                try
                {
                    _bus.Connect();

                    for (var i = 0; i < GroupAddressON.Count; i++)
                    {
                        GroupAddress _groupAddress = GroupAddress.Parse(GroupAddressON[i]);
                        GroupValue _groupValue = new GroupValue(true);
                        _bus.WriteValue(_groupAddress, _groupValue, Priority.Low);

                        //GroupAddress _groupAddressMeter = GroupAddress.Parse(GroupAddressMeter[i]);
                        //GroupValue groupValue = _bus.ReadValue(_groupAddressMeter, Priority.Low);

                        //DataPointTranslator _dpt = new DataPointTranslator();
                        //decimal _value = (decimal)_dpt.FromDataPoint("9.001", groupValue.Value);
                        //storeValueToDB(_value, MeterSerial, ChannelsArray[i]);
                    }

                    _bus.Disconnect();
                    _bus.Dispose();
                    updateSchedulerTable(_TaskID, false);
                    updatePillarDeparturesSQL(_PillarID, _channelGroup, true);
                    updateTask(_taskguid, "On");
                    emailWaring(_TaskID, _TaskSubject, _TaskStart, _TaskEnd, _channelGroup, _PillarID, null, null, null);
                }
                catch (ConnectorException ex)
                {
                    updateSchedulerTable(_TaskID, true);
                    updateReportScheduler1(_TaskID, ex.ErrorReason);
                    emailWaring(_TaskID, _TaskSubject, _TaskStart, _TaskEnd, _channelGroup, _PillarID, ex, null, null);
                    if (_bus != null)
                    {
                        _bus.Disconnect();
                        _bus.Dispose();
                    }
                }
                catch (ConnectionException ex)
                {
                    updateSchedulerTable(_TaskID, true);
                    updateReportScheduler2(_TaskID, ex.ErrorReason);
                    emailWaring(_TaskID, _TaskSubject, _TaskStart, _TaskEnd, _channelGroup, _PillarID, null, ex, null);
                    if (_bus != null)
                    {
                        _bus.Disconnect();
                        _bus.Dispose();
                    }
                }
                catch (NoResponseReceivedException ex)
                {
                    updateSchedulerTable(_TaskID, true);
                    updateReportScheduler3(_TaskID, ex.ErrorReason);
                    emailWaring(_TaskID, _TaskSubject, _TaskStart, _TaskEnd, _channelGroup, _PillarID, null, null, ex);
                    if (_bus != null)
                    {
                        _bus.Disconnect();
                        _bus.Dispose();
                    }
                }
                finally
                {
                    if (_bus != null)
                    {
                        _bus.Disconnect();
                        _bus.Dispose();
                    }
                }
            }
        }
开发者ID:Costas47,项目名称:KNXWorker,代码行数:101,代码来源:Program.cs

示例4: meterCurrent


//.........这里部分代码省略.........
                    sqlSelect = "SELECT [MeasureCurrent Address] FROM [db_knx].[dbo].[" + TypeKNX + "_" + MeterSerial + "] WHERE [Departure] = " + ChannelsArray[i] + ";";

                    using (SqlCommand sqlComm = new SqlCommand(sqlSelect, conn))
                    {
                        SqlDataReader _dt = sqlComm.ExecuteReader();

                        while (_dt.Read())
                        {
                            if (!_dt.IsDBNull(0))
                            {
                                GroupAddressMeasure.Add(_dt["MeasureCurrent Address"].ToString());
                            }
                        }

                        _dt.Close();
                    }
                }

                conn.Close();
            }

            Ping pingOrder = new Ping();
            for (var i = 0; i < 4; i++)
            {
                try
                {
                    pingOrder.Send(AddressIP);
                }
                catch (PingException ex)
                {

                }
            }
            pingOrder = null;

            using (Bus _bus = new Bus(new KnxIpTunnelingConnectorParameters(AddressIP, ushort.Parse(AddressPort), AddressNat)))
            {
                try
                {
                    _bus.Connect();

                    for (var i = 0; i < GroupAddressMeasure.Count; i++)
                    {
                        GroupValue groupValue = _bus.ReadValue(GroupAddress.Parse(GroupAddressMeasure[i]), Priority.Low);
                        if (groupValue != null)
                        {
                            try
                            {
                                DataPointTranslator _dpt = new DataPointTranslator();
                                decimal _value = (decimal)_dpt.FromDataPoint("9.001", groupValue.Value);
                                storeCurrentValueToDB(_value, MeterSerial, ChannelsArray[i]);
                            }
                            catch (Exception exception)
                            {
                                Console.WriteLine(exception);
                            }
                        }
                    }

                    _bus.Disconnect();
                    _bus.Dispose();
                    updateTask(_taskguid, "Meter");
                }
                catch (ConnectorException ex)
                {
                    updateReportScheduler1(_TaskID, ex.ErrorReason);
                    if (_bus != null)
                    {
                        _bus.Disconnect();
                        _bus.Dispose();
                    }
                }
                catch (ConnectionException ex)
                {
                    updateReportScheduler2(_TaskID, ex.ErrorReason);
                    if (_bus != null)
                    {
                        _bus.Disconnect();
                        _bus.Dispose();
                    }
                }
                catch (NoResponseReceivedException ex)
                {
                    updateReportScheduler3(_TaskID, ex.ErrorReason);
                    if (_bus != null)
                    {
                        _bus.Disconnect();
                        _bus.Dispose();
                    }
                }
                finally
                {
                    if (_bus != null)
                    {
                        _bus.Disconnect();
                        _bus.Dispose();
                    }
                }
            }
        }
开发者ID:Costas47,项目名称:KNXWorker,代码行数:101,代码来源:Program.cs


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