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

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

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 45 by william, Fri Mar 8 03:41:18 2013 UTC revision 54 by william, Fri Mar 8 08:51:10 2013 UTC
# Line 3  using System.Collections.Generic; Line 3  using System.Collections.Generic;
3  using System.Linq;  using System.Linq;
4  using System.Text;  using System.Text;
5  using libxmltv.Interfaces;  using libxmltv.Interfaces;
6    using System.ComponentModel;
7    using System.Windows.Forms;
8    using System.Threading;
9    
10  namespace libxmltv.Core  namespace libxmltv.Core
11  {  {
12      internal class XMLTVRuntimeInstance : MarshalByRefObject, IXMLTVRuntimeInstance      [Serializable]
13        internal class XMLTVRuntimeInstance : MarshalByRefObject, IXMLTVRuntimeInstance, ISerializer<XMLTVRuntimeInstance>, IGetCreatedInstanceEvent, ISetCreatedInstanceEvent, IDestroyInstance
14      {      {
15          public XMLTVRuntimeInstance(string xmlfile) { CreateInstance(xmlfile); }          Thread worker;
16          private void CreateInstance(string xmlfile)          public XMLTVRuntimeInstance(string xmlfile)
17          {          {
18              using (Instance = new XMLTVInstance(xmlfile, this))              worker = new Thread(new ParameterizedThreadStart(CreateInstance));
19                //CreateInstance(xmlfile);
20                worker.Start(xmlfile);
21            }
22            //public XMLTVRuntimeInstance(string xmlfile) : this(xmlfile, null) { }
23            //public XMLTVRuntimeInstance(string xmlfile, EventHandler<CancelEventArgs> t) { CreateInstance(xmlfile,t); }
24            private void CreateInstance(object xmlfile)
25            {            
26                //CancelEvent = t;
27                using (XMLTVInstance instance = new XMLTVInstance(xmlfile.ToString(), this))
28              {              {
29                    if (OnInstanceCreated != null)
30                    {
31                        OnInstanceCreated.Invoke(this,new EventArgs());
32                    }
33              }              }
34          }          }
35          internal XMLTVInstance Instance { get; private set; }  
36            //internal XMLTVInstance Instance { get; private set; }
37    
38          #region IXMLTV_LOADER members          #region IXMLTV_LOADER members
39          public System.IO.FileInfo XmlFile { get; set; }          public System.IO.FileInfo XmlFile { get; set; }
40          public System.Xml.Linq.XDocument XmlDoc { get; set; }          public string XmlDoc { get; set; }
41          #endregion          #endregion
42          #region IXMLTV_PARSER Members          #region IXMLTV_PARSER Members
43          public IXMLTVSource Source { get; set; }          public IXMLTVSource Source { get; set; }
# Line 27  namespace libxmltv.Core Line 45  namespace libxmltv.Core
45          public Dictionary<int, IXMLTVProgram> Programs { get; set; }          public Dictionary<int, IXMLTVProgram> Programs { get; set; }
46          #endregion            #endregion  
47            
48          //public void Dispose()          public EventHandler<EventArgs> OnInstanceCreated { get; set; }
49          //{          public EventHandler<EventArgs> GetOnInstanceCreated() { return OnInstanceCreated; }
50          //    IsDisposing = true;          public void SetOnInstanceCreated(EventHandler<EventArgs> event_instance) { OnInstanceCreated = event_instance; }
51          //    //throw new NotImplementedException();  
52          //}          public IXMLTVSerializer<XMLTVRuntimeInstance> Serializer
53          public bool IsDisposing { get; private set; }          {
54                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            }
62            public void DestroyInstance()
63            {
64                xmltv_logger.Log.Debug.WriteLine("Destoying Instance of: '{0}'", this.GetType().Name);
65                this.IsAborting = true;
66                if (worker == null)
67                {
68                    xmltv_logger.Log.Debug.WriteLine("Unable to destroy instance of: '{0}' - worker thread is null", this.GetType().Name);
69                    return;
70                }
71                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            }
88            public bool IsAborting
89            {
90                get;
91                private set;
92            }        
93      }      }
94    
95      internal class XMLTVInstance : IDisposable      internal class XMLTVInstance : IDisposable

Legend:
Removed from v.45  
changed lines
  Added in v.54

  ViewVC Help
Powered by ViewVC 1.1.22