コード例 #1
0
 public void Initialize(Dictionary <string, object> appInfo, Dictionary <string, object> entryPointInfo)
 {
     _mediaState  = new MediaState();
     DebugEnabled = bool.Parse(CommonFunctions.GetSetting("Debug"));
 }
コード例 #2
0
        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);
                }
            }
        }
コード例 #3
0
        /// <summary>
        /// Initializes Twitter, including showing login screen
        /// </summary>
        private void InitializeTwitter()
        {
            if (bool.Parse(CommonFunctions.GetSetting("EventsEnabled_Service_Twitter")) || bool.Parse(CommonFunctions.GetSetting("EventsEnabled_Service_TwitterFriends")))
            {
                _twitter = new TwitterAPI();

                if (string.IsNullOrEmpty(CommonFunctions.GetSetting("Twitter_AccessToken")) || string.IsNullOrEmpty(CommonFunctions.GetSetting("Twitter_AccessTokenSecret")))
                {
                    // Show Twitter login screen
                    TwitterLoginScreen();
                }
                else
                {
                    if (!InitializeTwitterApi(CommonFunctions.GetSetting("Twitter_AccessToken"), CommonFunctions.GetSetting("Twitter_AccessTokenSecret")))
                    {
                        // Show Twitter login screen
                        TwitterLoginScreen();
                    }
                }

                // Get latest friend update status id
                if (bool.Parse(CommonFunctions.GetSetting("EventsEnabled_Service_TwitterFriends")) && !disableTwitterNotifications)
                {
                    if (!_twitter.UpdateLatestTwitterStatusId())
                    {
                        _host.MediaCenterEnvironment.Dialog("Error getting latest Twitter status ID, disabling Twitter friend status update notifications", AppName, DialogButtons.Ok, 10, true);
                        disableTwitterNotifications = true;
                    }
                }
            }
        }