网络精灵

来源:互联网 发布:ubuntu 更新gcc6.0 编辑:程序博客网 时间:2024/05/01 15:13
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; }        }           }}


0 0
原创粉丝点击