123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- using System;
- using System.Collections.Generic;
- using System.Text;
- 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; }
- }
- }
- }
|