网络精灵

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

namespace Day08_02网络精灵
{
   public  class ChannelA:ChannelBase
    {
       public override void Fetch()
       {

       }
    }
}

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

namespace Day08_02网络精灵
{
   public class ChannelB:ChannelBase
    {
       public override void Fetch()
       {

       }
    }
}

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

namespace Day08_02网络精灵
{
   public abstract class ChannelBase
    {
        /// 频道名称
       private string channelName;
       public string ChannelName { get; set; }
       /// 频道路径
       private string path;
       public string Path { get; set; }
       /// 节目列表
       private List<TvProgram> programList;
       public List<TvProgram> ProgramList { get; set; }
       //Fetch,读取频道的xml文件
       public abstract void Fetch();
    }
}

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

namespace Day08_02网络精灵
{
   public class ChannelFactory
    {
       public static ChannelBase CreateChannel(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 Day08_02网络精灵
{
    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)
            {
                //一个item就是一个Channel对象
                string type = item["channelType"].InnerText;
                ChannelBase channel = ChannelFactory.CreateChannel(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 Day08_02网络精灵
{
   public  class TvProgram
   {
       //播出时间
       private DateTime playTime;
       public DateTime PlayTime { get; set; }
       //时段
       private string median;
       public string Median { get; set; }
       //名称
       private string programName;
       public string ProgramName { get; set; }
       //文件路径
       private string filePath;
       public string FilePath  { get; set; }
   }
}

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

namespace Day08_02网络精灵
{
   public  class TypeAchannel:ChannelBase
    {
       public override void Fetch()
       {
           XmlDocument xmlDoc=new XmlDocument();
           try
           {
               xmlDoc.Load(Path);
           }
           catch (Exception ex)
           {
               Console.WriteLine("文件加载"+ex.Message);
               return;
           }
           XmlElement elem = xmlDoc.DocumentElement;
           if (ProgramList==null)
           {
               ProgramList = new List<TvProgram>();
           }
           foreach (XmlNode node in elem.ChildNodes)
           {
               if (node .Name=="tvProgramTable")
               {
                   foreach (XmlNode subNode in node.ChildNodes)
                   {
                       TvProgram program = new TvProgram();
                       program.PlayTime = DateTime.Parse(subNode["playTime"].InnerText);
                       program.Median = subNode["meridien"].InnerText;
                       program.ProgramName = subNode["programName"].InnerText;
                       program.FilePath = subNode["path"].InnerText;
                       this.ProgramList.Add(program);
                   }
               }
           }
       }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Day08_02网络精灵
{
    static class Program
    {
        /// <summary>
        /// 应用程序的主入口点。
        /// </summary>
        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new Form1());
        }
    }
}

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值