--- trunk/libxmltv/Core/XMLTVProgram.cs 2013/03/09 10:27:39 73 +++ trunk/libxmltv/Core/XMLTVProgram.cs 2013/03/09 11:06:39 74 @@ -3,13 +3,15 @@ using System.Linq; using System.Text; using libxmltv.Interfaces; +using System.Xml.Linq; +using System.Reflection; namespace libxmltv.Core { [Serializable] - internal class XMLTVProgram : IXMLTVProgram + internal class XMLTVProgram : XMLTVBase, IXMLTVProgram { - public XMLTVProgram() + public XMLTVProgram() : base(null,XMLTVConstants.PROGRAM_ELEMENT) { Id = 0; Start = new DateTime(); @@ -19,6 +21,14 @@ SubTitle = string.Empty; Description = string.Empty; } + public XMLTVProgram(XMLTVRuntimeInstance instance, XElement node) + : base(instance, XMLTVConstants.PROGRAM_ELEMENT) + { + xmltv_logger.Verbose.Debug.WriteLine("Creating Instance of XMLTVProgram"); + // do the work here + xmltv_logger.Verbose.Debug.WriteLine("Created Instance of XMLTVProgram"); + //UpdateInstance(); + } #region IXMLTVProgram members public int Id { get; set; } public DateTime Start { get; set; } @@ -32,5 +42,38 @@ { 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")); } + + private void UpdateInstance() + { + bool found_field = false; + var instance_type = this.GetInstance().GetType(); + var fields = instance_type.GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance); + foreach (var field in fields) + { + if (field.FieldType == typeof(List)) + { + found_field = true; + try + { + xmltv_logger.Verbose.Debug.WriteLine("Updating instance with program information: {0}", this.ToString()); + //field.SetValue(this.GetInstance(), new List() { this }); + + var list = (List)field.GetValue(this.GetInstance()); + list.Add(this); + field.SetValue(this.GetInstance(), list); + break; + } + catch (Exception ex) + { + xmltv_logger.Verbose.Error.WriteLine("Unable to update instance with program information."); + xmltv_logger.Verbose.Error.WriteLine(ex.ToString()); + } + } + } + if (!found_field) + { + xmltv_logger.Verbose.Error.WriteLine("Unable to update instance with program information."); + } + } } }