/[xmltv_parser]/trunk/libxmltv/Core/XMLTVProgram.cs
ViewVC logotype

Annotation of /trunk/libxmltv/Core/XMLTVProgram.cs

Parent Directory Parent Directory | Revision Log Revision Log


Revision 74 - (hide annotations) (download)
Sat Mar 9 11:06:39 2013 UTC (6 years, 8 months ago) by william
File size: 3202 byte(s)

1 william 73 using System;
2     using System.Collections.Generic;
3     using System.Linq;
4     using System.Text;
5     using libxmltv.Interfaces;
6 william 74 using System.Xml.Linq;
7     using System.Reflection;
8 william 73
9     namespace libxmltv.Core
10     {
11     [Serializable]
12 william 74 internal class XMLTVProgram : XMLTVBase<XMLTVRuntimeInstance>, IXMLTVProgram
13 william 73 {
14 william 74 public XMLTVProgram() : base(null,XMLTVConstants.PROGRAM_ELEMENT)
15 william 73 {
16     Id = 0;
17     Start = new DateTime();
18     Stop = new DateTime();
19     Channel = new XMLTVChannel();
20     Title = string.Empty;
21     SubTitle = string.Empty;
22     Description = string.Empty;
23     }
24 william 74 public XMLTVProgram(XMLTVRuntimeInstance instance, XElement node)
25     : base(instance, XMLTVConstants.PROGRAM_ELEMENT)
26     {
27     xmltv_logger.Verbose.Debug.WriteLine("Creating Instance of XMLTVProgram");
28     // do the work here
29     xmltv_logger.Verbose.Debug.WriteLine("Created Instance of XMLTVProgram");
30     //UpdateInstance();
31     }
32 william 73 #region IXMLTVProgram members
33     public int Id { get; set; }
34     public DateTime Start { get; set; }
35     public DateTime Stop { get; set; }
36     public IXMLTVChannel Channel { get; set; }
37     public string Title { get; set; }
38     public string SubTitle { get; set; }
39     public string Description { get; set; }
40     #endregion
41     public override string ToString()
42     {
43     return string.Format("{0}: {1} - {2} ({3}) ['{4}' <==> '{5}']", Id, Title, SubTitle, Channel.ToString(), Start.ToString("yyyy/MM/dd hh:mm tt"), Stop.ToString("yyyy/MM/dd hh:mm tt"));
44     }
45 william 74
46     private void UpdateInstance()
47     {
48     bool found_field = false;
49     var instance_type = this.GetInstance().GetType();
50     var fields = instance_type.GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
51     foreach (var field in fields)
52     {
53     if (field.FieldType == typeof(List<IXMLTVChannel>))
54     {
55     found_field = true;
56     try
57     {
58     xmltv_logger.Verbose.Debug.WriteLine("Updating instance with program information: {0}", this.ToString());
59     //field.SetValue(this.GetInstance(), new List<IXMLTVChannel>() { this });
60    
61     var list = (List<IXMLTVProgram>)field.GetValue(this.GetInstance());
62     list.Add(this);
63     field.SetValue(this.GetInstance(), list);
64     break;
65     }
66     catch (Exception ex)
67     {
68     xmltv_logger.Verbose.Error.WriteLine("Unable to update instance with program information.");
69     xmltv_logger.Verbose.Error.WriteLine(ex.ToString());
70     }
71     }
72     }
73     if (!found_field)
74     {
75     xmltv_logger.Verbose.Error.WriteLine("Unable to update instance with program information.");
76     }
77     }
78 william 73 }
79     }

  ViewVC Help
Powered by ViewVC 1.1.22