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());
            }
        }
        /// <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());
            }
        }
        /// <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());
            }
        }
예제 #4
0
        /// <param name="url">The shared document's URL.</param>
        /// <param name="completionHandler">
        ///   <para>An action the system calls subsequent to the creation of a placeholder.</para>
        ///   <para tool="nullallowed">This parameter can be <see langword="null" />.</para>
        /// </param>
        /// <summary>When implemented by the developer, creates a specified placeholder for a previously defined URL.</summary>
        /// <remarks>
        ///   <para>The developer must override this method. This method is called to provide a placeholder for documents that are returned by the Document Picker but that are not locally stored.</para>
        ///   <para tool="threads">This can be used from a background thread.</para>
        /// </remarks>
        public override void ProvidePlaceholderAtUrl(NSUrl url, Action <NSError> completionHandler)
        {
            try
            {
                string       identifier   = this.GetPersistentIdentifier(url);
                ItemMetadata itemMetadata = this.StorageManager.GetItemMetadata(identifier);
                if (!itemMetadata.IsExists)
                {
                    completionHandler?.Invoke(NSFileProviderErrorFactory.CreateNonExistentItemError(identifier));
                    return;
                }
                NSUrl   placeholderUrl = NSFileProviderManager.GetPlaceholderUrl(url);
                NSError error;
                NSFileManager.DefaultManager.CreateDirectory(placeholderUrl.RemoveLastPathComponent(), true, null, out error);
                if (error != null)
                {
                    completionHandler?.Invoke(error);
                    return;
                }

                INSFileProviderItem providerItem = ProviderItem.CreateFromMetadata(itemMetadata);
                NSFileProviderManager.WritePlaceholder(placeholderUrl, providerItem, out error);
                completionHandler?.Invoke(error);
            }
            catch (Exception ex)
            {
                NSError error = this.MapError(ex);
                completionHandler?.Invoke(error);
            }
        }
예제 #5
0
        /// <param name="fileUrl">The URL for the file.</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, imports the resource at the specified <paramref name="fileUrl" /> into the directory that is identified by <paramref name="parentItemIdentifier" />.</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 ImportDocument(NSUrl fileUrl, string parentItemIdentifier, Action <INSFileProviderItem, NSError> completionHandler)
        {
            try
            {
                fileUrl.StartAccessingSecurityScopedResource();
                FolderMetadata parentMetadata = StorageManager.GetFolderMetadata(parentItemIdentifier);
                if (!parentMetadata.IsExists)
                {
                    completionHandler?.Invoke(null, NSFileProviderErrorFactory.CreateNonExistentItemError(parentItemIdentifier));
                    return;
                }

                IEnumerable <string> existsNames = StorageManager.GetFolderChildrenMetadatas(parentMetadata).Select(x => x.Name);
                string       fileName            = GetNewFileName(fileUrl.LastPathComponent, existsNames);
                FileMetadata createdFile         = StorageManager.CreateFileOnServer(parentMetadata, fileName);
                createdFile = StorageManager.WriteFileContentOnServer(createdFile, fileUrl.Path);
                completionHandler?.Invoke(ProviderItem.CreateFromMetadata(createdFile), null);
                this.StorageManager.NotifyEnumerator(parentItemIdentifier);
            }
            catch (Exception ex)
            {
                NSError error = this.MapError(ex);
                completionHandler?.Invoke(null, error);
            }
            finally
            {
                fileUrl.StopAccessingSecurityScopedResource();
            }
        }
예제 #6
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());
            }
        }
예제 #7
0
        public override INSFileProviderItem GetItem(NSString identifier, out NSError error)
        {
            error = null;
            try
            {
                ItemMetadata itemMetadata = this.StorageManager.GetItemMetadata(identifier);
                if (!itemMetadata.IsExists)
                {
                    error = NSFileProviderErrorFactory.CreateNonExistentItemError(identifier);
                    return(null);
                }

                return(ProviderItem.CreateFromMetadata(itemMetadata));
            }
            catch (Exception ex)
            {
                error = this.MapError(ex);
            }

            return(null);
        }
예제 #8
0
        /// <param name="url">The shared document's URL.</param>
        /// <summary>When implemented by the developer, informs a file provider extension that there has been a change in a document.</summary>
        /// <remarks>
        ///   <para>You must override this method.Do not call super.</para>
        ///   <para tool="threads">This can be used from a background thread.</para>
        /// </remarks>
        public override void ItemChangedAtUrl(NSUrl url)
        {
            string identifier = this.GetPersistentIdentifier(url);

            try
            {
                FileMetadata item = this.StorageManager.GetFileMetadata(identifier);
                if (!item.ExistsLocal)
                {
                    throw NSFileProviderErrorFactory.CreateNonExistentItemError().AsException();
                }

                item = StorageManager.ResetLocalVersion(item);
                this.StorageManager.PushToServer(item);
            }
            catch (Exception e)
            {
                NSError localFileUploadError = MapError(e);
                StorageManager.SetUploadError(url, localFileUploadError);
            }
        }