网络精灵

编程入门 行业动态 更新时间:2024-10-28 13:19:52
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml;

namespace 网络电视
{
    public class ChannelA : ChannelBase
    {
        public override void Fetch()
        {
            XmlDocument doc = new XmlDocument();
            doc.Load(Path);
            XmlNode root = doc.DocumentElement;

            foreach (XmlNode item in root.ChildNodes)
            {
                //一个Item
                if (item.Name == "tvProgramTable")
                {
                    foreach (XmlNode child in item.ChildNodes)
                    {
                        //一个child是一个节目单对象
                        TvProgram tv = new TvProgram();
                        tv.PlayTime = Convert.ToDateTime(child["playTime"].InnerText);
                        tv.Median = child["meridien"].InnerText;
                        tv.ProgramName = child["programName"].InnerText;
                        tv.FilePath = child["path"].InnerText;

                        ProgramList.Add(tv);

                    }
                }
            }
        }


        

    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml;

namespace 网络电视
{
  public  class ChannelB:ChannelBase
    {
      public override void Fetch()
      {
          XmlDocument doc = new XmlDocument();
          doc.Load(Path);
          XmlNode root = doc.DocumentElement;
          foreach (XmlNode item in root.ChildNodes)
          {
              foreach (XmlNode child in item.ChildNodes)
              {
                  TvProgram tp = new TvProgram();
                  tp.PlayTime = Convert.ToDateTime(child["playTime"].InnerText);
                  tp.ProgramName = child["name"].InnerText;
                  tp.FilePath = child["path"].InnerText;

                  ProgramList.Add(tp);
              }
          }
      }  

     
    }
}


    

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using  System.Xml;
namespace 网络电视
{
  public   abstract class ChannelBase
    {
        public ChannelBase()
        {
            programList = new List<TvProgram>();
        }

        #region 属性


        
        private string channelName;
        public string ChannelName
        {
            get { return channelName; }
            set { channelName = value; }
        }
       
        private string path;
        public string Path
        {
            get { return path; }
            set { path = value; }
        }
       
        private List<TvProgram> programList;
        public List<TvProgram> ProgramList
        {
            get { return programList; }
            set { this.programList = value; }
        }
        #endregion

        //Fetch,读取频道的xml文件
        public abstract void Fetch();
    }
}

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace 网络电视
{
 public   class ChannelFactory
    {

     
        public static ChannelBase CreatChannel(string type)
        {
            ChannelBase channel = null;
            switch (type)
            {

                case "TypeA":
                    channel = new ChannelA();
                    break;
                case "TypeB":
                    channel = new ChannelB();
                    break;


            }
            return channel;
        }


    
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml;

namespace 网络电视
{
  public  class ChannelManager
    {
        private Dictionary<string, ChannelBase> fullChannels = null;

        public Dictionary<string, ChannelBase> FullChannels
        {
            get { return fullChannels; }
            set { fullChannels = value; }
        }

        public ChannelManager()
        {
            fullChannels=new Dictionary<string, ChannelBase>();
        }

        public void ChangeXmlToList()
        {
           XmlDocument doc=new XmlDocument();
            doc.Load("files/FullChannels.xml");
            XmlNode root = doc.DocumentElement;
            foreach (XmlNode item in root.ChildNodes)
            {
                string type = item["channelType"].InnerText;
                ChannelBase channel = ChannelFactory.CreatChannel(type);
                channel.ChannelName = item["tvChannel"].InnerText;
                channel.Path = item["path"].InnerText;
                fullChannels.Add(channel.ChannelName, channel);


            }
        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace 网络电视
{
  public  class TvProgram
    {
         private DateTime playTime;
        public DateTime PlayTime
        {
            get { return playTime; }
            set { playTime = value; }
        }
        /// <summary>
        /// 时段
        /// </summary>
        private string median;
        public string Median
        {
            get { return median; }
            set { median = value; }
        }
       
        private string programName;
        public string ProgramName
        {
            get { return programName; }
            set { programName = value; }
        }
       
        private string filePath;
         public string FilePath
        {
            get { return filePath; }
            set { filePath = value; }
        }
       
    }
}


更多推荐

网络精灵

本文发布于:2023-06-14 01:09:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1421430.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:精灵   网络

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!