ClearCache() static private method

static private ClearCache ( ) : void
return void
Beispiel #1
0
        private bool TestAccount(TraktAuthenticationToken token)
        {
            // test account by requesting the user settings
            var response = TraktAPI.TraktAPI.GetUserSettings();

            if (response == null || response.User == null)
            {
                GUIUtils.ShowNotifyDialog(Translation.Error, Translation.FailedOnlineSettings);
                return(false);
            }
            else
            {
                // Save New Account Settings
                TraktSettings.Username       = response.User.Username;
                TraktSettings.OnlineSettings = response;

                TraktSettings.AccountStatus = ConnectionState.Connected;
                InitProperties();

                // clear caches
                // watchlists are stored by user so dont need clearing.
                GUINetwork.ClearCache();
                GUICalendarTV.ClearCache();
                GUIRecommendationsMovies.ClearCache();
                GUIRecommendationsShows.ClearCache();

                // clear any stored user data
                TraktCache.ClearSyncCache();

                // persist settings
                TraktSettings.SaveSettings(false);

                return(true);
            }
        }
        private void TestAccount(TraktAccount account)
        {
            TraktResponse response = null;

            if (NewAccount)
            {
                if (lblTestConnect != null)
                {
                    GUIControl.SetControlLabel(GetID, lblTestConnect.GetID, Translation.CreatingAccount);
                }

                GUIWindowManager.Process();
                response = TraktAPI.TraktAPI.CreateAccount(account);
            }
            else
            {
                if (lblTestConnect != null)
                {
                    GUIControl.SetControlLabel(GetID, lblTestConnect.GetID, Translation.SigningIntoAccount);
                }

                GUIWindowManager.Process();
                response = TraktAPI.TraktAPI.TestAccount(account);
            }

            if (response.Status == "failure")
            {
                string errorMessage = string.IsNullOrEmpty(response.Error) ? response.Message : response.Error;
                GUIUtils.ShowNotifyDialog(Translation.Error, errorMessage);
                if (lblTestConnect != null)
                {
                    GUIControl.SetControlLabel(GetID, lblTestConnect.GetID, string.Empty);
                }
            }
            else
            {
                // Save New Account Settings
                TraktSettings.Username = account.Username;
                TraktSettings.Password = account.Password;
                if (!TraktSettings.UserLogins.Exists(u => u.Username == TraktSettings.Username))
                {
                    TraktSettings.UserLogins.Add(new TraktAuthentication {
                        Username = TraktSettings.Username, Password = TraktSettings.Password
                    });
                }
                TraktSettings.AccountStatus = ConnectionState.Connected;
                HideAccountControls();
                InitProperties();

                // clear caches
                // watch lists are stored by user so dont need clearing.
                GUINetwork.ClearCache();
                GUICalendar.ClearCache();
                GUIRecommendationsMovies.ClearCache();
                GUIRecommendationsShows.ClearCache();
            }
        }
Beispiel #3
0
        protected override void OnClicked(int controlId, GUIControl control, Action.ActionType actionType)
        {
            // wait for any background action to finish
            if (GUIBackgroundTask.Instance.IsBusy)
            {
                return;
            }

            switch (controlId)
            {
            // Facade
            case (50):
                if (actionType == Action.ActionType.ACTION_SELECT_ITEM)
                {
                    var selectedUser = Facade.SelectedListItem.TVTag as TraktUserSummary;
                    if (selectedUser == null)
                    {
                        break;
                    }

                    if (!selectedUser.IsPrivate)
                    {
                        GUIUserProfile.CurrentUser = selectedUser.Username;
                        GUIWindowManager.ActivateWindow((int)TraktGUIWindows.UserProfile);
                    }
                    else
                    {
                        if (GUIUtils.ShowYesNoDialog(Translation.Network, string.Format(Translation.SendFollowRequest, selectedUser.Username), true))
                        {
                            GUINetwork.FollowUser(selectedUser);
                            GUINetwork.ClearCache();
                        }
                    }
                }
                break;

            // Layout Button
            case (2):
                CurrentLayout = GUICommon.ShowLayoutMenu(CurrentLayout, PreviousSelectedIndex);
                break;

            default:
                break;
            }
            base.OnClicked(controlId, control, actionType);
        }
        private void DisconnectAccount()
        {
            TraktLogger.Info("Disconnecting Account: {0}", TraktSettings.Username);

            // clear account settings
            TraktSettings.Username      = string.Empty;
            TraktSettings.Password      = string.Empty;
            TraktSettings.AccountStatus = ConnectionState.Disconnected;

            InitProperties();

            // clear caches
            // watchlists are stored by user so dont need clearing.
            GUINetwork.ClearCache();
            GUICalendar.ClearCache();
            GUIRecommendationsMovies.ClearCache();
            GUIRecommendationsShows.ClearCache();

            // clear any stored user data
            TraktCache.ClearSyncCache();
        }
Beispiel #5
0
        private void DisconnectAccount()
        {
            TraktLogger.Info("Revoking application access to trakt.tv account");

            GUIBackgroundTask.Instance.ExecuteInBackgroundAndCallback(() =>
            {
                TraktAPI.TraktAPI.RevokeToken();
                return(true);
            },
                                                                      delegate(bool success, object result)
            {
                if (success)
                {
                    // clear account settings
                    TraktSettings.Username              = string.Empty;
                    TraktSettings.UserAccessToken       = string.Empty;
                    TraktSettings.UserAccessTokenExpiry = string.Empty;
                    TraktSettings.UserRefreshToken      = string.Empty;
                    TraktSettings.AccountStatus         = ConnectionState.Disconnected;

                    InitProperties();

                    // clear caches
                    // watchlists are stored by user so dont need clearing.
                    GUINetwork.ClearCache();
                    GUICalendarTV.ClearCache();
                    GUIRecommendationsMovies.ClearCache();
                    GUIRecommendationsShows.ClearCache();

                    // clear any stored user data
                    TraktCache.ClearSyncCache();

                    // persist settings
                    TraktSettings.SaveSettings(false);
                }
            }, Translation.AuthorizingApplication, false);
        }
        private void TestAccount(TraktAuthentication account)
        {
            TraktUserToken response = null;

            if (NewAccount)
            {
                // No longer supported with v2 API.
                //if (lblTestConnect != null)
                //    GUIControl.SetControlLabel(GetID, lblTestConnect.GetID, Translation.CreatingAccount);

                //GUIWindowManager.Process();
                //response = TraktAPI.v1.TraktAPI.CreateAccount(account);
            }
            else
            {
                if (lblTestConnect != null)
                {
                    GUIControl.SetControlLabel(GetID, lblTestConnect.GetID, Translation.SigningIntoAccount);
                }

                GUIWindowManager.Process();
                response = TraktAPI.TraktAPI.Login(account.ToJSON());
            }

            if (response == null || string.IsNullOrEmpty(response.Token))
            {
                GUIUtils.ShowNotifyDialog(Translation.Error, Translation.FailedLogin);
                if (lblTestConnect != null)
                {
                    GUIControl.SetControlLabel(GetID, lblTestConnect.GetID, string.Empty);
                }
            }
            else
            {
                // Save User Token
                TraktAPI.TraktAPI.UserToken = response.Token;

                // Save New Account Settings
                TraktSettings.Username = account.Username;
                TraktSettings.Password = account.Password;
                if (!TraktSettings.UserLogins.Exists(u => u.Username == TraktSettings.Username))
                {
                    TraktSettings.UserLogins.Add(new TraktAuthentication {
                        Username = TraktSettings.Username, Password = TraktSettings.Password
                    });
                }
                TraktSettings.AccountStatus = ConnectionState.Connected;
                HideAccountControls();
                InitProperties();

                // clear caches
                // watchlists are stored by user so dont need clearing.
                GUINetwork.ClearCache();
                GUICalendar.ClearCache();
                GUIRecommendationsMovies.ClearCache();
                GUIRecommendationsShows.ClearCache();

                // clear any stored user data
                TraktCache.ClearSyncCache();
            }
        }
Beispiel #7
0
        protected override void OnShowContextMenu()
        {
            if (GUIBackgroundTask.Instance.IsBusy)
            {
                return;
            }

            var selectedItem = this.Facade.SelectedListItem;

            if (selectedItem == null)
            {
                return;
            }

            var selectedUser = selectedItem.TVTag as TraktUserSummary;

            if (selectedUser == null)
            {
                return;
            }

            var dlg = (IDialogbox)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_MENU);

            if (dlg == null)
            {
                return;
            }

            dlg.Reset();
            dlg.SetHeading(GUIUtils.PluginName());

            GUIListItem listItem = null;

            // Follow User
            // Only show menu item if user has an account as this is an unprotected area.
            if (!string.IsNullOrEmpty(TraktSettings.UserAccessToken) && !((selectedItem as GUIUserListItem).IsFollowed))
            {
                listItem = new GUIListItem(Translation.FollowUser);
                dlg.Add(listItem);
                listItem.ItemId = (int)ContextMenuItem.FollowUser;
            }

            // User Profile
            if (!selectedUser.IsPrivate)
            {
                listItem = new GUIListItem(Translation.UserProfile);
                dlg.Add(listItem);
                listItem.ItemId = (int)ContextMenuItem.UserProfile;
            }

            // Change Layout
            listItem = new GUIListItem(Translation.ChangeLayout);
            dlg.Add(listItem);
            listItem.ItemId = (int)ContextMenuItem.ChangeLayout;

            // Show Context Menu
            dlg.DoModal(GUIWindowManager.ActiveWindow);
            if (dlg.SelectedId < 0)
            {
                return;
            }

            switch (dlg.SelectedId)
            {
            case ((int)ContextMenuItem.FollowUser):
                if (GUIUtils.ShowYesNoDialog(Translation.Network, string.Format(Translation.SendFollowRequest, selectedItem.Label), true))
                {
                    GUINetwork.FollowUser(selectedUser);
                    GUINetwork.ClearCache();
                    (selectedItem as GUIUserListItem).IsFollowed = true;
                }
                break;

            case ((int)ContextMenuItem.UserProfile):
                GUIUserProfile.CurrentUser = selectedUser.Username;
                GUIWindowManager.ActivateWindow((int)TraktGUIWindows.UserProfile);
                break;

            case ((int)ContextMenuItem.ChangeLayout):
                CurrentLayout = GUICommon.ShowLayoutMenu(CurrentLayout, PreviousSelectedIndex);
                break;
            }

            base.OnShowContextMenu();
        }