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 { 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()); } }
/// <param name="itemIdentifier">The persistent identifier for the item.</param> /// <param name="destParentItemIdentifier">The parent directory's persistent identifier.</param> /// <param name="newName"> /// <para>The new name for the item.</para> /// <para tool="nullallowed">This parameter can be <see langword="null" />.</para> /// </param> /// <param name="completionHandler">A handler to run after the operation completes.</param> /// <summary>When implemented by the developer, moves the identified item to a new name under a new parent.</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 ReparentItem(string itemIdentifier, string destParentItemIdentifier, string newName, Action <INSFileProviderItem, NSError> completionHandler) { try { ItemMetadata item = this.StorageManager.GetItemMetadata(itemIdentifier); FolderMetadata destinationFolder = this.StorageManager.GetFolderMetadata(destParentItemIdentifier); string name = newName ?? item.Name; this.StorageManager.MoveItem(item, destinationFolder, name); // Only item's name and parent identifier should be changed. string oldParentIdentifier = item.ParentIdentifier; item.ParentIdentifier = destParentItemIdentifier; item.Name = name; completionHandler(ProviderItem.CreateFromMetadata(item), null); this.StorageManager.NotifyEnumerator(oldParentIdentifier, item.ParentIdentifier); } catch (PreconditionFailedException) { completionHandler?.Invoke(null, NSFileProviderErrorFactory.CreateFilenameCollisionError()); } catch (ForbiddenException) { completionHandler?.Invoke(null, NSFileProviderErrorFactory.CreateFilenameCollisionError()); } catch (Exception ex) { NSError error = this.MapError(ex); completionHandler?.Invoke(null, error); } }
/// <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="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); } }
/// <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(); } }
/// <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); } }
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()); } }
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); }
/// <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); } }
/// <param name="itemIdentifier">The persistent identifier for the item.</param> /// <param name="completionHandler">A handler to run after the operation completes.</param> /// <summary>When implemented by the developer, deletes the identified item 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 DeleteItem(string itemIdentifier, Action <NSError> completionHandler) { try { ItemMetadata metadata = this.StorageManager.GetItemMetadata(itemIdentifier); if (!metadata.IsExists) { completionHandler?.Invoke(null); return; } this.StorageManager.Delete(metadata); completionHandler?.Invoke(null); } catch (MethodNotAllowedException) { completionHandler?.Invoke(NSFileProviderErrorFactory.CreateFilenameCollisionError()); } catch (Exception ex) { NSError error = this.MapError(ex); completionHandler?.Invoke(error); } }