43 |
|
|
44 |
private void InternalDictionaryAddKnownProperties() |
private void InternalDictionaryAddKnownProperties() |
45 |
{ |
{ |
46 |
Properties = new Dictionary<string, object>(); |
Properties = new PropertyDictionary(); |
47 |
Properties.Add("Id", 0); |
Properties.AddProperty("Id", 0); |
48 |
Properties.Add(XMLTVConstants.Programs.ProgramStart, new DateTime()); |
Properties.AddProperty(XMLTVConstants.Programs.ProgramStart, new DateTime()); |
49 |
Properties.Add(XMLTVConstants.Programs.ProgramStop, new DateTime()); |
Properties.AddProperty(XMLTVConstants.Programs.ProgramStop, new DateTime()); |
50 |
Properties.Add(XMLTVConstants.Programs.ProgramChannelId, string.Empty); |
Properties.AddProperty(XMLTVConstants.Programs.ProgramChannelId, string.Empty); |
51 |
Properties.Add(XMLTVConstants.Programs.ProgramTitle, string.Empty); |
Properties.AddProperty(XMLTVConstants.Programs.ProgramTitle, string.Empty); |
52 |
Properties.Add(XMLTVConstants.Programs.ProgramSubTitle, string.Empty); |
Properties.AddProperty(XMLTVConstants.Programs.ProgramSubTitle, string.Empty); |
53 |
Properties.Add(XMLTVConstants.Programs.ProgramDescription, string.Empty); |
Properties.AddProperty(XMLTVConstants.Programs.ProgramDescription, string.Empty); |
54 |
} |
} |
55 |
|
|
56 |
public Dictionary<string, object> Properties { get; private set; } |
#region Property Dictionary Support |
57 |
|
public PropertyDictionary Properties { get; private set; } |
58 |
private void InternalDictionaryTestOrThrow() |
#endregion |
|
{ |
|
|
if (Properties == null) { throw new NullReferenceException("Properties collection has not been initialized."); } |
|
|
//if (Properties.Count == 0) { throw new IndexOutOfRangeException("Properties collection has 0 elements."); } |
|
|
} |
|
|
private void InternalProperyExistsOrThrow(string propertyname) |
|
|
{ |
|
|
InternalDictionaryTestOrThrow(); |
|
|
//if (!ContainsProperty(propertyname)) { throw new KeyNotFoundException(string.Format("Property '{0}' does not exist.", propertyname)); } |
|
|
} |
|
|
|
|
|
public void RemoveProperty(string propertyname) |
|
|
{ |
|
|
if (ContainsProperty(propertyname)) |
|
|
{ |
|
|
Properties.Remove(propertyname); |
|
|
} |
|
|
else |
|
|
{ |
|
|
throw new ArgumentException(string.Format("Property '{0}' deos not exist", propertyname), propertyname); |
|
|
} |
|
|
} |
|
59 |
|
|
|
public void AddProperty(string propertyname) { AddProperty(propertyname, new object()); } |
|
|
public void AddProperty(string propertyname, object propertyvalue) |
|
|
{ |
|
|
if (!ContainsProperty(propertyname)) |
|
|
{ |
|
|
Properties.Add(propertyname, propertyvalue); |
|
|
} |
|
|
else |
|
|
{ |
|
|
SetProperty(propertyname, propertyvalue); |
|
|
} |
|
|
} |
|
|
public bool ContainsProperty(string propertyname) |
|
|
{ |
|
|
return Properties.ContainsKey(propertyname); |
|
|
} |
|
|
public object GetProperty(string propertyname) |
|
|
{ |
|
|
InternalProperyExistsOrThrow(propertyname); |
|
|
if (!ContainsProperty(propertyname)) { throw new KeyNotFoundException(string.Format("Property '{0}' does not exist.", propertyname)); } |
|
|
return Properties[propertyname]; |
|
|
} |
|
|
public void SetProperty(string propertyname, object propertyvalue) |
|
|
{ |
|
|
InternalProperyExistsOrThrow(propertyname); |
|
|
if (!ContainsProperty(propertyname)) { throw new KeyNotFoundException(string.Format("Property '{0}' does not exist.", propertyname)); } |
|
|
Properties[propertyname] = propertyvalue; |
|
|
} |
|
60 |
#endregion |
#endregion |
61 |
public override string ToString() |
public override string ToString() |
62 |
{ |
{ |
63 |
return string.Format("{0}: {1} - {2} ({3}) ['{4}' <==> '{5}']", |
return string.Format("{0}: {1} - {2} ({3}) ['{4}' <==> '{5}']", |
64 |
GetProperty("Id").ToString(), |
Properties["Id"].ToString(), |
65 |
GetProperty(XMLTVConstants.Programs.ProgramTitle).ToString(), |
Properties[(XMLTVConstants.Programs.ProgramTitle)].ToString(), |
66 |
GetProperty(XMLTVConstants.Programs.ProgramSubTitle).ToString(), |
Properties[(XMLTVConstants.Programs.ProgramSubTitle)].ToString(), |
67 |
GetProperty(XMLTVConstants.Programs.ProgramChannelId).ToString(), |
Properties[(XMLTVConstants.Programs.ProgramChannelId)].ToString(), |
68 |
((DateTime)GetProperty(XMLTVConstants.Programs.ProgramStart)).ToString("yyyy/MM/dd hh:mm tt"), |
((DateTime) Properties[XMLTVConstants.Programs.ProgramStart]).ToString("yyyy/MM/dd hh:mm tt"), |
69 |
((DateTime)GetProperty(XMLTVConstants.Programs.ProgramStop)).ToString("yyyy/MM/dd hh:mm tt")); |
((DateTime) Properties[XMLTVConstants.Programs.ProgramStop]).ToString("yyyy/MM/dd hh:mm tt")); |
70 |
} |
} |
71 |
|
|
72 |
|
|
86 |
{ |
{ |
87 |
|
|
88 |
var list = (List<IXMLTVProgram>)field.GetValue(this.GetInstance()); |
var list = (List<IXMLTVProgram>)field.GetValue(this.GetInstance()); |
89 |
this.SetProperty("Id", list.Count + 1); |
Properties["Id"] = list.Count + 1; |
90 |
list.Add(this); |
list.Add(this); |
91 |
xmltv_logger.Verbose.Debug.WriteLine("Updating instance with program information: {0}", this.ToString()); |
xmltv_logger.Verbose.Debug.WriteLine("Updating instance with program information: {0}", this.ToString()); |
92 |
field.SetValue(this.GetInstance(), list); |
field.SetValue(this.GetInstance(), list); |
242 |
if(node == null){throw new NullReferenceException("The node instance was null");} |
if(node == null){throw new NullReferenceException("The node instance was null");} |
243 |
if (node.Value != null) |
if (node.Value != null) |
244 |
{ |
{ |
245 |
instance.AddProperty(XMLTVConstants.Programs.ProgramTitle, node.Value); |
instance.Properties.AddProperty(XMLTVConstants.Programs.ProgramTitle, node.Value); |
246 |
xmltv_logger.Verbose.Debug.WriteLine("\tprogram_title: {0}", node.Value); |
xmltv_logger.Verbose.Debug.WriteLine("\tprogram_title: {0}", node.Value); |
247 |
} |
} |
248 |
} |
} |
261 |
var start = node.Attribute(XMLTVConstants.Programs.ProgramStart); |
var start = node.Attribute(XMLTVConstants.Programs.ProgramStart); |
262 |
var t_start = start == null ? new DateTime() : ParseDate(start.Value); |
var t_start = start == null ? new DateTime() : ParseDate(start.Value); |
263 |
if (!t_start.Equals(new DateTime())) { xmltv_logger.Verbose.Debug.WriteLine("\tprogram_start: {0}", start); } |
if (!t_start.Equals(new DateTime())) { xmltv_logger.Verbose.Debug.WriteLine("\tprogram_start: {0}", start); } |
264 |
instance.AddProperty(XMLTVConstants.Programs.ProgramStart, t_start); |
instance.Properties.AddProperty(XMLTVConstants.Programs.ProgramStart, t_start); |
265 |
|
|
266 |
var stop = node.Attribute(XMLTVConstants.Programs.ProgramStop); |
var stop = node.Attribute(XMLTVConstants.Programs.ProgramStop); |
267 |
var t_stop = stop == null ? new DateTime() : ParseDate(stop.Value); |
var t_stop = stop == null ? new DateTime() : ParseDate(stop.Value); |
268 |
if (!t_stop.Equals(new DateTime())) { xmltv_logger.Verbose.Debug.WriteLine("\tprogram_stop: {0}", stop); } |
if (!t_stop.Equals(new DateTime())) { xmltv_logger.Verbose.Debug.WriteLine("\tprogram_stop: {0}", stop); } |
269 |
instance.AddProperty(XMLTVConstants.Programs.ProgramStop, t_stop); |
instance.Properties.AddProperty(XMLTVConstants.Programs.ProgramStop, t_stop); |
270 |
|
|
271 |
var channelid = node.Attribute(XMLTVConstants.Programs.ProgramChannelId); |
var channelid = node.Attribute(XMLTVConstants.Programs.ProgramChannelId); |
272 |
if (channelid != null) |
if (channelid != null) |
273 |
{ |
{ |
274 |
if (!string.IsNullOrEmpty(channelid.Value)) { xmltv_logger.Verbose.Debug.WriteLine("\tprogram_channelid: {0}", channelid.Value); } |
if (!string.IsNullOrEmpty(channelid.Value)) { xmltv_logger.Verbose.Debug.WriteLine("\tprogram_channelid: {0}", channelid.Value); } |
275 |
instance.AddProperty(XMLTVConstants.Programs.ProgramChannelId, channelid.Value); |
instance.Properties.AddProperty(XMLTVConstants.Programs.ProgramChannelId, channelid.Value); |
276 |
} |
} |
277 |
|
|
278 |
} |
} |
290 |
if (node == null) { throw new NullReferenceException("The node instance was null"); } |
if (node == null) { throw new NullReferenceException("The node instance was null"); } |
291 |
if (node.Value != null) |
if (node.Value != null) |
292 |
{ |
{ |
293 |
instance.AddProperty(XMLTVConstants.Programs.ProgramSubTitle, node.Value); |
instance.Properties.AddProperty(XMLTVConstants.Programs.ProgramSubTitle, node.Value); |
294 |
xmltv_logger.Verbose.Debug.WriteLine("\tprogram_subtitle: {0}", node.Value); |
xmltv_logger.Verbose.Debug.WriteLine("\tprogram_subtitle: {0}", node.Value); |
295 |
} |
} |
296 |
} |
} |
306 |
if (node == null) { throw new NullReferenceException("The node instance was null"); } |
if (node == null) { throw new NullReferenceException("The node instance was null"); } |
307 |
if (node.Value != null) |
if (node.Value != null) |
308 |
{ |
{ |
309 |
instance.AddProperty(XMLTVConstants.Programs.ProgramDescription, node.Value); |
instance.Properties.AddProperty(XMLTVConstants.Programs.ProgramDescription, node.Value); |
310 |
xmltv_logger.Verbose.Debug.WriteLine("\tprogram_description: {0}", node.Value); |
xmltv_logger.Verbose.Debug.WriteLine("\tprogram_description: {0}", node.Value); |
311 |
} |
} |
312 |
} |
} |