private async Task QueryStructure() { var dav = new WebDAVClient(_workingAccount.GetUri(), await App.AccountService.GetCredentials(_workingAccount)); try { var entries = await dav.GetEntries(_workingPath, true); if (entries.Count == 0) throw new Exception("No entries found"); bool _firstItem = false; // display all items linear // we cannot wait till an item is displayed, instead for a fluid // behaviour we should calculate fadeIn-delays. int delayStart = 0; int delayStep = 50; // ms foreach (var item in entries) { File fileItem = new File() { FileName = item.FileName, FilePath = item.FilePath.ToString(), FileSize = item.Size, FileType = item.MimeType, FileCreated = item.Created, FileLastModified = item.LastModified, IsDirectory = item.IsDirectory }; bool display = true; switch (_views[_viewIndex]) { case "detail": if (!_firstItem) { _firstItem = true; // Root if (fileItem.IsDirectory) { if (item.FilePath.ToString() == _workingAccount.WebDAVPath) { // cannot go up further display = false; } else { fileItem.IsRootItem = true; fileItem.FilePath = fileItem.FileParentPath; } } } if (display) { FileDetailViewControl detailControl = new FileDetailViewControl() { DataContext = fileItem, Opacity = 0, Background = new SolidColorBrush() { Color = Colors.Transparent }, }; DetailList.Items.Add(detailControl); detailControl.Delay(delayStart, () => { detailControl.FadeIn(100); }); delayStart += delayStep; } break; case "tile": if (!_firstItem) { _firstItem = true; // Root if (fileItem.IsDirectory) { if (item.FilePath.ToString() == _workingAccount.WebDAVPath) { // cannot go up further display = false; } else { fileItem.IsRootItem = true; fileItem.FilePath = fileItem.FileParentPath; } } } if (display) { FileMultiTileViewControl multiControl = new FileMultiTileViewControl(_workingAccount, fileItem, true) { Width = 200, Height = 200, Opacity = 0, Margin = new Thickness(0, 0, 10, 10), }; multiControl.Tap += new EventHandler<System.Windows.Input.GestureEventArgs>(TileListSelectionChanged); // sometimes the exception "wrong parameter" is thrown - but why??? TileView.Children.Add(multiControl); multiControl.Delay(delayStart, () => { multiControl.FadeIn(100); }); } break; } } progress.IsVisible = false; } catch (Exception ex) { progress.IsVisible = false; var webException = ex as WebException; var webResponse = webException != null ? webException.Response as HttpWebResponse : null; if (webException != null && webException.Status == WebExceptionStatus.ProtocolError && webResponse != null && webResponse.StatusCode == HttpStatusCode.Unauthorized) { MessageBox.Show("FetchFile_Unauthorized".Translate(), "Error_Caption".Translate(), MessageBoxButton.OK); } else { MessageBox.Show("FetchFile_Unexpected_Result".Translate(), "Error_Caption".Translate(), MessageBoxButton.OK); } } }
private void FetchStructureComplete(DAVRequestResult result, object userObj) { if (result.Status == ServerStatus.MultiStatus && !result.Request.ErrorOccured && result.Items.Count > 0) { bool _firstItem = false; // display all items linear // we cannot wait till an item is displayed, instead for a fluid // behaviour we should calculate fadeIn-delays. int delayStart = 0; int delayStep = 50; // ms foreach (DAVRequestResult.Item item in result.Items) { File fileItem = new File() { FileName = item.LocalReference, FilePath = item.Reference, FileSize = item.ContentLength, FileType = item.ContentType, FileCreated = item.CreationDate, FileLastModified = item.LastModified, IsDirectory = item.ResourceType == ResourceType.Collection }; bool display = true; Dispatcher.BeginInvoke(() => { switch (_views[_viewIndex]) { case "detail": if (!_firstItem) { _firstItem = true; // Root if (fileItem.IsDirectory) { if (item.Reference == _workingAccount.WebDAVPath) { // cannot go up further display = false; } else { fileItem.IsRootItem = true; fileItem.FilePath = fileItem.FileParentPath; } } } if (display) { FileDetailViewControl detailControl = new FileDetailViewControl() { DataContext = fileItem, Opacity = 0, Background = new SolidColorBrush() { Color = Colors.Transparent }, }; DetailList.Items.Add(detailControl); detailControl.Delay(delayStart, () => { detailControl.FadeIn(100); }); delayStart += delayStep; } break; case "tile": if (!_firstItem) { _firstItem = true; // Root if (fileItem.IsDirectory) { if (item.Reference == _workingAccount.WebDAVPath) { // cannot go up further display = false; } else { fileItem.IsRootItem = true; fileItem.FilePath = fileItem.FileParentPath; } } } if (display) { FileMultiTileViewControl multiControl = new FileMultiTileViewControl(_workingAccount, fileItem, true) { Width = 200, Height = 200, Opacity = 0, Margin = new Thickness(0, 0, 10, 10), }; multiControl.Tap += new EventHandler<System.Windows.Input.GestureEventArgs>(TileListSelectionChanged); // sometimes the exception "wrong parameter" is thrown - but why??? TileView.Children.Add(multiControl); multiControl.Delay(delayStart, () => { multiControl.FadeIn(100); }); } break; } }); } Dispatcher.BeginInvoke(() => { progress.IsVisible = false; }); } else { Dispatcher.BeginInvoke(() => { progress.IsVisible = false; if (result.Status == ServerStatus.Unauthorized) { MessageBox.Show("FetchFile_Unauthorized".Translate(), "Error_Caption".Translate(), MessageBoxButton.OK); } else { MessageBox.Show("FetchFile_Unexpected_Result".Translate(), "Error_Caption".Translate(), MessageBoxButton.OK); } }); } }