internal bool Start() { try { LoadSettings(); LoadExternalConfig(); if (String.IsNullOrEmpty(_serverHost)) { if (!Configure()) { return(false); } } bool clientStarted = false; try { IPAddress serverIP = Network.GetIPFromName(_serverHost); IPEndPoint endPoint = new IPEndPoint(serverIP, Server.DefaultPort); clientStarted = StartClient(endPoint); } catch (Exception ex) { IrssLog.Error(ex); MessageBox.Show("Failed to start IR Server communications, refer to log file for more details.", "Media Center Blaster - Error", MessageBoxButtons.OK, MessageBoxIcon.Error); clientStarted = false; } if (clientStarted) { _notifyIcon.Visible = true; _mediaState = new MediaState(); _mediaState.OnMSASEvent += new MediaState.MSASEventHandler(OnMSASEvent); _mediaState.TV.MediaChanged += new EventHandler(TV_MediaChanged); _mediaState.Connect(); return(true); } else { Configure(); } } catch (Exception ex) { IrssLog.Error(ex); _mediaState = null; } return(false); }
internal bool Start() { try { LoadSettings(); LoadExternalConfig(); if (String.IsNullOrEmpty(_serverHost)) { if (!Configure()) return false; } bool clientStarted = false; try { IPAddress serverIP = Network.GetIPFromName(_serverHost); IPEndPoint endPoint = new IPEndPoint(serverIP, Server.DefaultPort); clientStarted = StartClient(endPoint); } catch (Exception ex) { IrssLog.Error(ex); MessageBox.Show("Failed to start IR Server communications, refer to log file for more details.", "Media Center Blaster - Error", MessageBoxButtons.OK, MessageBoxIcon.Error); clientStarted = false; } if (clientStarted) { _notifyIcon.Visible = true; _mediaState = new MediaState(); _mediaState.OnMSASEvent += new MediaState.MSASEventHandler(OnMSASEvent); _mediaState.TV.MediaChanged += new EventHandler(TV_MediaChanged); _mediaState.Connect(); return true; } else { Configure(); } } catch (Exception ex) { IrssLog.Error(ex); _mediaState = null; } return false; }
public void Launch(AddInHost host) { _host = host; // Do not run this on extenders as extenders don't support MSAS if (_host.MediaCenterEnvironment.Capabilities.ContainsKey("Console")) { try { // Initialize FB session InitializeFacebook(); // Initialize Twitter session InitializeTwitter(); // Connect must be done here and not in Initialize, else the events are not launched (if using MSASEventHandler) // or _mediaState will always be null. _mediaState.Connect(); _application = new Application(_host); int.TryParse(CommonFunctions.GetSetting("PollingInterval"), out _pollingInterval); int twitterStatusUpdateQueryCounter = 0; // Used to ensure that Twitter friend updates are not queried more that 100 times per hour, which is the limit int twitterStatusUpdateQueryCounterLimit = 3600000 / int.Parse(CommonFunctions.GetSetting("Service_Twitter_Friends_TimesPerHour")) / _pollingInterval; while (true) { Sleep(_pollingInterval); bool runApp = false; // DoEvents must be done here, else _mediaState doesn't contain current states System.Windows.Forms.Application.DoEvents(); if (bool.Parse(CommonFunctions.GetSetting("EventsEnabled_Service_Facebook")) && EventTimeEnabled("Service_Facebook_TimeEnabled")) { if (_fbApi != null && !string.IsNullOrEmpty(_fbApi.AccessToken)) { runApp = true; } } if ((bool.Parse(CommonFunctions.GetSetting("EventsEnabled_Service_Xml")) && EventTimeEnabled("Service_Xml_TimeEnabled")) || (bool.Parse(CommonFunctions.GetSetting("EventsEnabled_Service_Twitter")) && EventTimeEnabled("Service_Twitter_TimeEnabled"))) { // If event is enabled and also allowed by time settings runApp = true; } if (runApp) { runApp = false; _application.Run(); } if (!disableTwitterNotifications) { // For showing Twitter updates of friends if (bool.Parse(CommonFunctions.GetSetting("EventsEnabled_Service_TwitterFriends")) && twitterStatusUpdateQueryCounter++ > twitterStatusUpdateQueryCounterLimit) { twitterStatusUpdateQueryCounter = 0; // Check if Twitter suspend time has passed if (DateTime.Now.CompareTo(_twitterSuspendTime) < 0) // returns greater than zero if current time is past suspend end time { // Twitter update is still suspended, just get latest ID in order not to spam user with queued tweets after suspend period ends _twitter.UpdateLatestTwitterStatusId(); } else if (!_twitter.UpdateLatestTwitterStatusChanges()) { _host.MediaCenterEnvironment.Dialog("Error getting Twitter updates, retrying later.", AppName, DialogButtons.Ok, 5, true); } } if (bool.Parse(CommonFunctions.GetSetting("EventsEnabled_Service_TwitterFriends"))) { ShowNextTwitterStatus(); } } } } catch (Exception exc) { _host.MediaCenterEnvironment.Dialog("Unable to launch, quitting. " + exc.ToString(), AppName, DialogButtons.Ok, 0, true); } } }