コード例 #1
0
        public async Task StartDirectoryListing(ResourceInfo resourceInfoToExclude, string viewName = null)
        {
            // clear instantly, so the user will not see invalid listings
            FilesAndFolders.Clear();
            Folders.Clear();

            var client = await ClientService.GetClient();

            if (client == null || IsSelecting)
            {
                return;
            }

            _continueListing = true;

            if (PathStack.Count == 0)
            {
                PathStack.Add(new PathInfo
                {
                    ResourceInfo = new ResourceInfo()
                    {
                        Name = "Nextcloud",
                        Path = "/"
                    },
                    IsRoot = true
                });
            }

            var path = PathStack.Count > 0 ? PathStack[PathStack.Count - 1].ResourceInfo.Path : "/";
            List <ResourceInfo> list = null;

            try
            {
                if (viewName == "sharesIn" | viewName == "sharesOut" | viewName == "sharesLink")
                {
                    PathStack.Clear();
                    list = await client.GetSharesView(viewName);
                }
                else if (viewName == "favorites")
                {
                    PathStack.Clear();
                    list = await client.GetFavorites();
                }
                else
                {
                    list = await client.List(path);
                }
            }
            catch (ResponseError e)
            {
                ResponseErrorHandlerService.HandleException(e);
            }

            if (list != null)
            {
                foreach (var item in list)
                {
                    if (resourceInfoToExclude != null && item == resourceInfoToExclude)
                    {
                        continue;
                    }

                    FilesAndFolders.Add(new FileOrFolder(item));

                    if (!item.IsDirectory)
                    {
                        continue;
                    }
                    if (RemoveResourceInfos != null)
                    {
                        var index = RemoveResourceInfos.FindIndex(res => res.Path.Equals(item.Path, StringComparison.Ordinal));
                        if (index == -1)
                        {
                            Folders.Add(new FileOrFolder(item));
                        }
                    }
                    else
                    {
                        Folders.Add(new FileOrFolder(item));
                    }
                }
            }

            switch (SettingsService.Instance.LocalSettings.PreviewImageDownloadMode)
            {
            case PreviewImageDownloadMode.Always:
                DownloadPreviewImages();
                break;

            case PreviewImageDownloadMode.WiFiOnly:
                var connectionProfile = NetworkInformation.GetInternetConnectionProfile();
                // connectionProfile can be null (e.g. airplane mode)
                if (connectionProfile != null && connectionProfile.IsWlanConnectionProfile)
                {
                    DownloadPreviewImages();
                }
                break;

            case PreviewImageDownloadMode.Never:
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            SortList();
        }
コード例 #2
0
        public async Task <bool> StartSync()
        {
            if (!SyncDbUtils.LockFolderSyncInfo(_folderSyncInfo))
            {
                return(false);
            }

            try
            {
                _client = await ClientService.GetClient();

                if (_client == null)
                {
                    // ERROR
                    throw new NullReferenceException(_resourceLoader.GetString(ResourceConstants.SyncService_Error_CannotCreateClient));
                }

                var changedCount = 0;
                var oldList      = SyncDbUtils.GetAllSyncInfoDetails(_folderSyncInfo);
                Debug.WriteLine("Sid List before Sync: ");

                foreach (var detail in oldList)
                {
                    Debug.WriteLine("Detail: " + detail);
                }

                var sid        = SyncDbUtils.GetSyncInfoDetail(_resourceInfo, _folderSyncInfo);
                var errorCount = 0;

                try
                {
                    if (sid == null)
                    {
                        sid = new SyncInfoDetail(_folderSyncInfo)
                        {
                            Path     = _resourceInfo.Path,
                            FilePath = _baseFolder.Path,
                        };

                        SyncDbUtils.SaveSyncInfoDetail(sid);
                    }
                    else
                    {
                        _sidList.Remove(sid);
                        sid.Error = null;
                    }

                    changedCount = await SyncFolder(_resourceInfo, _baseFolder);

                    foreach (var detail in oldList)
                    {
                        if (_sidList.Contains(detail) || !detail.FilePath.StartsWith(_baseFolder.Path))
                        {
                            continue;
                        }
                        // The items left here must have been deleted both remotely and locally so the sid is obsolete.
                        SyncDbUtils.DeleteSyncInfoDetail(detail, false);
                        changedCount++;
                    }
                    errorCount = SyncDbUtils.GetErrorConflictCount(_folderSyncInfo);
                }
                catch (Exception e)
                {
                    sid.Error = string.Format(_resourceLoader.GetString("UnexpectedException"), e.Message);
                    errorCount++;
                }

                SyncDbUtils.SaveSyncInfoDetail(sid);
                var newSidList = SyncDbUtils.GetAllSyncInfoDetails(_folderSyncInfo);
                Debug.WriteLine("Sid List after Sync: ");

                foreach (var detail in newSidList)
                {
                    Debug.WriteLine("Detail: " + detail);
                }

                ToastNotificationService.ShowSyncFinishedNotification(_folderSyncInfo.Path, changedCount, errorCount);
                return(errorCount == 0);
            }
            finally
            {
                SyncDbUtils.UnlockFolderSyncInfo(_folderSyncInfo);
            }
        }
コード例 #3
0
        public async Task <bool> StartSync()
        {
            if (!SyncDbUtils.LockFolderSyncInfo(folderSyncInfo))
            {
                return(false);
            }

            try
            {
                client = await ClientService.GetClient();

                if (client == null)
                {
                    // ERROR
                    throw new Exception("Error creating webdav client");
                }

                int changedCount = 0;
                List <SyncInfoDetail> oldList = SyncDbUtils.GetAllSyncInfoDetails(folderSyncInfo);
                Debug.WriteLine("Sid List before Sync: ");

                foreach (SyncInfoDetail detail in oldList)
                {
                    Debug.WriteLine("Detail: " + detail.ToString());
                }

                var sid        = SyncDbUtils.GetSyncInfoDetail(resourceInfo, folderSyncInfo);
                var errorCount = 0;

                try
                {
                    if (sid == null)
                    {
                        sid = new SyncInfoDetail(folderSyncInfo)
                        {
                            Path     = resourceInfo.Path,
                            FilePath = baseFolder.Path,
                        };

                        SyncDbUtils.SaveSyncInfoDetail(sid);
                    }
                    else
                    {
                        sidList.Remove(sid);
                        sid.Error = null;
                    }

                    changedCount = await SyncFolder(resourceInfo, baseFolder);

                    foreach (SyncInfoDetail detail in oldList)
                    {
                        if (!sidList.Contains(detail) && detail.FilePath.StartsWith(baseFolder.Path))
                        {
                            // The items left here must have been deleted both remotely and locally so the sid is obsolete.
                            SyncDbUtils.DeleteSyncInfoDetail(detail, false);
                            changedCount++;
                        }
                    }
                    errorCount = SyncDbUtils.GetErrorConflictCount(folderSyncInfo);
                }
                catch (Exception e)
                {
                    sid.Error = e.Message;
                    errorCount++;
                }

                SyncDbUtils.SaveSyncInfoDetail(sid);
                List <SyncInfoDetail> newSidList = SyncDbUtils.GetAllSyncInfoDetails(folderSyncInfo);
                Debug.WriteLine("Sid List after Sync: ");

                foreach (SyncInfoDetail detail in newSidList)
                {
                    Debug.WriteLine("Detail: " + detail.ToString());
                }

                ToastNotificationService.ShowSyncFinishedNotification(folderSyncInfo.Path, changedCount, errorCount);
                return(errorCount == 0);
            }
            finally
            {
                SyncDbUtils.UnlockFolderSyncInfo(folderSyncInfo);
            }
        }
コード例 #4
0
        public async Task StartDirectoryListing(ResourceInfo resourceInfoToExclude)
        {
            var client = await ClientService.GetClient();

            if (client == null || IsSelecting)
            {
                return;
            }

            _continueListing = true;

            var path = PathStack.Count > 0 ? PathStack[PathStack.Count - 1].ResourceInfo.Path : "/";
            List <ResourceInfo> list = null;

            try
            {
                list = await client.List(path);
            }
            catch (ResponseError e)
            {
                ResponseErrorHandlerService.HandleException(e);
            }

            FilesAndFolders.Clear();
            Folders.Clear();

            if (list != null)
            {
                foreach (var item in list)
                {
                    if (resourceInfoToExclude != null && item == resourceInfoToExclude)
                    {
                        continue;
                    }

                    FilesAndFolders.Add(new FileOrFolder(item));

                    if (item.IsDirectory)
                    {
                        if (RemoveResourceInfos != null)
                        {
                            int index = RemoveResourceInfos.FindIndex(
                                delegate(ResourceInfo res)
                            {
                                return(res.Path.Equals(item.Path, StringComparison.Ordinal));
                            });
                            if (index == -1)
                            {
                                Folders.Add(new FileOrFolder(item));
                            }
                        }
                        else
                        {
                            Folders.Add(new FileOrFolder(item));
                        }
                    }
                }
            }

            switch (SettingsService.Instance.LocalSettings.PreviewImageDownloadMode)
            {
            case PreviewImageDownloadMode.Always:
                DownloadPreviewImages();
                break;

            case PreviewImageDownloadMode.WiFiOnly:
                var connectionProfile = NetworkInformation.GetInternetConnectionProfile();
                // connectionProfile can be null (e.g. airplane mode)
                if (connectionProfile != null && connectionProfile.IsWlanConnectionProfile)
                {
                    DownloadPreviewImages();
                }
                break;

            case PreviewImageDownloadMode.Never:
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            SortList();
        }