private async void DoDisplayChannelInfo(IChannel channel)
        {
            if (channel != null)
            {
                ChannelInformation form = new ChannelInformation(this)
                {
                    MyChannel = channel,
                    MyContext = _context
                };

                if (form.ShowDialog() == DialogResult.OK)
                {
                    TextBoxLogWriteLine("Channel '{0}' : updating...", channel.Name);

                    channel.Description = form.GetChannelDescription;
                    channel.Input.KeyFrameInterval = form.KeyframeInterval;

                    if (channel.EncodingType != ChannelEncodingType.None && channel.Encoding != null && channel.State == ChannelState.Stopped)
                    {
                        channel.Encoding.SystemPreset = form.SystemPreset; // we update the system preset
                    }

                    // HLS Fragment per segment
                    if (form.HLSFragPerSegment != null)
                    {
                        if (channel.Output == null)
                        {
                            channel.Output = new ChannelOutput() { Hls = new ChannelOutputHls() { FragmentsPerSegment = form.HLSFragPerSegment } };
                        }
                        else if (channel.Output.Hls == null)
                        {
                            channel.Output.Hls = new ChannelOutputHls() { FragmentsPerSegment = form.HLSFragPerSegment };
                        }
                        else
                        {
                            channel.Output.Hls.FragmentsPerSegment = form.HLSFragPerSegment;
                        }
                    }
                    else // form.HLSFragPerSegment is null
                    {
                        if (channel.Output != null && channel.Output.Hls != null && channel.Output.Hls.FragmentsPerSegment != null)
                        {
                            channel.Output.Hls.FragmentsPerSegment = null;
                        }
                    }

                    // Input allow list
                    if (form.GetInputIPAllowList != null)
                    {
                        if (channel.Input.AccessControl == null)
                        {
                            channel.Input.AccessControl = new ChannelAccessControl();
                        }
                        channel.Input.AccessControl.IPAllowList = form.GetInputIPAllowList;
                    }
                    else
                    {
                        if (channel.Input.AccessControl != null)
                        {
                            channel.Input.AccessControl.IPAllowList = null;
                        }
                    }


                    // Preview allow list
                    if (form.GetPreviewAllowList != null)
                    {
                        if (channel.Preview.AccessControl == null)
                        {
                            channel.Preview.AccessControl = new ChannelAccessControl();
                        }
                        channel.Preview.AccessControl.IPAllowList = form.GetPreviewAllowList;

                    }
                    else
                    {
                        if (channel.Preview.AccessControl != null)
                        {
                            channel.Preview.AccessControl.IPAllowList = null;
                        }
                    }


                    // Client Access Policy
                    if (form.GetChannelClientPolicy != null)
                    {
                        if (channel.CrossSiteAccessPolicies == null)
                        {
                            channel.CrossSiteAccessPolicies = new CrossSiteAccessPolicies();
                        }
                        channel.CrossSiteAccessPolicies.ClientAccessPolicy = form.GetChannelClientPolicy;

                    }
                    else
                    {
                        if (channel.CrossSiteAccessPolicies != null)
                        {
                            channel.CrossSiteAccessPolicies.ClientAccessPolicy = null;
                        }
                    }


                    // Cross domain  Policy
                    if (form.GetChannelCrossdomaintPolicy != null)
                    {
                        if (channel.CrossSiteAccessPolicies == null)
                        {
                            channel.CrossSiteAccessPolicies = new CrossSiteAccessPolicies();
                        }
                        channel.CrossSiteAccessPolicies.CrossDomainPolicy = form.GetChannelCrossdomaintPolicy;

                    }
                    else
                    {
                        if (channel.CrossSiteAccessPolicies != null)
                        {
                            channel.CrossSiteAccessPolicies.CrossDomainPolicy = null;
                        }
                    }
                    await Task.Run(() => ChannelInfo.ChannelExecuteOperationAsync(channel.SendUpdateOperationAsync, channel, "updated", _context, this, dataGridViewChannelsV));
                }
            }
        }
Esempio n. 2
0
        private async void DoDisplayChannelInfo(List<IChannel> channels)
        {
            var firstchannel = channels.FirstOrDefault();
            bool multiselection = channels.Count > 1;

            if (firstchannel != null)
            {
                ChannelInformation form = new ChannelInformation(this)
                {
                    MyChannel = firstchannel,
                    MyContext = _context,
                    MultipleSelection = multiselection
                };

                if (form.ShowDialog() == DialogResult.OK)
                {
                    var modifications = form.Modifications;
                    if (multiselection)
                    {
                        var formSettings = new SettingsSelection("channels", modifications);
                        if (formSettings.ShowDialog() != DialogResult.OK)
                        {
                            return;
                        }
                        else
                        {
                            modifications = (ExplorerChannelModifications)formSettings.SettingsObject;
                        }
                    }

                    foreach (var channel in channels)
                    {
                        TextBoxLogWriteLine("Channel '{0}' : updating...", channel.Name);

                        if (modifications.Description) // let' update description if needed
                        {
                            channel.Description = form.GetChannelDescription;
                        }
                        if (modifications.KeyFrameInterval)
                        {
                            channel.Input.KeyFrameInterval = form.KeyframeInterval;
                        }

                        if (channel.EncodingType == firstchannel.EncodingType)
                        {
                            if (channel.EncodingType != ChannelEncodingType.None && channel.Encoding != null && channel.State == ChannelState.Stopped)
                            {
                                if (modifications.SystemPreset)
                                {
                                    channel.Encoding.SystemPreset = form.SystemPreset; // we update the system preset
                                }


                                if (modifications.AudioStreams) // user modified it
                                {
                                    channel.Encoding.AudioStreams = form.AudioStreamList;
                                }

                                if (modifications.VideoStreams) // user modified it
                                {
                                    channel.Encoding.VideoStreams = form.VideoStreamList;
                                }
                            }
                            else if (channel.EncodingType != ChannelEncodingType.None && channel.State != ChannelState.Stopped)
                            {
                                TextBoxLogWriteLine("Channel '{0}' : must be stoped to update the encoding settings", channel.Name);
                            }
                            else if (channel.EncodingType != ChannelEncodingType.None && channel.Encoding == null)
                            {
                                TextBoxLogWriteLine("Channel '{0}' : configured as encoding channel but settings are null", channel.Name, true);
                            }
                        }

                        if (modifications.HLSFragPerSegment)
                        {
                            // HLS Fragment per segment
                            if (form.HLSFragPerSegment != null)
                            {
                                if (channel.Output == null)
                                {
                                    channel.Output = new ChannelOutput() { Hls = new ChannelOutputHls() { FragmentsPerSegment = form.HLSFragPerSegment } };
                                }
                                else if (channel.Output.Hls == null)
                                {
                                    channel.Output.Hls = new ChannelOutputHls() { FragmentsPerSegment = form.HLSFragPerSegment };
                                }
                                else
                                {
                                    channel.Output.Hls.FragmentsPerSegment = form.HLSFragPerSegment;
                                }
                            }
                            else // form.HLSFragPerSegment is null
                            {
                                if (channel.Output != null && channel.Output.Hls != null && channel.Output.Hls.FragmentsPerSegment != null)
                                {
                                    channel.Output.Hls.FragmentsPerSegment = null;
                                }
                            }
                        }

                        if (modifications.InputIPAllowList)
                        {
                            // Input allow list
                            if (form.GetInputIPAllowList != null)
                            {
                                if (channel.Input.AccessControl == null)
                                {
                                    channel.Input.AccessControl = new ChannelAccessControl();
                                }
                                channel.Input.AccessControl.IPAllowList = form.GetInputIPAllowList;
                            }
                            else
                            {
                                if (channel.Input.AccessControl != null)
                                {
                                    channel.Input.AccessControl.IPAllowList = null;
                                }
                            }
                        }

                        if (modifications.PreviewIPAllowList)
                        {
                            // Preview allow list
                            if (form.GetPreviewAllowList != null)
                            {
                                if (channel.Preview.AccessControl == null)
                                {
                                    channel.Preview.AccessControl = new ChannelAccessControl();
                                }
                                channel.Preview.AccessControl.IPAllowList = form.GetPreviewAllowList;
                            }
                            else
                            {
                                if (channel.Preview.AccessControl != null)
                                {
                                    channel.Preview.AccessControl.IPAllowList = null;
                                }
                            }
                        }


                        if (modifications.ClientAccessPolicy)
                        {
                            // Client Access Policy
                            if (form.GetChannelClientPolicy != null)
                            {
                                if (channel.CrossSiteAccessPolicies == null)
                                {
                                    channel.CrossSiteAccessPolicies = new CrossSiteAccessPolicies();
                                }
                                channel.CrossSiteAccessPolicies.ClientAccessPolicy = form.GetChannelClientPolicy;

                            }
                            else
                            {
                                if (channel.CrossSiteAccessPolicies != null)
                                {
                                    channel.CrossSiteAccessPolicies.ClientAccessPolicy = null;
                                }
                            }
                        }

                        if (modifications.CrossDomainPolicy)
                        {
                            // Cross domain  Policy
                            if (form.GetChannelCrossdomainPolicy != null)
                            {
                                if (channel.CrossSiteAccessPolicies == null)
                                {
                                    channel.CrossSiteAccessPolicies = new CrossSiteAccessPolicies();
                                }
                                channel.CrossSiteAccessPolicies.CrossDomainPolicy = form.GetChannelCrossdomainPolicy;

                            }
                            else
                            {
                                if (channel.CrossSiteAccessPolicies != null)
                                {
                                    channel.CrossSiteAccessPolicies.CrossDomainPolicy = null;
                                }
                            }
                        }

                        await Task.Run(() => ChannelInfo.ChannelExecuteOperationAsync(channel.SendUpdateOperationAsync, channel, "updated", _context, this, dataGridViewChannelsV));
                    }
                }
            }
        }