Tip - Single seat, wait for services to start before running Mediaportal (1 Viewer)

Shazell

Portal Member
June 5, 2007
32
3
Home Country
United Kingdom United Kingdom
Well I have a feeling that I have the same problem.

Often when I start up MP (I have the autostart plugin switch to MyTV on startup) I end up with a screen prompting me to select the tvserver as it cannot be found.

I will endeavour to get some logs for this tonight and post a proper report.

But if the problem is just that the SQL service has not started then that should be a fairly easy fix. the TV service one is already in and the code is practically the same

TVservice startup delay in /trunk/mediaportal/xbmc/MediaPortal.cs

Code:
  312        if (_waitForTvServer)
  313         {
  314           Log.Info("Main: Wait for TvServer requested. Checking if installed...");
  315           System.ServiceProcess.ServiceController ctrl = new System.ServiceProcess.ServiceController("TVService");
  316           try
  317           {
  318             string name = ctrl.ServiceName;
  319           }
  320           catch (Exception)
  321           {
  322             ctrl = null;
  323             Log.Info("Main: TvServer not installed, so we can go on.");
  324           }
  325           if (ctrl != null)
  326           {
  327             Log.Info("Main: TvServer found. Checking status...");
  328             if (ctrl.Status == System.ServiceProcess.ServiceControllerStatus.StartPending)
  329             {
  330               Log.Info("Main: TvServer is start pending. Waiting until it starts up...");
  331               if (splashScreen != null)
  332                 splashScreen.SetInformation("Waiting for startup of TvServer...");
  333               try
  334               {
  335                 ctrl.WaitForStatus(System.ServiceProcess.ServiceControllerStatus.Running);
  336               }
  337               catch (Exception) { }
  338               if (ctrl.Status == System.ServiceProcess.ServiceControllerStatus.Running)
  339                 Log.Info("Main: Ok. TvServer is started.");
  340               else
  341                 Log.Info("Main: Failed. TvServer is in status {0}", ctrl.Status.ToString());
  342             }
  343             Log.Info("Main: TvServer is in status {0}. So we can go on.", ctrl.Status.ToString());
  344             ctrl.Close();
  345           }
  346         }

Now I am not a dev with access, and only really an amateur at this :p

But adding this afterwards should work for MSSQL server

Code:
  312        if (_waitForSQLServer)
  313         {
  314           Log.Info("Main: Wait for SQLServer requested. Checking if installed...");
  315           System.ServiceProcess.ServiceController ctrl = new System.ServiceProcess.ServiceController("MSSQL$SQLEXPRESS");
  316           try
  317           {
  318             string name = ctrl.ServiceName;
  319           }
  320           catch (Exception)
  321           {
  322             ctrl = null;
  323             Log.Info("Main: SQLServer not installed, so we can go on.");
  324           }
  325           if (ctrl != null)
  326           {
  327             Log.Info("Main: SQLServer found. Checking status...");
  328             if (ctrl.Status == System.ServiceProcess.ServiceControllerStatus.StartPending)
  329             {
  330               Log.Info("Main: SQLServer is start pending. Waiting until it starts up...");
  331               if (splashScreen != null)
  332                 splashScreen.SetInformation("Waiting for startup of SQLServer...");
  333               try
  334               {
  335                 ctrl.WaitForStatus(System.ServiceProcess.ServiceControllerStatus.Running);
  336               }
  337               catch (Exception) { }
  338               if (ctrl.Status == System.ServiceProcess.ServiceControllerStatus.Running)
  339                 Log.Info("Main: Ok. SQLServer is started.");
  340               else
  341                 Log.Info("Main: Failed. SQLServer is in status {0}", ctrl.Status.ToString());
  342             }
  343             Log.Info("Main: SQLServer is in status {0}. So we can go on.", ctrl.Status.ToString());
  344             ctrl.Close();
  345           }
  346         }

These lines need to be added as well
Code:
  108   private static bool _waitForTvServer = false;
[I]  109   private static bool _waitForSQLServer = false;[/I]

  253         _waitForTvServer = xmlreader.GetValueAsBool("general", "wait for tvserver", false);  
[I]  254         _waitForSQLServer = xmlreader.GetValueAsBool("general", "wait for sqlserver", false);[/I]

As well as the configuration form being updated
 

rtv

Retired Team Member
  • Premium Supporter
  • April 7, 2005
    3,622
    301
    Osnabruck
    Home Country
    Germany Germany
    I wonder who did that...

    Code:
    315 System.ServiceProcess.ServiceController ctrl = new System.ServiceProcess.ServiceController("TVService");
    316 try 
    317 { 
    318   string name = ctrl.ServiceName; 
    319 } 
    320 catch (Exception) 
    321 { 
    322   ctrl = null; 
    323   Log.Info("Main: TvServer not installed, so we can go on."); 
    324 }

    There are various issues with this code.
    1. Exceptions are bad for performance - a simple "== null" check for ctrl would have been better.
    2. The ServiceController's Konstruktor needs priviledged access. It's call however is NOT in the try-catch block. So if some user does not run MP with Administrator rights (after installation) this will fail.

    Here are some docs:
    ServiceController Constructor (String) (System.ServiceProcess)

    In general the current implementation can hardly be considered more than a workaround. And if even that might cause troubles :rolleyes:
     

    Hetfield

    Portal Pro
    March 3, 2007
    69
    9
    Home Country
    Finland Finland
    Off topic

    It's also quite complex:

    if (ctrl != null) {
    // ...
    // 20 lines of code with a lot of conditions and try/catches
    if(something) {
    // some code
    } else {
    // some code
    }
    // ...
    }

    Should be done like:

    if (ctrl == null) return;
    // ...
    // maximum 5-10 lines, no deep condition structures or try/catches
    // ...

    ExtractMethod and proper usage of conditions makes miracles. If I wouldn't need to work, I would be MP developer :)
     

    Shazell

    Portal Member
    June 5, 2007
    32
    3
    Home Country
    United Kingdom United Kingdom
    It also seem to not work

    2008-02-29 19:20:21.046875 [Info.][MPMain]: Main: Wait for TvServer requested. Checking if installed...
    2008-02-29 19:20:21.125000 [Info.][MPMain]: Main: TvServer found. Checking status...
    2008-02-29 19:20:21.125000 [Info.][MPMain]: Main: TvServer is in status Stopped. So we can go on.

    I thought it was supposed to wait until the service is running not stopped.

    Should I post this in the bugs section?
     

    Hetfield

    Portal Pro
    March 3, 2007
    69
    9
    Home Country
    Finland Finland
    Any progress?

    Is there happening anything with this issue? The problem is now known, so has there been a fix, or will there be?
     

    tourettes

    Retired Team Member
  • Premium Supporter
  • January 7, 2005
    17,301
    4,800
    Is there happening anything with this issue? The problem is now known, so has there been a fix, or will there be?

    I guess not anyone of the team's devs are experiencing this bug -> low priority. But if you have programming background please provide a patch :)
     

    Hetfield

    Portal Pro
    March 3, 2007
    69
    9
    Home Country
    Finland Finland
    Is there happening anything with this issue? The problem is now known, so has there been a fix, or will there be?

    I guess not anyone of the team's devs are experiencing this bug -> low priority. But if you have programming background please provide a patch :)

    :-D

    At least for one - two months I have no time at all. I work with C# all days, and on the evenings I write my thesis. But maybe after that I could try if the problem still exists. Anyway, for me it would be easy to test and reproduce the problem.
     

    Spooky

    MP Donator
  • Premium Supporter
  • February 14, 2005
    1,187
    47
    void 4tl
    Home Country
    Austria Austria
    As indicated here I got the same problem. Using a batch script is all nice and good, but I would prefer if the "Wait for TvServer" option actually works :)
     

    rtv

    Retired Team Member
  • Premium Supporter
  • April 7, 2005
    3,622
    301
    Osnabruck
    Home Country
    Germany Germany
    Well I did a little change for RC1 - so please try again after installing that ;)
     

    Hetfield

    Portal Pro
    March 3, 2007
    69
    9
    Home Country
    Finland Finland
    Thanks (not tested yet)

    Thank you very much, hopefully it works. It's also important to fix the problems which users suffer, not only developers. Many non-programmer wouldn't use software which has start up problems. :D

    By the way, how it works actually by your fix? Does it wait before MediaPortal is shown, or when going to "My TV"? Any kind of fix is decent, but only having to wait when starting to view TV would be the best solution.
     

    Users who are viewing this thread

    Top Bottom