示例#1
0
 void MainWindow_OnToggleWatched(List<AnimeEpisodeVM> episodes, bool state)
 {
     string msg = string.Format("OnToggleWatched: {0} / {1}", episodes.Count, state);
     BaseConfig.MyAnimeLog.Write(msg);
 }
示例#2
0
 private void SaveOrRestoreFacadeItems(bool save)
 {
     if (save)
     {
         //save
         lstFacadeItems = new List<GUIListItem>(m_Facade.Count);
         for (int item = 0; item < m_Facade.Count; item++)
             lstFacadeItems.Add(m_Facade[item]);
     }
     else if (lstFacadeItems != null)
     {
         //restore
         GUIListItem selectedItem = m_Facade.SelectedListItem;
         m_Facade.Clear();
         for (int item = 0; item < lstFacadeItems.Count; item++)
         {
             m_Facade.Add(lstFacadeItems[item]);
             if (lstFacadeItems[item] == selectedItem)
                 m_Facade.SelectedListItemIndex = m_Facade.Count - 1;
         }
         lstFacadeItems = null;
     }
 }
示例#3
0
        void bgLoadFacade()
        {
            try
            {
                GUIListItem item = null;
                int selectedIndex = -1;
                int count = 0;
                bool delayedImageLoading = false;
                List<AnimeGroupVM> groups = null;
                List<GroupFilterVM> groupFilters = null;
                List<GUIListItem> list = new List<GUIListItem>();
                BackGroundLoadingArgumentType type = BackGroundLoadingArgumentType.None;

                switch (listLevel)
                {
                    #region Group Filters
                    case Listlevel.GroupFilter:
                        {
                            // List/Poster/Banner

                            setGUIProperty("SimpleCurrentView", "Group Filters");

                            if (groupViewMode != GUIFacadeControl.Layout.List)
                            {
                                // reinit the itemsList
                                delayedImageLoading = true;
                                ReportFacadeLoadingProgress(BackGroundLoadingArgumentType.DelayedImgInit, 0, null);
                            }

                            // text as usual
                            ReportFacadeLoadingProgress(BackGroundLoadingArgumentType.SetFacadeMode, 0, GUIFacadeControl.Layout.List);

                            if (workerFacade.CancellationPending)
                                return;

                            BaseConfig.MyAnimeLog.Write("bgLoadFacde: Group Filters");
                            groupFilters = FacadeHelper.GetGroupFilters();
                            type = BackGroundLoadingArgumentType.ListFullElement;

                            setGUIProperty(guiProperty.GroupCount, groupFilters.Count.ToString());

                            foreach (GroupFilterVM grpFilter in groupFilters)
                            {
                                if (workerFacade.CancellationPending) return;
                                try
                                {
                                    item = null;

                                    SetGroupFilterListItem(ref item, grpFilter);

                                    if (curGroupFilter != null)
                                    {
                                        if (grpFilter.GroupFilterID.Value == curGroupFilter.GroupFilterID.Value)
                                        {
                                            selectedIndex = count;
                                        }
                                    }
                                    else
                                    {
                                        if (selectedIndex == -1)
                                            selectedIndex = count;
                                    }

                                    if (workerFacade.CancellationPending) return;
                                    else
                                    {
                                        list.Add(item);
                                    }

                                }
                                catch (Exception ex)
                                {
                                    string msg = string.Format("The 'LoadFacade' function has generated an error displaying list items: {0} - {1}", listLevel, ex.ToString());
                                    BaseConfig.MyAnimeLog.Write(msg);
                                }
                                count++;
                            }
                        }
                        break;
                    #endregion

                    #region Group Filters - Sub
                    case Listlevel.GroupFilterSub:
                        {
                            // List/Poster/Banner

                            setGUIProperty("SimpleCurrentView", curGroupFilter.GroupFilterName);

                            if (groupViewMode != GUIFacadeControl.Layout.List)
                            {
                                // reinit the itemsList
                                delayedImageLoading = true;
                                ReportFacadeLoadingProgress(BackGroundLoadingArgumentType.DelayedImgInit, 0, null);
                            }

                            // text as usual
                            ReportFacadeLoadingProgress(BackGroundLoadingArgumentType.SetFacadeMode, 0, GUIFacadeControl.Layout.List);

                            if (workerFacade.CancellationPending)
                                return;

                            BaseConfig.MyAnimeLog.Write("bgLoadFacde: Group Filters");
                            groupFilters = FacadeHelper.GetGroupFilters();
                            type = BackGroundLoadingArgumentType.ListFullElement;

                            setGUIProperty(guiProperty.GroupCount, "0");

                            foreach (GroupFilterVM grpFilter in FacadeHelper.GetTopLevelPredefinedGroupFilters())
                            {
                                if (workerFacade.CancellationPending) return;
                                try
                                {
                                    item = null;

                                    SetGroupFilterListItem(ref item, grpFilter);

                                    if (curGroupFilter != null)
                                    {
                                        if (grpFilter.GroupFilterID.Value == curGroupFilter.GroupFilterID.Value)
                                        {
                                            selectedIndex = count;
                                        }
                                    }
                                    else
                                    {
                                        if (selectedIndex == -1)
                                            selectedIndex = count;
                                    }

                                    if (workerFacade.CancellationPending) return;
                                    else
                                    {
                                        list.Add(item);
                                    }

                                }
                                catch (Exception ex)
                                {
                                    string msg = string.Format("The 'LoadFacade' function has generated an error displaying list items: {0} - {1}", listLevel, ex.ToString());
                                    BaseConfig.MyAnimeLog.Write(msg);
                                }
                                count++;
                            }
                        }
                        break;
                    #endregion

                    #region Group Filters - Sub2
                    case Listlevel.GroupFilterSub2:
                        {
                            // List/Poster/Banner

                            setGUIProperty("SimpleCurrentView", curGroupFilter.GroupFilterName);

                            if (groupViewMode != GUIFacadeControl.Layout.List)
                            {
                                // reinit the itemsList
                                delayedImageLoading = true;
                                ReportFacadeLoadingProgress(BackGroundLoadingArgumentType.DelayedImgInit, 0, null);
                            }

                            // text as usual
                            ReportFacadeLoadingProgress(BackGroundLoadingArgumentType.SetFacadeMode, 0, GUIFacadeControl.Layout.List);

                            if (workerFacade.CancellationPending)
                                return;

                            BaseConfig.MyAnimeLog.Write("bgLoadFacde: Group Filters");
                            groupFilters = FacadeHelper.GetGroupFilters();
                            type = BackGroundLoadingArgumentType.ListFullElement;

                            setGUIProperty(guiProperty.GroupCount, "0");

                            foreach (GroupFilterVM grpFilter in FacadeHelper.GetGroupFiltersForPredefined(curGroupFilterSub))
                            {
                                if (workerFacade.CancellationPending) return;
                                try
                                {
                                    item = null;

                                    SetGroupFilterListItem(ref item, grpFilter);

                                    if (curGroupFilter != null)
                                    {
                                        if (grpFilter.GroupFilterID.Value == curGroupFilter.GroupFilterID.Value)
                                        {
                                            selectedIndex = count;
                                        }
                                    }
                                    else
                                    {
                                        if (selectedIndex == -1)
                                            selectedIndex = count;
                                    }

                                    if (workerFacade.CancellationPending) return;
                                    else
                                    {
                                        list.Add(item);
                                    }

                                }
                                catch (Exception ex)
                                {
                                    string msg = string.Format("The 'LoadFacade' function has generated an error displaying list items: {0} - {1}", listLevel, ex.ToString());
                                    BaseConfig.MyAnimeLog.Write(msg);
                                }
                                count++;
                            }
                        }
                        break;
                    #endregion

                    #region Groups
                    case Listlevel.Group:
                        {
                            // List/Poster/Banner

                            setGUIProperty("SimpleCurrentView", curGroupFilter.GroupFilterName);

                            if (groupViewMode != GUIFacadeControl.Layout.List)
                            {
                                // reinit the itemsList
                                delayedImageLoading = true;
                                ReportFacadeLoadingProgress(BackGroundLoadingArgumentType.DelayedImgInit, 0, null);
                            }

                            if (groupViewMode != GUIFacadeControl.Layout.List)
                            {
                                // graphical
                                ReportFacadeLoadingProgress(BackGroundLoadingArgumentType.SetFacadeMode, 0, GUIFacadeControl.Layout.AlbumView);
                            }
                            else
                            {
                                // text as usual
                                ReportFacadeLoadingProgress(BackGroundLoadingArgumentType.SetFacadeMode, 0, GUIFacadeControl.Layout.List);
                            }

                            if (workerFacade.CancellationPending)
                                return;

                            if (curGroupFilterSub2 == null)
                                groups = JMMServerHelper.GetAnimeGroupsForFilter(curGroupFilter);
                            else
                            {
                                groups = new List<AnimeGroupVM>();

                                List<AnimeGroupVM> tempGroups = JMMServerHelper.GetAnimeGroupsForFilter(GroupFilterHelper.AllGroupsFilter);
                                foreach (AnimeGroupVM grp in tempGroups)
                                {
                                    if (curGroupFilterSub2.GroupFilterID.Value == Constants.StaticGF.Predefined_Categories_Child)
                                    {
                                        if (grp.Categories.Contains(curGroupFilterSub2.PredefinedCriteria))
                                            groups.Add(grp);
                                    }
                                    if (curGroupFilterSub2.GroupFilterID.Value == Constants.StaticGF.Predefined_Years_Child)
                                    {
                                        // find all the groups that qualify by this year
                                        int startYear = 0;
                                        if (!grp.Stat_AirDate_Min.HasValue) continue;
                                        startYear = grp.Stat_AirDate_Min.Value.Year;

                                        int endYear = int.MaxValue;
                                        if (grp.Stat_AirDate_Max.HasValue) endYear = grp.Stat_AirDate_Max.Value.Year;

                                        int critYear = 0;
                                        if (!int.TryParse(curGroupFilterSub2.PredefinedCriteria, out critYear)) continue;

                                        if (critYear >= startYear && critYear <= endYear) groups.Add(grp);

                                    }
                                }
                            }

                            // re-sort if user has set a quick sort
                            if (GroupFilterQuickSorts.ContainsKey(curGroupFilter.GroupFilterID.Value))
                            {
                                BaseConfig.MyAnimeLog.Write("APPLYING QUICK SORT");

                                GroupFilterSorting sortType = GroupFilterHelper.GetEnumForText_Sorting(GroupFilterQuickSorts[curGroupFilter.GroupFilterID.Value].SortType);
                                SortPropOrFieldAndDirection sortProp = GroupFilterHelper.GetSortDescription(sortType, GroupFilterQuickSorts[curGroupFilter.GroupFilterID.Value].SortDirection);
                                List<SortPropOrFieldAndDirection> sortCriteria = new List<SortPropOrFieldAndDirection>();
                                sortCriteria.Add(sortProp);
                                groups = Sorting.MultiSort<AnimeGroupVM>(groups, sortCriteria);
                            }

                            // Update Series Count Property
                            setGUIProperty(guiProperty.GroupCount, groups.Count.ToString());
                            type = (groupViewMode != GUIFacadeControl.Layout.List) ? BackGroundLoadingArgumentType.ListElementForDelayedImgLoading : BackGroundLoadingArgumentType.ListFullElement;

                            int seriesCount = 0;

                            double totalTime = 0;
                            DateTime start = DateTime.Now;

                            BaseConfig.MyAnimeLog.Write("Building groups: " + curGroupFilter.GroupFilterName);
                            foreach (AnimeGroupVM grp in groups)
                            {
                                if (workerFacade.CancellationPending) return;
                                try
                                {
                                    item = null;

                                    //BaseConfig.MyAnimeLog.Write(string.Format("{0} - {1}", grp.GroupName, grp.AniDBRating));

                                    SetGroupListItem(ref item, grp);

                                    if (settings.HideWatchedFiles && grp.UnwatchedEpisodeCount <= 0)
                                    {
                                        //watched files should be hidden and entire group is watched
                                        // -> hide entire group
                                        continue;
                                    }

                                    seriesCount += grp.AllSeriesCount;

                                    if (curAnimeGroup != null)
                                    {
                                        if (grp.AnimeGroupID == curAnimeGroup.AnimeGroupID)
                                        {
                                            selectedIndex = count;
                                        }
                                    }
                                    else
                                    {
                                        if (selectedIndex == -1)
                                            selectedIndex = count;
                                    }

                                    if (workerFacade.CancellationPending) return;
                                    else
                                    {
                                        list.Add(item);
                                    }

                                }
                                catch (Exception ex)
                                {
                                    string msg = string.Format("The 'LoadFacade' function has generated an error displaying list items: {0} - {1}", listLevel, ex.ToString());
                                    BaseConfig.MyAnimeLog.Write(msg);
                                }
                                count++;
                            }

                            TimeSpan ts2 = DateTime.Now - start;
                            totalTime += ts2.TotalMilliseconds;

                            BaseConfig.MyAnimeLog.Write("Total time for rendering groups: {0}-{1}", groups.Count, totalTime);

                            setGUIProperty(guiProperty.SeriesCount, seriesCount.ToString());

                        }
                        break;
                    #endregion

                    #region Series
                    case Listlevel.Series:
                        {
                            // this level includes series as well as sub-groups

                            if (seriesViewMode != GUIFacadeControl.Layout.List)
                            {
                                // reinit the itemsList
                                delayedImageLoading = true;
                                ReportFacadeLoadingProgress(BackGroundLoadingArgumentType.DelayedImgInit, 0, null);
                            }

                            if (workerFacade.CancellationPending) return;

                            List<SortPropOrFieldAndDirection> sortCriteria = null;

                            List<AnimeGroupVM> subGroups = curAnimeGroupViewed.SubGroups;
                            if (subGroups.Count > 0)
                            {
                                sortCriteria = new List<SortPropOrFieldAndDirection>();
                                sortCriteria.Add(new SortPropOrFieldAndDirection("SortName", false, SortType.eString));
                                subGroups = Sorting.MultiSort<AnimeGroupVM>(subGroups, sortCriteria);
                            }

                            // get the series for this group
                            List<AnimeSeriesVM> seriesList = curAnimeGroupViewed.ChildSeries;
                            if (seriesList.Count > 0)
                            {
                                sortCriteria = new List<SortPropOrFieldAndDirection>();
                                sortCriteria.Add(new SortPropOrFieldAndDirection("AirDate", false, SortType.eDateTime));
                                seriesList = Sorting.MultiSort<AnimeSeriesVM>(seriesList, sortCriteria);
                            }
                            //if (seriesList.Count == 0)
                            //	bFacadeEmpty = true;

                            // Update Series Count Property
                            setGUIProperty(guiProperty.SeriesCount, seriesList.Count.ToString());

                            // now sort the groups by air date

                            type = BackGroundLoadingArgumentType.ListFullElement;

                            foreach (AnimeGroupVM grp in subGroups)
                            {
                                if (workerFacade.CancellationPending) return;
                                try
                                {
                                    item = null;

                                    SetGroupListItem(ref item, grp);

                                    if (settings.HideWatchedFiles && grp.UnwatchedEpisodeCount <= 0)
                                    {
                                        //watched files should be hidden and entire group is watched
                                        // -> hide entire group
                                        continue;
                                    }

                                    if (workerFacade.CancellationPending) return;
                                    else
                                    {
                                        list.Add(item);
                                    }

                                }
                                catch (Exception ex)
                                {
                                    string msg = string.Format("The 'LoadFacade' function has generated an error displaying list items: {0} - {1}", listLevel, ex.ToString());
                                    BaseConfig.MyAnimeLog.Write(msg);
                                }
                            }

                            foreach (AnimeSeriesVM ser in seriesList)
                            {
                                //BaseConfig.MyAnimeLog.Write("LoadFacade-Series:: {0}", ser);
                                if (workerFacade.CancellationPending) return;
                                try
                                {
                                    item = null;

                                    SetSeriesListItem(ref item, ser);

                                    if (settings.HideWatchedFiles && ser.UnwatchedEpisodeCount <= 0)
                                    {
                                        //watched files should be hidden and entire series is watched
                                        // -> hide entire series
                                        continue;
                                    }

                                    if (workerFacade.CancellationPending) return;
                                    else
                                    {
                                        list.Add(item);
                                    }

                                }
                                catch (Exception ex)
                                {
                                    string msg = string.Format("The 'LoadFacade' function has generated an error displaying list items: {0} - {1}", listLevel, ex.ToString());
                                    BaseConfig.MyAnimeLog.Write(msg);
                                }
                                count++;
                            }
                        }
                        break;
                    #endregion

                    #region Episode Types
                    case Listlevel.EpisodeTypes:
                        {

                            if (workerFacade.CancellationPending) return;

                            //List<AnimeEpisodeType> anEpTypes = AnimeSeries.GetEpisodeTypes(curAnimeSeries.AnimeSeriesID.Value);
                            type = BackGroundLoadingArgumentType.ListFullElement;
                            foreach (AnimeEpisodeTypeVM anEpType in curAnimeSeries.EpisodeTypesToDisplay)
                            {
                                item = null;
                                SetEpisodeTypeListItem(ref item, anEpType);

                                if (workerFacade.CancellationPending) return;
                                else
                                {
                                    list.Add(item);
                                }
                                count++;
                            }
                        }
                        break;
                    #endregion

                    #region Episodes
                    case Listlevel.Episode:
                        {

                            if (workerFacade.CancellationPending) return;

                            if (curAnimeSeries == null) return;

                            // get the episodes for this series / episode types
                            //BaseConfig.MyAnimeLog.Write("GetEpisodes:: {0}", curAnimeSeries.AnimeSeriesID.Value);

                            //List<AnimeEpisode> episodeList = AnimeSeries.GetEpisodes(curAnimeSeries.AnimeSeriesID.Value);
                            curAnimeSeries.RefreshEpisodes();
                            List<AnimeEpisodeVM> episodeList = curAnimeSeries.GetEpisodesToDisplay(curAnimeEpisodeType.EpisodeType);

                            // Update Series Count Property
                            //setGUIProperty(guiProperty.SeriesCount, episodeList.Count.ToString());

                            bool foundFirstUnwatched = false;
                            type = BackGroundLoadingArgumentType.ListFullElement;
                            foreach (AnimeEpisodeVM ep in episodeList)
                            {
                                //BaseConfig.MyAnimeLog.Write("LoadFacade-Episodes:: {0}", ep);
                                if (workerFacade.CancellationPending) return;
                                try
                                {
                                    item = null;
                                    bool isWatched = SetEpisodeListItem(ref item, ep);

                                    if (isWatched && settings.HideWatchedFiles)
                                        continue;

                                    if (!foundFirstUnwatched && !isWatched && ep.LocalFileCount > 0)
                                    {
                                        selectedIndex = count;
                                        foundFirstUnwatched = true;
                                    }

                                    if (workerFacade.CancellationPending) return;
                                    else
                                    {
                                        list.Add(item);
                                    }

                                }
                                catch (Exception ex)
                                {
                                    string msg = string.Format("The 'LoadFacade' function has generated an error displaying list items: {0} - {1}", listLevel, ex.ToString());
                                    BaseConfig.MyAnimeLog.Write(msg);
                                }
                                count++;
                            }

                            SetFanartForEpisodes();
                        }
                        setGUIProperty(guiProperty.EpisodeCount, count.ToString());
                        break;
                    #endregion

                }

                #region Report ItemToAutoSelect

                if (selectedIndex == -1)
                    selectedIndex = 0;

                BaseConfig.MyAnimeLog.Write("Report ItemToAutoSelect: {0}", selectedIndex.ToString());

                #endregion

                ReportFacadeLoadingProgress(type, selectedIndex, list);

                SetFacade();

                #region DelayedImageLoading

                // we only use delayed image loading for the main groups view
                // since the other views will not have enough items to be concerned about

                if (delayedImageLoading && groups != null)
                {
                    BaseConfig.MyAnimeLog.Write("delayedImageLoading: Started");
                    // This is a perfect oportunity to use all cores on the machine
                    // we queue each image up to be loaded, resize and put them into memory in parallel

                    // Set the amount of threads to the amount of CPU cores in the machine.
                    int MaxThreads = Environment.ProcessorCount;
                    // This keeps track of how many of the threads have terminated
                    int done = 0;
                    // Pool of threads.
                    List<Thread> ImageLoadThreadPool = new List<Thread>();
                    // List of Groups in the facade. This is checked by the threads to get groups to load fanart for.
                    List<KeyValuePair<AnimeGroupVM, int>> FacadeGroups = new List<KeyValuePair<AnimeGroupVM, int>>();

                    // Fill the list of groups in order of their proximity to the current selection. This makes the groups currently shown load first, and then further out.
                    FacadeHelper.ProximityForEach(groups, selectedIndex, delegate(AnimeGroupVM grp, int currIndex)
                    {
                        FacadeGroups.Add(new KeyValuePair<AnimeGroupVM, int>(grp, currIndex));
                    });

                    // Create number of threads based on MaxThreads. MaxThreads should be the amount of CPU cores.
                    for (int i = 0; i < MaxThreads; i++)
                    {
                        // Create a new thread. The function it should run is written here using the delegate word.
                        Thread thread = new Thread(new ThreadStart(delegate()
                        {
                            // The number of groups left to load in the facade. Is renewed on each loop of the threads do while loop.
                            int FacadeGroupCount = 0;

                            do
                            {
                                // create varible to store the group.
                                KeyValuePair<AnimeGroupVM, int> group = new KeyValuePair<AnimeGroupVM, int>();

                                // The FacadeGroups list is accessed by all threads, therefor it is in a locked section to make it thread safe.
                                lock (FacadeGroups)
                                {
                                    // Dtore into the facadeGroupCount varible which is in the threads scope.
                                    FacadeGroupCount = FacadeGroups.Count;

                                    // If there are groups left to load, and the facade is not stopping, load a group and remove it from the list.
                                    if (FacadeGroupCount > 0 && !workerFacade.CancellationPending)
                                    {
                                        group = FacadeGroups[0];
                                        FacadeGroups.RemoveAt(0);
                                    }
                                    // Ether their are no more groups or the facade is stopping, so we should exit while marking us as finished.
                                    else
                                    {
                                        Interlocked.Increment(ref done);
                                        return;
                                    }
                                }

                                // If a group was loaded, get it's image, then report that the image is loaded to the facadeworker.
                                // the facade worker (which is another thread itself) will handle putting the image into the facade for us.
                                if (group.Key != null)
                                {
                                    string img = ImageAllocator.GetGroupImage(group.Key, groupViewMode);
                                    ReportFacadeLoadingProgress(BackGroundLoadingArgumentType.DelayedImgLoading, group.Value, img);
                                }

                            }
                            // while there are still groups left to load, repeat loop.
                            while (FacadeGroupCount > 0);

                        }));

                        // Make the thread a lower priority. Everything else should have a higher priority then this background image loading.
                        thread.Priority = ThreadPriority.BelowNormal;

                        // add this thread to the thread pool.
                        ImageLoadThreadPool.Add(thread);

                    }

                    // for each thread in the thread pool, start it.
                    foreach (Thread thread in ImageLoadThreadPool)
                        thread.Start();

                    // Do not continue untill all the image loading threads are finished. Currently we are in the facade background worker thread. The image loading threads call
                    // this thread's ProgressChanged function, which then adds the images that were loaded in to the facade. If we go beyond this point before the image loading
                    // threads finish, then that ProgressChanged function might not exisit any more since this facade background worker thread could have finished already.
                    while (done < MaxThreads)
                        Thread.Sleep(500);

                    BaseConfig.MyAnimeLog.Write("ImageLoad: Finished");

                }

                #endregion

                if (animeSeriesIDToBeRated.HasValue && BaseConfig.Settings.DisplayRatingDialogOnCompletion)
                {
                    JMMServerBinary.Contract_AnimeSeries contract = JMMServerVM.Instance.clientBinaryHTTP.GetSeries(animeSeriesIDToBeRated.Value,
                        JMMServerVM.Instance.CurrentUser.JMMUserID);
                    if (contract != null)
                    {
                        AnimeSeriesVM ser = new AnimeSeriesVM(contract);
                        Utils.PromptToRateSeriesOnCompletion(ser);
                    }

                    animeSeriesIDToBeRated = null;
                }

            }

            catch (Exception e)
            {
                BaseConfig.MyAnimeLog.Write("The 'LoadFacade' function has generated an error: {0}", e.ToString());
            }
        }
示例#4
0
        private void DoSearch(int start)
        {
            SearchCollection.SearchMatch match = null;

            //search
            if (settings.FindFilter)
            {
                List<int> lstMatches = new List<int>();
                if (search.GetMatches(start, lstMatches, ref match))
                {
                    //copy current list
                    if (lstFacadeItems == null)
                        SaveOrRestoreFacadeItems(true);

                    //find all matching items
                    List<GUIListItem> lstMatchingItems = new List<GUIListItem>(lstMatches.Count);
                    int selectedItem = -1;
                    for (int index = 0; index < m_Facade.Count; index++)
                    {
                        if (lstMatches.Contains(index))
                        {
                            lstMatchingItems.Add(m_Facade[index]);
                            if (index == match.Index)
                                selectedItem = lstMatchingItems.Count - 1; ;
                        }
                    }

                    //update the list
                    m_Facade.Clear();
                    for (int index = 0; index < lstMatchingItems.Count; index++)
                        m_Facade.Add(lstMatchingItems[index]);
                    m_Facade.SelectedListItemIndex = selectedItem;
                }
            }
            else
            {
                match = search.GetMatch(start);

                //select match
                SelectItem(match != null ? match.Index : -1);
            }

            //update sceen
            if (match != null)
            {
                //match found
                searchText = match.Text;
                searchMatch = m_Facade.SelectedListItem.Label;
            }
            else
            {
                //no match found
                searchText = new string('*', search.Input.Length);
                searchMatch = string.Empty;
            }
        }
示例#5
0
        void workerFacade_ProgressChanged(object sender, ProgressChangedEventArgs e)
        {
            try
            {

                BackgroundFacadeLoadingArgument arg = e.UserState as BackgroundFacadeLoadingArgument;

                if (workerFacade.CancellationPending)
                {
                    BaseConfig.MyAnimeLog.Write("bg_ProgressChanged cancelled");
                    return;
                }

                if (arg == null || arg.Type == BackGroundLoadingArgumentType.None) return;

                switch (arg.Type)
                {
                    case BackGroundLoadingArgumentType.ListFullElement:
                    case BackGroundLoadingArgumentType.ListElementForDelayedImgLoading:
                        List<GUIListItem> ls = arg.Argument as List<GUIListItem>;
                        if (m_Facade != null && ls != null && ls.Count > 0)
                        {
                            foreach (GUIListItem gli in ls)
                            {
                                //BaseConfig.MyAnimeLog.Write("workerFacade_ProgressChanged - ListElementForDelayedImgLoading");
                                // Messages are not recieved in OnMessage for Filmstrip, instead subscribe to OnItemSelected
                                if (m_Facade.CurrentLayout == GUIFacadeControl.Layout.Filmstrip || m_Facade.CurrentLayout == GUIFacadeControl.Layout.CoverFlow)
                                    gli.OnItemSelected += new GUIListItem.ItemSelectedHandler(onFacadeItemSelected);

                                AddFacadeItem(gli);
                                if (arg.Type == BackGroundLoadingArgumentType.ListElementForDelayedImgLoading)
                                {
                                    if (itemsForDelayedImgLoading == null)
                                        itemsForDelayedImgLoading = new List<GUIListItem>();
                                    itemsForDelayedImgLoading.Add(gli);
                                }
                            }
                            if (this.m_Facade.SelectedListItemIndex < 1)
                            {
                                this.m_Facade.Focus = true;
                                SelectItem(arg.IndexArgument);
                            }
                        }
                        break;
                    case BackGroundLoadingArgumentType.DelayedImgLoading:
                        {
                            if (itemsForDelayedImgLoading != null && itemsForDelayedImgLoading.Count > arg.IndexArgument)
                            {
                                string image = arg.Argument as string;
                                itemsForDelayedImgLoading[arg.IndexArgument].IconImageBig = image;
                            }
                        }
                        break;

                    case BackGroundLoadingArgumentType.DelayedImgInit:
                        itemsForDelayedImgLoading = null;
                        break;
                    case BackGroundLoadingArgumentType.SetFacadeMode:
                        GUIFacadeControl.Layout viewMode = (GUIFacadeControl.Layout)arg.Argument;
                        //setFacadeMode(viewMode);
                        break;

                    case BackGroundLoadingArgumentType.ElementSelection:
                        {
                            // thread told us which element it'd like to select
                            // however the user might have already started moving around
                            // if that is the case, we don't select anything
                            if (this.m_Facade != null && this.m_Facade.SelectedListItemIndex < 1)
                            {
                                this.m_Facade.Focus = true;
                                SelectItem(arg.IndexArgument);
                            }
                        }
                        break;
                }

            }
            catch (Exception ex)
            {
                BaseConfig.MyAnimeLog.Write(string.Format("Error in bg_ProgressChanged: {0}: {1}", ex.Message, ex.InnerException));
            }
        }
        private void OnFirstStart()
        {
            if (isFirstInitDone)
              return;
              fanartTexture.Filename = GUIGraphicsContext.Skin + @"\Media\hover_my anime3.jpg";
              Breadcrumbs = new List<History>() {new History()};
              if (string.IsNullOrEmpty(MainWindow.settings.JMMServer_Address) ||
              string.IsNullOrEmpty(MainWindow.settings.JMMServer_Port))
              {
              Utils.DialogMsg(Translation.Error, Translation.PleaseExitMPFirst);
              return;
              }

              // check if we can connect to JMM Server
              // and load the default user
              List<JMMUserVM> allUsers = JMMServerHelper.GetAllUsers();
              if (allUsers.Count == 0)
              {
              Utils.DialogMsg(Translation.Error, Translation.ErrorConnectingJMMServer);
              return;
              }
              else
              {
              // check for last jmm user
              if (string.IsNullOrEmpty(MainWindow.settings.CurrentJMMUserID))
              {
                  if (!JMMServerVM.Instance.PromptUserLogin())
                      return;

                  // user has logged in, so save to settings so we will log in as the same user next time
                  MainWindow.settings.CurrentJMMUserID = JMMServerVM.Instance.CurrentUser.JMMUserID.ToString();
                  settings.Save();
              }
              else
              {
                  JMMUserVM selUser = null;
                  foreach (JMMUserVM user in allUsers)
                  {
                      if (user.JMMUserID.ToString().Equals(MainWindow.settings.CurrentJMMUserID))
                      {
                          selUser = user;
                          break;
                      }
                  }

                  if (selUser == null)
                  {
                      if (!JMMServerVM.Instance.PromptUserLogin())
                          return;

                      // user has logged in, so save to settings so we will log in as the same user next time
                      MainWindow.settings.CurrentJMMUserID = JMMServerVM.Instance.CurrentUser.JMMUserID.ToString();
                      settings.Save();
                  }
                  else
                  {
                      bool authed = JMMServerVM.Instance.AuthenticateUser(selUser.Username, "");
                      string password = "";
                      while (!authed)
                      {
                          // prompt user for a password
                          if (Utils.DialogText(ref password, true, GUIWindowManager.ActiveWindow))
                          {
                              authed = JMMServerVM.Instance.AuthenticateUser(selUser.Username, password);
                              if (!authed)
                              {
                                  Utils.DialogMsg(Translation.Error, Translation.IncorrectPasswordTryAgain);
                              }
                          }
                          else return;
                      }

                      JMMServerVM.Instance.SetCurrentUser(selUser);

                      // user has logged in, so save to settings so we will log in as the same user next time
                      settings.CurrentJMMUserID = JMMServerVM.Instance.CurrentUser.JMMUserID.ToString();
                      settings.Save();
                  }
              }
              }

              JMMServerVM.Instance.ServerStatusEvent += new JMMServerVM.ServerStatusEventHandler(Instance_ServerStatusEvent);

              isFirstInitDone = true;
        }
        private ContextMenuAction ShowSeasonSelectionMenuTvDB(AnimeSeriesVM ser, int animeID, int tvdbid, string previousMenu)
        {
            try
              {
            List<int> seasons = new List<int>(JMMServerVM.Instance.clientBinaryHTTP.GetSeasonNumbersForSeries(tvdbid));
            if (seasons.Count == 0)
            {
              this.Alert(Translation.SeasonResults, string.Empty, Translation.NoSeasonsFound);
              return ContextMenuAction.Exit;
            }
            ContextMenu cmenu = new ContextMenu(Translation.SelectSeason, previousmenu: previousMenu);
            foreach (int season in seasons)
            {
              int local = season;
              cmenu.AddAction(Translation.Season + " " + season.ToString(Globals.Culture), () =>
              {
            JMMServerVM.Instance.clientBinaryHTTP.RemoveLinkAniDBTvDBForAnime(animeID);
            LinkAniDBToTVDB(ser, animeID, enEpisodeType.Episode, 1, tvdbid, local, 1);
              });
            }
            return cmenu.Show();
              }
              catch (Exception ex)
              {
            BaseConfig.MyAnimeLog.Write("Error in ShowSeasonSelectionMenu:: {0}", ex);
              }

              return ContextMenuAction.Exit;
        }
示例#8
0
        private bool SearchTrakt(AnimeSeriesVM ser, string searchCriteria, string previousMenu)
        {
            if (searchCriteria.Length == 0)
                return true;

            int aniDBID = ser.AniDB_Anime.AnimeID;

            List<TraktTVShowResponseVM> TraktSeriesSearchResults = new List<TraktTVShowResponseVM>();
            List<JMMServerBinary.Contract_TraktTVShowResponse> traktResults = JMMServerVM.Instance.clientBinaryHTTP.SearchTrakt(searchCriteria);
            foreach (JMMServerBinary.Contract_TraktTVShowResponse traktResult in traktResults)
                TraktSeriesSearchResults.Add(new TraktTVShowResponseVM(traktResult));

            BaseConfig.MyAnimeLog.Write("Found {0} trakt results for {1}", TraktSeriesSearchResults.Count, searchCriteria);
            if (TraktSeriesSearchResults.Count > 0)
            {
                GUIDialogMenu dlg = (GUIDialogMenu)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_MENU);
                if (dlg == null)
                    return true;

                //keep showing the dialog until the user closes it
                int selectedLabel = 0;
                while (true)
                {
                    dlg.Reset();
                    dlg.SetHeading("Trakt Search Results");

                    if (previousMenu != string.Empty)
                        dlg.Add("<<< " + previousMenu);

                    foreach (TraktTVShowResponseVM res in TraktSeriesSearchResults)
                    {
                        string disp = string.Format("{0} ({1})", res.title, res.year);
                        dlg.Add(disp);
                    }

                    dlg.SelectedLabel = selectedLabel;
                    dlg.DoModal(GUIWindowManager.ActiveWindow);
                    selectedLabel = dlg.SelectedLabel;

                    int selection = selectedLabel + ((previousMenu == string.Empty) ? 1 : 0);
                    if (selection == 0)
                        return true; // previous menu

                    if (selection > 0 && selection <= TraktSeriesSearchResults.Count)
                    {
                        TraktTVShowResponseVM res = TraktSeriesSearchResults[selection - 1];

                        LinkAniDBToTrakt(ser, aniDBID, res.TraktID, 1);
                        return false;
                    }

                    return true;
                }
            }
            else
            {
                GUIDialogOK dlgOK = (GUIDialogOK)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_OK);
                if (null != dlgOK)
                {
                    dlgOK.SetHeading("Search Results");
                    dlgOK.SetLine(1, string.Empty);
                    dlgOK.SetLine(2, "No results found");
                    dlgOK.DoModal(GUIWindowManager.ActiveWindow);
                }
                return true;
            }
        }
        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 ShowContextMenuPostProcessing(string previousMenu)
        {
            GUIListItem currentitem = m_Facade.SelectedListItem;
              if (currentitem == null)
            return ContextMenuAction.Exit;

              AnimeGroupVM grp = currentitem.TVTag as AnimeGroupVM;
              List<AnimeEpisodeVM> episodes = new List<AnimeEpisodeVM>();
              if (grp == null)
              {
            AnimeSeriesVM ser = currentitem.TVTag as AnimeSeriesVM;
            if (ser == null)
            {
              AnimeEpisodeVM ep = currentitem.TVTag as AnimeEpisodeVM;
              episodes.Add(ep);
            }
            else
            {
              foreach (AnimeEpisodeVM ep in ser.AllEpisodes)
              {
            episodes.Add(ep);
              }
            }
              }
              else
              {
            List<AnimeSeriesVM> seriesList = grp.AllSeries;
            foreach (AnimeSeriesVM ser in seriesList)
            {
              foreach (AnimeEpisodeVM ep in ser.AllEpisodes)
              {
            episodes.Add(ep);
              }
            }

              }

              //keep showing the dialog until the user closes it
              string currentMenu = "Associate with a ffdshow raw preset";
              int selectedLabel = 0;
              int intLabel = 0;

              FFDShowHelper ffdshowHelper = new FFDShowHelper();
              List<string> presets = ffdshowHelper.Presets;

              string selectedPreset = ffdshowHelper.findSelectedPresetForMenu(episodes);

              ContextMenu cmenu = new ContextMenu(Translation.AssociateFFDshowPreset, previousmenu: previousMenu);
              cmenu.AddAction(Translation.RemoveOldPresetAssociation, () =>
              {
            ffdshowHelper.deletePreset(episodes);
            Utils.DialogMsg(Translation.Confirmation, Translation.OldPresetRemove);
              });
              foreach (string preset in presets)
              {
            string local = preset;
            cmenu.AddAction(Translation.SetPreset + ": " + preset, () =>
            {
              ffdshowHelper.addPreset(episodes, local);
              Utils.DialogMsg(Translation.Confirmation, string.Format(Translation.PresetAdded, local));
            }, local == selectedPreset);
              }
              return cmenu.Show();
        }
        private ContextMenuAction SearchTheTvDB(AnimeSeriesVM ser, string searchCriteria, string previousMenu)
        {
            if (searchCriteria.Length == 0)
            return ContextMenuAction.Exit;

              int aniDBID = ser.AniDB_Anime.AnimeID;

              List<TVDBSeriesSearchResultVM> TVDBSeriesSearchResults = new List<TVDBSeriesSearchResultVM>();
              List<JMMServerBinary.Contract_TVDBSeriesSearchResult> tvResults = new List<Contract_TVDBSeriesSearchResult>(JMMServerVM.Instance.clientBinaryHTTP.SearchTheTvDB(searchCriteria.Trim()));
              foreach (JMMServerBinary.Contract_TVDBSeriesSearchResult tvResult in tvResults)
            TVDBSeriesSearchResults.Add(new TVDBSeriesSearchResultVM(tvResult));

              BaseConfig.MyAnimeLog.Write("Found {0} tvdb results for {1}", TVDBSeriesSearchResults.Count, searchCriteria);
              if (TVDBSeriesSearchResults.Count > 0)
              {
            ContextMenu cmenu = new ContextMenu(Translation.TVDBSearchResults, previousmenu: previousMenu);
            foreach (TVDBSeriesSearchResultVM res in TVDBSeriesSearchResults)
            {
              TVDBSeriesSearchResultVM local = res;
              string disp = String.Format("{0} ({1}) / {2}", res.SeriesName, res.Language, res.Id);
              cmenu.AddAction(disp, () => LinkAniDBToTVDB(ser, aniDBID, enEpisodeType.Episode, 1, local.SeriesID, 1, 1));
            }
            return cmenu.Show();
              }
              this.Alert(Translation.SearchResults, string.Empty, Translation.NoResultsFound);
              return ContextMenuAction.Exit;
        }
        private ContextMenuAction SearchTheMovieDB(AnimeSeriesVM ser, string searchCriteria, string previousMenu)
        {
            if (searchCriteria.Length == 0)
            return ContextMenuAction.Exit;
              int aniDbid = ser.AniDB_Anime.AnimeID;

              List<MovieDBMovieSearchResultVM> movieDbSeriesSearchResults = new List<MovieDBMovieSearchResultVM>();
              List<Contract_MovieDBMovieSearchResult> movieResults = new List<Contract_MovieDBMovieSearchResult>(JMMServerVM.Instance.clientBinaryHTTP.SearchTheMovieDB(searchCriteria.Trim()));
              foreach (Contract_MovieDBMovieSearchResult movieResult in movieResults)
            movieDbSeriesSearchResults.Add(new MovieDBMovieSearchResultVM(movieResult));

              BaseConfig.MyAnimeLog.Write("Found {0} moviedb results for {1}", movieDbSeriesSearchResults.Count, searchCriteria);

              if (movieDbSeriesSearchResults.Count > 0)
              {
            ContextMenu cmenu = new ContextMenu(Translation.SearchResults, previousmenu: previousMenu);
            foreach (MovieDBMovieSearchResultVM res in movieDbSeriesSearchResults)
            {
              MovieDBMovieSearchResultVM local = res;
              cmenu.AddAction(res.MovieName, () => LinkAniDBToMovieDB(ser, aniDbid, local.MovieID));

            }
            return cmenu.Show();
              }
              this.Alert(Translation.SearchResults, string.Empty, Translation.NoResultsFound);
              return ContextMenuAction.Exit;
        }
        private ContextMenuAction SearchMAL(AnimeSeriesVM ser, string searchCriteria, string previousMenu)
        {
            if (searchCriteria.Length == 0)
            return ContextMenuAction.Exit;

              int aniDbid = ser.AniDB_Anime.AnimeID;

              List<MALSearchResultVM> malSearchResults = new List<MALSearchResultVM>();
              List<Contract_MALAnimeResponse> malResults = new List<Contract_MALAnimeResponse>(JMMServerVM.Instance.clientBinaryHTTP.SearchMAL(searchCriteria.Trim()));
              foreach (Contract_MALAnimeResponse malResult in malResults)
            malSearchResults.Add(new MALSearchResultVM(malResult));

              BaseConfig.MyAnimeLog.Write("Found {0} MAL results for {1}", malSearchResults.Count, searchCriteria);

              if (malSearchResults.Count > 0)
              {
            ContextMenu cmenu = new ContextMenu(Translation.SearchResults, previousmenu: previousMenu);
            foreach (MALSearchResultVM res in malSearchResults)
            {
              MALSearchResultVM local = res;
              cmenu.AddAction(String.Format("{0} ({1} {2})", res.title, res.episodes, Translation.EpisodesShort), () => LinkAniDBToMAL(ser, aniDbid, local.id, local.title));

            }
            return cmenu.Show();
              }
              this.Alert(Translation.SearchResults, string.Empty, Translation.NoResultsFound);
              return ContextMenuAction.Exit;
        }
示例#14
0
        private bool SearchTheMovieDB(AnimeSeriesVM ser, string searchCriteria, string previousMenu)
        {
            if (searchCriteria.Length == 0)
                return true;

            int aniDBID = ser.AniDB_Anime.AnimeID;

            List<MovieDBMovieSearchResultVM> MovieDBSeriesSearchResults = new List<MovieDBMovieSearchResultVM>();
            List<JMMServerBinary.Contract_MovieDBMovieSearchResult> movieResults = JMMServerVM.Instance.clientBinaryHTTP.SearchTheMovieDB(searchCriteria.Trim());
            foreach (JMMServerBinary.Contract_MovieDBMovieSearchResult movieResult in movieResults)
                MovieDBSeriesSearchResults.Add(new MovieDBMovieSearchResultVM(movieResult));

            BaseConfig.MyAnimeLog.Write("Found {0} moviedb results for {1}", MovieDBSeriesSearchResults.Count, searchCriteria);

            if (MovieDBSeriesSearchResults.Count > 0)
            {
                GUIDialogMenu dlg = (GUIDialogMenu)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_MENU);
                if (dlg == null)
                    return true;

                //keep showing the dialog until the user closes it
                int selectedLabel = 0;
                while (true)
                {
                    dlg.Reset();
                    dlg.SetHeading("Search Results");

                    if (previousMenu != string.Empty)
                        dlg.Add("<<< " + previousMenu);
                    foreach (MovieDBMovieSearchResultVM res in MovieDBSeriesSearchResults)
                        dlg.Add(res.MovieName);

                    dlg.SelectedLabel = selectedLabel;
                    dlg.DoModal(GUIWindowManager.ActiveWindow);
                    selectedLabel = dlg.SelectedLabel;

                    int selection = selectedLabel + ((previousMenu == string.Empty) ? 1 : 0);
                    if (selection == 0)
                        return true; //previous menu

                    if (selection > 0 && selection <= MovieDBSeriesSearchResults.Count)
                    {
                        MovieDBMovieSearchResultVM res = MovieDBSeriesSearchResults[selection - 1];

                        LinkAniDBToMovieDB(ser, aniDBID, res.MovieID);
                        return false;
                    }

                    return true;
                }
            }
            else
            {
                GUIDialogOK dlgOK = (GUIDialogOK)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_OK);
                if (null != dlgOK)
                {
                    dlgOK.SetHeading("Search Results");
                    dlgOK.SetLine(1, string.Empty);
                    dlgOK.SetLine(2, "No results found");
                    dlgOK.DoModal(GUIWindowManager.ActiveWindow);
                }
                return true;
            }
        }
        public string LoadLocalThumbnail(int episodeID)
        {
            string thumbnail = "";

              try
              {
              List<Contract_VideoDetailed> epContracts =
                  new List<Contract_VideoDetailed>(JMMServerVM.Instance.clientBinaryHTTP.GetFilesForEpisode(episodeID,
                      JMMServerVM.Instance.CurrentUser.JMMUserID));

              if (epContracts.Any())
              {
                  foreach (Contract_VideoDetailed epcontract in epContracts)
                  {
                      Contract_VideoLocal_Place v = epcontract.Places.FirstOrDefault(a => a != null);
                      if (v == null)
                      {
                        //BaseConfig.MyAnimeLog.Write($"Found no ep contract place for: {episodeID}");
                        continue;
                      }

                      string episodeFilePath = v.FilePath;
                      int importFolderId = v.ImportFolderID;

                      // Check if we have folder ID in dictionary first
                      if (!BaseConfig.Settings.ImportFolderMappings.ContainsKey(importFolderId))
                      {
                        //BaseConfig.MyAnimeLog.Write($"Found no import mapping for folder ID: {importFolderId}");
                        continue;
                      }

                      //BaseConfig.MyAnimeLog.Write("FILE PATH: " + episodeFilePath);
                      //BaseConfig.MyAnimeLog.Write("IMPORT FOLDER ID: " + importFolderId);

                      // Full episode file path with file extension
                      string episodeFilePathWithExtension =
                          Path.Combine(BaseConfig.Settings.ImportFolderMappings[importFolderId], episodeFilePath);

                      // Full episode file path without file extension
                      string episodeFileNameWithoutExtension =
                          Path.GetFileNameWithoutExtension(episodeFilePathWithExtension);
                      string episodeFilePathWithoutExtension = Path.Combine(
                          Path.GetDirectoryName(episodeFilePathWithExtension), episodeFileNameWithoutExtension);

                      //BaseConfig.MyAnimeLog.Write("Episode file path without extension: " + episodeFilePathWithoutExtension);

                      // Thumbnail format: <episode_full_path_without_extension>.jpg <--- the Mediaportal default
                      if (File.Exists(episodeFilePathWithoutExtension + ".jpg"))
                      {
                          thumbnail = episodeFilePathWithoutExtension + ".jpg";
                          return thumbnail;
                      }

                        //BaseConfig.MyAnimeLog.Write("Episode file path with extensions: " + episodeFilePathWithExtension);

                        // Thumbnail format: <episode_full_path_with_extension>.jpg <--- the standard in programs like Video Thumbnails Maker
                        if (File.Exists(episodeFilePathWithExtension + ".jpg"))
                      {
                          thumbnail = episodeFilePathWithExtension + ".jpg";
                          return thumbnail;
                      }
                  }
              }
                BaseConfig.MyAnimeLog.Write("We don't have episode contracts for: {0}", episodeID);

            }
            catch (Exception ex)
              {
              BaseConfig.MyAnimeLog.Write("Error in LoadLocalThumbnail: {0}", ex);
              }

              return thumbnail;
        }
示例#16
0
        private bool SearchTheTvDBMenu(AnimeSeriesVM ser, string previousMenu)
        {
            //string searchCriteria = "";
            int aniDBID = ser.AniDB_Anime.AnimeID;

            GUIDialogMenu dlg = (GUIDialogMenu)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_MENU);
            if (dlg == null)
                return true;

            //keep showing the dialog until the user closes it
            int selectedLabel = 0;
            string currentMenu = "Search The TvDB";
            while (true)
            {
                dlg.Reset();
                dlg.SetHeading(currentMenu);

                if (previousMenu != string.Empty)
                    dlg.Add("<<< " + previousMenu);
                dlg.Add("Search using:   " + ser.AniDB_Anime.FormattedTitle);
                dlg.Add("Manual Search");

                List<CrossRef_AniDB_TvDBVMV2> CrossRef_AniDB_TvDBResult = new List<CrossRef_AniDB_TvDBVMV2>();
                List<JMMServerBinary.Contract_Azure_CrossRef_AniDB_TvDB> xrefs = JMMServerVM.Instance.clientBinaryHTTP.GetTVDBCrossRefWebCache(aniDBID);
                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);
                    }

                    dlg.Add("Community Says:   " + xrefSummary);
                }

                dlg.SelectedLabel = selectedLabel;
                dlg.DoModal(GUIWindowManager.ActiveWindow);
                selectedLabel = dlg.SelectedLabel;

                int selection = selectedLabel + ((previousMenu == string.Empty) ? 1 : 0);
                switch (selection)
                {
                    case 0:
                        //show previous
                        return true;
                    case 1:
                        if (!SearchTheTvDB(ser, ser.AniDB_Anime.FormattedTitle, currentMenu))
                            return false;
                        break;
                    case 2:
                        {
                            if (Utils.DialogText(ref searchText, GetID))
                            {
                                if (!SearchTheTvDB(ser, searchText, currentMenu))
                                    return false;
                            }
                        }
                        break;
                    case 3:

                        string res = JMMServerVM.Instance.clientBinaryHTTP.RemoveLinkAniDBTvDBForAnime(aniDBID);
                        if (res.Length > 0)
                        {
                            Utils.DialogMsg("Error", res);
                            return false;
                        }

                        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 false;
                    default:
                        //close menu
                        return false;
                }
            }
        }
        protected override void OnClicked(int controlId, GUIControl control, MediaPortal.GUI.Library.Action.ActionType actionType)
        {
            if (actionType == MediaPortal.GUI.Library.Action.ActionType.ACTION_MOUSE_DOUBLECLICK)
              {
            OnShowContextMenu();
            return;
              }

              if (actionType == MediaPortal.GUI.Library.Action.ActionType.ACTION_PLAY)
              {
            if (MediaPortal.Player.g_Player.Playing == false)
              BaseConfig.MyAnimeLog.Write("Pressed the play button");
              }
              MainMenu menu = new MainMenu();
              menu.Add(btnDisplayOptions, () =>
              {
            m_Facade.Focus = true;
            ShowDisplayOptionsMenu(string.Empty);
              });
              menu.Add(btnWindowUtilities, () =>
              {
            SetGlobalIDs();
            GUIWindowManager.ActivateWindow(Constants.WindowIDs.ADMIN);
              });
              menu.Add(btnWindowCalendar, () =>
              {
            SetGlobalIDs();
            GUIWindowManager.ActivateWindow(Constants.WindowIDs.CALENDAR);
              });
              menu.Add(btnWindowDownloads, () =>
              {
            SetGlobalIDs();
            GUIWindowManager.ActivateWindow(Constants.WindowIDs.DOWNLOADS);
              });
              menu.Add(btnWindowContinueWatching, () =>
              {
            SetGlobalIDs();
            GUIWindowManager.ActivateWindow(Constants.WindowIDs.WATCHING);
              });
              menu.Add(btnWindowRecommendations, () =>
              {
            SetGlobalIDs();
            GUIWindowManager.ActivateWindow(Constants.WindowIDs.RECOMMENDATIONS);
              });
              menu.Add(btnWindowRandom, () =>
              {
            /*
            GroupFilterVM grpFilter = new GroupFilterVM();
            grpFilter.GroupFilterName = "All";
            grpFilter.GroupFilterID = 16;
            grpFilter.FilterType = 4;
            RandomWindow_LevelObject = grpFilter;
            RandomWindow_RandomLevel = RandomSeriesEpisodeLevel.GroupFilter;
            RandomWindow_RandomType = RandomObjectType.Series;
            GUIWindowManager.ActivateWindow(Constants.WindowIDs.RANDOM);*/
            ShowContextMenuGroupFilter("");
              });
              menu.Add(btnChangeLayout, () =>
              {
            m_Facade.Focus = true;
            ShowLayoutMenu(string.Empty);
              });
              menu.Add(btnFilters, () =>
              {
              m_Facade.Focus = true;
              ShowFilterOptions(string.Empty);
              });
              menu.Add(btnSwitchUser, () =>
              {
              if (JMMServerVM.Instance.PromptUserLogin())
              {
              Breadcrumbs = new List<History>() {new History()};

              // user has logged in, so save to settings so we will log in as the same user next time
              settings.CurrentJMMUserID =
                  JMMServerVM.Instance.CurrentUser.JMMUserID.ToString(CultureInfo.InvariantCulture);
              settings.Save();

              LoadFacade();
              }
              else
              {

              }
              });
              menu.Add(btnSettings, () =>
              {
            m_Facade.Focus = true;
            ShowOptionsDisplayMenu(string.Empty);
              });
              if (menu.Check(control))
            return;

              try
              {
            if (actionType != MediaPortal.GUI.Library.Action.ActionType.ACTION_SELECT_ITEM) return; // some other events raised onClicked too for some reason?
            if (control == this.m_Facade)
            {
              UpdateSearchPanel(false);

              if (this.m_Facade.SelectedListItem == null || this.m_Facade.SelectedListItem.TVTag == null)
            return;
              IVM cur = m_Facade.SelectedListItem.TVTag as IVM;
              if (cur == null)
            return;
              if (cur is AnimeGroupVM)
            cur = GetChildrenLevelForGroup((AnimeGroupVM)cur);
              if (cur is AnimeSeriesVM)
            cur = GetChildrenLevelForSeries((AnimeSeriesVM)cur);
              if (cur is AnimeEpisodeVM)
              {
            AnimeEpisodeVM ep = (AnimeEpisodeVM)cur;
            BaseConfig.MyAnimeLog.Write("Selected to play: {0}", ep.EpisodeNumberAndName);
            vidHandler.ResumeOrPlay(ep);
              }
              else
              {
            BaseConfig.MyAnimeLog.Write("Clicked to " + cur.GetType().ToString());
            Breadcrumbs.Add(new History() { Listing = cur });
            LoadFacade();
            this.m_Facade.Focus = true;
              }
            }
              }
              catch (Exception ex)
              {
            BaseConfig.MyAnimeLog.Write("Error in OnClicked: {0} - {1}", ex.Message, ex.ToString());
              }

              base.OnClicked(controlId, control, actionType);
        }
示例#18
0
        private bool ShowContextMenuPostProcessing(string previousMenu)
        {
            GUIDialogMenu dlg = (GUIDialogMenu)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_MENU);
            if (dlg == null)
                return true;

            GUIListItem currentitem = this.m_Facade.SelectedListItem;
            if (currentitem == null)
                return true;

            AnimeGroupVM grp = currentitem.TVTag as AnimeGroupVM;
            List<AnimeEpisodeVM> episodes = new List<AnimeEpisodeVM>();
            if (grp == null)
            {
                AnimeSeriesVM ser = currentitem.TVTag as AnimeSeriesVM;
                if (ser == null)
                {
                    AnimeEpisodeVM ep = currentitem.TVTag as AnimeEpisodeVM;
                    episodes.Add(ep);
                }
                else
                {
                    foreach (AnimeEpisodeVM ep in ser.AllEpisodes)
                    {
                        episodes.Add(ep);
                    }
                }
            }
            else
            {
                List<AnimeSeriesVM> seriesList = grp.AllSeries;
                foreach (AnimeSeriesVM ser in seriesList)
                {
                    foreach (AnimeEpisodeVM ep in ser.AllEpisodes)
                    {
                        episodes.Add(ep);
                    }
                }

            }

            if (episodes == null)
                return true;

            //keep showing the dialog until the user closes it
            string currentMenu = "Associate with a ffdshow raw preset";
            int selectedLabel = 0;
            int intLabel = 0;

            FFDShowHelper ffdshowHelper = new FFDShowHelper();
            List<string> presets = ffdshowHelper.Presets;

            string selectedPreset = ffdshowHelper.findSelectedPresetForMenu(episodes);

            while (true)
            {
                dlg.Reset();
                dlg.SetHeading(currentMenu);

                if (previousMenu != string.Empty)
                {
                    dlg.Add("<<< " + previousMenu);
                    intLabel++;
                }

                dlg.Add("Remove old preset association");
                intLabel++;
                foreach (string preset in presets)
                {
                    dlg.Add("Set preset: " + preset);
                    // preset selected
                    if (selectedPreset == preset)
                        selectedLabel = intLabel;

                    intLabel++;
                }

                dlg.SelectedLabel = selectedLabel;
                dlg.DoModal(GUIWindowManager.ActiveWindow);
                selectedLabel = dlg.SelectedLabel;

                int selection = selectedLabel + ((previousMenu == string.Empty) ? 1 : 0);

                if (selection == 0)
                {
                    //show previous
                    return true;
                }
                else if (selection == -1)
                {
                    //close menu
                    return false;
                }
                else
                {
                    string message = "";
                    if (selection == 1)
                    {
                        //DB remove preset
                        ffdshowHelper.deletePreset(episodes);
                        message = "Old preset successfully removed.";
                    }
                    else
                    {
                        //DB associate serie/group with preset
                        string choosenPreset = presets.ToArray()[selection - 2];
                        ffdshowHelper.addPreset(episodes, choosenPreset);
                        message = "Preset \"" + choosenPreset + "\" successfully added.";
                    }
                    Utils.DialogMsg("Confirmation", message);
                    return false;
                }
            }
        }
示例#19
0
 protected void ToggleWatchedEvent(List<AnimeEpisodeVM> episodes, bool state)
 {
     if (OnToggleWatched != null)
     {
         OnToggleWatched(episodes, state);
     }
 }
 private void button5_Click(object sender, EventArgs e)
 {
     List<string> sel = new List<string>();
       foreach (string s in listBox_history.SelectedItems)
       {
     sel.Add(s);
       }
       foreach (string s in sel)
       {
     listBox_history.Items.Remove(s);
       }
 }
        void downloadImagesWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            // 1. Download posters from AniDB
              List<JMMServerBinary.Contract_AniDBAnime> contracts = new List<Contract_AniDBAnime>(JMMServerVM.Instance.clientBinaryHTTP.GetAllAnime());

              int i = 0;
              foreach (JMMServerBinary.Contract_AniDBAnime anime in contracts)
              {
            //Thread.Sleep(5); // don't use too many resources
            imageHelper.DownloadAniDBCover(new AniDB_AnimeVM(anime), false);
            i++;

            //if (i == 80) break;
              }

              // 2. Download posters from TvDB
              List<JMMServerBinary.Contract_TvDB_ImagePoster> posters = new List<Contract_TvDB_ImagePoster>(JMMServerVM.Instance.clientBinaryHTTP.GetAllTvDBPosters(null));
              foreach (JMMServerBinary.Contract_TvDB_ImagePoster poster in posters)
              {
            //Thread.Sleep(5); // don't use too many resources
            imageHelper.DownloadTvDBPoster(new TvDB_ImagePosterVM(poster), false);
              }

              // 2a. Download posters from MovieDB
              List<JMMServerBinary.Contract_MovieDB_Poster> moviePosters = new List<Contract_MovieDB_Poster>(JMMServerVM.Instance.clientBinaryHTTP.GetAllMovieDBPosters(null));
              foreach (JMMServerBinary.Contract_MovieDB_Poster poster in moviePosters)
              {
            //Thread.Sleep(5); // don't use too many resources
            imageHelper.DownloadMovieDBPoster(new MovieDB_PosterVM(poster), false);
              }

              // 3. Download wide banners from TvDB
              List<JMMServerBinary.Contract_TvDB_ImageWideBanner> banners = new List<Contract_TvDB_ImageWideBanner>(JMMServerVM.Instance.clientBinaryHTTP.GetAllTvDBWideBanners(null));
              foreach (JMMServerBinary.Contract_TvDB_ImageWideBanner banner in banners)
              {
            //Thread.Sleep(5); // don't use too many resources
            imageHelper.DownloadTvDBWideBanner(new TvDB_ImageWideBannerVM(banner), false);
              }

              // 4. Download fanart from TvDB
              List<JMMServerBinary.Contract_TvDB_ImageFanart> fanarts = new List<Contract_TvDB_ImageFanart>(JMMServerVM.Instance.clientBinaryHTTP.GetAllTvDBFanart(null));
              foreach (JMMServerBinary.Contract_TvDB_ImageFanart fanart in fanarts)
              {
            //Thread.Sleep(5); // don't use too many resources
            imageHelper.DownloadTvDBFanart(new TvDB_ImageFanartVM(fanart), false);
              }

              // 4a. Download fanart from MovieDB
              List<JMMServerBinary.Contract_MovieDB_Fanart> movieFanarts = new List<Contract_MovieDB_Fanart>(JMMServerVM.Instance.clientBinaryHTTP.GetAllMovieDBFanart(null));
              foreach (JMMServerBinary.Contract_MovieDB_Fanart fanart in movieFanarts)
              {
            //Thread.Sleep(5); // don't use too many resources
            imageHelper.DownloadMovieDBFanart(new MovieDB_FanartVM(fanart), false);
              }

              // 5. Download episode images from TvDB
              List<JMMServerBinary.Contract_TvDB_Episode> eps = new List<Contract_TvDB_Episode>(JMMServerVM.Instance.clientBinaryHTTP.GetAllTvDBEpisodes(null));
              foreach (JMMServerBinary.Contract_TvDB_Episode episode in eps)
              {
            //Thread.Sleep(5); // don't use too many resources
            imageHelper.DownloadTvDBEpisode(new TvDB_EpisodeVM(episode), false);
              }

              // 6. Download posters from Trakt
              List<JMMServerBinary.Contract_Trakt_ImagePoster> traktPosters = new List<Contract_Trakt_ImagePoster>(JMMServerVM.Instance.clientBinaryHTTP.GetAllTraktPosters(null));
              foreach (JMMServerBinary.Contract_Trakt_ImagePoster traktposter in traktPosters)
              {
            //Thread.Sleep(5); // don't use too many resources
            if (string.IsNullOrEmpty(traktposter.ImageURL)) continue;
            imageHelper.DownloadTraktPoster(new Trakt_ImagePosterVM(traktposter), false);
              }

              // 7. Download fanart from Trakt
              List<JMMServerBinary.Contract_Trakt_ImageFanart> traktFanarts = new List<Contract_Trakt_ImageFanart>(JMMServerVM.Instance.clientBinaryHTTP.GetAllTraktFanart(null));
              foreach (JMMServerBinary.Contract_Trakt_ImageFanart traktFanart in traktFanarts)
              {
            //Thread.Sleep(5); // don't use too many resources
            if (string.IsNullOrEmpty(traktFanart.ImageURL)) continue;
            imageHelper.DownloadTraktFanart(new Trakt_ImageFanartVM(traktFanart), false);
              }

              // 8. Download episode images from Trakt
              List<JMMServerBinary.Contract_Trakt_Episode> traktEpisodes = new List<Contract_Trakt_Episode>(JMMServerVM.Instance.clientBinaryHTTP.GetAllTraktEpisodes(null));
              foreach (JMMServerBinary.Contract_Trakt_Episode traktEp in traktEpisodes)
              {
            //Thread.Sleep(5); // don't use too many resources
            if (string.IsNullOrEmpty(traktEp.EpisodeImage)) continue;

            // special case for trak episodes
            // Trakt will return the fanart image when no episode image exists, but we don't want this
            int pos = traktEp.EpisodeImage.IndexOf(@"episodes/");
            if (pos <= 0) continue;

            imageHelper.DownloadTraktEpisode(new Trakt_EpisodeVM(traktEp), false);
              }
        }