예제 #1
0
        void _EndRequest(IAsyncResult result)
        {
            RequestStruct obj = (RequestStruct)result.AsyncState;

            try
            {
                // must catch "NotFoundError" when 5xx occurs (likely is)
                HttpWebResponse  response      = obj.Request.EndGetResponse(result) as HttpWebResponse;
                DAVRequestResult requestResult = new DAVRequestResult(this, response, _relativeHost);
                obj.Callback(requestResult, obj.UserObject);
            }
            catch (WebException we)
            {
                LastException = we;
                obj.Callback(new DAVRequestResult(this, ServerStatus.InternalServerError), obj.UserObject);
            }
        }
예제 #2
0
        /// <summary>
        /// Tries to fetch a given path and refreshes the views.
        /// </summary>
        /// <param name="path"></param>
        private void FetchStructure(string path)
        {
            _board = (Storyboard)Resources["DropFileListFadeOut"] as Storyboard;

            if (_dropFileListFadeOutCompleted == null)
            {
                _dropFileListFadeOutCompleted = new EventHandler(delegate
                {
                    _context.Files.Clear();
                    _collector.Raise(_dropFileListFadeOutCompleted);
                });
                _board.Completed += _dropFileListFadeOutCompleted;
            }

            if (_overlay == null)
            {
                _overlay = new ProgressOverlayPopup()
                {
                    BackgroundColor = Colors.Transparent
                };

            }
            _overlay.Show();

            _result = null;
            _board.Begin();
            _collector.WaitFor(_dropFileListFadeOutCompleted);
            _collector.WaitFor("FileListReceived");

            _collector.Complete = () =>
            {
                FetchStructureCompleteHandler(_result);
                Dispatcher.BeginInvoke(() =>
                {
                    ((Storyboard)Resources["DropFileListFadeIn"] as Storyboard).Begin();
                    _overlay.Hide();
                });
            };

            if (_workingAccount != null)
            {
                var dav = new WebDAV(_workingAccount.GetUri(), _workingAccount.GetCredentials());
                dav.StartRequest(DAVRequestHeader.CreateListing(path), DAVRequestBody.CreateAllPropertiesListing(), null, FetchStructureComplete);
            }
        }
예제 #3
0
        private void FetchStructureCompleteHandler(DAVRequestResult result)
        {
            if (result.Status == ServerStatus.MultiStatus && !result.Request.ErrorOccured && result.Items.Count > 0)
            {
                //Utility.DebugXML(result.GetRawResponse());
                var first_item = false;

                foreach (DAVRequestResult.Item item in result.Items)
                {
                    Dispatcher.BeginInvoke(() =>
                    {
                        // a first element usually is the root folder
                        // and the name is empty
                        if (!first_item)
                        {
                            first_item = true;

                            if (item.Reference == _workingAccount.WebDAVPath)
                            {
                                // cannot go up further
                                ToggleDirectoryUpStatus(false);
                                _directoryUpReference = null;
                                CurrentDirectoryName.Text = "";
                            }
                            else
                            {
                                ToggleDirectoryUpStatus(true);
                                _directoryUpReference = item.ParentReference;
                                CurrentDirectoryName.Text = item.LocalReference;
                            }
                        }
                        else
                        {
                            _context.Files.Add(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
                            });
                        }
                    });
                }
            }
            else
            {
                Dispatcher.BeginInvoke(() =>
                {
                    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);
                    }
                });
            }
        }
예제 #4
0
 private void FetchStructureComplete(DAVRequestResult result, object userObj)
 {
     _result = result;
     _collector.Raise("FileListReceived");
 }
예제 #5
0
 void _EndRequest(IAsyncResult result)
 {
     RequestStruct obj = (RequestStruct)result.AsyncState;
     try
     {
         // must catch "NotFoundError" when 5xx occurs (likely is)
         HttpWebResponse response = obj.Request.EndGetResponse(result) as HttpWebResponse;
         DAVRequestResult requestResult = new DAVRequestResult(this, response, _relativeHost);
         obj.Callback(requestResult, obj.UserObject);
     }
     catch (WebException we)
     {
         LastException = we;
         obj.Callback(new DAVRequestResult(this, ((HttpWebResponse)we.Response).StatusCode, ((HttpWebResponse)we.Response).StatusDescription), obj.UserObject);
     }
 }
예제 #6
0
        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);
                    }
                });
            }
        }