private ContextMenuAction ShowDisplayOptionsMenu(string previousMenu)
 {
     ContextMenu cmenu = new ContextMenu(Translation.DisplayOptions, previousMenu);
       cmenu.Add(Translation.ChangeLayout, () => ShowLayoutMenu(Translation.DisplayOptions));
       return cmenu.Show();
 }
        private ContextMenuAction ShowContextMenuSeriesEdit(string previousMenu)
        {
            GUIListItem currentitem = m_Facade.SelectedListItem;
              if (currentitem == null)
            return ContextMenuAction.Exit;

              AnimeSeriesVM ser = currentitem.TVTag as AnimeSeriesVM;
              if (ser == null)
            return ContextMenuAction.Exit;

              string currentMenu = ser.SeriesName + " - " + Translation.Edit;
              ContextMenu cmenu = new ContextMenu(currentMenu, previousmenu: previousMenu);
              // ReSharper disable ImplicitlyCapturedClosure
              cmenu.Add(Translation.SetDefaultAudioLanguage, () =>
              // ReSharper restore ImplicitlyCapturedClosure
              {
            string language = ser.DefaultAudioLanguage;
            if (Utils.DialogLanguage(ref language, false))
            {
              ser.DefaultAudioLanguage = language;
              ser.Save();
              return ContextMenuAction.Exit;
            }
            return ContextMenuAction.Continue;
              });
              // ReSharper disable ImplicitlyCapturedClosure
              cmenu.Add(Translation.SetDefaultSubtitleLanguage, () =>
              // ReSharper restore ImplicitlyCapturedClosure
              {
            string language = ser.DefaultSubtitleLanguage;
            if (Utils.DialogLanguage(ref language, true))
            {
              ser.DefaultSubtitleLanguage = language;
              ser.Save();
              return ContextMenuAction.Exit;
            }
            return ContextMenuAction.Continue;
              });
              cmenu.Add(Translation.DeleteThisSeriesEpisodes, () =>
              {
            if (ser.AnimeSeriesID.HasValue)
            {
              if (Utils.DialogConfirm(Translation.AreYouSure))
              {
            JMMServerVM.Instance.clientBinaryHTTP.DeleteAnimeSeries(ser.AnimeSeriesID.Value, false, false);
            LoadFacade();
            return ContextMenuAction.Exit;
              }
            }
            return ContextMenuAction.Continue;
              });
              return cmenu.Show();
        }
        private ContextMenuAction ShowContextMenuTVDB(AnimeSeriesVM ser, string previousMenu)
        {
            GUIListItem currentitem = m_Facade.SelectedListItem;
              if (currentitem == null)
            return ContextMenuAction.Exit;

              int tvdbid;
              int season;
              string displayName;

              if (ser.CrossRef_AniDB_TvDBV2.Count > 0 && ser.TvDBSeriesV2.Count > 0 && ser.AniDB_Anime.AniDB_AnimeCrossRefs != null && ser.AniDB_Anime.AniDB_AnimeCrossRefs.TvDBCrossRefExists)
              {
            displayName = ser.AniDB_Anime.AniDB_AnimeCrossRefs.TvDBSeries[0].SeriesName;
            tvdbid = ser.CrossRef_AniDB_TvDBV2[0].TvDBID;
            season = ser.CrossRef_AniDB_TvDBV2[0].TvDBSeasonNumber;
              }
              else
            return ContextMenuAction.PreviousMenu;
              ContextMenu cmenu = new ContextMenu(displayName, previousmenu: previousMenu);
              // ReSharper disable ImplicitlyCapturedClosure
              cmenu.AddAction(Translation.RemoveTVDBAssociation, () => JMMServerVM.Instance.clientBinaryHTTP.RemoveLinkAniDBTvDBForAnime(ser.AniDB_Anime.AnimeID));
              // ReSharper restore ImplicitlyCapturedClosure
              cmenu.Add(string.Format(Translation.SwitchSeason, season.ToString(Globals.Culture)), () =>
              {
            if (ser.CrossRef_AniDB_TvDBV2.Count < 2)
            {
              return ShowSeasonSelectionMenuTvDB(ser, ser.AniDB_Anime.AnimeID, tvdbid, displayName);
            }
            Utils.DialogMsg(Translation.Error, Translation.CannotEditTvDBLink);
            return ContextMenuAction.Continue;
              });
              return cmenu.Show();
        }
        private ContextMenuAction ShowContextMenuGroupEdit(string previousMenu)
        {
            GUIListItem currentitem = m_Facade.SelectedListItem;
              if (currentitem == null)
            return ContextMenuAction.Exit;

              AnimeGroupVM grp = currentitem.TVTag as AnimeGroupVM;
              if (grp == null)
            return ContextMenuAction.Exit;

              string currentMenu = grp.GroupName + " - " + Translation.Edit;
              ContextMenu cmenu = new ContextMenu(currentMenu, previousmenu: previousMenu);
              cmenu.Add(Translation.RenameGroup, () =>
              {
            string name = grp.GroupName;
            if (Utils.DialogText(ref name, GetID) && name != string.Empty)
            {
              if (name != grp.GroupName)
              {
            grp.GroupName = name;
            grp.SortName = Utils.GetSortName(name);
            grp.Save();
            LoadFacade();
              }
              return ContextMenuAction.Exit;
            }
            return ContextMenuAction.Continue;
              });
              cmenu.Add(Translation.ChangeSortName, () =>
              {
            string sortName = grp.SortName;
            if (Utils.DialogText(ref sortName, GetID))
            {
              grp.SortName = sortName;
              grp.Save();
              LoadFacade();
              return ContextMenuAction.Exit;
            }
            return ContextMenuAction.Continue;
              });
              List<AnimeSeriesVM> allSeries = grp.AllSeries;
              AnimeSeriesVM equalSeries = null;
              if (allSeries.Count == 1)
            equalSeries = allSeries[0];
              if (equalSeries != null)
              {
            cmenu.Add(Translation.SetDefaultAudioLanguage, () =>
            {
              String language = equalSeries.DefaultAudioLanguage;
              if (Utils.DialogLanguage(ref language, false))
              {
            equalSeries.DefaultAudioLanguage = language;
            equalSeries.Save();
            return ContextMenuAction.Exit;
              }
              return ContextMenuAction.Continue;
            });
            cmenu.Add(Translation.SetDefaultSubtitleLanguage, () =>
            {
              String language = equalSeries.DefaultSubtitleLanguage;
              if (Utils.DialogLanguage(ref language, true))
              {
            equalSeries.DefaultSubtitleLanguage = language;
            equalSeries.Save();
            return ContextMenuAction.Exit;
              }
              return ContextMenuAction.Continue;
            });
              }
              if (grp.DefaultAnimeSeriesID.HasValue)
              {
            // ReSharper disable ImplicitlyCapturedClosure
            cmenu.Add(Translation.RemoveDefaultSeries, () =>
            // ReSharper restore ImplicitlyCapturedClosure
            {
              JMMServerVM.Instance.clientBinaryHTTP.RemoveDefaultSeriesForGroup(grp.AnimeGroupID);
              grp.DefaultAnimeSeriesID = null;
              return ContextMenuAction.Continue;
            });
              }
              if (allSeries.Count > 1)
              {
            // ReSharper disable ImplicitlyCapturedClosure
            cmenu.Add(Translation.SetDefaultSeries, () =>
            // ReSharper restore ImplicitlyCapturedClosure
            {
              AnimeSeriesVM ser = null;
              if (Utils.DialogSelectSeries(ref ser, allSeries))
              {
            if (ser.AnimeSeriesID.HasValue)
            {
              grp.DefaultAnimeSeriesID = ser.AnimeSeriesID;
              JMMServerVM.Instance.clientBinaryHTTP.SetDefaultSeriesForGroup(grp.AnimeGroupID, ser.AnimeSeriesID.Value);
            }
              }
              return ContextMenuAction.Continue;
            });
              }
              // ReSharper disable ImplicitlyCapturedClosure
              cmenu.Add(Translation.DeleteThisGroupSeriesEpisodes, () =>
              // ReSharper restore ImplicitlyCapturedClosure
              {
            if (Utils.DialogConfirm(Translation.AreYouSure))
            {
              JMMServerVM.Instance.clientBinaryHTTP.DeleteAnimeGroup(grp.AnimeGroupID, false);
              LoadFacade();
              return ContextMenuAction.Exit;
            }
            return ContextMenuAction.Continue;
              });
              return cmenu.Show();
        }
        private ContextMenuAction ShowContextMenuSeries(string previousMenu)
        {
            GUIListItem currentitem = this.m_Facade.SelectedListItem;
              if (currentitem == null)
            return ContextMenuAction.Exit;

              AnimeSeriesVM ser = currentitem.TVTag as AnimeSeriesVM;
              if (ser == null)
            return ContextMenuAction.Exit;

              ContextMenu cmenu = new ContextMenu(ser.SeriesName, previousmenu: previousMenu);
              cmenu.AddAction(Translation.SeriesInformation, () => ShowAnimeInfoWindow(ser));
              cmenu.AddAction(Translation.MarkAllAsWatched, () =>
              {
            if (ser.AnimeSeriesID.HasValue)
            {
              JMMServerHelper.SetWatchedStatusOnSeries(true, Int32.MaxValue, ser.AnimeSeriesID.Value);
              Contract_AnimeSeries contract = JMMServerVM.Instance.clientBinaryHTTP.GetSeries(ser.AnimeSeriesID.Value, JMMServerVM.Instance.CurrentUser.JMMUserID);
              if (contract != null)
              {
            AnimeSeriesVM serTemp = new AnimeSeriesVM(contract);
            if(serTemp != null)
              Utils.PromptToRateSeriesOnCompletion(serTemp);
              }
              LoadFacade();
            }
              });
              cmenu.AddAction(Translation.MarkAllAsUnwatched, () =>
              {
            if (ser.AnimeSeriesID.HasValue)
            {
              JMMServerHelper.SetWatchedStatusOnSeries(false, Int32.MaxValue, ser.AnimeSeriesID.Value);
              LoadFacade();
            }
              });
              cmenu.AddAction(Translation.RateSeries, () =>
              {
              if (ser == null)
              {
              BaseConfig.MyAnimeLog.Write("Error during rating = series was null!");
              }
              if (ser.AnimeSeriesID.HasValue)
              {
              Utils.PromptToRateSeriesMaually(ser);
              }
              });
              cmenu.Add(Translation.Databases + " ...", () => ShowContextMenuDatabases(ser, ser.SeriesName));
              cmenu.Add(Translation.Images + " ...", () => ShowContextMenuImages(ser.SeriesName));
              cmenu.Add(Translation.EditSeries + " ...", () => ShowContextMenuSeriesEdit(ser.SeriesName));
              // ReSharper disable ImplicitlyCapturedClosure
              cmenu.AddAction(Translation.RandomEpisode, () =>
              // ReSharper restore ImplicitlyCapturedClosure
              {
            RandomWindow_CurrentEpisode = null;
            RandomWindow_CurrentSeries = null;
            RandomWindow_LevelObject = ser;
            RandomWindow_RandomLevel = RandomSeriesEpisodeLevel.Series;
            RandomWindow_RandomType = RandomObjectType.Episode;
            GUIWindowManager.ActivateWindow(Constants.WindowIDs.RANDOM);
              });
              cmenu.Add(Translation.PostProcessing + " ...", () => ShowContextMenuPostProcessing(ser.SeriesName));
              return cmenu.Show();
        }
        private ContextMenuAction ShowContextMenuEpisode(string previousMenu)
        {
            GUIListItem currentitem = this.m_Facade.SelectedListItem;
              if (currentitem == null)
            return ContextMenuAction.Exit;

              GUIDialogMenu dlg = (GUIDialogMenu)GUIWindowManager.GetWindow((int)Window.WINDOW_DIALOG_MENU);
              if (dlg == null)
            return ContextMenuAction.Exit;

              AnimeEpisodeVM episode = currentitem.TVTag as AnimeEpisodeVM;
              if (episode == null)
            return ContextMenuAction.Exit;
              bool isWatched = (episode.IsWatched == 1);

              ContextMenu cmenu = new ContextMenu(episode.EpisodeNumberAndName, previousmenu: previousMenu);
              cmenu.AddAction(isWatched ? Translation.MarkAsUnwatched : Translation.MarkAsWatched, () =>
              {
            BaseConfig.MyAnimeLog.Write("Toggle watched status: {0} - {1}", isWatched, episode);
            episode.ToggleWatchedStatus(!isWatched);
            LoadFacade();
              });
              AnimeSeriesVM ser = GetTopSerie();
              AnimeEpisodeTypeVM e = GetTopEpType();
              enEpisodeType ept = enEpisodeType.Episode;
              if (e != null)
            ept = e.EpisodeType;
              cmenu.AddAction(Translation.MarkAllAsWatched, () =>
              {
              if (ser == null)
              {
              // If we can't get a top series we fallback on what the episode tells us
              BaseConfig.MyAnimeLog.Write("Error during watch state change - series was null!");
              ser = episode.AnimeSeries;
              }

              if (ser?.AnimeSeriesID != null)
              {
              BaseConfig.MyAnimeLog.Write("Marking series as watched: ID -> {0} - Name -> {1}", ser.AnimeSeriesID,
                  ser.SeriesName);

              JMMServerVM.Instance.clientBinaryHTTP.SetWatchedStatusOnSeries(ser.AnimeSeriesID.Value, true,
                  Int32.MaxValue, (int) ept, JMMServerVM.Instance.CurrentUser.JMMUserID);

              if (BaseConfig.Settings.DisplayRatingDialogOnCompletion)
              {
                  Contract_AnimeSeries contract =
                      JMMServerVM.Instance.clientBinaryHTTP.GetSeries(ser.AnimeSeriesID.Value,
                          JMMServerVM.Instance.CurrentUser.JMMUserID);
                  if (contract != null)
                  {
                      ser = new AnimeSeriesVM(contract);
                      if (ser?.AnimeSeriesID != null)
                          ReplaceSerie(ser.AnimeSeriesID.Value, ser);
                      Utils.PromptToRateSeriesOnCompletion(ser);
                  }
              }
              LoadFacade();
              }
              });
              cmenu.AddAction(Translation.MarkAllAsUnwatched, () =>
              {
              if (ser == null)
              {
              // If we can't get a top series we fallback on what the episode tells us
              BaseConfig.MyAnimeLog.Write("Error during watch state change - series was null!");
              ser = episode.AnimeSeries;
              }

              if (ser?.AnimeSeriesID != null)
              {
              BaseConfig.MyAnimeLog.Write("Marking series as un-watched: ID -> {0} - Name -> {1}", ser.AnimeSeriesID,
                  ser.SeriesName);

              JMMServerVM.Instance.clientBinaryHTTP.SetWatchedStatusOnSeries(ser.AnimeSeriesID.Value, false,
                  Int32.MaxValue, (int) ept, JMMServerVM.Instance.CurrentUser.JMMUserID);
              LoadFacade();
              }
              });
              cmenu.AddAction(Translation.MarkAllPreviousAsWatched, () =>
              {
              if (ser == null)
              {
              // If we can't get a top series we fallback on what the episode tells us
              BaseConfig.MyAnimeLog.Write("Error during watch state change - series was null!");
              ser = episode.AnimeSeries;
              }

              if (ser?.AnimeSeriesID != null)
              {
              JMMServerVM.Instance.clientBinaryHTTP.SetWatchedStatusOnSeries(ser.AnimeSeriesID.Value, false,
                  episode.EpisodeNumber - 1, (int)ept, JMMServerVM.Instance.CurrentUser.JMMUserID);

              Contract_AnimeSeries contract =
                  JMMServerVM.Instance.clientBinaryHTTP.GetSeries(ser.AnimeSeriesID.Value,
                      JMMServerVM.Instance.CurrentUser.JMMUserID);
              if (contract != null)
              {
                  ser = new AnimeSeriesVM(contract);
                  if (ser?.AnimeSeriesID != null)
                      ReplaceSerie(ser.AnimeSeriesID.Value, ser);
                  Utils.PromptToRateSeriesOnCompletion(ser);
              }
              LoadFacade();
              }
              });
              cmenu.AddAction(Translation.MarkAllPreviousAsUnwatched, () =>
              {
              if (ser == null)
              {
              // If we can't get a top series we fallback on what the episode tells us
              BaseConfig.MyAnimeLog.Write("Error during watch state change - series was null!");
              ser = episode.AnimeSeries;
              }

              if (ser?.AnimeSeriesID != null)
              {
              JMMServerVM.Instance.clientBinaryHTTP.SetWatchedStatusOnSeries(ser.AnimeSeriesID.Value, true,
                  episode.EpisodeNumber - 1, (int) ept, JMMServerVM.Instance.CurrentUser.JMMUserID);
              LoadFacade();
              }
              });
              cmenu.AddAction(Translation.RateSeries, () =>
              {
              if (ser == null)
              {
              // If we can't get a top series we fallback on what the episode tells us
              BaseConfig.MyAnimeLog.Write("Error during rating = series was null!");
              ser = episode.AnimeSeries;
              }

              if (ser?.AnimeSeriesID != null)
              {
              Utils.PromptToRateSeriesMaually(ser);
              }
              });
              cmenu.Add(Translation.AssociateFileEpisode, () =>
              {
            List<VideoLocalVM> unlinkedVideos = JMMServerHelper.GetUnlinkedVideos();
            if (unlinkedVideos.Count == 0)
            {
              this.Alert(Translation.Error, string.Empty, Translation.NoUnlinkedFilesToSelect);
              return ContextMenuAction.Continue;
            }
            ContextMenu cfmenu = new ContextMenu(Translation.SelectFile);
            foreach (VideoLocalVM fl in unlinkedVideos)
            {
              VideoLocalVM local = fl;
              cfmenu.AddAction(fl.FileName + " - " + fl.ImportFolder.ImportFolderLocation, () =>
              {
            JMMServerHelper.LinkedFileToEpisode(local.VideoLocalID, episode.AnimeEpisodeID);
            LoadFacade();
              });
            }
            cfmenu.Show();
            return ContextMenuAction.Exit;
              });
              cmenu.Add(Translation.RemoveFileFromEpisode, () =>
              {
            List<VideoDetailedVM> vidList = episode.FilesForEpisode;
            if (vidList.Count == 0)
            {
              this.Alert(Translation.Error, string.Empty, Translation.ThisEpisodeHasNoAssociatedFiles);
              return ContextMenuAction.Continue;
            }
            ContextMenu cfmenu = new ContextMenu(Translation.SelectFile);
            foreach (VideoDetailedVM fl in vidList)
            {
              VideoDetailedVM local = fl;
              cfmenu.AddAction(Path.GetFileName(fl.FileName), () =>
              {
            string res = JMMServerVM.Instance.clientBinaryHTTP.RemoveAssociationOnFile(local.VideoLocalID, episode.AniDB_EpisodeID);
            if (!String.IsNullOrEmpty(res))
              Utils.DialogMsg(Translation.Error, res);
            LoadFacade();
              });
            }
            cfmenu.Show();
            return ContextMenuAction.Exit;
              });
              cmenu.AddAction(Translation.DownloadThisEpisode, () => DownloadHelper.SearchEpisode(episode));
              cmenu.Add(Translation.PostProcessing + " ...", () => ShowContextMenuPostProcessing(episode.EpisodeNumberAndName));

              return cmenu.Show();
        }
        private ContextMenuAction ShowContextMenuGroup(string previousMenu)
        {
            GUIListItem currentitem = m_Facade.SelectedListItem;
              if (currentitem == null)
              return ContextMenuAction.Exit;
              AnimeGroupVM grp = currentitem.TVTag as AnimeGroupVM;
              if (grp == null)
              return ContextMenuAction.Exit;

              ContextMenu cmenu = new ContextMenu(grp.GroupName, previousmenu: previousMenu);

              if (grp.SubGroups.Count == 0)
              {
              cmenu.AddAction(grp.IsFave == 1 ? Translation.RemoveFromFavorites : Translation.AddToFavorites, () =>
              {
                  grp.IsFave = grp.IsFave == 1 ? 0 : 1;
                  grp.Save();
                  EvaluateVisibility();
              });
              }

              cmenu.AddAction(Translation.MarkAllAsWatched, () =>
              {
              foreach (AnimeSeriesVM ser in grp.AllSeries)
              {
                  if (ser.AnimeSeriesID.HasValue)
                      JMMServerHelper.SetWatchedStatusOnSeries(true, Int32.MaxValue, ser.AnimeSeriesID.Value);
              }
              LoadFacade();
              });
              cmenu.AddAction(Translation.MarkAllAsUnwatched, () =>
              {
              foreach (AnimeSeriesVM ser in grp.AllSeries)
              {
                  if (ser.AnimeSeriesID.HasValue)
                      JMMServerHelper.SetWatchedStatusOnSeries(false, Int32.MaxValue, ser.AnimeSeriesID.Value);
              }
              LoadFacade();
              });
              if (grp.AllSeries.Count == 1)
              {
              cmenu.AddAction(Translation.SeriesInformation, () => ShowAnimeInfoWindow(grp.AllSeries[0]));
              }
              History h = GetCurrent();
              if (h.Listing is GroupFilterVM)
              {
              GroupFilterVM gf = (GroupFilterVM) h.Listing;
              cmenu.Add(Translation.QuickSort + " ...", () =>
              {
                  string sortType = "";
                  GroupFilterSortDirection sortDirection = GroupFilterSortDirection.Asc;
                  if (gf.GroupFilterID.HasValue)
                  {
                      if (GroupFilterQuickSorts.ContainsKey(gf.GroupFilterID.Value))
                          sortDirection = GroupFilterQuickSorts[gf.GroupFilterID.Value].SortDirection;
                      if (!Utils.DialogSelectGFQuickSort(ref sortType, ref sortDirection, gf.GroupFilterName))
                      {
                          if (!GroupFilterQuickSorts.ContainsKey(gf.GroupFilterID.Value))
                              GroupFilterQuickSorts[gf.GroupFilterID.Value] = new QuickSort();
                          GroupFilterQuickSorts[gf.GroupFilterID.Value].SortType = sortType;
                          GroupFilterQuickSorts[gf.GroupFilterID.Value].SortDirection = sortDirection;
                          LoadFacade();
                          return ContextMenuAction.Exit;
                      }
                  }
                  return ContextMenuAction.Continue;
              });
              if ((gf.GroupFilterID.HasValue) && (GroupFilterQuickSorts.ContainsKey(gf.GroupFilterID.Value)))
              {
                  cmenu.AddAction(Translation.RemoveQuickSort, () =>
                  {
                      GroupFilterQuickSorts.Remove(gf.GroupFilterID.Value);
                      LoadFacade();
                  });
              }
              }

              // ReSharper disable ImplicitlyCapturedClosure
              cmenu.AddAction(Translation.RandomSeries, () =>
              // ReSharper restore ImplicitlyCapturedClosure
              {
              RandomWindow_CurrentEpisode = null;
              RandomWindow_CurrentSeries = null;
              RandomWindow_LevelObject = grp;
              RandomWindow_RandomLevel = RandomSeriesEpisodeLevel.Group;
              RandomWindow_RandomType = RandomObjectType.Series;
              GUIWindowManager.ActivateWindow(Constants.WindowIDs.RANDOM);
              });
              // ReSharper disable ImplicitlyCapturedClosure
              cmenu.AddAction(Translation.RandomEpisode, () =>
              // ReSharper restore ImplicitlyCapturedClosure
              {
              RandomWindow_CurrentEpisode = null;
              RandomWindow_CurrentSeries = null;
              RandomWindow_LevelObject = grp;
              RandomWindow_RandomLevel = RandomSeriesEpisodeLevel.Group;
              RandomWindow_RandomType = RandomObjectType.Episode;
              GUIWindowManager.ActivateWindow(Constants.WindowIDs.RANDOM);
              });

              cmenu.Add(Translation.AdvancedOptions + " ...", () => ShowContextMenuAdvancedOptionsGroup(grp.GroupName));

              return cmenu.Show();
        }
        private ContextMenuAction ShowContextMenuDatabases(AnimeSeriesVM ser, string previousMenu)
        {
            string currentMenu = ser.SeriesName + " " + Translation.Databases;

              bool hasTvDbLink = ser.CrossRef_AniDB_TvDBV2.Count > 0 && ser.AniDB_Anime.AniDB_AnimeCrossRefs != null && ser.AniDB_Anime.AniDB_AnimeCrossRefs.TvDBCrossRefExists;
              bool hasMovieDbLink = ser.CrossRef_AniDB_MovieDB != null && ser.AniDB_Anime.AniDB_AnimeCrossRefs != null && ser.AniDB_Anime.AniDB_AnimeCrossRefs.MovieDB_Movie != null;
              bool hasMalLink = ser.CrossRef_AniDB_MAL != null && ser.CrossRef_AniDB_MAL.Count > 0;

              ContextMenu cmenu = new ContextMenu(currentMenu, previousmenu: previousMenu);

              string tvdbText = Translation.SearchTheTvDB;
              string moviedbText = Translation.SearchTheMovieDB;
              string malText = Translation.SearchMAL;

              if ((hasTvDbLink) && (ser.AniDB_Anime.AniDB_AnimeCrossRefs != null))
            tvdbText += string.Format(" ({0}: {1})", Translation.Current, ser.AniDB_Anime.AniDB_AnimeCrossRefs.TvDBSeries[0].SeriesName);

              if ((hasMovieDbLink) && (ser.AniDB_Anime.AniDB_AnimeCrossRefs != null))
            moviedbText += string.Format(" ({0}: {1})", Translation.Current, ser.AniDB_Anime.AniDB_AnimeCrossRefs.MovieDB_Movie.MovieName);

              if (hasMalLink)
            malText += string.Format(" ({0}: {1})", Translation.Current, (ser.CrossRef_AniDB_MAL.Count == 1) ? ser.CrossRef_AniDB_MAL[0].MALTitle : Translation.MultipleLinks);

              if (!hasMovieDbLink)
              {
            cmenu.Add(tvdbText, () => SearchTheTvDBMenu(ser, currentMenu));
            cmenu.Add(malText, () => SearchMALMenu(ser, currentMenu));
              }

              if (!hasTvDbLink)
            cmenu.Add(moviedbText, () => SearchTheMovieDBMenu(ser, currentMenu));
              if (hasTvDbLink)
            cmenu.Add(Translation.TheTVDB + " ...", () => ShowContextMenuTVDB(ser, currentMenu));
              if (hasMalLink)
            cmenu.Add(Translation.MAL + " ...", () => ShowContextMenuMAL(ser, currentMenu));
              if (hasMovieDbLink)
            cmenu.Add(Translation.TheMovieDB + " ...", () => ShowContextMenuMovieDB(ser, currentMenu));
              return cmenu.Show();
        }
        private ContextMenuAction ShowContextMenuAdvancedOptionsGroup(string previousMenu)
        {
            GUIListItem currentitem = m_Facade.SelectedListItem;
            if (currentitem == null)
                return ContextMenuAction.Exit;
            AnimeGroupVM grp = currentitem.TVTag as AnimeGroupVM;
            if (grp == null)
                return ContextMenuAction.Exit;

            ContextMenu cmenu = new ContextMenu(Translation.AdvancedOptions, previousmenu: previousMenu);
            cmenu.Add(Translation.EditGroup + " ...", () => ShowContextMenuGroupEdit(grp.GroupName));
            if (grp.AllSeries.Count == 1)
            {
                cmenu.Add(Translation.Databases + " ...",
                    () => ShowContextMenuDatabases(grp.AllSeries[0], Translation.GroupMenu));
                cmenu.Add(Translation.Images + " ...", () => ShowContextMenuImages(grp.GroupName));
            }
            cmenu.Add(Translation.PostProcessing + " ...", () => ShowContextMenuPostProcessing(grp.GroupName));

            return cmenu.Show();
        }
        private ContextMenuAction SearchTheTvDBMenu(AnimeSeriesVM ser, string previousMenu)
        {
            //string searchCriteria = "";
              int aniDBID = ser.AniDB_Anime.AnimeID;
              ContextMenu cmenu = new ContextMenu(Translation.SearchTheTvDB, previousMenu);
              cmenu.Add(Translation.SearchUsing + ": " + ser.AniDB_Anime.FormattedTitle, () => SearchTheTvDB(ser, ser.AniDB_Anime.FormattedTitle, Translation.SearchTheTvDB));
              cmenu.Add(Translation.ManualSearch, () =>
              {
            if (Utils.DialogText(ref searchText, GetID))
              return SearchTheTvDB(ser, searchText, Translation.SearchTheTvDB);
            return ContextMenuAction.Continue;
              });

              List<CrossRef_AniDB_TvDBVMV2> CrossRef_AniDB_TvDBResult = new List<CrossRef_AniDB_TvDBVMV2>();
              List<JMMServerBinary.Contract_Azure_CrossRef_AniDB_TvDB> xrefs = new List<Contract_Azure_CrossRef_AniDB_TvDB>(JMMServerVM.Instance.clientBinaryHTTP.GetTVDBCrossRefWebCache(aniDBID, false));
              if (xrefs != null && xrefs.Count > 0)
              {
            string xrefSummary = string.Empty;
            foreach (JMMServerBinary.Contract_Azure_CrossRef_AniDB_TvDB xref in xrefs)
            {

              CrossRef_AniDB_TvDBVMV2 xrefAzure = new CrossRef_AniDB_TvDBVMV2(xref);
              CrossRef_AniDB_TvDBResult.Add(xrefAzure);
              xrefSummary += Environment.NewLine;
              xrefSummary += string.Format("AniDB {0}:{1} -- TvDB {2}: {3}:{4}",
            xref.AniDBStartEpisodeType, xref.AniDBStartEpisodeNumber, xref.TvDBTitle, xref.TvDBSeasonNumber, xref.TvDBStartEpisodeNumber);
            }

            cmenu.AddAction(Translation.CommunitySays + ": " + xrefSummary, () =>
            {
              string res = JMMServerVM.Instance.clientBinaryHTTP.RemoveLinkAniDBTvDBForAnime(aniDBID);
              if (res.Length > 0)
            Utils.DialogMsg(Translation.Error, res);
              else
              {
            foreach (CrossRef_AniDB_TvDBVMV2 xref in CrossRef_AniDB_TvDBResult)
            {
              LinkAniDBToTVDB(ser, xref.AnimeID, (enEpisodeType)xref.AniDBStartEpisodeType,
                              xref.AniDBStartEpisodeNumber, xref.TvDBID,
                              xref.TvDBSeasonNumber, xref.TvDBStartEpisodeNumber);
            }
              }
            });
              }
              return cmenu.Show();
        }
        private ContextMenuAction SearchTheMovieDBMenu(AnimeSeriesVM ser, string previousMenu)
        {
            int aniDBID = ser.AniDB_Anime.AnimeID;
              ContextMenu cmenu = new ContextMenu(Translation.SearchTheMovieDB, previousMenu);
              cmenu.Add(Translation.SearchUsing + ": " + ser.AniDB_Anime.FormattedTitle, () => SearchTheMovieDB(ser, ser.AniDB_Anime.FormattedTitle, Translation.SearchTheMovieDB));
              cmenu.Add(Translation.ManualSearch, () =>
              {
            searchText = ser.AniDB_Anime.FormattedTitle;
            if (Utils.DialogText(ref searchText, GetID))
              return SearchTheMovieDB(ser, ser.AniDB_Anime.FormattedTitle, Translation.SearchTheMovieDB);
            return ContextMenuAction.Continue;
              });
              Contract_CrossRef_AniDB_OtherResult xref = JMMServerVM.Instance.clientBinaryHTTP.GetOtherAnimeCrossRefWebCache(aniDBID, (int)CrossRefType.MovieDB);
              if (xref != null)
              {

            CrossRef_AniDB_OtherResultVM crossrossRefAniDbOtherResult = new CrossRef_AniDB_OtherResultVM(xref);
            cmenu.AddAction(Translation.CommunitySays + ": " + crossrossRefAniDbOtherResult.CrossRefID, () => LinkAniDBToMovieDB(ser, crossrossRefAniDbOtherResult.AnimeID, Int32.Parse(crossrossRefAniDbOtherResult.CrossRefID)));
              }
              return cmenu.Show();
        }
        private ContextMenuAction SearchMALMenu(AnimeSeriesVM ser, string previousMenu)
        {
            int aniDBID = ser.AniDB_Anime.AnimeID;

              ContextMenu cmenu = new ContextMenu(Translation.SearchMAL, previousmenu: previousMenu);
              cmenu.Add(Translation.SearchUsing + ": " + ser.AniDB_Anime.FormattedTitle, () => SearchMAL(ser, ser.AniDB_Anime.FormattedTitle, Translation.SearchMAL));
              cmenu.Add(Translation.ManualSearch, () =>
              {
            searchText = ser.AniDB_Anime.FormattedTitle;
            if (Utils.DialogText(ref searchText, GetID))
              return SearchMAL(ser, searchText, Translation.SearchMAL);
            return ContextMenuAction.Continue;
              });
              return cmenu.Show();
        }