admin管理员组

文章数量:1609986

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());
        }
    }
}

本文标签: 精灵网络