--- trunk/libxmltv/Core/XMLTVProgram.cs 2013/03/10 09:43:49 97 +++ trunk/libxmltv/Core/XMLTVProgram.cs 2013/03/10 18:19:12 120 @@ -54,8 +54,12 @@ } #region Property Dictionary Support - private PropertyDictionary _MetaData; - public PropertyDictionary MetaData { get { return _MetaData; } private set { _MetaData = value; } } + private IPropertyDictionary _MetaData; + public IPropertyDictionary MetaData { get { return _MetaData; } private set { _MetaData = value; } } + public ExtraList GetExtraMetaData() + { + return (ExtraList)this.MetaData[XMLTVConstants.Programs.ProgramExtraMetaData]; + } #endregion #endregion @@ -63,9 +67,9 @@ { return string.Format("{0}: {1} - {2} ({3}) ['{4}' <==> '{5}']", MetaData["Id"].ToString(), - MetaData[(XMLTVConstants.Programs.ProgramTitle)].ToString(), - MetaData[(XMLTVConstants.Programs.ProgramSubTitle)].ToString(), - MetaData[(XMLTVConstants.Programs.ProgramChannelId)].ToString(), + MetaData[XMLTVConstants.Programs.ProgramTitle].ToString(), + MetaData[XMLTVConstants.Programs.ProgramSubTitle].ToString(), + MetaData[XMLTVConstants.Programs.ProgramChannelId].ToString(), ((DateTime)MetaData[XMLTVConstants.Programs.ProgramStart]).ToString("yyyy/MM/dd hh:mm tt"), ((DateTime)MetaData[XMLTVConstants.Programs.ProgramStop]).ToString("yyyy/MM/dd hh:mm tt")); } @@ -80,13 +84,13 @@ var fields = instance_type.GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance); foreach (var field in fields) { - if (field.FieldType == typeof(List)) + if (field.FieldType == typeof(ProgramList)) { found_field = true; try { - - var list = (List)field.GetValue(this.GetInstance()); + + var list = (ProgramList)field.GetValue(this.GetInstance()); MetaData["Id"] = list.Count + 1; list.Add(this); xmltv_logger.Verbose.Debug.WriteLine("Updating instance with program information: {0}", this.ToString()); @@ -161,6 +165,7 @@ var ctors = type.GetConstructors(flags); bool has_default_ctor = false; foreach (var ctor in ctors) { if (ctor.GetParameters().Count() == 0) { has_default_ctor = true; } } + ctors = null; if (!has_default_ctor) { continue; } raw_instance = Activator.CreateInstance(type, flags, null, new object[0], culture); if (raw_instance != null) @@ -169,47 +174,60 @@ if (handler_value != null && handler_value.ToString() == node.Name.ToString()) { handler_type = type; + handler_value = null; + raw_instance = null; + handler_prop = null; + iface = null; break; } + handler_value = null; } + raw_instance = null; } + handler_prop = null; } + iface = null; } } + t = null; + asm = null; + types = null; + classes = null; if (handler_type == null) { - StringBuilder node_builder = new StringBuilder(); - node_builder.AppendFormat("<{0} ", node.Name); - if (node.HasAttributes) { foreach (var attribute in node.Attributes()) { node_builder.AppendFormat("{0}=\"{1}\" ", attribute.Name, attribute.Value); } } - string node_text = string.Format("{0}>", node_builder.ToString().TrimEnd(new char[] { ' ' })); - xmltv_logger.Verbose.Warn.WriteLine("Ignoring unhandled extra meta-data: {0}", node_text); + try + { + raw_instance = Activator.CreateInstance(typeof(UnhandledExtraProgramMetaData), flags, null, new object[] { this, node }, culture); + } + catch (Exception ex) { throw ex; } + + if (raw_instance == null) + { + StringBuilder node_builder = new StringBuilder(); + node_builder.AppendFormat("<{0} ", node.Name); + if (node.HasAttributes) { foreach (var attribute in node.Attributes()) { node_builder.AppendFormat("{0}=\"{1}\" ", attribute.Name, attribute.Value); } } + string node_text = string.Format("{0}>", node_builder.ToString().TrimEnd(new char[] { ' ' })); + xmltv_logger.Verbose.Warn.WriteLine("Ignoring unhandled extra meta-data: {0}", node_text); + } } else { - raw_instance = Activator.CreateInstance(handler_type, flags, null, new object[] { this, node }, culture); + try + { + raw_instance = Activator.CreateInstance(handler_type, flags, null, new object[] { this, node }, culture); + } + catch (Exception ex) { throw ex; } } + raw_instance = null; + flags = 0; + culture = null; + node = null; } - #region sub-classes - #region program title - private class title : XMLTVBase - { - public title() : base(null, XMLTVConstants.Programs.ProgramTitle) { } - public title(XMLTVProgram instance, XElement node) - : base(instance, XMLTVConstants.Programs.ProgramTitle) - { - if(node == null){throw new NullReferenceException("The node instance was null");} - if (node.Value != null) - { - instance.MetaData.AddProperty(XMLTVConstants.Programs.ProgramTitle, node.Value); - xmltv_logger.Verbose.Debug.WriteLine("\tprogram_title: {0}", node.Value); - } - } - } - #endregion - #region program stop/start/channel (programme) + #region sub-classes + #region programme: stop/start/channelid private class programme : XMLTVBase { public programme() : base(null, XMLTVConstants.Programs.RootElement) { } @@ -237,11 +255,28 @@ } } + node = null; } } #endregion - - #region sub title + #region title + private class title : XMLTVBase + { + public title() : base(null, XMLTVConstants.Programs.ProgramTitle) { } + public title(XMLTVProgram instance, XElement node) + : base(instance, XMLTVConstants.Programs.ProgramTitle) + { + if (node == null) { throw new NullReferenceException("The node instance was null"); } + if (node.Value != null) + { + instance.MetaData.AddProperty(XMLTVConstants.Programs.ProgramTitle, node.Value); + xmltv_logger.Verbose.Debug.WriteLine("\tprogram_title: {0}", node.Value); + } + node = null; + } + } + #endregion + #region sub-title private class subtitle : XMLTVBase { public subtitle() : base(null, XMLTVConstants.Programs.ProgramSubTitle) { } @@ -254,10 +289,11 @@ instance.MetaData.AddProperty(XMLTVConstants.Programs.ProgramSubTitle, node.Value); xmltv_logger.Verbose.Debug.WriteLine("\tprogram_subtitle: {0}", node.Value); } + node = null; } } #endregion - #region sub title + #region description private class description : XMLTVBase { public description() : base(null, XMLTVConstants.Programs.ProgramDescription) { } @@ -270,9 +306,34 @@ instance.MetaData.AddProperty(XMLTVConstants.Programs.ProgramDescription, node.Value); xmltv_logger.Verbose.Debug.WriteLine("\tprogram_description: {0}", node.Value); } + node = null; } } #endregion + + #region UnhandledExtraMetaData + private class UnhandledExtraProgramMetaData : XMLTVBase + { + public UnhandledExtraProgramMetaData() : base(null, null) { } + public UnhandledExtraProgramMetaData(XMLTVProgram instance, XElement node) + : base(instance, null) + { + if (node == null) { throw new NullReferenceException("The node instance was null"); } + xmltv_logger.Verbose.Debug.WriteLine("Parsng unhandled extra program meta-data: {0}", node.Name.ToString()); + if (this.GetInstance() != null) + { + List list = new List(); + if (!instance.MetaData.ContainsProperty(XMLTVConstants.Programs.ProgramExtraMetaData)) { instance.MetaData.AddProperty(XMLTVConstants.Programs.ProgramExtraMetaData, new List()); } + else { list = (List)instance.MetaData[XMLTVConstants.Programs.ProgramExtraMetaData]; } + ExtraMetaData data = new ExtraMetaData(node); + list.Add(data); + instance.MetaData[XMLTVConstants.Programs.ProgramExtraMetaData] = list; + data = null; + } + node = null; + } + } + #endregion #endregion } }