1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768 |
- using System;
- using System.Collections.Generic;
- namespace Wayne.Lib
- {
-
-
-
- public class ConnectionChecker
- {
- private readonly IList<ConnectableItem> connectableItems = new List<ConnectableItem>();
- private readonly object connectableItemsLock=new object();
-
-
-
-
- public bool IsConnectedToAll()
- {
- lock (connectableItemsLock)
- {
- foreach (var connectableItem in connectableItems)
- {
- if (connectableItem.Connectable.ConnectionState != DeviceConnectionState.Connected)
- return false;
- }
- }
- return true;
- }
-
-
-
-
-
- public void AddConnectableToCheck(IConnectable connectable, string connectableDisplayName)
- {
- if(connectable == null)
- throw new ArgumentNullException("connectable", "A instance of IConnectable is required.");
- connectableItems.Add(new ConnectableItem() { Connectable = connectable, DisplayName = connectableDisplayName});
- }
-
-
-
-
- public IList<string> GetUnconnectedAsText()
- {
- IList<string> reasons = new List<string>();
- foreach (var connectableItem in connectableItems)
- {
- if (connectableItem.Connectable.ConnectionState != DeviceConnectionState.Connected)
- reasons.Add(connectableItem.DisplayName + ".ConnectionState = " + connectableItem.Connectable.ConnectionState);
- }
- return reasons;
- }
- class ConnectableItem
- {
- public IConnectable Connectable { get; set; }
- public string DisplayName { get; set; }
- }
- }
- }
|