Example #1
0
        public Tuple <bool, IReadOnlyList <AtemDevice> > SetDeviceEnabled(string address, int port, bool enabled)
        {
            var id = AtemDeviceExt.Id(address, port);

            lock (_devices)
            {
                var changed = false;
                if (_devices.TryGetValue(id, out AtemDevice device))
                {
                    // Set state
                    device.Enabled = enabled;
                    // Now we should remember it
                    device.Remember = true;

                    // Persist to db
                    _dbDevices.Upsert(id, device);

                    // Ensure connection state
                    SetupConnection(device);

                    changed = true;
                }

                return(Tuple.Create(changed, ListDevices()));
            }
        }
Example #2
0
        public Tuple <bool, IReadOnlyList <AtemDevice> > AddDevice(string address, int port)
        {
            var id = AtemDeviceExt.Id(address, port);

            lock (_devices)
            {
                if (_devices.TryGetValue(id, out AtemDevice device))
                {
                    device.Remember = true;
                    device.Enabled  = true;


                    _dbDevices.Upsert(id, device);

                    // startup connection
                    SetupConnection(device);
                }
                else
                {
                    var doc = _devices[id] = new AtemDevice(new AtemDeviceInfo(id, "", DateTime.MinValue, address, port, new List <string>()))
                    {
                        Remember = true, // Remember anything created manually
                        Enabled  = true, // Enable for connections
                    };

                    _dbDevices.Upsert(id, doc);

                    // startup connection
                    SetupConnection(doc);
                }

                return(Tuple.Create(true, ListDevices()));
            }
        }
Example #3
0
        public Tuple <bool, IReadOnlyList <AtemDevice> > ForgetDevice(string address, int port)
        {
            var id = AtemDeviceExt.Id(address, port);

            lock (_devices)
            {
                var changed = false;
                if (_devices.TryGetValue(id, out AtemDevice device))
                {
                    // shutdown the connection
                    device.Enabled = false;
                    SetupConnection(device);

                    // TODO - don't delete it, unless it has not been seen in a while
                    _dbDevices.Delete(id);
                    changed = _devices.Remove(id);
                }

                return(Tuple.Create(changed, ListDevices()));
            }
        }
Example #4
0
 public static string Id(this AtemDeviceInfo info)
 {
     return(AtemDeviceExt.Id(info.Address, info.Port));
 }