public AtemRepository(IHubContext <DevicesHub> context, TransferJobMonitor transfers) { _db = new LiteDatabase(@"MyData.db"); _dbDevices = _db.GetCollection <AtemDevice>("devices"); _devices = new Dictionary <string, AtemDevice>(); _context = context; _transfers = transfers; // Load up old devices foreach (AtemDevice device in _dbDevices.FindAll()) { device.Subscriptions = new HashSet <string>(); SetupConnection(device); _devices[device.Info.Id()] = device; } SendDevicesDebounce = Util.Util.Debounce(() => _context.Clients.All.SendAsync("devices", ListDevices()), 500); _discovery = new AtemDiscoveryService(5000); _discovery.OnDeviceSeen += OnDeviceSeen; _discovery.OnDeviceLost += OnDeviceLost; }
public AtemMediaCache(TransferJobMonitor monitor) { _monitor = monitor; }
public AtemClientExt(string deviceId, AtemClient client, IHubContext <DevicesHub> context, TransferJobMonitor transfers, HashSet <string> subscriptions) { _deviceId = deviceId; _profile = new DeviceProfileHandler(); _subscriptions = subscriptions; _state = new AtemState(); _context = context; _mediaCache = new AtemMediaCache(transfers); Client = client; Client.OnReceive += _profile.HandleCommands; Client.OnConnection += sender => { Connected = true; OnChange?.Invoke(this); SendState(GetState()); }; Client.OnDisconnect += sender => { Connected = false; OnChange?.Invoke(this); SendState(null); }; Client.OnReceive += (sender, commands) => { var changedPaths = new HashSet <string>(); var errors = new List <string>(); lock (_state) { foreach (var command in commands) { var res = AtemStateBuilder.Update(_state, command); changedPaths.AddRange(res.ChangedPaths); if (!res.Success) { if (res.Errors.Count > 0) { errors.AddRange(res.Errors); } else { errors.Add($"Failed to update state for {command.GetType().Name}"); } } } } AtemState newState = GetState(); /* * var diffs = new Dictionary<string, object>(); * foreach (string path in changedPaths) * { * diffs.Add(path, new object()); // TODO * }*/ SendStateDiff(GetState(), changedPaths); _mediaCache.EnsureMediaIsDownloaded(Client, newState); }; Client.DataTransfer.OnJobStarted += (sender, job) => transfers.JobStarted(deviceId, job); Client.DataTransfer.OnJobQueued += (sender, job) => transfers.JobQueued(deviceId, job); }