网络精灵

  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.Linq;  
  4. using System.Text;  
  5. using System.Threading.Tasks;  
  6. using System.Xml;  
  7.   
  8. namespace 网络电视  
  9. {  
  10.     public class ChannelA : ChannelBase  
  11.     {  
  12.         public override void Fetch()  
  13.         {  
  14.             XmlDocument doc = new XmlDocument();  
  15.             doc.Load(Path);  
  16.             XmlNode root = doc.DocumentElement;  
  17.   
  18.             foreach (XmlNode item in root.ChildNodes)  
  19.             {  
  20.                 //一个Item  
  21.                 if (item.Name == "tvProgramTable")  
  22.                 {  
  23.                     foreach (XmlNode child in item.ChildNodes)  
  24.                     {  
  25.                         //一个child是一个节目单对象  
  26.                         TvProgram tv = new TvProgram();  
  27.                         tv.PlayTime = Convert.ToDateTime(child["playTime"].InnerText);  
  28.                         tv.Median = child["meridien"].InnerText;  
  29.                         tv.ProgramName = child["programName"].InnerText;  
  30.                         tv.FilePath = child["path"].InnerText;  
  31.   
  32.                         ProgramList.Add(tv);  
  33.   
  34.                     }  
  35.                 }  
  36.             }  
  37.         }  
  38.   
  39.   
  40.           
  41.   
  42.     }  
  43. }  
[csharp] view plain copy
 
 在CODE上查看代码片派生到我的代码片
  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.Linq;  
  4. using System.Text;  
  5. using System.Threading.Tasks;  
  6. using System.Xml;  
  7.   
  8. namespace 网络电视  
  9. {  
  10.   public  class ChannelB:ChannelBase  
  11.     {  
  12.       public override void Fetch()  
  13.       {  
  14.           XmlDocument doc = new XmlDocument();  
  15.           doc.Load(Path);  
  16.           XmlNode root = doc.DocumentElement;  
  17.           foreach (XmlNode item in root.ChildNodes)  
  18.           {  
  19.               foreach (XmlNode child in item.ChildNodes)  
  20.               {  
  21.                   TvProgram tp = new TvProgram();  
  22.                   tp.PlayTime = Convert.ToDateTime(child["playTime"].InnerText);  
  23.                   tp.ProgramName = child["name"].InnerText;  
  24.                   tp.FilePath = child["path"].InnerText;  
  25.   
  26.                   ProgramList.Add(tp);  
  27.               }  
  28.           }  
  29.       }    
  30.   
  31.        
  32.     }  
  33. }  
  34.   
  35.   
  36.       
[csharp] view plain copy
 
 在CODE上查看代码片派生到我的代码片
  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.Linq;  
  4. using System.Text;  
  5. using System.Threading.Tasks;  
  6. using  System.Xml;  
  7. namespace 网络电视  
  8. {  
  9.   public   abstract class ChannelBase  
  10.     {  
  11.         public ChannelBase()  
  12.         {  
  13.             programList = new List<TvProgram>();  
  14.         }  
  15.  
  16.         #region 属性  
  17.   
  18.   
  19.           
  20.         private string channelName;  
  21.         public string ChannelName  
  22.         {  
  23.             get { return channelName; }  
  24.             set { channelName = value; }  
  25.         }  
  26.          
  27.         private string path;  
  28.         public string Path  
  29.         {  
  30.             get { return path; }  
  31.             set { path = value; }  
  32.         }  
  33.          
  34.         private List<TvProgram> programList;  
  35.         public List<TvProgram> ProgramList  
  36.         {  
  37.             get { return programList; }  
  38.             set { this.programList = value; }  
  39.         }  
  40.         #endregion  
  41.   
  42.         //Fetch,读取频道的xml文件  
  43.         public abstract void Fetch();  
  44.     }  
  45. }  
[csharp] view plain copy
 
 在CODE上查看代码片派生到我的代码片
  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.Diagnostics;  
  4. using System.Linq;  
  5. using System.Text;  
  6. using System.Threading.Tasks;  
  7.   
  8. namespace 网络电视  
  9. {  
  10.  public   class ChannelFactory  
  11.     {  
  12.   
  13.        
  14.         public static ChannelBase CreatChannel(string type)  
  15.         {  
  16.             ChannelBase channel = null;  
  17.             switch (type)  
  18.             {  
  19.   
  20.                 case "TypeA":  
  21.                     channel = new ChannelA();  
  22.                     break;  
  23.                 case "TypeB":  
  24.                     channel = new ChannelB();  
  25.                     break;  
  26.   
  27.   
  28.             }  
  29.             return channel;  
  30.         }  
  31.   
  32.   
  33.       
  34.     }  
  35. }  
[csharp] view plain copy
 
 在CODE上查看代码片派生到我的代码片
  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.Linq;  
  4. using System.Text;  
  5. using System.Threading.Tasks;  
  6. using System.Xml;  
  7.   
  8. namespace 网络电视  
  9. {  
  10.   public  class ChannelManager  
  11.     {  
  12.         private Dictionary<string, ChannelBase> fullChannels = null;  
  13.   
  14.         public Dictionary<string, ChannelBase> FullChannels  
  15.         {  
  16.             get { return fullChannels; }  
  17.             set { fullChannels = value; }  
  18.         }  
  19.   
  20.         public ChannelManager()  
  21.         {  
  22.             fullChannels=new Dictionary<string, ChannelBase>();  
  23.         }  
  24.   
  25.         public void ChangeXmlToList()  
  26.         {  
  27.            XmlDocument doc=new XmlDocument();  
  28.             doc.Load("files/FullChannels.xml");  
  29.             XmlNode root = doc.DocumentElement;  
  30.             foreach (XmlNode item in root.ChildNodes)  
  31.             {  
  32.                 string type = item["channelType"].InnerText;  
  33.                 ChannelBase channel = ChannelFactory.CreatChannel(type);  
  34.                 channel.ChannelName = item["tvChannel"].InnerText;  
  35.                 channel.Path = item["path"].InnerText;  
  36.                 fullChannels.Add(channel.ChannelName, channel);  
  37.   
  38.   
  39.             }  
  40.         }  
  41.     }  
  42. }  
[csharp] view plain copy
 
 在CODE上查看代码片派生到我的代码片
  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.Linq;  
  4. using System.Text;  
  5. using System.Threading.Tasks;  
  6.   
  7. namespace 网络电视  
  8. {  
  9.   public  class TvProgram  
  10.     {  
  11.          private DateTime playTime;  
  12.         public DateTime PlayTime  
  13.         {  
  14.             get { return playTime; }  
  15.             set { playTime = value; }  
  16.         }  
  17.         /// <summary>  
  18.         /// 时段  
  19.         /// </summary>  
  20.         private string median;  
  21.         public string Median  
  22.         {  
  23.             get { return median; }  
  24.             set { median = value; }  
  25.         }  
  26.          
  27.         private string programName;  
  28.         public string ProgramName  
  29.         {  
  30.             get { return programName; }  
  31.             set { programName = value; }  
  32.         }  
  33.          
  34.         private string filePath;  
  35.          public string FilePath  
  36.         {  
  37.             get { return filePath; }  
  38.             set { filePath = value; }  
  39.         }  
  40.          
  41.     }  
  42. }  


原文地址:https://www.cnblogs.com/wangbenqing/p/6607502.html