Пример #1
0
        /// <summary>
        /// Starts running an application
        /// Because the Windows Media Center object is guaranteed to be valid only until the Launch
        /// method returns, an on-demand application must make all calls to the Windows Media Center
        /// API within the context of the application's Launch method. Calling the Windows Media
        /// Center object after the Launch method returns can result in a fatal error. If your
        /// application's Launch method spawns multiple threads, those threads must all be terminated
        /// before your Launch method returns. After calling the Launch method, if you do not call
        /// any method directly from the host object, .NET remoting releases unused objects every
        /// five minutes. To avoid this, use the host object or use the objects within five minutes
        /// to prevent them from being released.
        /// </summary>
        /// <param name="host">An application uses this interface to access other interfaces provided by the Microsoft.MediaCenter namespace</param>
        public void Launch(AddInHost host)
        {
            try
            {
                //  Lower the priority of this thread
                System.Threading.Thread.CurrentThread.Priority = ThreadPriority.Lowest;

                //  Setup TCP socket listener
                m_socketServer.StartListening(GetPortNumber(m_basePortNumber));
                m_socketServer.NewMessage += new EventHandler<SocketEventArgs>(m_socketServer_NewMessage);
                m_socketServer.Connected += new EventHandler<SocketEventArgs>(m_socketServer_Connected);

                //  Setup HTTP socket listener
                m_httpServer.StartListening(GetPortNumber(m_basePortNumber) + 10);
                m_httpServer.NewRequest += new EventHandler<HttpEventArgs>(m_httpServer_NewRequest);

                //EventLog.WriteEntry("VmcController Client AddIn", "Listening on port " + m_socketServer.PortNumber + " (Version " + VersionInfo + ")", EventLogEntryType.Information);

                if (System.IO.File.Exists(System.Environment.GetEnvironmentVariable("windir") + "\\ehome\\vmcController.xml"))
                {
                    XmlDocument doc = new XmlDocument();
                    doc.Load(System.Environment.GetEnvironmentVariable("windir") + "\\ehome\\vmcController.xml");
                    XmlNode startupCommand = doc.DocumentElement.SelectSingleNode("startupMacro");

                    if (startupCommand == null)
                    {
                        //AddInHost.Current.MediaCenterEnvironment.Dialog("startup node not found", "", DialogButtons.Ok, 5, false);
                    }
                    else
                    {
                        MacroCmd macro = new MacroCmd();
                        OpResult result = macro.Execute(startupCommand.InnerText);
                        result = null;
                        macro = null;
                    }
                    doc = null;
                }

                //  Wait until exit request from host
                m_waitHandle.WaitOne();
            }
            catch (Exception ex)
            {
                //EventLog.WriteEntry("VmcController Client AddIn", "Exception in Launch: " + ex.ToString(), EventLogEntryType.Error);
            }
            finally
            {
                //  Shutdown listener
                if (m_socketServer.PortNumber > 0)
                    m_socketServer.StopListening();
            }
        }
Пример #2
0
        /// <summary>
        /// Starts running an application
        /// Because the Windows Media Center object is guaranteed to be valid only until the Launch
        /// method returns, an on-demand application must make all calls to the Windows Media Center
        /// API within the context of the application's Launch method. Calling the Windows Media
        /// Center object after the Launch method returns can result in a fatal error. If your
        /// application's Launch method spawns multiple threads, those threads must all be terminated
        /// before your Launch method returns. After calling the Launch method, if you do not call
        /// any method directly from the host object, .NET remoting releases unused objects every
        /// five minutes. To avoid this, use the host object or use the objects within five minutes
        /// to prevent them from being released.
        /// </summary>
        /// <param name="host">An application uses this interface to access other interfaces provided by the Microsoft.MediaCenter namespace</param>
        public void Launch(AddInHost host)
        {
            try
            {
                //  Lower the priority of this thread
                Thread.CurrentThread.Priority = ThreadPriority.Lowest;

                //  Setup HTTP socket listener
                m_httpServer.StartListening(GetPortNumber(m_basePortNumber) + 10);

                if (System.IO.File.Exists(System.Environment.GetEnvironmentVariable("windir") + "\\ehome\\vmcController.xml"))
                {
                    XmlDocument doc = new XmlDocument();
                    doc.Load(System.Environment.GetEnvironmentVariable("windir") + "\\ehome\\vmcController.xml");
                    XmlNode startupCommand = doc.DocumentElement.SelectSingleNode("startupMacro");

                    if (startupCommand != null)
                    {
                        MacroCmd macro = new MacroCmd();
                        OpResult result = macro.Execute(startupCommand.InnerText);
                        result = null;
                        macro = null;
                    }
                    doc = null;
                }

                //  Wait until exit request from host
                m_waitHandle.WaitOne();

            }
            catch (Exception)
            {
            }
        }