/// <param name="observer">To be added.</param>
        /// <param name="startPage">To be added.</param>
        /// <summary>To be added.</summary>
        /// <remarks>To be added.</remarks>
        public void EnumerateItems(INSFileProviderEnumerationObserver observer, NSData startPage)
        {
            try
            {
                FolderMetadata metadata = storageManager.GetFolderMetadata(this.enumeratedItemIdentifier);
                if (!metadata.IsExists)
                {
                    observer.FinishEnumerating(NSFileProviderErrorFactory.CreateNonExistentItemError(enumeratedItemIdentifier));
                    return;
                }

                ItemMetadata[] metadatas = this.storageManager.GetFolderChildrenMetadatas(metadata);
                this.SyncAnchor = this.synchronizationSimulator.AddChangeSet(metadatas);

                INSFileProviderItem[] items = ProviderItem.CreateFromMetadatas(metadatas);
                observer.DidEnumerateItems(items);
                observer.FinishEnumerating((NSData)null);
            }
            catch (UnauthorizedException)
            {
                observer.FinishEnumerating(NSFileProviderErrorFactory.CreatesNotAuthenticatedError());
            }
            catch (WebDavHttpException)
            {
                observer.FinishEnumerating(NSErrorFactory.CreateUnspecifiedNetworkError());
            }
            catch (Exception)
            {
                observer.FinishEnumerating(NSErrorFactory.CreateUnspecifiedError());
            }
        }
        public void EnumerateChanges(INSFileProviderChangeObserver observer, NSData syncAnchor)
        {
            uint anchor = GetAnchorFromNsData(syncAnchor);

            try
            {
                FolderMetadata metadata = storageManager.GetFolderMetadata(this.enumeratedItemIdentifier);
                if (!metadata.IsExists)
                {
                    observer.FinishEnumerating(NSFileProviderErrorFactory.CreateNonExistentItemError(enumeratedItemIdentifier));
                    return;
                }

                ItemMetadata[] metadatas = this.storageManager.GetFolderChildrenMetadatas(metadata);
                ChangeSet      diff      = this.synchronizationSimulator.GetDiff(anchor, metadatas);
                observer.DidDeleteItems(diff.DeletedId);
                INSFileProviderItem[] updatedItems = ProviderItem.CreateFromMetadatas(diff.Updated);
                observer.DidUpdateItems(updatedItems);

                this.SyncAnchor = this.synchronizationSimulator.AddChangeSet(metadatas);
                observer.FinishEnumeratingChanges(this.GetCurrentAnchorNsData(this.SyncAnchor), false);
            }
            catch (UnauthorizedException)
            {
                observer.FinishEnumerating(NSFileProviderErrorFactory.CreatesNotAuthenticatedError());
            }
            catch (WebDavHttpException)
            {
                observer.FinishEnumerating(NSErrorFactory.CreateUnspecifiedNetworkError());
            }
            catch (Exception)
            {
                observer.FinishEnumerating(NSErrorFactory.CreateUnspecifiedError());
            }
        }
        public void EnumerateChanges(INSFileProviderChangeObserver observer, NSData syncAnchor)
        {
            try
            {
                FileMetadata metadata = storageManager.GetFileMetadata(this.EnumeratedItemIdentifier);
                if (!metadata.IsExists)
                {
                    observer.DidDeleteItems(new[] { EnumeratedItemIdentifier });
                    observer.FinishEnumeratingChanges(this.GetNsDataFromUint(this.SyncAnchor++), false);
                    return;
                }

                observer.DidUpdateItems(new[] { ProviderItem.CreateFromMetadata(metadata) });
                observer.FinishEnumeratingChanges(this.GetNsDataFromUint(this.SyncAnchor++), false);
            }
            catch (UnauthorizedException)
            {
                observer.FinishEnumerating(NSFileProviderErrorFactory.CreatesNotAuthenticatedError());
            }
            catch (WebDavHttpException)
            {
                observer.FinishEnumerating(NSErrorFactory.CreateUnspecifiedNetworkError());
            }
            catch (Exception)
            {
                observer.FinishEnumerating(NSErrorFactory.CreateUnspecifiedError());
            }
        }
        /// <param name="observer">To be added.</param>
        /// <param name="startPage">To be added.</param>
        /// <summary>To be added.</summary>
        /// <remarks>To be added.</remarks>
        public void EnumerateItems(INSFileProviderEnumerationObserver observer, NSData startPage)
        {
            try
            {
                var metadata = storageManager.GetFileMetadata(this.EnumeratedItemIdentifier);
                if (!metadata.IsExists)
                {
                    observer.FinishEnumerating(NSFileProviderErrorFactory.CreateNonExistentItemError(EnumeratedItemIdentifier));
                    return;
                }

                INSFileProviderItem item = ProviderItem.CreateFromMetadata(metadata);
                observer.DidEnumerateItems(new[] { item });
                observer.FinishEnumerating((NSData)null);
            }
            catch (UnauthorizedException)
            {
                observer.FinishEnumerating(NSFileProviderErrorFactory.CreateNonExistentItemError(this.EnumeratedItemIdentifier));
            }
            catch (WebDavHttpException)
            {
                observer.FinishEnumerating(NSErrorFactory.CreateUnspecifiedNetworkError());
            }
            catch (Exception)
            {
                observer.FinishEnumerating(NSErrorFactory.CreateUnspecifiedError());
            }
        }
Exemple #5
0
        /// <param name="directoryName">The directory name.</param>
        /// <param name="parentItemIdentifier">The parent directory's persistent identifier.</param>
        /// <param name="completionHandler">A handler to run after the operation completes.</param>
        /// <summary>When implemented by the developer, creates a new directory in the specified location and runs a handler when the operation is complete.</summary>
        /// <remarks>
        ///   <para>(More documentation for this node is coming)</para>
        ///   <para tool="threads">This can be used from a background thread.</para>
        /// </remarks>
        public override void CreateDirectory(string directoryName, string parentItemIdentifier, Action <INSFileProviderItem, NSError> completionHandler)
        {
            try
            {
                FolderMetadata parentFolder = this.StorageManager.GetFolderMetadata(parentItemIdentifier);
                if (!parentFolder.ExistsOnServer)
                {
                    completionHandler?.Invoke(null, NSErrorFactory.CreateUnspecifiedError());
                    return;
                }

                FolderMetadata createdFolder = this.StorageManager.CreateFolderOnServer(parentFolder, directoryName);
                completionHandler?.Invoke(ProviderItem.CreateFromMetadata(createdFolder), null);
                this.StorageManager.NotifyEnumerator(parentItemIdentifier);
            }
            catch (MethodNotAllowedException)
            {
                completionHandler?.Invoke(null, NSFileProviderErrorFactory.CreateFilenameCollisionError());
            }
            catch (Exception ex)
            {
                NSError error = this.MapError(ex);
                completionHandler?.Invoke(null, error);
            }
        }
Exemple #6
0
        /// <summary>The create upload uploadError.</summary>
        /// <returns>The <see cref="NSError"/>.</returns>
        private NSError CreateUploadError()
        {
            if (string.IsNullOrEmpty(this.UploadErrorDomain))
            {
                return(null);
            }

            if (this.UploadErrorInfo == null)
            {
                return(NSErrorFactory.CreateNSError(this.UploadErrorDomain, this.UploadErrorCode));
            }

            Dictionary <string, string> uploadErrorInfo = this.UploadErrorInfo;

            return(NSErrorFactory.CreateNSError(this.UploadErrorDomain, this.UploadErrorCode, uploadErrorInfo));
        }
Exemple #7
0
        private NSError MapError(Exception localFileUploadError)
        {
            switch (localFileUploadError)
            {
            case NSErrorException error:
                return(error.Error);

            case NotFoundException _:
                return(NSFileProviderErrorFactory.CreateNonExistentItemError());

            case UnauthorizedException _:
                return(NSFileProviderErrorFactory.CreatesNotAuthenticatedError());

            case WebDavHttpException _:
                return(NSErrorFactory.CreateUnspecifiedNetworkError());

            default:
                return(NSErrorFactory.CreateUnspecifiedError());
            }
        }