public override void OnEvent(DeviceEvents deviceEvents) { base.OnEvent(deviceEvents); foreach (DeviceEvent deviceEvent in deviceEvents.services) { if (deviceEvent.eventType == "start_scan") { ScanSubdeviceNotify scanSubdeviceNotify = JsonUtil.ConvertDicToObject <ScanSubdeviceNotify>( deviceEvent.paras); if (subDevDiscoveryListener != null) { subDevDiscoveryListener.OnScan(scanSubdeviceNotify); } } else if (deviceEvent.eventType == "add_sub_device_notify") { SubDevicesInfo subDevicesInfo = JsonUtil.ConvertDicToObject <SubDevicesInfo>( deviceEvent.paras); OnAddSubDevices(subDevicesInfo); } else if (deviceEvent.eventType == "delete_sub_device_notify") { SubDevicesInfo subDevicesInfo = JsonUtil.ConvertDicToObject <SubDevicesInfo>( deviceEvent.paras); OnDeleteSubDevices(subDevicesInfo); } } }
private static IDictionary <string, string> getDeviceEvents(DeviceEvents events) { var results = new Dictionary <string, string>(); for (var j = 1; j <= events.Count; j++) { results.Add(events[j].Name, events[j].EventID); } return(results); }
protected override void OnSessionChange(SessionChangeDescription changeDescription) { base.OnSessionChange(changeDescription); switch (changeDescription.Reason) { case SessionChangeReason.SessionLock: DeviceEvents.OnDeviceLocked(); break; case SessionChangeReason.SessionUnlock: DeviceEvents.OnDeviceUnlocked(); break; } }
private void OnEvent(RawMessage message) { DeviceEvents deviceEvents = JsonUtil.ConvertJsonStringToObject <DeviceEvents>(message.ToString()); if (deviceEvents == null) { Log.Error("invalid events"); return; } device.OnEvent(deviceEvents); }
public IEnumerable <IEvent> GetMatches(params Func <IEvent, bool>[] filters) { var deviceMatches = DeviceEvents.GetMatches(filters).Cast <IEvent>(); var networkEvents = NetworkEvents.GetMatches(filters).Cast <IEvent>(); var result = deviceMatches.Concat(networkEvents); result = result.OrderBy(x => x.TimeStamp); result = result.ToArray(); return(result); }
/// <summary> /// 事件上报 /// </summary> /// <param name="evnt">事件</param> public void ReportEvent(DeviceEvent evnt) { string deviceId = clientConf.DeviceId; DeviceEvents events = new DeviceEvents(); events.deviceId = deviceId; List <DeviceEvent> services = new List <DeviceEvent>(); services.Add(evnt); events.services = services; Report(new PubMessage(CommonTopic.TOPIC_SYS_EVENTS_UP, events)); }
public AddDeviceViewModel(IDeviceRelatedRepository repo) { Repository = repo; AddDeviceCommand = RegisterCommandAction( (obj) => { var newDevice = new Device { InventoryNumber = InputtedInventoryNumber, DeviceTypeID = SelectedDeviceType.ID, NetworkName = InputtedNetworkName, }; try { Repository.AddDevice(newDevice); Repository.SaveChanges(); // Device should be counted as added to storage when added var addedDeviceNote = new DeviceMovementHistoryNote { // N/A cabinet in N/A housing TargetCabinetID = -4, DeviceID = newDevice.ID, Reason = "Доставлено на склад", Date = DateTime.Now }; Repository.FixDeviceMovement(addedDeviceNote); Repository.SaveChanges(); DeviceEvents.RaiseOnNewDeviceAdded(newDevice); InputtedInventoryNumber = ""; InputtedNetworkName = ""; MessageToUser = "******"; } catch (Exception e) { MessageToUser = e.Message; Repository.RemoveDevice(newDevice); } }, (obj) => { return(!string.IsNullOrEmpty(InputtedInventoryNumber) && !string.IsNullOrEmpty(InputtedNetworkName) && SelectedDeviceType != null); } ); }
private InputManager() { _stagingArea = new Stack(); InputDeviceEvents = new DeviceEvents[(int)InputDeviceType.Last]; for (int i = 0; i < (int)InputDeviceType.Last; i++) { InputDeviceEvents[i] = new DeviceEvents(); } _continueProcessingStagingAreaCallback = new DispatcherOperationCallback(ProcessStagingArea); _buttonDevice = new ButtonDevice(this); _touchDevice = new TouchDevice(this); _genericDevice = new GenericDevice(this); }
/// <summary> /// 事件回调,由SDK自动调用 /// </summary> /// <param name="deviceEvents">设备事件</param> public virtual void OnEvent(DeviceEvents deviceEvents) { // 子设备的 if (deviceEvents.deviceId != null && deviceEvents.deviceId != this.deviceId) { return; } foreach (DeviceEvent evnt in deviceEvents.services) { IService deviceService = this.GetService(evnt.serviceId); if (deviceService != null) { deviceService.OnEvent(evnt); } } }
public void Add(IEvent @event) { if (@event is IDeviceEvent) { var deviceEvent = (IDeviceEvent)@event; DeviceEvents.Add(deviceEvent); return; } if (@event is INetworkEvent) { var networkEvent = (INetworkEvent)@event; NetworkEvents.Add(networkEvent); return; } throw new Exception("Unknown event type " + @event.GetType()); }
public ConfigureIPSettingsViewModel(IIPAddressRepository repo) { NetworkConfigurator = new NetworkConfigurator(new XMLNetworkConfigurationReader()); Repository = repo; InputtedNetworkMask = NetworkConfigurator.Mask.ToString(); ApplyNetworkSettingsChangesCommand = RegisterCommandAction( (obj) => { try { NetworkConfigurator.Mask = byte.Parse(InputtedNetworkMask); Repository.SetNewRangeOfIPAddresses(NetworkConfigurator.IPAddresses); Repository.SaveChanges(); NetworkConfigurator.WriteMask(new XMLNetworkConfigurationWriter()); MessageToUser = "******"; DeviceEvents.RaiseOnNetworkConfigurationChanged( InputtedNetworkAddress, byte.Parse(InputtedNetworkMask) ); } catch (Exception e) { MessageToUser = e.Message; } }, (obj) => { // Move to special validator class soon try { var mask = byte.Parse(InputtedNetworkMask); if (mask <= 32 && mask >= 0) { return(true); } return(false); } catch { return(false); } } ); }
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 ) ); } ); }
public IEnumerator <IEvent> GetEnumerator() { var sources = new [] { DeviceEvents.Select(x => x as IEvent).GetEnumerator(), NetworkEvents.Select(x => x as IEvent).GetEnumerator() }; var more = new bool[sources.Length]; for (var i = 0; i < sources.Length; i++) { more[i] = sources[i].MoveNext(); } while (more.Contains(true)) { var smallestIndex = -1; for (var i = 0; i < sources.Length; i++) { if (!more[i]) { continue; } if (smallestIndex == -1 || sources[i].Current.TimeStamp < sources[smallestIndex].Current.TimeStamp) { smallestIndex = i; } } ; yield return(sources[smallestIndex].Current); more[smallestIndex] = sources[smallestIndex].MoveNext(); } }
public static void TestPriorityQueue(int numOperations) { Console.WriteLine("\n------ Testing priority queue ------"); Random rand = new Random(0); PriorityQueue <DeviceEvents> pq = new PriorityQueue <DeviceEvents>(); for (int op = 0; op < numOperations; op++) { int opType = rand.Next((int)EventType.CommEvent, (int)EventType.UserCancel); if (opType == (int)EventType.CommEvent) { double priority = (100.0 - 1.0) * rand.NextDouble() + 1.0; pq.Enqueue(new DeviceEvents(EventType.CommEvent, priority)); if (pq.IsConsistent() == false) { Console.WriteLine($"Test fails after enqueue operation # {op}"); } } else { if (pq.Count() > 0) { DeviceEvents e = pq.Dequeue(); if (pq.IsConsistent() == false) { Console.WriteLine($"Test fails after dequeue operation # {op}"); } } } } Console.WriteLine("All tests passed"); }
public PubMessage(string topic, DeviceEvents events) { this.Topic = topic; this.Message = JsonUtil.ConvertObjectToJsonString(events); }