本文整理汇总了C#中ConnectionState类的典型用法代码示例。如果您正苦于以下问题:C# ConnectionState类的具体用法?C# ConnectionState怎么用?C# ConnectionState使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ConnectionState类属于命名空间,在下文中一共展示了ConnectionState类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ExcuteSQLBulkCopy
public void ExcuteSQLBulkCopy(DataTable Datatable, string TableName, ConnectionState connectionstate, ref bool executionSucceeded)
{
try
{
if (objConnection.State == System.Data.ConnectionState.Closed)
{
objConnection.Open();
}
SqlBulkCopy.BatchSize = Datatable.Rows.Count;
SqlBulkCopy.BulkCopyTimeout = 0;
SqlBulkCopy.DestinationTableName = TableName;
SqlBulkCopy.WriteToServer(Datatable);
SqlBulkCopy.Close();
executionSucceeded = true;
}
catch (Exception ex)
{
executionSucceeded = false;
HandleExceptions(ex);
}
finally
{
//SqlBulkCopy.ColumnMappings.Clear();
if (connectionstate == ConnectionState.CloseOnExit)
{
if (objConnection.State == System.Data.ConnectionState.Open)
{
objConnection.Close();
}
}
}
}
示例2: OnStateChanged
private void OnStateChanged(ConnectionState newState)
{
if (_stateChanged != null)
{
_stateChanged(this, newState);
}
}
示例3: SerialConnection
private SerialConnection()
{
Devices = new ObservableCollection<DeviceInformation>();
State = ConnectionState.Disconnected;
Debugger = Debugger.Instance;
LookForBluetoothDevices();
}
示例4: Open
public override void Open()
{
if (State == ConnectionState.Open)
throw new Exception("Connection is already open");
_state = ConnectionState.Open;
}
示例5: Close
public override void Close()
{
if (State == ConnectionState.Closed)
throw new Exception("Connection is already closed");
_state = ConnectionState.Closed;
}
示例6: connectionChanged
private void connectionChanged(ConnectionInformation information, ConnectionState state)
{
if (state == ConnectionState.CLOSED)
{
CloseConnection(information);
}
}
示例7: OnStateChanged
public void OnStateChanged(ConnectionState connectionState)
{
if (callback != null)
{
callback(connectionState);
}
}
示例8: Open
public bool Open()
{
if (m_State == ConnectionState.Disconnected)
{
int numUnits = m_PM3.DiscoverUnits();
if (numUnits > 0)
{
try
{
m_Port = 0;
m_State = ConnectionState.Connected;
}
catch (PM3Exception e)
{
Debug.WriteLine(string.Format("[Connection.Open] {0}", e.Message));
}
}
}
else
{
Debug.WriteLine("[Connection.Open] Connection already open");
}
return IsOpen;
}
示例9: AcceptCallback
public void AcceptCallback(IAsyncResult result)
{
// Get the socket that handles the client request
// listener represents the connection 'server' (that waits for clients to connect) and not the
// individual client connections
Socket listener = (Socket)result.AsyncState;
Socket handler = listener.EndAccept(result);
// Tell the main client thread we got one client so that it can keep waiting for others :)
gAllDone.Set();
// From now on this is a separate thread :) cool!
// Lets keep the state of this thing shall we?
ConnectionState state = new ConnectionState();
state.mSocket = handler;
// TODO: Implement version control here
// Valid connections start with a 'YELLOW' to which we respond 'SUP'
byte[] yellowShakeBuffer = new byte[16];
int read = handler.Receive(yellowShakeBuffer);
string yellowString = ServerApi.CONNECTION_ENCODING.GetString(yellowShakeBuffer, 0, read);
if (yellowString.Equals("YELLOW"))
{
// Answer and start waiting for data baby!
handler.Send(ServerApi.CONNECTION_ENCODING.GetBytes("SUP"));
handler.BeginReceive(state.mBuffer, 0, ConnectionState.BufferSize, SocketFlags.Peek,
new AsyncCallback(ReadCallback), state);
}
else
{
// Ooops, not a valid client!
handler.Close();
}
}
示例10: SendCSAFECommand
public bool SendCSAFECommand(uint[] cmdData, ushort cmdDataCount, uint[] rspData, ref ushort rspDataCount)
{
if (IsOpen)
{
try
{
m_PM3.SendCSAFECommand(m_Port, cmdData, cmdDataCount, rspData, ref rspDataCount);
return true;
}
catch (WriteFailedException e)
{
m_State = ConnectionState.SendError;
Debug.WriteLine(string.Format("[Connection.SendCSAFECommand] {0}", e.Message));
}
catch (ReadTimeoutException e)
{
m_State = ConnectionState.SendError;
Debug.WriteLine(string.Format("[Connection.SendCSAFECommand] {0}", e.Message));
}
catch (DeviceClosedException e)
{
m_State = ConnectionState.Disconnected;
Debug.WriteLine(string.Format("[Connection.SendCSAFECommand] {0}", e.Message));
}
}
return false;
}
示例11: Open
public override void Open()
{
m_StorageAccount = CloudStorageAccount.Parse(m_ConnectionString);
m_State = ConnectionState.Open;
// TODO (Matt Magurany 8/14/2012): Consider creating an HTTP request for batching here
}
示例12: Handle
/// <summary>Executes behavior.</summary>
/// <param name="state">Connection state.</param>
public void Handle(ConnectionState state)
{
if (state == ConnectionState.Connected)
_viewModel.IsBusy = false;
else
ErrorManager.Error(state.ToString());
}
示例13: OnMessageReceived
private async void OnMessageReceived(object sender, MessageReceivedEventArgs args)
{
if (OnData == null) return;
var exceptionOccured = false;
try
{
var text = args.Message;
OnData(sender, new DataReceivedEventArgs { TextData = text });
}
catch (Exception)
{
exceptionOccured = true;
}
// cannot await in catch
if (exceptionOccured)
{
_connectionState = ConnectionState.Failed;
try
{
await Reconnect();
}
catch (Exception e)
{
Error(e);
}
}
}
示例14: BeginConnect
protected async Task BeginConnect(CancellationToken parentCancelToken)
{
try
{
using (await _lock.LockAsync().ConfigureAwait(false))
{
_parentCancelToken = parentCancelToken;
await _taskManager.Stop().ConfigureAwait(false);
_taskManager.ClearException();
State = ConnectionState.Connecting;
_cancelSource = new CancellationTokenSource();
CancelToken = CancellationTokenSource.CreateLinkedTokenSource(_cancelSource.Token, parentCancelToken).Token;
_lastHeartbeat = DateTime.UtcNow;
await _engine.Connect(Host, CancelToken).ConfigureAwait(false);
await Run().ConfigureAwait(false);
}
}
catch (Exception ex)
{
//TODO: Should this be inside the lock?
await _taskManager.SignalError(ex).ConfigureAwait(false);
throw;
}
}
示例15: CiiClient
public CiiClient()
{
logger = Logger.Instance;
StatusCallbacks = new Dictionary<uint, ReceiveStatusHandler>();
statusCallbacksLock = new object();
loginAcceptEvent = new AutoResetEvent(false);
messagesInFlight = new CiiMessagesInFlight();
connectionState = ConnectionState.NotConnected;
//
// Prebuild the Communications arrays
//
MessageTypeGet = BitConverter.GetBytes((uint)CiiMessageType.MtGetCommand);
MessageTypeAction = BitConverter.GetBytes((uint)CiiMessageType.MtActionCommand);
BytesLogin = BitConverter.GetBytes((uint)CiiMessageType.MtLogin);
asyncErrorEvent = new AutoResetEvent(false);
asyncErrors = new Queue<string>();
asyncErrorsLock = new object();
asyncErrorThread = new Thread(AsyncErrorThread);
asyncErrorThread.IsBackground = true;
asyncErrorThread.Priority = ThreadPriority.AboveNormal;
asyncErrorThread.Name = "AsyncErrorThread";
asyncErrorThread.Start();
}
开发者ID:michaelbeckertainstruments,项目名称:common-instrument-interface-client-csharp,代码行数:26,代码来源:CiiClient.cs