Beispiel #1
0
        private async Task DisconnectServer(bool showMessage, string msg = null)
        {
            pathStack.Clear();
            NetworkItemGroupSource.Clear();

            IsLoadingFolders = false;
            IsLoadingFiles   = false;
            IsConnecting     = false;
            IsDisconnected   = true;
            ShowOrderBy      = false;
            VisibleToUpper   = false;
            //CurrentFolderInfo = null;
            DisplayCurrentPath = string.Empty;

            if (showMessage)
            {
                var resource = ResourceLoader.GetForCurrentView();
                if (string.IsNullOrEmpty(msg))
                {
                    msg = resource.GetString("Message/Error/DisconnectedServer");
                }

                var dlg = DialogHelper.GetSimpleContentDialog(
                    resource.GetString("Server/Disonnect/General/Text"),
                    msg,
                    resource.GetString("Button/Close/Content"));
                await dlg.ShowAsync();

                App.ContentDlgOp = null;
            }
        }
Beispiel #2
0
        private async Task LoadBatchOneDriveFolderAsync(IEnumerable <NetworkItemInfo> folderList, string folderGroupName)
        {
            if ((bool)folderList?.Any())
            {
                //신규 그룹 생성
                NetworkItemGroup group = null;
                group = NetworkItemGroupSource.FirstOrDefault(x => x.Type == StorageItemTypes.Folder);
                if (group == null)
                {
                    group = new NetworkItemGroup(StorageItemTypes.Folder, folderGroupName);
                    await GalaSoft.MvvmLight.Threading.DispatcherHelper.RunAsync(() => NetworkItemGroupSource.Insert(0, group));
                }
                foreach (var folderItem in folderList)
                {
                    await GalaSoft.MvvmLight.Threading.DispatcherHelper.RunAsync(() => group.Items.Add(folderItem));
                }

                //폴더 썸네일 로드
                LoadOneDriveFoldersThumbnail(folderList, _CancellationTokenSource.Token);
            }
        }
Beispiel #3
0
        private async void RequestPlayback(DecoderTypes decoderType, NetworkItemInfo networkItemInfo, bool isPrevOrNext)
        {
            if (!VersionHelper.IsUnlockNetworkPlay)
            {
                MessengerInstance.Send(new Message(), "CheckInterstitialAd");
                return;
            }

            MessengerInstance.Send(new Message("IsOpen", true)
                                   .Add("LoadingTitle", ResourceLoader.GetForCurrentView().GetString("Loading/Playback/Text")), "ShowLoadingPanel");

            var items = NetworkItemGroupSource.Where(x => x.Type == StorageItemTypes.File).SelectMany(x => x.Items).ToList();
            var item  = networkItemInfo;
            var index = items.IndexOf(item);

            NetworkItemInfo prevItemInfo = null;
            NetworkItemInfo currItemInfo = item;
            NetworkItemInfo nextItemInfo = null;

            if ((bool)items?.Any())
            {
                if (index > 0)
                {
                    prevItemInfo = items[index - 1];
                }

                if (index < items.Count - 1)
                {
                    nextItemInfo = items[index + 1];
                }
            }

            var msg = new Message()
                      .Add("PrevPlayListFile", prevItemInfo)
                      .Add("CurrPlayListFile", currItemInfo)
                      .Add("NextPlayListFile", nextItemInfo)
                      .Add("DecoderType", decoderType);

            //Stream videoStream = null;
            //IItemContentRequest request = null;

            switch (ConnectedServerType)
            {
            case ServerTypes.OneDrive:
                /*
                 * request = OneDriveClient.Drive.Root.ItemWithPath(GetAbsolutePath(networkItemInfo)).Content.Request();
                 * // videoStream = await request.GetAsync();
                 *
                 * var provider = OneDriveClient.AuthenticationProvider as MsaAuthenticationProvider;
                 * var url = request.RequestUrl + "?access_token=" + provider.CurrentAccountSession.AccessToken;
                 *
                 * var webReq = System.Net.WebRequest.Create(url);
                 * var webRes = await webReq.GetResponseAsync();
                 * //Stream stream = webRes.GetResponseStream();
                 * url = url.Replace("https://", "http://");
                 *
                 * //        msg.Add("CurrPlayListFileStream", stream.AsRandomAccessStream());
                 * msg.Add("CurrPlayListFileUrl", url);
                 * msg.Add("CurrPlayListFileContentType", request.ContentType);
                 */

                for (int i = 0; i < currItemInfo.SubtitleList?.Count; i++)
                {
                    currItemInfo.SubtitleList[i] = (await GetStreamingUrlAsync(GetAbsolutePath(currItemInfo.ParentFolderPath, currItemInfo.SubtitleList[i]))).AbsoluteUri;
                }

                currItemInfo.Uri = await GetStreamingUrlAsync(GetAbsolutePath(currItemInfo));

                break;
            }

            MessengerInstance.Send(msg, "RequestPlayback");
        }
Beispiel #4
0
        private async Task LoadBatchOneDriveFilesAsync(IEnumerable <NetworkItemInfo> fileList, string fileGroupName)
        {
            if (fileList != null)
            {
                var videoList = fileList.Where(x => MediaFileSuffixes.VIDEO_SUFFIX.Any(y => x.Name.ToUpper().EndsWith(y)));
                //자막 리스트 생성
                _CurrentSubtitleFileList = fileList.Where(x => MediaFileSuffixes.CLOSED_CAPTION_SUFFIX.Any(y => x.Name.ToUpper().EndsWith(y))).Select(x => x.Name).ToList();

                int itemCount      = videoList.Count();
                int itemTotalCount = itemCount;
                await GalaSoft.MvvmLight.Threading.DispatcherHelper.RunAsync(() => itemTotalCount += NetworkItemGroupSource.Where(x => x.Type == StorageItemTypes.File).SelectMany(x => x.Items).Count());

                NetworkItemGroup group = null;
                var    isOrderByName   = _Sort == SortType.Name || _Sort == SortType.NameDescending;
                var    isMultiGroup    = isOrderByName && itemTotalCount > GROUP_MAX_ITME_COUNT;
                string groupName       = isMultiGroup ? null : fileGroupName;

                foreach (var videoItem in videoList)
                {
                    if (isMultiGroup)
                    {
                        groupName = _CharacterGroupings.Lookup(videoItem.Name);
                        var tmp = NetworkItemGroupSource.FirstOrDefault(x => x.Name == fileGroupName);
                        if (tmp != null)
                        {
                            //페이징으로 인해 파일이 계속적으로 추가되어 그룹이 변경되는 경우에 다시 그룹에 추가
                            await GalaSoft.MvvmLight.Threading.DispatcherHelper.RunAsync(() =>
                            {
                                NetworkItemGroupSource.Remove(tmp);
                                var items = tmp.Items;

                                foreach (var old in tmp.Items)
                                {
                                    var tmpGroupName = _CharacterGroupings.Lookup(old.Name);
                                    var tmpGroup     = NetworkItemGroupSource.FirstOrDefault(x => x.Name == tmpGroupName);

                                    if (tmpGroup == null)
                                    {
                                        tmpGroup = new NetworkItemGroup(StorageItemTypes.File, tmpGroupName);
                                        NetworkItemGroupSource.Add(tmpGroup);
                                    }

                                    tmpGroup.Items.Add(old);
                                }
                            });
                        }
                    }
                    //그룹이 변경되는 경우
                    if (group == null || group.Name != groupName)
                    {
                        //신규 그룹 생성
                        await GalaSoft.MvvmLight.Threading.DispatcherHelper.RunAsync(() =>
                        {
                            group = NetworkItemGroupSource.FirstOrDefault(x => x.Name == groupName);
                            if (group == null)
                            {
                                group = new NetworkItemGroup(StorageItemTypes.File, groupName);
                                NetworkItemGroupSource.Add(group);
                            }
                        });
                    }

                    await GalaSoft.MvvmLight.Threading.DispatcherHelper.RunAsync(() => group.Items.Add(videoItem));
                }

                LoadOneDriveFilesThumbnail(videoList, _CancellationTokenSource.Token);
            }
        }
Beispiel #5
0
        private async Task LoadOneDriveFoldersAsync()
        {
            if (_CancellationTokenSource != null)
            {
                //썸네일 로드 실행전 이전 요청을 취소시킴
                _CancellationTokenSource.Cancel();
            }

            if (_CancellationTokenSource == null || _CancellationTokenSource.IsCancellationRequested)
            {
                _CancellationTokenSource = new CancellationTokenSource();
            }

            _CurrentSubtitleFileList = null;

            //모든 자식 요소 삭제
            NetworkItemGroupSource.Clear();
            //로딩 표시
            IsLoadingFolders = true;
            IsLoadingFiles   = true;

            var folderGroupName = ResourceLoader.GetForCurrentView().GetString("List/Folder/Text");
            var fileGroupName   = ResourceLoader.GetForCurrentView().GetString("List/File/Text");
            var isOrderByName   = _Sort == SortType.Name || _Sort == SortType.NameDescending;

            string path = string.Join("/", pathStack.Select(x => x.Name).Reverse());

            //경로를 타이틀 영역에 표시
            DisplayCurrentPath = path;

            await ThreadPool.RunAsync(async handler =>
            {
                try
                {
                    IItemChildrenCollectionPage page = null;
                    //var suffixed = MediaFileSuffixes.VIDEO_SUFFIX.Union(MediaFileSuffixes.CLOSED_CAPTION_SUFFIX);
                    //var endswithFilter = string.Join(" or ", suffixed.Select(s => $"endswith(name, '{s}')"));
                    var filterString = "folder ne null or (file ne null and image eq null and audio eq null)";
                    var sortString   = _Sort == SortType.Name ? "name" : _Sort == SortType.NameDescending ? "name desc" : _Sort == SortType.CreatedDate ? "lastModifiedDateTime" : "lastModifiedDateTime desc";


                    if (pathStack.Any())
                    {
                        //var itemRequest = OneDriveClient.Drive.Items[networkItem.Id].Children.Request();// new List<Option> { new QueryOption("filter", "folder ne null or video ne null or (file ne null and image eq null and audio eq null)") });
                        var itemRequest = OneDriveClient.Drive.Root.ItemWithPath(path).Children.Request();
                        page            = await itemRequest.Filter(filterString)
                                          .Expand("thumbnails(select=medium)")
                                          .OrderBy(sortString)
                                          .GetAsync();
                    }
                    else
                    {
                        var itemRequest = OneDriveClient.Drive.Root.Children.Request();//.Expand("thumbnails,children(expand=thumbnails)");
                        page            = await itemRequest.Filter(filterString)
                                          .Expand("thumbnails(select=medium)")
                                          .OrderBy(sortString)
                                          .GetAsync();
                    }

                    //상위 버튼 및 하드웨어 백버튼 변경 처리
                    ChangeToUpperAndBackButton();

                    _ThumbnailListInCurrentFolder.Clear();
                    //기간 지난 썸네일 캐시 삭제
                    ThumbnailDAO.DeletePastPeriodThumbnail(Settings.Thumbnail.RetentionPeriod);
                    //썸네일 캐시 (이미지 바이트 데이터 제외)를 로드
                    LoadThumbnailMetadataInFolder(page.CurrentPage);

                    var ffList     = page.CurrentPage.Select(x => x.ToNetworkItemInfo(NetworkItemTapped, NetworkItemRightTapped, NetworkItemHolding, isOrderByName));
                    var folderList = ffList.Where(x => !x.IsFile).ToList();
                    await LoadBatchOneDriveFolderAsync(folderList, folderGroupName);
                    await GalaSoft.MvvmLight.Threading.DispatcherHelper.RunAsync(() => IsLoadingFolders = false);

                    var fileList = ffList.Where(x => x.IsFile).ToList();
                    await LoadBatchOneDriveFilesAsync(fileList, fileGroupName);
                    await GalaSoft.MvvmLight.Threading.DispatcherHelper.RunAsync(() => IsLoadingFiles = false);

                    //페이징 처리
                    await Task.Factory.StartNew(async() =>
                    {
                        //폴더 로딩 표시기 시작
                        await GalaSoft.MvvmLight.Threading.DispatcherHelper.RunAsync(() => { IsLoadingFolders = true; IsLoadingFiles = true; });
                        while (page.NextPageRequest != null)
                        {
                            //다음 페이지 패치
                            page = await page.NextPageRequest.GetAsync();

                            //썸네일 캐시 (이미지 바이트 데이터 제외)를 로드
                            LoadThumbnailMetadataInFolder(page.CurrentPage);

                            ffList     = page.CurrentPage.Select(x => x.ToNetworkItemInfo(NetworkItemTapped, NetworkItemRightTapped, NetworkItemHolding, isOrderByName));
                            folderList = ffList.Where(x => !x.IsFile).ToList();
                            await LoadBatchOneDriveFolderAsync(folderList, folderGroupName);

                            fileList = ffList.Where(x => x.IsFile).ToList();
                            await LoadBatchOneDriveFilesAsync(fileList, fileGroupName);
                        }

                        //폴더 로딩 표시기 정지
                        await GalaSoft.MvvmLight.Threading.DispatcherHelper.RunAsync(() => { IsLoadingFolders = false; IsLoadingFiles = false; });
                    });
                }
                catch (Exception)
                {
                    GalaSoft.MvvmLight.Threading.DispatcherHelper.CheckBeginInvokeOnUI(async() =>
                    {
                        await DisconnectOneDriveServer(true);
                    });
                }
            });
        }
        protected override void OrderByChanged()
        {
            string nonGroupFileName   = ResourceLoader.GetForCurrentView().GetString("List/File/Text");
            string nonGroupFolderName = ResourceLoader.GetForCurrentView().GetString("List/Folder/Text");

            var isOrderByName = _Sort == SortType.Name || _Sort == SortType.NameDescending;
            List <NetworkItemInfo> folderItems = null;
            List <NetworkItemInfo> fileItems   = null;

            switch (_Sort)
            {
            case SortType.Name:
                folderItems = NetworkItemGroupSource.Where(x => x.Type == StorageItemTypes.Folder).SelectMany(x => x.Items).OrderBy(x => x.Name).ToList();
                fileItems   = NetworkItemGroupSource.Where(x => x.Type == StorageItemTypes.File).SelectMany(x => x.Items).OrderBy(x => x.Name).ToList();
                break;

            case SortType.NameDescending:
                folderItems = NetworkItemGroupSource.Where(x => x.Type == StorageItemTypes.Folder).SelectMany(x => x.Items).OrderByDescending(x => x.Name).ToList();
                fileItems   = NetworkItemGroupSource.Where(x => x.Type == StorageItemTypes.File).SelectMany(x => x.Items).OrderByDescending(x => x.Name).ToList();
                break;

            case SortType.CreatedDate:
                folderItems = NetworkItemGroupSource.Where(x => x.Type == StorageItemTypes.Folder).SelectMany(x => x.Items).OrderBy(x => x.Modified).ToList();
                fileItems   = NetworkItemGroupSource.Where(x => x.Type == StorageItemTypes.File).SelectMany(x => x.Items).OrderBy(x => x.Modified).ToList();
                break;

            case SortType.CreatedDateDescending:
                folderItems = NetworkItemGroupSource.Where(x => x.Type == StorageItemTypes.Folder).SelectMany(x => x.Items).OrderByDescending(x => x.Modified).ToList();
                fileItems   = NetworkItemGroupSource.Where(x => x.Type == StorageItemTypes.File).SelectMany(x => x.Items).OrderByDescending(x => x.Modified).ToList();
                break;
            }

            //리스트 전체 초기화
            NetworkItemGroupSource.Clear();
            //폴더 재추가
            if (folderItems != null && folderItems.Count > 0)
            {
                NetworkItemGroup folderGroup = new NetworkItemGroup(StorageItemTypes.Folder, nonGroupFolderName);
                NetworkItemGroupSource.Add(folderGroup);

                foreach (var item in folderItems)
                {
                    item.IsOrderByName = isOrderByName;
                    folderGroup.Items.Add(item);
                }
            }
            //파일 재추가
            if (fileItems != null && fileItems.Count > 0)
            {
                NetworkItemGroup fileGroup = null;
                var fileStartIndex         = NetworkItemGroupSource.Any(x => x.Type == StorageItemTypes.Folder) ? 1 : 0;

                if (isOrderByName && fileItems.Count > GROUP_MAX_ITME_COUNT)
                {
                    foreach (var item in fileItems)
                    {
                        var groupName = _CharacterGroupings.Lookup(item.Name);
                        fileGroup = NetworkItemGroupSource.FirstOrDefault(x => x.Name == groupName);

                        if (fileGroup == null)
                        {
                            fileGroup = new NetworkItemGroup(StorageItemTypes.File, groupName);
                            NetworkItemGroupSource.Add(fileGroup);
                        }

                        item.IsOrderByName = isOrderByName;
                        fileGroup.Items.Add(item);
                    }
                }
                else
                {
                    fileGroup = new NetworkItemGroup(StorageItemTypes.File, nonGroupFileName);
                    NetworkItemGroupSource.Add(fileGroup);

                    foreach (var item in fileItems)
                    {
                        item.IsOrderByName = isOrderByName;
                        fileGroup.Items.Add(item);
                    }
                }
            }
        }