/*
         * public static XMLScreenInformation ToXML(Screen screen)
         * {
         *  return new XMLScreenInformation(new XMLRectangle(screen.Bounds.X, screen.Bounds.Y, screen.Bounds.Width, screen.Bounds.Height), screen.DeviceName, screen.Primary);
         * }
         * public static XMLScreenInformation ToXML(ScreenInformation screen)
         * {
         *  return new XMLScreenInformation(ToXML(screen.Bounds), screen.DeviceID, screen.Primary);
         * }
         *
         * public static ScreenInformation ToNET(XMLScreenInformation screen)
         * {
         *  return new ScreenInformation(ToNET(screen.Bounds), screen.DeviceID, screen.Primary);
         * }
         * public static ScreenInformation[] ToNET(XMLScreenInformation[] screens)
         * {
         *  List<ScreenInformation> lista = new List<ScreenInformation>();
         *  foreach (var screen in screens)
         *  {
         *      lista.Add(ToNET(screen));
         *  }
         *  return lista.ToArray();
         * }
         *
         * public static XMLPlayerWindowInformation ToXML(PlayerWindowInformation info)
         * {
         *  MemoryStream mem = new MemoryStream();
         *
         *  if (info.Background != null)
         *      info.Background.Save(mem, info.Background.RawFormat);
         *
         *  return new XMLPlayerWindowInformation() { Components = ToXML(info.Components).ToArray(), Display = ToXML(info.Display), Background = mem.ToArray(), BackgroundImageLayout = Convert.ToInt32(info.BackgroundImageLayout) };
         * }
         * public static PlayerWindowInformation ToNET(XMLPlayerWindowInformation info)
         * {
         *  Image background = null;
         *
         *  if (info.Background != null && info.Background.Length > 0)
         *      background = Image.FromStream(new MemoryStream(info.Background));
         *
         *  return new PlayerWindowInformation() { Components = ToNET(info.Components), Display = ToNET(info.Display), Background = background, BackgroundImageLayout = (ImageLayout)info.BackgroundImageLayout };
         * }
         *
         * public static XMLPlayerWindowInformation2 ToXML(PlayerWindowInformation2 info)
         * {
         *  ScreenInformation[] keys = info.Configuration.Keys.ToArray();
         *  ItemConfiguration[][] values = new ItemConfiguration[keys.Length][];
         *
         *  XMLScreenInformation[] newKeys = new XMLScreenInformation[keys.Length];
         *  XMLItemConfiguration[][] newValues = new XMLItemConfiguration[keys.Length][];
         *
         *  int index = 0;
         *
         *  foreach (var key in keys)
         *  {
         *      values[index] = info.Configuration[key].ToArray();
         *
         *      newKeys[index] = ToXML(key);
         *
         *      newValues[index++] = ToXML(values[index]).ToArray();
         *  }
         *
         *  XMLPlayerWindowInformation2 res = new XMLPlayerWindowInformation2() { Displays = newKeys, Components = newValues };
         *
         *  return res;
         * }
         * public static PlayerWindowInformation2 ToNET(XMLPlayerWindowInformation2 info)
         * {
         *  PlayerWindowInformation2 res = new PlayerWindowInformation2();
         *  int index = 0;
         *
         *  foreach (var key in info.Displays)
         *  {
         *      res.Configuration.Add(ToNET(key), ToNET(info.Components[index]));
         *  }
         *
         *  return res;
         * }
         *
         */
        #endregion
        #region TV

        public static XMLChannel ToXML(Channel channel)
        {
            ChannelDVBT ch = channel as ChannelDVBT;

            return(new XMLChannel
            {
                AudioDecoderDevice = ch.AudioDecoderDevice,
                AudioDecoderType = Convert.ToInt32(ch.AudioDecoderType),
                AudioPid = ch.AudioPid,
                AudioPids = ch.AudioPids,
                AudioRendererDevice = ch.AudioRendererDevice,
                Bandwidth = ch.Bandwidth,
                CaptureDevice = ch.CaptureDevice,
                ChannelNumber = ch.ChannelNumber,
                EcmPid = ch.EcmPid,
                EcmPids = ch.EcmPids,
                Frequency = ch.Frequency,
                Guard = Convert.ToInt32(ch.Guard),
                H264DecoderDevice = ch.H264DecoderDevice,
                HAlpha = Convert.ToInt32(ch.HAlpha),
                InnerFEC = Convert.ToInt32(ch.InnerFEC),
                InnerFECRate = Convert.ToInt32(ch.InnerFECRate),
                Logo = ch.Logo,
                LPInnerFEC = Convert.ToInt32(ch.LPInnerFEC),
                LPInnerFECRate = Convert.ToInt32(ch.LPInnerFECRate),
                Mode = Convert.ToInt32(ch.Mode),
                Modulation = Convert.ToInt32(ch.Modulation),
                MPEG2DecoderDevice = ch.MPEG2DecoderDevice,
                Name = ch.Name,
                ONID = ch.ONID,
                OtherFrequencyInUse = ch.OtherFrequencyInUse,
                OuterFEC = Convert.ToInt32(ch.OuterFEC),
                OuterFECRate = Convert.ToInt32(ch.OuterFECRate),
                PcrPid = ch.PcrPid,
                PmtPid = ch.PmtPid,
                ReferenceClock = Convert.ToInt32(ch.ReferenceClock),
                SID = ch.SID,
                SymbolRate = ch.SymbolRate,
                TeletextPid = ch.TeletextPid,
                TSID = ch.TSID,
                TunerDevice = ch.TunerDevice,
                VideoAspectRatioFactor = ch.VideoAspectRatioFactor,
                VideoDecoderType = Convert.ToInt32(ch.VideoDecoderType),
                VideoKeepAspectRatio = ch.VideoKeepAspectRatio,
                VideoOffset = NetToXMLConverter.ToXML(ch.VideoOffset),
                VideoPid = ch.VideoPid,
                VideoRendererDevice = ch.VideoRendererDevice,
                VideoZoom = ch.VideoZoom,
                VideoZoomMode = Convert.ToInt32(ch.VideoZoom)
            });
        }
 public static Channel ToNET(XMLChannel channel)
 {
     return(new ChannelDVBT
     {
         AudioDecoderDevice = channel.AudioDecoderDevice,
         AudioDecoderType = (TV2Lib.ChannelDVB.AudioType)channel.AudioDecoderType,
         AudioPid = channel.AudioPid,
         AudioPids = channel.AudioPids,
         AudioRendererDevice = channel.AudioRendererDevice,
         Bandwidth = channel.Bandwidth,
         CaptureDevice = channel.CaptureDevice,
         ChannelNumber = channel.ChannelNumber,
         EcmPid = channel.EcmPid,
         EcmPids = channel.EcmPids,
         Frequency = channel.Frequency,
         Guard = (DirectShowLib.BDA.GuardInterval)channel.Guard,
         H264DecoderDevice = channel.H264DecoderDevice,
         HAlpha = (DirectShowLib.BDA.HierarchyAlpha)channel.HAlpha,
         InnerFEC = (DirectShowLib.BDA.FECMethod)channel.InnerFEC,
         InnerFECRate = (DirectShowLib.BDA.BinaryConvolutionCodeRate)channel.InnerFECRate,
         Logo = channel.Logo,
         LPInnerFEC = (DirectShowLib.BDA.FECMethod)channel.LPInnerFEC,
         LPInnerFECRate = (DirectShowLib.BDA.BinaryConvolutionCodeRate)channel.LPInnerFECRate,
         Mode = (DirectShowLib.BDA.TransmissionMode)channel.Mode,
         Modulation = (DirectShowLib.BDA.ModulationType)channel.Modulation,
         MPEG2DecoderDevice = channel.MPEG2DecoderDevice,
         Name = channel.Name,
         ONID = channel.ONID,
         OtherFrequencyInUse = channel.OtherFrequencyInUse,
         OuterFEC = (DirectShowLib.BDA.FECMethod)channel.OuterFEC,
         OuterFECRate = (DirectShowLib.BDA.BinaryConvolutionCodeRate)channel.OuterFECRate,
         PcrPid = channel.PcrPid,
         PmtPid = channel.PmtPid,
         ReferenceClock = (TV2Lib.ChannelDVB.Clock)channel.ReferenceClock,
         SID = channel.SID,
         SymbolRate = channel.SymbolRate,
         TeletextPid = channel.TeletextPid,
         TSID = channel.TSID,
         TunerDevice = channel.TunerDevice,
         VideoAspectRatioFactor = channel.VideoAspectRatioFactor,
         VideoDecoderType = (TV2Lib.ChannelDVB.VideoType)channel.VideoDecoderType,
         VideoKeepAspectRatio = channel.VideoKeepAspectRatio,
         VideoOffset = NetToXMLConverter.ToNET(channel.VideoOffset),
         VideoPid = channel.VideoPid,
         VideoRendererDevice = channel.VideoRendererDevice,
         VideoZoom = channel.VideoZoom,
         VideoZoomMode = (VideoSizeMode)channel.VideoZoom
     });
 }