Ejemplo n.º 1
0
        /// <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);
            }
        }
Ejemplo n.º 2
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);
            }
        }
Ejemplo n.º 3
0
        /// <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);
            }
        }