protected void OnUpdatedTemplates(DeviceHolder device)
 {
     if (UpdatedTemplates != null)
     {
         UpdatedTemplates(this, new HostEventArgs(device));
     }
 }
 public Channel GetChannel(string label)
 {
     if (channelInfos_ != null && channelInfos_.ContainsKey(label))
     {
         CasparChannelInformation info = channelInfos_[label];
         if (devices_ != null && devices_.ContainsKey(info.Hostname))
         {
             DeviceHolder device = devices_[info.Hostname];
             if ((device.CasparDevice.Channels.Count >= info.Channel) && (info.Channel > 0))
             {
                 return(device.CasparDevice.Channels[info.Channel - 1]);
             }
         }
     }
     return(null);
 }
 internal HostEventArgs(DeviceHolder device)
 {
     Device = device;
 }
 protected void OnUpdatedTemplates(DeviceHolder device)
 {
     if (UpdatedTemplates != null)
         UpdatedTemplates(this, new HostEventArgs(device));
 }
 internal HostEventArgs(DeviceHolder device)
 {
     Device = device;
 }
        public void SetChannels(CasparChannelInformationList channels)
        {
            if (channels != null)
            {
                Dictionary <string, DeviceHolder>             newDevices      = new Dictionary <string, DeviceHolder>();
                Dictionary <string, CasparChannelInformation> newChannelInfos = new Dictionary <string, CasparChannelInformation>();
                foreach (CasparChannelInformation channelInfo in channels)
                {
                    if (!newDevices.ContainsKey(channelInfo.Hostname))
                    {
                        DeviceHolder device = null;

                        //Get device from old collection or create new
                        if (devices_ != null && devices_.ContainsKey(channelInfo.Hostname))
                        {
                            device = devices_[channelInfo.Hostname];
                            devices_.Remove(channelInfo.Hostname);

                            device.Channels.Clear();
                        }
                        else
                        {
                            device = CreateDevice(channelInfo.Hostname, channelInfo.Port);
                        }

                        //add device to new collection
                        if (device != null)
                        {
                            device.Channels.Add(channelInfo);
                            channelInfo.Online = device.HasValidConnection;
                            newDevices.Add(channelInfo.Hostname, device);
                        }
                    }
                    else
                    {
                        newDevices[channelInfo.Hostname].Channels.Add(channelInfo);
                        channelInfo.Online = newDevices[channelInfo.Hostname].HasValidConnection;
                    }

                    newChannelInfos.Add(channelInfo.Label, channelInfo);
                }

                if (connected)
                {
                    //disconnect from unused devices
                    if (devices_ != null)
                    {
                        foreach (DeviceHolder device in devices_.Values)
                        {
                            device.CasparDevice.Disconnect();
                        }
                    }

                    //connect to new devices
                    foreach (DeviceHolder device in newDevices.Values)
                    {
                        if (!device.CasparDevice.IsConnected)
                        {
                            device.CasparDevice.Connect();
                        }
                    }
                }

                //set new collection as current
                System.Threading.Interlocked.Exchange <Dictionary <string, DeviceHolder> >(ref devices_, newDevices);
                System.Threading.Interlocked.Exchange <Dictionary <string, CasparChannelInformation> >(ref channelInfos_, newChannelInfos);

                UpdateValidConnections();
            }
        }