Example #1
0
        public async void Next(int pageIndex)
        {
            if (pageIndex == 0)
            {
                try
                {
                    IsLoading = true;

                    if (UseExcelFileSource)
                    {
                        DataTable = await ExcelHelper.CreateDataTableFromExcel(FilePath);
                    }
                    else
                    {
                        MediaFileInfoList = await MediaFileInfo.Create(FolderPath, UseParentFolderName, MediaType);
                    }
                }
                finally
                {
                    IsLoading = false;
                }
            }
            else if (pageIndex == 1 || pageIndex == 2)
            {
                if (UseExcelFileSource)
                {
                    List <MediaFileInfo> mediaFileInfoList = new List <MediaFileInfo>();
                    for (int i = 0; i < DataTable.Rows.Count; i++)
                    {
                        MediaFileInfo mediaFileInfo = MediaFileInfo.Create();
                        mediaFileInfo.MediaItemName = DataTable.Rows[i].GetDataCellValue <String>(NameColumn);

                        if (String.IsNullOrWhiteSpace(mediaFileInfo.MediaItemName))
                        {
                            continue;
                        }

                        PersonalInfo personalInfo = new PersonalInfo();
                        personalInfo.Seen           = DataTable.Rows[i].GetDataCellValue <Boolean>(SeenColumn);
                        personalInfo.Favorite       = DataTable.Rows[i].GetDataCellValue <Boolean>(FavoriteColumn);
                        personalInfo.Watchlist      = DataTable.Rows[i].GetDataCellValue <Boolean>(WatchlistColumn);
                        personalInfo.LocalPath      = DataTable.Rows[i].GetDataCellValue <String>(LocalPathColumn);
                        personalInfo.PersonalRating = DataTable.Rows[i].GetDataCellValue <Double>(PersonalRatingColumn);
                        mediaFileInfo.PersonalInfo  = personalInfo;

                        mediaFileInfoList.Add(mediaFileInfo);
                    }

                    MediaFileInfoList = mediaFileInfoList;
                }

                try
                {
                    IsLoading = true;

                    for (int i = 0; i < MediaFileInfoList.Count; i++)
                    {
                        double percent = (double)(i + 1) / MediaFileInfoList.Count;
                        Progress = Math.Floor(percent * 100);

                        MediaFileInfo mediaFileInfo = MediaFileInfoList[i];
                        if (String.IsNullOrWhiteSpace(mediaFileInfo.MediaItemName))
                        {
                            continue;
                        }

                        if (CancellationTokenSource.IsCancellationRequested)
                        {
                            break;
                        }

                        mediaFileInfo.FoundMediaItems = await App.Repository.FindAsync(mediaFileInfo.MediaItemName, Properties.Settings.Default.Language,
                                                                                       MediaType, CancellationTokenSource.Token);

                        if (mediaFileInfo.FoundMediaItems.Count > 0)
                        {
                            mediaFileInfo.SelectedMediaItem = mediaFileInfo.FoundMediaItems[0];
                        }
                    }
                }
                catch (TaskCanceledException)
                {
                    return;
                }
                finally
                {
                    IsLoading = false;
                }
            }
            else if (pageIndex == 3)
            {
                IsCompleted = SelectedMediaFileInfoList.Count > 0;
            }
        }