//初始化基本设备搜索条件界面。 private void FilterBasicInit() { if (this.filterBasic != null) { DeviceFilterCollection _Filters = new DeviceFilterCollection(); if (m_SearchConfig.UseDefaultConfig) { _Filters.Add(new AC.Base.DeviceSearchs.AddressFilter()); _Filters.Add(new AC.Base.DeviceSearchs.NameFilter()); _Filters.Add(new AC.Base.DeviceSearchs.DeviceTypeFilter()); } else { foreach (string strSearchFilterName in m_SearchConfig.SearchFilterNames) { string[] strFilterName = strSearchFilterName.Split(new char[] { '@' }); if (strFilterName.Length == 2) { Type typ = this.m_Application.GetDeviceFilterType(strFilterName[1]); if (typ != null) { IDeviceFilter _Filter = this.m_Application.GetDeviceFilter(typ, this.m_Account); _Filter.SetFilterName(strFilterName[0]); _Filters.Add(_Filter); } } } } this.filterBasic.Filters = _Filters; } }
/// <summary> /// 设置搜索筛选器。 /// </summary> /// <param name="filter">传入需要设置的搜索筛选器对象</param> public void SetFilter(IDeviceFilter filter) { this.m_Filter = filter as AC.Base.DeviceSearchs.DeviceTypeFilter; if (this.m_Filter.DeviceType == null) { this.m_Value.SelectedIndex = 0; } else { for (int intIndex = 1; intIndex < this.m_Value.Items.Count; intIndex++) { if (this.m_Value.Items[intIndex] is DeviceType) { DeviceType _DeviceType = this.m_Value.Items[intIndex] as DeviceType; if (_DeviceType.Type.Equals(this.m_Filter.DeviceType)) { this.m_Value.SelectedIndex = intIndex; return; } } } this.m_Value.SelectedIndex = 0; } }
public BleDeviceProvider(IDeviceClassProtocol <TIdentifier> deviceClassProtocol, IBleDeviceFactory <TBleDevice, TIdentifier> deviceFactory, IBleInfrastructure bleInfrastructure) { _deviceClassProtocol = deviceClassProtocol; _deviceFactory = deviceFactory; _bleInfrastructure = bleInfrastructure; _generalDeviceFilter = new GeneralDeviceFilter(deviceClassProtocol); }
public Task <IBleResult <IDevice> > SearchForFirstDeviceAsync(IDeviceFilter deviceFilter, CancellationToken cancellationToken) { var foundDevice = GetConnectedDevices(deviceFilter).FirstOrDefault(); return(foundDevice != null ? Task.FromResult(BleResult.Success(foundDevice)) : _bleAvailabilityManager.ExecuteWithBleAvailabilityCheckAsync(async() => { var result = await ExecuteDeviceSearchAsync(deviceFilter, true, cancellationToken).ConfigureAwait(false); return result.Convert(list => list.FirstOrDefault()); })); }
public BleDeviceBase(IDevice device, T id, IDeviceClassProtocol <T> deviceClassProtocol, IBleInfrastructure bleInfrastructure) { DeviceId = id; BehaviorFactory = new DeviceBehaviorFactory(this, bleInfrastructure.Executor, bleInfrastructure.Logger); _device = device; _bleInfrastructure = bleInfrastructure; _deviceSearchFilter = new SpecificDeviceFilter <T>(id, deviceClassProtocol); _deviceCharacteristics = CreateCharacteristics(deviceClassProtocol, _bleInfrastructure.CharacteristicFactory, _bleInfrastructure.ExecutionProvider); _bleInfrastructure.ConnectionManager.AddListener(this); }
public SearchAdapter(IAdapter bleAdapter, IObserver <IDevice> observer, IDeviceFilter deviceFilter, bool stopAfterFirstResult, IExecutor executor, IBleLogger logger, CancellationToken cancellationToken) { _bleAdapter = bleAdapter; _observer = observer; _deviceFilter = deviceFilter; _stopAfterFirstResult = stopAfterFirstResult; _executor = executor; _logger = logger; _searchCancellation = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken); _searchCancellation.Token.Register(OnSearchInterrupted, false); _logger?.Log(LogSender, $"Starting search {DateTime.Now} (stopAfterFirstResult={stopAfterFirstResult})"); _executor.RunWithoutAwaiting(() => TryStartSearchAsync(_searchCancellation.Token)); }
/// <summary> /// 设置搜索筛选器。 /// </summary> /// <param name="filter">传入需要设置的搜索筛选器对象</param> public void SetFilter(IDeviceFilter filter) { this.m_Filter = filter as AC.Base.DeviceSearchs.NameFilter; string strValue = ""; if (this.m_Filter.Name != null) { foreach (string s in this.m_Filter.Name) { strValue += " " + s; } if (strValue.Length > 0) { strValue = strValue.Substring(1); } } this.m_Value.Text = strValue; }
public DeviceSearchAndFilteringViewModel(IDeviceFilter filter) { DevicesFilter = filter; FilterDevicesCommand = RegisterCommandAction( (obj) => { DevicesFilter.Criteria.First(c => c.DeviceTypeName == "Сервер").State = IsServersIncluded; DevicesFilter.Criteria.First(c => c.DeviceTypeName == "Коммутатор").State = IsSwitchesIncluded; DevicesFilter.Criteria.First(c => c.DeviceTypeName == "Персональный компьютер").State = IsPCIncluded; DevicesFilter.SearchQuery = InputtedSearchQuery; DeviceEvents.RaiseOnDeviceFilteringCriteriaChanged( DevicesFilter.Filter( (ResolveDependency <IDevicesListViewModel>() as DevicesListViewModel). AllDevices ) ); } ); }
/// <summary> /// 设置搜索筛选器。 /// </summary> /// <param name="filter">传入需要设置的搜索筛选器对象</param> public void SetFilter(IDeviceFilter filter) { this.m_Filter = filter as AC.Base.DeviceSearchs.CommonCustomClassifyFilter; this.labName.Text = this.m_Filter.FilterName + ":"; AC.Base.ClassifySearchs.ClassifySearch _Search = new AC.Base.ClassifySearchs.ClassifySearch(this.m_Application); _Search.Filters.Add(new AC.Base.ClassifySearchs.ParentIdFilter(0)); _Search.Filters.Add(new AC.Base.ClassifySearchs.ClassifyTypeFilter(typeof(CommonCustomClassify))); foreach (CommonCustomClassify _Classify in _Search.Search()) { if (_Classify.Name.Equals(this.m_Filter.FilterName)) { this.FillClassifys(_Classify.Children, ""); } } if (this.m_Filter.Classify == null) { this.m_Value.SelectedIndex = 0; } else { for (int intIndex = 1; intIndex < this.m_Value.Items.Count; intIndex++) { if (this.m_Value.Items[intIndex] is CommonCustomClassifyInfo) { CommonCustomClassifyInfo _Classify = this.m_Value.Items[intIndex] as CommonCustomClassifyInfo; if (_Classify.Classify.Equals(this.m_Filter.Classify)) { this.m_Value.SelectedIndex = intIndex; return; } } } this.m_Value.SelectedIndex = 0; } }
public static void FindDevices(Context paramContext, IDiscoveryHandler paramDiscoveryHandler, IDeviceFilter paramDeviceFilter) { BluetoothAdapter localBluetoothAdapter = BluetoothAdapter.DefaultAdapter; if (localBluetoothAdapter == null) { paramDiscoveryHandler.DiscoveryError("No bluetooth radio found"); } else if (!localBluetoothAdapter.IsEnabled) { paramDiscoveryHandler.DiscoveryError("Bluetooth radio is currently disabled"); } else { if (localBluetoothAdapter.IsDiscovering) { localBluetoothAdapter.CancelDiscovery(); } new BluetoothDiscoverer(paramContext.ApplicationContext, paramDiscoveryHandler, paramDeviceFilter).DoBluetoothDiscovery(); } }
public BluetoothDiscoverer(Context paramContext, IDiscoveryHandler paramDiscoveryHandler, IDeviceFilter paramDeviceFilter) { this.mContext = paramContext; this.deviceFilter = paramDeviceFilter; this.mDiscoveryHandler = paramDiscoveryHandler; }
private async Task <IBleResult <IReadOnlyList <IDevice> > > ExecuteDeviceSearchAsync(IDeviceFilter deviceFilter, bool stopAfterFirstResult, CancellationToken cancellationToken) { IBleResult <IReadOnlyList <IDevice> > result = null; try { await _searchSemaphore.WaitAsync(cancellationToken).ConfigureAwait(false); try { var searchResult = await _bleAdapter.SearchAsync(deviceFilter, stopAfterFirstResult, _executor, _logger, cancellationToken); result = BleResult.Success(searchResult); } finally { _searchSemaphore.Release(); } } catch (OperationCanceledException) { } catch (Exception e) { result = BleResult.Failure <IReadOnlyList <IDevice> >(e); } return(result); }
public static Task <IReadOnlyList <IDevice> > SearchAsync(this IAdapter bleAdapter, IDeviceFilter deviceFilter, bool stopAfterFirstResult, IExecutor executor, IBleLogger logger, CancellationToken cancellationToken) { return(new ObserverTaskBuilder <IDevice>(observer => bleAdapter.Search(observer, deviceFilter, stopAfterFirstResult, executor, logger, cancellationToken)).Task); }
public IReadOnlyList <IDevice> GetConnectedDevices(IDeviceFilter deviceFilter) { return(_bleAdapter.ConnectedDevices.Where(deviceFilter.IsWantedDevice).ToList()); }
private void AddFilter(IDeviceFilter filter, bool isReadonly) { this.RowCount++; this.RowStyles.Add(new RowStyle()); Type typControl = this.m_Application.GetControlType(filter.GetType(), typeof(System.Windows.Forms.Control)); if (typControl == null) { Label lab = new Label(); lab.Text = "未发现 " + filter.GetType().FullName + " 的筛选器控件"; lab.AutoEllipsis = true; lab.Padding = new System.Windows.Forms.Padding(3); lab.Dock = DockStyle.Bottom; this.Controls.Add(lab); if (this.EnabledRemove) { System.Windows.Forms.Button btnFilterRemove = new Button(); btnFilterRemove.Image = Properties.Resources.DeleteBlack; btnFilterRemove.Width = 24; btnFilterRemove.FlatStyle = FlatStyle.Flat; btnFilterRemove.FlatAppearance.BorderSize = 0; btnFilterRemove.Dock = DockStyle.Right; btnFilterRemove.Click += new EventHandler(btnFilterRemove_Click); this.Controls.Add(btnFilterRemove); } } else { System.Reflection.ConstructorInfo ciFilter = typControl.GetConstructor(new System.Type[] { }); object objFilterInstance = ciFilter.Invoke(new object[] { }); IDeviceFilterControl _FilterControl = objFilterInstance as IDeviceFilterControl; _FilterControl.SetApplication(this.m_Application); if (objFilterInstance is IUseAccount) { IUseAccount useAccount = objFilterInstance as IUseAccount; useAccount.SetAccount(this.m_Account); } _FilterControl.SetFilter(filter); Control ctl = objFilterInstance as Control; ctl.Dock = DockStyle.Bottom; if (isReadonly) { ctl.Enabled = false; } this.Controls.Add(ctl); if (this.EnabledRemove) { if (isReadonly) { Control ctlButton = new Control(); this.Controls.Add(ctlButton); } else { System.Windows.Forms.Button btnFilterRemove = new Button(); btnFilterRemove.Image = Properties.Resources.DeleteBlack; btnFilterRemove.Width = 24; btnFilterRemove.FlatStyle = FlatStyle.Flat; btnFilterRemove.FlatAppearance.BorderSize = 0; btnFilterRemove.Dock = DockStyle.Right; btnFilterRemove.Click += new EventHandler(btnFilterRemove_Click); this.Controls.Add(btnFilterRemove); } } } }
/// <summary> /// 添加设备筛选条件。 /// </summary> /// <param name="filter"></param> public void AddFilter(IDeviceFilter filter) { this.AddFilter(filter, false); }
public static SearchAdapter Search(this IAdapter bleAdapter, IObserver <IDevice> observer, IDeviceFilter deviceFilter, bool stopAfterFirstResult, IExecutor executor, IBleLogger logger, CancellationToken cancellationToken) { return(new SearchAdapter(bleAdapter, observer, deviceFilter, stopAfterFirstResult, executor, logger, cancellationToken)); }
public Task <IBleResult <IReadOnlyList <IDevice> > > SearchForAllDevicesAsync(IDeviceFilter deviceFilter, CancellationToken cancellationToken) { return(_bleAvailabilityManager.ExecuteWithBleAvailabilityCheckAsync(() => ExecuteDeviceSearchAsync(deviceFilter, false, cancellationToken))); }
public static Type GetDeviceType <T>(this IDeviceFilter <T> filter) where T : IDevice { return(typeof(T)); }
public Task <IBleResult> BeginSearchForAllDevicesAsync(IObserver <IDevice> observer, IDeviceFilter deviceFilter, CancellationToken cancellationToken) { return(_bleAvailabilityManager.ExecuteWithBleAvailabilityCheckAsync(async() => { await _searchSemaphore.WaitAsync(cancellationToken).ConfigureAwait(false); var searchCompletionObserver = new SearchCompletedObserver(observer, completedSuccessfully => _searchSemaphore.Release()); try { _bleAdapter.Search(searchCompletionObserver, deviceFilter, false, _executor, _logger, cancellationToken); } catch { _searchSemaphore.Release(); throw; } return BleResult.Success(); })); }