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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 54 - (hide annotations) (download)
Fri Mar 8 08:51:10 2013 UTC (7 years, 7 months ago) by william
Original Path: trunk/libxmltv/Core/XMLTVInstance.cs
File size: 4606 byte(s)

1 william 36 using System;
2     using System.Collections.Generic;
3     using System.Linq;
4     using System.Text;
5     using libxmltv.Interfaces;
6 william 46 using System.ComponentModel;
7 william 54 using System.Windows.Forms;
8     using System.Threading;
9 william 36
10     namespace libxmltv.Core
11     {
12 william 49 [Serializable]
13 william 54 internal class XMLTVRuntimeInstance : MarshalByRefObject, IXMLTVRuntimeInstance, ISerializer<XMLTVRuntimeInstance>, IGetCreatedInstanceEvent, ISetCreatedInstanceEvent, IDestroyInstance
14 william 36 {
15 william 54 Thread worker;
16     public XMLTVRuntimeInstance(string xmlfile)
17     {
18     worker = new Thread(new ParameterizedThreadStart(CreateInstance));
19     //CreateInstance(xmlfile);
20     worker.Start(xmlfile);
21     }
22 william 52 //public XMLTVRuntimeInstance(string xmlfile) : this(xmlfile, null) { }
23     //public XMLTVRuntimeInstance(string xmlfile, EventHandler<CancelEventArgs> t) { CreateInstance(xmlfile,t); }
24 william 54 private void CreateInstance(object xmlfile)
25     {
26 william 52 //CancelEvent = t;
27 william 54 using (XMLTVInstance instance = new XMLTVInstance(xmlfile.ToString(), this))
28 william 45 {
29 william 54 if (OnInstanceCreated != null)
30     {
31     OnInstanceCreated.Invoke(this,new EventArgs());
32     }
33 william 45 }
34     }
35 william 46
36 william 49 //internal XMLTVInstance Instance { get; private set; }
37 william 36
38     #region IXMLTV_LOADER members
39     public System.IO.FileInfo XmlFile { get; set; }
40 william 49 public string XmlDoc { get; set; }
41 william 36 #endregion
42     #region IXMLTV_PARSER Members
43     public IXMLTVSource Source { get; set; }
44     public Dictionary<string, IXMLTVChannel> Channels { get; set; }
45     public Dictionary<int, IXMLTVProgram> Programs { get; set; }
46     #endregion
47 william 44
48 william 54 public EventHandler<EventArgs> OnInstanceCreated { get; set; }
49     public EventHandler<EventArgs> GetOnInstanceCreated() { return OnInstanceCreated; }
50     public void SetOnInstanceCreated(EventHandler<EventArgs> event_instance) { OnInstanceCreated = event_instance; }
51    
52 william 51 public IXMLTVSerializer<XMLTVRuntimeInstance> Serializer
53     {
54 william 52 get
55     {
56     ///* We have to set CancelEvent to null, before returning a new instance of the serializer otherwise all subscribers to the event will have to be marked as serializeable.
57     // Most subscribers will be of type: System.Windows.Forms which is not marked as serializable and will fail to serialize. */
58     //if (CancelEvent != null) { CancelEvent = null; }
59     return new XMLTVSerializer<XMLTVRuntimeInstance>(this);
60     }
61 william 51 }
62 william 54 public void DestroyInstance()
63 william 46 {
64 william 54 xmltv_logger.Log.Debug.WriteLine("Destoying Instance of: '{0}'", this.GetType().Name);
65     this.IsAborting = true;
66     if (worker == null)
67 william 46 {
68 william 54 xmltv_logger.Log.Debug.WriteLine("Unable to destroy instance of: '{0}' - worker thread is null", this.GetType().Name);
69     return;
70 william 46 }
71 william 54 else
72     {
73     if (worker.IsAlive)
74     {
75     xmltv_logger.Log.Verbose.Debug.WriteLine("Requesting Instance to Abort...");
76     while (worker.IsAlive)
77     {
78     worker.Abort();
79     Application.DoEvents();
80     }
81     }
82     else
83     {
84     xmltv_logger.Log.Debug.WriteLine("Instance of: '{0}'- already destroyed.", this.GetType().Name);
85     }
86     }
87 william 46 }
88 william 54 public bool IsAborting
89     {
90     get;
91     private set;
92     }
93 william 36 }
94    
95 william 44 internal class XMLTVInstance : IDisposable
96 william 36 {
97     public XMLTVInstance(string xmlfile, XMLTVRuntimeInstance instance)
98     {
99     CreateLoader(xmlfile, instance);
100     CreateParser(instance);
101     }
102    
103     private void CreateLoader(string xml_file, XMLTVRuntimeInstance instance)
104     {
105 william 44 //XMLTVLoader loader = new XMLTVLoader(xml_file, instance);
106     XMLTVLoader.CreateInstance(xml_file, instance);
107 william 36 }
108     private void CreateParser(XMLTVRuntimeInstance instance)
109     {
110 william 44 //XMLTVParser parser = new XMLTVParser(instance);
111     XMLTVParser.CreateInstance(instance);
112 william 36 }
113 william 44
114     public void Dispose()
115     {
116     //throw new NotImplementedException();
117     }
118 william 36 }
119     }

  ViewVC Help
Powered by ViewVC 1.1.22