public AtemMacroStore(string address)
        {
            _macros           = new Dictionary <uint, MacroPropertiesGetCommand>();
            _client           = new AtemClient(address, false);
            _profile          = new DeviceProfileHandler();
            _dataTransferLock = new object();

            _client.OnReceive += _profile.HandleCommands;
            _client.OnReceive += OnCommand;

            _client.Connect();
        }
Example #2
0
        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);
        }