From 36951e97c0d6cf9afb64e1c1d37b30a26479028f Mon Sep 17 00:00:00 2001 From: Alex Soto Date: Thu, 29 Jun 2017 22:27:56 -0500 Subject: [PATCH 1/5] [FileProvider] Add Xcode 9 Beta 1 Bindings --- src/Constants.iOS.cs.in | 1 + src/fileprovider.cs | 301 ++++++++++++++++++ src/foundation.cs | 20 ++ src/frameworks.sources | 1 + src/generator.cs | 2 + src/uikit.cs | 96 ++++++ tests/introspection/ApiSignatureTest.cs | 4 + tests/introspection/ApiTypoTest.cs | 1 + tests/introspection/iOS/iOSApiProtocolTest.cs | 3 + tools/common/Frameworks.cs | 1 + 10 files changed, 430 insertions(+) create mode 100644 src/fileprovider.cs diff --git a/src/Constants.iOS.cs.in b/src/Constants.iOS.cs.in index 27e6a28f6794..7d9412c2d961 100644 --- a/src/Constants.iOS.cs.in +++ b/src/Constants.iOS.cs.in @@ -113,5 +113,6 @@ namespace MonoTouch { public const string IdentityLookupLibrary = "/System/Library/Frameworks/IdentityLookup.framework/IdentityLookup"; public const string CoreMLLibrary = "/System/Library/Frameworks/CoreML.framework/CoreML"; public const string VisionLibrary = "/System/Library/Frameworks/Vision.framework/Vision"; + public const string FileProviderLibrary = "/System/Library/Frameworks/FileProvider.framework/FileProvider"; } } diff --git a/src/fileprovider.cs b/src/fileprovider.cs new file mode 100644 index 000000000000..5787aa9b3263 --- /dev/null +++ b/src/fileprovider.cs @@ -0,0 +1,301 @@ +// +// FileProvider C# bindings +// +// Authors: +// Alex Soto +// +// Copyright 2017 Xamarin Inc. All rights reserved. +// + +#if XAMCORE_2_0 + +using System; +using XamCore.ObjCRuntime; +using XamCore.CoreGraphics; +using XamCore.Foundation; + +namespace XamCore.FileProvider { + + [iOS (11,0)] + [ErrorDomain ("NSFileProviderErrorDomain")] + [Native] + public enum NSFileProviderErrorCode : nint { + NotAuthenticated = -1000, + FilenameCollision = -1001, + SyncAnchorExpired = -1002, + InsufficientQuota = -1003, + ServerUnreachable = -1004, + NoSuchItem = -1005 + } + + [iOS (11,0)] + enum NSFileProviderItemIdentifier { + // Lets follow swift names + [Field ("NSFileProviderRootContainerItemIdentifier")] + RootContainer, + + [Field ("NSFileProviderWorkingSetContainerItemIdentifier")] + WorkingSet, + + [Field ("NSFileProviderAllDirectoriesContainerItemIdentifier")] + AllDirectories, + } + + [iOS (11,0)] + [Native] + [Flags] + public enum NSFileProviderItemCapabilities : nuint { + Reading = 1 << 0, + Writing = 1 << 1, + Reparenting = 1 << 2, + Renaming = 1 << 3, + Trashing = 1 << 4, + Deleting = 1 << 5, + AddingSubItems = Writing, + ContentEnumerating = Reading, + All = Reading | Writing | Reparenting | Renaming | Trashing | Deleting + } + + [iOS (11,0)] + [DisableDefaultCtor] + [BaseType (typeof (NSObject))] + interface NSFileProviderDomain { + + [Export ("initWithIdentifier:displayName:pathRelativeToDocumentStorage:")] + IntPtr Constructor (string identifier, string displayName, string pathRelativeToDocumentStorage); + + [Export ("identifier")] + string Identifier { get; } + + [Export ("displayName")] + string DisplayName { get; } + + [Export ("pathRelativeToDocumentStorage")] + string PathRelativeToDocumentStorage { get; } + } + + interface INSFileProviderEnumerationObserver { } + + [iOS (11,0)] + [Protocol] + interface NSFileProviderEnumerationObserver { + + [Abstract] + [Export ("didEnumerateItems:")] + void DidEnumerateItems (INSFileProviderItem [] updatedItems); + + [Abstract] + [Export ("finishEnumeratingUpToPage:")] + void FinishEnumerating ([NullAllowed] NSData nextPage); + + [Abstract] + [Export ("finishEnumeratingWithError:")] + void FinishEnumerating (NSError error); + } + + interface INSFileProviderChangeObserver { } + + [iOS (11,0)] + [Protocol] + interface NSFileProviderChangeObserver { + + [Abstract] + [Export ("didUpdateItems:")] + void DidUpdateItems (INSFileProviderItem [] updatedItems); + + [Abstract] + [Export ("didDeleteItemsWithIdentifiers:")] + void DidDeleteItems (string [] deletedItemIdentifiers); + + [Abstract] + [Export ("finishEnumeratingChangesUpToSyncAnchor:moreComing:")] + void FinishEnumeratingChanges (NSData anchor, bool moreComing); + + [Abstract] + [Export ("finishEnumeratingWithError:")] + void FinishEnumerating (NSError error); + } + + interface INSFileProviderEnumerator { } + + [iOS (11,0)] + [Protocol] + interface NSFileProviderEnumerator { + + [Abstract] + [Export ("invalidate")] + void Invalidate (); + + [Abstract] + [Export ("enumerateItemsForObserver:startingAtPage:")] + void EnumerateItems (INSFileProviderEnumerationObserver observer, NSData page); + + [Export ("enumerateChangesForObserver:fromSyncAnchor:")] + void EnumerateChanges (INSFileProviderChangeObserver observer, NSData anchor); + + [Export ("currentSyncAnchorWithCompletionHandler:")] + void CurrentSyncAnchor (Action completionHandler); + } + + interface INSFileProviderItem { } + + [iOS (11,0)] + [Protocol] + interface NSFileProviderItem { + + [Advice ("Use 'NSFileProviderItemIdentifierExtensions.GetValue (ItemIdentifier)' to get a 'NSFileProviderItemIdentifier' enum.")] + [Abstract] + [Export ("itemIdentifier")] + NSString ItemIdentifier { get; } + + [Advice ("Use 'NSFileProviderItemIdentifierExtensions.GetValue (ParentItemIdentifier)' to get a 'NSFileProviderItemIdentifier' enum.")] + [Abstract] + [Export ("parentItemIdentifier")] + NSString ParentItemIdentifier { get; } + + [Abstract] + [Export ("filename")] + string Filename { get; } + + [Abstract] + [Export ("typeIdentifier")] + string TypeIdentifier { get; } + + [Export ("capabilities")] + NSFileProviderItemCapabilities GetCapabilities (); + + [return: NullAllowed] + [Export ("documentSize", ArgumentSemantic.Copy)] + NSNumber GetDocumentSize (); + + [return: NullAllowed] + [Export ("childItemCount", ArgumentSemantic.Copy)] + NSNumber GetChildItemCount (); + + [return: NullAllowed] + [Export ("creationDate", ArgumentSemantic.Copy)] + NSDate GetCreationDate (); + + [return: NullAllowed] + [Export ("contentModificationDate", ArgumentSemantic.Copy)] + NSDate GetContentModificationDate (); + + [return: NullAllowed] + [Export ("lastUsedDate", ArgumentSemantic.Copy)] + NSDate GetLastUsedDate (); + + [return: NullAllowed] + [Export ("tagData", ArgumentSemantic.Copy)] + NSData GetTagData (); + + [return: NullAllowed] + [Export ("favoriteRank", ArgumentSemantic.Copy)] + NSNumber GetFavoriteRank (); + + [Export ("isTrashed")] + bool IsTrashed (); + + [Export ("isUploaded")] + bool IsUploaded (); + + [Export ("isUploading")] + bool IsUploading (); + + [return: NullAllowed] + [Export ("uploadingError", ArgumentSemantic.Copy)] + NSError GetUploadingError (); + + [Export ("isDownloaded")] + bool IsDownloaded (); + + [Export ("isDownloading")] + bool IsDownloading (); + + [return: NullAllowed] + [Export ("downloadingError", ArgumentSemantic.Copy)] + NSError GetDownloadingError (); + + [Export ("isMostRecentVersionDownloaded")] + bool IsMostRecentVersionDownloaded (); + + [Export ("isShared")] + bool IsShared (); + + [Export ("isSharedByCurrentUser")] + bool IsSharedByCurrentUser (); + + [return: NullAllowed] + [Export ("ownerNameComponents")] + NSPersonNameComponents GetOwnerNameComponents (); + + [return: NullAllowed] + [Export ("mostRecentEditorNameComponents")] + NSPersonNameComponents GetMostRecentEditorNameComponents (); + + [return: NullAllowed] + [Export ("versionIdentifier")] + NSData GetVersionIdentifier (); + + [return: NullAllowed] + [Export ("userInfo")] + NSDictionary GetUserInfo (); + } + + [iOS (11,0)] + [BaseType (typeof (NSObject))] + [DisableDefaultCtor] + interface NSFileProviderManager { + + [Static] + [Export ("defaultManager", ArgumentSemantic.Strong)] + NSFileProviderManager DefaultManager { get; } + + [Export ("signalEnumeratorForContainerItemIdentifier:completionHandler:")] + // Not Async'ified on pruppose, because this can switch from app to extension. + void SignalEnumerator (/*[BindAs (typeof (NSFileProviderItemIdentifier))]*/ NSString containerItemIdentifier, Action completion); + + // Not Async'ified on pruppose, because the task must be accesed while the completion action is performing... + [Export ("registerURLSessionTask:forItemWithIdentifier:completionHandler:")] + void Register (NSUrlSessionTask task, /*[BindAs (typeof (NSFileProviderItemIdentifier))]*/ NSString identifier, Action completion); + + [Export ("providerIdentifier")] + string ProviderIdentifier { get; } + + [Export ("documentStorageURL")] + NSUrl DocumentStorageUrl { get; } + + [Static] + [Export ("writePlaceholderAtURL:withMetadata:error:")] + bool WritePlaceholder (NSUrl placeholderUrl, INSFileProviderItem metadata, out NSError error); + + [Static] + [Export ("placeholderURLForURL:")] + NSUrl GetPlaceholderUrl (NSUrl url); + + [Static] + [Async] + [Export ("addDomain:completionHandler:")] + void AddDomain (NSFileProviderDomain domain, Action completionHandler); + + [Static] + [Async] + [Export ("removeDomain:completionHandler:")] + void RemoveDomain (NSFileProviderDomain domain, Action completionHandler); + + [Static] + [Async] + [Export ("getDomainsWithCompletionHandler:")] + void GetDomains (Action, NSError> completionHandler); + + [Static] + [Async] + [Export ("removeAllDomainsWithCompletionHandler:")] + void RemoveAllDomains (Action completionHandler); + + [Static] + [Export ("managerForDomain:")] + [return: NullAllowed] + NSFileProviderManager FromDomain (NSFileProviderDomain domain); + } +} +#endif diff --git a/src/foundation.cs b/src/foundation.cs index bb01d9299210..f62dc7117dee 100644 --- a/src/foundation.cs +++ b/src/foundation.cs @@ -43,6 +43,9 @@ using XamCore.Security; #if IOS using XamCore.CoreSpotlight; +#if XAMCORE_2_0 +using XamCore.FileProvider; +#endif #endif #if MONOMAC @@ -3049,6 +3052,8 @@ interface NSEnumerator { NSObject NextObject (); } + interface INSFileProviderItem { } + [BaseType (typeof (NSObject))] [DisableDefaultCtor] interface NSError : NSSecureCoding, NSCopying { @@ -3180,6 +3185,21 @@ interface NSError : NSSecureCoding, NSCopying { [Export ("userInfoValueProviderForDomain:")] [return: NullAllowed] NSErrorUserInfoValueProvider GetUserInfoValueProvider (string errorDomain); + +#if XAMCORE_2_0 && IOS + + // From NSError (NSFileProviderError) Category to avoid static category uglyness + + [iOS (11,0)] + [Static] + [Export ("fileProviderErrorForCollisionWithItem:")] + NSError GetFileProviderError (INSFileProviderItem existingItem); + + [iOS (11,0)] + [Static] + [Export ("fileProviderErrorForNonExistentItemWithIdentifier:")] + NSError GetFileProviderErrorForNonExistentItem (string itemIdentifier); +#endif #if false // FIXME that value is present in the header (7.0 DP 6) files but returns NULL (i.e. unusable) diff --git a/src/frameworks.sources b/src/frameworks.sources index e6fcf529be16..6e6b70944e7f 100644 --- a/src/frameworks.sources +++ b/src/frameworks.sources @@ -1652,6 +1652,7 @@ IOS_FRAMEWORKS = \ EventKit \ EventKitUI \ ExternalAccessory \ + FileProvider \ GLKit \ GameController \ GameplayKit \ diff --git a/src/generator.cs b/src/generator.cs index 69d920a0fe83..59f01fb2da82 100644 --- a/src/generator.cs +++ b/src/generator.cs @@ -729,6 +729,8 @@ public NamespaceManager (string prefix, string customObjCRuntimeNS, bool skipSys ImplicitNamespaces.Add (Get ("GameplayKit")); if (Frameworks.HaveSpriteKit) ImplicitNamespaces.Add (Get ("SpriteKit")); + if (Frameworks.HaveFileProvider && Generator.UnifiedAPI) + ImplicitNamespaces.Add (Get ("FileProvider")); // These are both types and namespaces NamespacesThatConflictWithTypes = new HashSet { diff --git a/src/uikit.cs b/src/uikit.cs index b3a2bfd95deb..17e0e901f948 100644 --- a/src/uikit.cs +++ b/src/uikit.cs @@ -24,6 +24,10 @@ #endif using XamCore.CoreData; +#if XAMCORE_2_0 && IOS +using XamCore.FileProvider; +#endif + using System; using System.ComponentModel; @@ -277,21 +281,27 @@ interface NSDataAsset : NSCopying NSString TypeIdentifier { get; } } + delegate void NSFileProviderExtensionFetchThumbnailsHandler (NSString identifier, [NullAllowed] NSData imageData, [NullAllowed] NSError error); + [NoWatch] [NoTV] [iOS (8,0)] [ThreadSafe] [BaseType (typeof (NSObject))] partial interface NSFileProviderExtension { + [Deprecated (PlatformName.iOS, 11, 0, message: "Use 'NSFileProviderManager' instead.")] [Static, Export ("writePlaceholderAtURL:withMetadata:error:")] bool WritePlaceholder (NSUrl placeholderUrl, NSDictionary metadata, ref NSError error); + [Deprecated (PlatformName.iOS, 11, 0, message: "Use 'FileProvider.NSFileProviderManager.GetPlaceholderUrl (NSUrl)' instead.")] [Static, Export ("placeholderURLForURL:")] NSUrl GetPlaceholderUrl (NSUrl url); + [Deprecated (PlatformName.iOS, 11, 0, message: "Use 'FileProvider.NSFileProviderManager.ProviderIdentifier' instead.")] [Export ("providerIdentifier")] string ProviderIdentifier { get; } + [Deprecated (PlatformName.iOS, 11, 0, message: "Use 'FileProvider.NSFileProviderManager.DocumentStorageUrl' instead.")] [Export ("documentStorageURL")] NSUrl DocumentStorageUrl { get; } @@ -314,6 +324,92 @@ partial interface NSFileProviderExtension { [Export ("stopProvidingItemAtURL:")] void StopProvidingItemAtUrl (NSUrl url); + +#if XAMCORE_2_0 && IOS + + [iOS (11,0)] + [Export ("itemForIdentifier:error:")] + [return: NullAllowed] + XamCore.FileProvider.INSFileProviderItem GetItem (/*[BindAs (typeof (NSFileProviderItemIdentifier))]*/ NSString identifier, out NSError error); + + // Inlining NSFileProviderExtension (NSFileProviderActions) so we get asyncs + + [iOS (11,0)] + [Async] + [Export ("importDocumentAtURL:toParentItemIdentifier:completionHandler:")] + void ImportDocument (NSUrl fileUrl, string parentItemIdentifier, Action completionHandler); + + [iOS (11,0)] + [Async] + [Export ("createDirectoryWithName:inParentItemIdentifier:completionHandler:")] + void CreateDirectory (string directoryName, string parentItemIdentifier, Action completionHandler); + + [iOS (11,0)] + [Async] + [Export ("renameItemWithIdentifier:toName:completionHandler:")] + void RenameItem (string itemIdentifier, string itemName, Action completionHandler); + + [iOS (11,0)] + [Async] + [Export ("reparentItemWithIdentifier:toParentItemWithIdentifier:completionHandler:")] + void ReparentItem (string itemIdentifier, string parentItemIdentifier, Action completionHandler); + + [iOS (11,0)] + [Async] + [Export ("trashItemWithIdentifier:completionHandler:")] + void TrashItem (string itemIdentifier, Action completionHandler); + + [iOS (11,0)] + [Async] + [Export ("untrashItemWithIdentifier:toParentItemIdentifier:completionHandler:")] + void UntrashItem (string itemIdentifier, [NullAllowed] string parentItemIdentifier, Action completionHandler); + + [iOS (11,0)] + [Async] + [Export ("deleteItemWithIdentifier:completionHandler:")] + void DeleteItem (string itemIdentifier, Action completionHandler); + + [iOS (11,0)] + [Async] + [Export ("setLastUsedDate:forItemIdentifier:completionHandler:")] + void SetLastUsedDate ([NullAllowed] NSDate lastUsedDate, string itemIdentifier, Action completionHandler); + + [iOS (11,0)] + [Async] + [Export ("setTagData:forItemIdentifier:completionHandler:")] + void SetTagData ([NullAllowed] NSData tagData, string itemIdentifier, Action completionHandler); + + [iOS (11,0)] + [Async] + [Export ("setFavoriteRank:forItemIdentifier:completionHandler:")] + void SetFavoriteRank ([NullAllowed] NSNumber favoriteRank, string itemIdentifier, Action completionHandler); + + [iOS (11,0)] + [Export ("enumeratorForContainerItemIdentifier:error:")] + [return: NullAllowed] + XamCore.FileProvider.INSFileProviderEnumerator GetEnumerator (string containerItemIdentifier, out NSError error); + + // From NSFileProviderExtension (NSFileProviderThumbnailing) + + [Export ("fetchThumbnailsForItemIdentifiers:requestedSize:perThumbnailCompletionHandler:completionHandler:")] + [Async] + NSProgress FetchThumbnails (/*[BindAs (typeof (NSFileProviderItemIdentifier []))]*/ NSString [] itemIdentifiers, CGSize size, NSFileProviderExtensionFetchThumbnailsHandler perThumbnailCompletionHandler, Action completionHandler); + + // From NSFileProviderExtension (NSFileProviderMessaging) + + // TODO: NSFileProviderMessageInterfaceName is not bound yet, comes from Foundation + //[Export ("supportedMessageInterfaceNamesForItemWithIdentifier:")] + //NSFileProviderMessageInterfaceName[] GetSupportedMessageInterfaceNames (/*[BindAs (typeof (NSFileProviderItemIdentifier))]*/ NSString identifier); + + // TODO: NSFileProviderMessageInterface is not bound yet, comes from Foundation + //[Export ("protocolForMessageInterface:")] + //Protocol GetProtocol (NSFileProviderMessageInterface messageInterface); + + // TODO: NSFileProviderMessageInterface is not bound yet, comes from Foundation + //[return: NullAllowed] + //[Export ("exportedObjectForMessageInterface:itemIdentifier:error:")] + //NSObject GetExportedObject (NSFileProviderMessageInterface messageInterface, /*[BindAs (typeof (NSFileProviderItemIdentifier))]*/ NSString identifier, out NSError error); +#endif } #endif // !WATCH diff --git a/tests/introspection/ApiSignatureTest.cs b/tests/introspection/ApiSignatureTest.cs index 82881018905a..bfd50cc1e95a 100644 --- a/tests/introspection/ApiSignatureTest.cs +++ b/tests/introspection/ApiSignatureTest.cs @@ -983,6 +983,10 @@ protected virtual bool IgnoreAsync (MethodInfo m) // It does not make sense for this API case "RequestData": return m.DeclaringType.Name == "PHAssetResourceManager"; + // It does not make sense for this API + case "Register": + case "SignalEnumerator": + return m.DeclaringType.Name == "NSFileProviderManager"; } return false; } diff --git a/tests/introspection/ApiTypoTest.cs b/tests/introspection/ApiTypoTest.cs index 86033723dfc6..ab059ac2a5f2 100644 --- a/tests/introspection/ApiTypoTest.cs +++ b/tests/introspection/ApiTypoTest.cs @@ -405,6 +405,7 @@ public virtual bool Skip (MemberInfo methodName, string typo) { "Unproject", "Uterance", "Unentitled", + "Untrash", "Utf", "Upce", "Uti", diff --git a/tests/introspection/iOS/iOSApiProtocolTest.cs b/tests/introspection/iOS/iOSApiProtocolTest.cs index 66cd77bf040d..37bee14364be 100644 --- a/tests/introspection/iOS/iOSApiProtocolTest.cs +++ b/tests/introspection/iOS/iOSApiProtocolTest.cs @@ -205,6 +205,7 @@ protected override bool Skip (Type type, string protocolName) case "HMTimeEvent": case "ILMessageFilterExtensionContext": // Conformance not in headers case "MSMessageLiveLayout": + case "NSFileProviderDomain": // Conformance not in headers return true; #if __WATCHOS__ case "CLKComplicationTemplate": @@ -338,6 +339,7 @@ protected override bool Skip (Type type, string protocolName) case "NSPropertyDescription": case "NSRelationshipDescription": case "MSMessageLiveLayout": + case "NSFileProviderDomain": // Conformance not in headers return true; #if __WATCHOS__ case "CLKComplicationTemplate": @@ -422,6 +424,7 @@ protected override bool Skip (Type type, string protocolName) case "ACAccountCredential": // b2: Conformance not in headers case "ILMessageFilterExtensionContext": // b2: Conformance not in headers case "HMCharacteristicEvent": // Selectors not available on 32 bit + case "NSFileProviderDomain": // Conformance not in headers return true; #if __WATCHOS__ diff --git a/tools/common/Frameworks.cs b/tools/common/Frameworks.cs index c61b3bfc0342..fda7d7b96812 100644 --- a/tools/common/Frameworks.cs +++ b/tools/common/Frameworks.cs @@ -251,6 +251,7 @@ public static Frameworks GetiOSFrameworks (Application app) { "IdentityLookup", "IdentityLookup", 11 }, { "CoreML", "CoreML", 11 }, { "Vision", "Vision", 11 }, + { "FileProvider", "FileProvider", 11 }, }; } return ios_frameworks; From 42e75f4484678d8d3ed8c7c0e5ad8a66d41ce428 Mon Sep 17 00:00:00 2001 From: Alex Soto Date: Fri, 30 Jun 2017 12:52:50 -0500 Subject: [PATCH 2/5] Better naming --- src/foundation.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/foundation.cs b/src/foundation.cs index f62dc7117dee..da72d8632534 100644 --- a/src/foundation.cs +++ b/src/foundation.cs @@ -3198,7 +3198,7 @@ interface NSError : NSSecureCoding, NSCopying { [iOS (11,0)] [Static] [Export ("fileProviderErrorForNonExistentItemWithIdentifier:")] - NSError GetFileProviderErrorForNonExistentItem (string itemIdentifier); + NSError GetFileProviderError (string nonExistentItemIdentifier); #endif #if false From fac8d9b25e8cb5639e92062ed583bc45237d0a97 Mon Sep 17 00:00:00 2001 From: Alex Soto Date: Fri, 30 Jun 2017 15:27:17 -0500 Subject: [PATCH 3/5] Feedback not related to BindAs --- src/fileprovider.cs | 2 +- src/uikit.cs | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/fileprovider.cs b/src/fileprovider.cs index 5787aa9b3263..27ab2f4eee1f 100644 --- a/src/fileprovider.cs +++ b/src/fileprovider.cs @@ -19,7 +19,7 @@ namespace XamCore.FileProvider { [iOS (11,0)] [ErrorDomain ("NSFileProviderErrorDomain")] [Native] - public enum NSFileProviderErrorCode : nint { + public enum NSFileProviderError : nint { NotAuthenticated = -1000, FilenameCollision = -1001, SyncAnchorExpired = -1002, diff --git a/src/uikit.cs b/src/uikit.cs index 17e0e901f948..33fe28decfaf 100644 --- a/src/uikit.cs +++ b/src/uikit.cs @@ -293,15 +293,15 @@ partial interface NSFileProviderExtension { [Static, Export ("writePlaceholderAtURL:withMetadata:error:")] bool WritePlaceholder (NSUrl placeholderUrl, NSDictionary metadata, ref NSError error); - [Deprecated (PlatformName.iOS, 11, 0, message: "Use 'FileProvider.NSFileProviderManager.GetPlaceholderUrl (NSUrl)' instead.")] + [Deprecated (PlatformName.iOS, 11, 0, message: "Use 'FileProvider::NSFileProviderManager.GetPlaceholderUrl (NSUrl)' instead.")] [Static, Export ("placeholderURLForURL:")] NSUrl GetPlaceholderUrl (NSUrl url); - [Deprecated (PlatformName.iOS, 11, 0, message: "Use 'FileProvider.NSFileProviderManager.ProviderIdentifier' instead.")] + [Deprecated (PlatformName.iOS, 11, 0, message: "Use 'FileProvider::NSFileProviderManager.ProviderIdentifier' instead.")] [Export ("providerIdentifier")] string ProviderIdentifier { get; } - [Deprecated (PlatformName.iOS, 11, 0, message: "Use 'FileProvider.NSFileProviderManager.DocumentStorageUrl' instead.")] + [Deprecated (PlatformName.iOS, 11, 0, message: "Use 'FileProvider::NSFileProviderManager.DocumentStorageUrl' instead.")] [Export ("documentStorageURL")] NSUrl DocumentStorageUrl { get; } From 0be06913010ee778b75f0dd8f739b4f7f9d3cdeb Mon Sep 17 00:00:00 2001 From: Alex Soto Date: Mon, 17 Jul 2017 21:00:02 -0500 Subject: [PATCH 4/5] [FileProvider] Removes BindAs, add manual code for it and updated to Beta 3 --- .../NSFileProviderItemIdentifierExtensions.cs | 29 ++++++++++++++ src/fileprovider.cs | 38 +++++++++++-------- src/frameworks.sources | 5 +++ src/uikit.cs | 32 ++++++++++++++-- 4 files changed, 84 insertions(+), 20 deletions(-) create mode 100644 src/FileProvider/NSFileProviderItemIdentifierExtensions.cs diff --git a/src/FileProvider/NSFileProviderItemIdentifierExtensions.cs b/src/FileProvider/NSFileProviderItemIdentifierExtensions.cs new file mode 100644 index 000000000000..de20d883368a --- /dev/null +++ b/src/FileProvider/NSFileProviderItemIdentifierExtensions.cs @@ -0,0 +1,29 @@ +// +// NSFileProviderItemIdentifierExtensions.cs +// +// Authors: +// Alex Soto +// +// Copyright 2017 Xamarin Inc. All rights reserved. +// + +#if XAMCORE_2_0 +using System; +using XamCore.Foundation; + +namespace XamCore.FileProvider { + public partial class NSFileProviderItemIdentifierExtensions { + + public static NSString[] GetConstants (this NSFileProviderItemIdentifier[] self) + { + if (self == null) + throw new ArgumentNullException (nameof (self)); + + var array = new NSString [self.Length]; + for (int n = 0; n < self.Length; n++) + array [n] = self [n].GetConstant (); + return array; + } + } +} +#endif diff --git a/src/fileprovider.cs b/src/fileprovider.cs index 27ab2f4eee1f..2da8d26e51f7 100644 --- a/src/fileprovider.cs +++ b/src/fileprovider.cs @@ -23,22 +23,20 @@ public enum NSFileProviderError : nint { NotAuthenticated = -1000, FilenameCollision = -1001, SyncAnchorExpired = -1002, + PageExpired = SyncAnchorExpired, InsufficientQuota = -1003, ServerUnreachable = -1004, - NoSuchItem = -1005 + NoSuchItem = -1005, } [iOS (11,0)] enum NSFileProviderItemIdentifier { - // Lets follow swift names + [Field ("NSFileProviderRootContainerItemIdentifier")] - RootContainer, + Root, [Field ("NSFileProviderWorkingSetContainerItemIdentifier")] WorkingSet, - - [Field ("NSFileProviderAllDirectoriesContainerItemIdentifier")] - AllDirectories, } [iOS (11,0)] @@ -53,7 +51,7 @@ public enum NSFileProviderItemCapabilities : nuint { Deleting = 1 << 5, AddingSubItems = Writing, ContentEnumerating = Reading, - All = Reading | Writing | Reparenting | Renaming | Trashing | Deleting + All = Reading | Writing | Reparenting | Renaming | Trashing | Deleting, } [iOS (11,0)] @@ -128,10 +126,10 @@ interface NSFileProviderEnumerator { [Abstract] [Export ("enumerateItemsForObserver:startingAtPage:")] - void EnumerateItems (INSFileProviderEnumerationObserver observer, NSData page); + void EnumerateItems (INSFileProviderEnumerationObserver observer, NSData startPage); [Export ("enumerateChangesForObserver:fromSyncAnchor:")] - void EnumerateChanges (INSFileProviderChangeObserver observer, NSData anchor); + void EnumerateChanges (INSFileProviderChangeObserver observer, NSData syncAnchor); [Export ("currentSyncAnchorWithCompletionHandler:")] void CurrentSyncAnchor (Action completionHandler); @@ -146,12 +144,12 @@ interface NSFileProviderItem { [Advice ("Use 'NSFileProviderItemIdentifierExtensions.GetValue (ItemIdentifier)' to get a 'NSFileProviderItemIdentifier' enum.")] [Abstract] [Export ("itemIdentifier")] - NSString ItemIdentifier { get; } + NSString Identifier { get; } [Advice ("Use 'NSFileProviderItemIdentifierExtensions.GetValue (ParentItemIdentifier)' to get a 'NSFileProviderItemIdentifier' enum.")] [Abstract] [Export ("parentItemIdentifier")] - NSString ParentItemIdentifier { get; } + NSString ParentIdentifier { get; } [Abstract] [Export ("filename")] @@ -250,13 +248,21 @@ interface NSFileProviderManager { [Export ("defaultManager", ArgumentSemantic.Strong)] NSFileProviderManager DefaultManager { get; } + [Protected] [Export ("signalEnumeratorForContainerItemIdentifier:completionHandler:")] - // Not Async'ified on pruppose, because this can switch from app to extension. - void SignalEnumerator (/*[BindAs (typeof (NSFileProviderItemIdentifier))]*/ NSString containerItemIdentifier, Action completion); + // Not Async'ified on purpose, because this can switch from app to extension. + void SignalEnumerator (NSString containerItemIdentifier, Action completion); - // Not Async'ified on pruppose, because the task must be accesed while the completion action is performing... + [Wrap ("SignalEnumerator (containerItemIdentifier.GetConstant (), completion)")] + void SignalEnumerator (NSFileProviderItemIdentifier containerItemIdentifier, Action completion); + + // Not Async'ified on purpose, because the task must be accesed while the completion action is performing... + [Protected] [Export ("registerURLSessionTask:forItemWithIdentifier:completionHandler:")] - void Register (NSUrlSessionTask task, /*[BindAs (typeof (NSFileProviderItemIdentifier))]*/ NSString identifier, Action completion); + void Register (NSUrlSessionTask task, NSString identifier, Action completion); + + [Wrap ("Register (task, identifier.GetConstant (), completion)")] + void Register (NSUrlSessionTask task, NSFileProviderItemIdentifier identifier, Action completion); [Export ("providerIdentifier")] string ProviderIdentifier { get; } @@ -285,7 +291,7 @@ interface NSFileProviderManager { [Static] [Async] [Export ("getDomainsWithCompletionHandler:")] - void GetDomains (Action, NSError> completionHandler); + void GetDomains (Action completionHandler); [Static] [Async] diff --git a/src/frameworks.sources b/src/frameworks.sources index 6e6b70944e7f..705d47aa281c 100644 --- a/src/frameworks.sources +++ b/src/frameworks.sources @@ -599,6 +599,11 @@ EVENTKITUI_SOURCES = \ EXTERNALACCESSORY_API_SOURCES = \ ExternalAccessory/EAEnums.cs \ +# FileProvider + +FILEPROVIDER_SOURCES = \ + FileProvider/NSFileProviderItemIdentifierExtensions.cs \ + # FinderSync FINDERSYNC_CORE_SOURCES = \ diff --git a/src/uikit.cs b/src/uikit.cs index 33fe28decfaf..2facec34ca78 100644 --- a/src/uikit.cs +++ b/src/uikit.cs @@ -327,10 +327,15 @@ partial interface NSFileProviderExtension { #if XAMCORE_2_0 && IOS + [Protected] [iOS (11,0)] [Export ("itemForIdentifier:error:")] [return: NullAllowed] - XamCore.FileProvider.INSFileProviderItem GetItem (/*[BindAs (typeof (NSFileProviderItemIdentifier))]*/ NSString identifier, out NSError error); + XamCore.FileProvider.INSFileProviderItem GetItem (NSString identifier, out NSError error); + + [iOS (11,0)] + [Wrap ("GetItem (identifier.GetConstant (), out error)")] + XamCore.FileProvider.INSFileProviderItem GetItem (NSFileProviderItemIdentifier identifier, out NSError error); // Inlining NSFileProviderExtension (NSFileProviderActions) so we get asyncs @@ -391,24 +396,43 @@ partial interface NSFileProviderExtension { // From NSFileProviderExtension (NSFileProviderThumbnailing) + [iOS (11,0)] [Export ("fetchThumbnailsForItemIdentifiers:requestedSize:perThumbnailCompletionHandler:completionHandler:")] [Async] - NSProgress FetchThumbnails (/*[BindAs (typeof (NSFileProviderItemIdentifier []))]*/ NSString [] itemIdentifiers, CGSize size, NSFileProviderExtensionFetchThumbnailsHandler perThumbnailCompletionHandler, Action completionHandler); + NSProgress FetchThumbnails (NSString [] itemIdentifiers, CGSize size, NSFileProviderExtensionFetchThumbnailsHandler perThumbnailCompletionHandler, Action completionHandler); + + [Async] + [iOS (11,0)] + [Wrap ("FetchThumbnails (itemIdentifiers.GetConstants (), size, perThumbnailCompletionHandler, completionHandler)")] + NSProgress FetchThumbnails (NSFileProviderItemIdentifier [] itemIdentifiers, CGSize size, NSFileProviderExtensionFetchThumbnailsHandler perThumbnailCompletionHandler, Action completionHandler); // From NSFileProviderExtension (NSFileProviderMessaging) // TODO: NSFileProviderMessageInterfaceName is not bound yet, comes from Foundation + //[iOS (11,0)] + //[Internal] //[Export ("supportedMessageInterfaceNamesForItemWithIdentifier:")] - //NSFileProviderMessageInterfaceName[] GetSupportedMessageInterfaceNames (/*[BindAs (typeof (NSFileProviderItemIdentifier))]*/ NSString identifier); + //NSFileProviderMessageInterfaceName[] GetSupportedMessageInterfaceNames (NSString identifier); + + //[iOS (11,0)] + //[Wrap ("GetSupportedMessageInterfaceNames (identifier.GetConstant ())")] + //NSFileProviderMessageInterfaceName[] GetSupportedMessageInterfaceNames (NSFileProviderItemIdentifier identifier); // TODO: NSFileProviderMessageInterface is not bound yet, comes from Foundation + //[iOS (11,0)] //[Export ("protocolForMessageInterface:")] //Protocol GetProtocol (NSFileProviderMessageInterface messageInterface); // TODO: NSFileProviderMessageInterface is not bound yet, comes from Foundation + //[iOS (11,0)] + //[Internal] //[return: NullAllowed] //[Export ("exportedObjectForMessageInterface:itemIdentifier:error:")] - //NSObject GetExportedObject (NSFileProviderMessageInterface messageInterface, /*[BindAs (typeof (NSFileProviderItemIdentifier))]*/ NSString identifier, out NSError error); + //NSObject GetExportedObject (NSFileProviderMessageInterface messageInterface, NSString identifier, out NSError error); + + //[iOS (11,0)] + //[Wrap ("GetExportedObject (messageInterface, identifier.GetConstant (), out error)")] + //NSObject GetExportedObject (NSFileProviderMessageInterface messageInterface, NSFileProviderItemIdentifier identifier, out NSError error); #endif } #endif // !WATCH From acd1ff83cecb0f8b7e705bf2ddf67ae60b6cf696 Mon Sep 17 00:00:00 2001 From: Alex Soto Date: Tue, 18 Jul 2017 12:57:45 -0500 Subject: [PATCH 5/5] [FileProvider] Implement feedback --- src/fileprovider.cs | 8 ++++---- src/foundation.cs | 2 -- src/uikit.cs | 23 ++++++++++++----------- 3 files changed, 16 insertions(+), 17 deletions(-) diff --git a/src/fileprovider.cs b/src/fileprovider.cs index 2da8d26e51f7..26a44d964e9a 100644 --- a/src/fileprovider.cs +++ b/src/fileprovider.cs @@ -1,4 +1,4 @@ -// +// // FileProvider C# bindings // // Authors: @@ -33,10 +33,10 @@ public enum NSFileProviderError : nint { enum NSFileProviderItemIdentifier { [Field ("NSFileProviderRootContainerItemIdentifier")] - Root, + RootContainer, [Field ("NSFileProviderWorkingSetContainerItemIdentifier")] - WorkingSet, + WorkingSetContainer, } [iOS (11,0)] @@ -84,7 +84,7 @@ interface NSFileProviderEnumerationObserver { [Abstract] [Export ("finishEnumeratingUpToPage:")] - void FinishEnumerating ([NullAllowed] NSData nextPage); + void FinishEnumerating ([NullAllowed] NSData upToPage); [Abstract] [Export ("finishEnumeratingWithError:")] diff --git a/src/foundation.cs b/src/foundation.cs index da72d8632534..8c328808d0b9 100644 --- a/src/foundation.cs +++ b/src/foundation.cs @@ -3052,8 +3052,6 @@ interface NSEnumerator { NSObject NextObject (); } - interface INSFileProviderItem { } - [BaseType (typeof (NSObject))] [DisableDefaultCtor] interface NSError : NSSecureCoding, NSCopying { diff --git a/src/uikit.cs b/src/uikit.cs index 2facec34ca78..94299b34ce95 100644 --- a/src/uikit.cs +++ b/src/uikit.cs @@ -331,43 +331,43 @@ partial interface NSFileProviderExtension { [iOS (11,0)] [Export ("itemForIdentifier:error:")] [return: NullAllowed] - XamCore.FileProvider.INSFileProviderItem GetItem (NSString identifier, out NSError error); + INSFileProviderItem GetItem (NSString identifier, out NSError error); [iOS (11,0)] [Wrap ("GetItem (identifier.GetConstant (), out error)")] - XamCore.FileProvider.INSFileProviderItem GetItem (NSFileProviderItemIdentifier identifier, out NSError error); + INSFileProviderItem GetItem (NSFileProviderItemIdentifier identifier, out NSError error); // Inlining NSFileProviderExtension (NSFileProviderActions) so we get asyncs [iOS (11,0)] [Async] [Export ("importDocumentAtURL:toParentItemIdentifier:completionHandler:")] - void ImportDocument (NSUrl fileUrl, string parentItemIdentifier, Action completionHandler); + void ImportDocument (NSUrl fileUrl, string parentItemIdentifier, Action completionHandler); [iOS (11,0)] [Async] [Export ("createDirectoryWithName:inParentItemIdentifier:completionHandler:")] - void CreateDirectory (string directoryName, string parentItemIdentifier, Action completionHandler); + void CreateDirectory (string directoryName, string parentItemIdentifier, Action completionHandler); [iOS (11,0)] [Async] [Export ("renameItemWithIdentifier:toName:completionHandler:")] - void RenameItem (string itemIdentifier, string itemName, Action completionHandler); + void RenameItem (string itemIdentifier, string itemName, Action completionHandler); [iOS (11,0)] [Async] [Export ("reparentItemWithIdentifier:toParentItemWithIdentifier:completionHandler:")] - void ReparentItem (string itemIdentifier, string parentItemIdentifier, Action completionHandler); + void ReparentItem (string itemIdentifier, string parentItemIdentifier, Action completionHandler); [iOS (11,0)] [Async] [Export ("trashItemWithIdentifier:completionHandler:")] - void TrashItem (string itemIdentifier, Action completionHandler); + void TrashItem (string itemIdentifier, Action completionHandler); [iOS (11,0)] [Async] [Export ("untrashItemWithIdentifier:toParentItemIdentifier:completionHandler:")] - void UntrashItem (string itemIdentifier, [NullAllowed] string parentItemIdentifier, Action completionHandler); + void UntrashItem (string itemIdentifier, [NullAllowed] string parentItemIdentifier, Action completionHandler); [iOS (11,0)] [Async] @@ -377,17 +377,17 @@ partial interface NSFileProviderExtension { [iOS (11,0)] [Async] [Export ("setLastUsedDate:forItemIdentifier:completionHandler:")] - void SetLastUsedDate ([NullAllowed] NSDate lastUsedDate, string itemIdentifier, Action completionHandler); + void SetLastUsedDate ([NullAllowed] NSDate lastUsedDate, string itemIdentifier, Action completionHandler); [iOS (11,0)] [Async] [Export ("setTagData:forItemIdentifier:completionHandler:")] - void SetTagData ([NullAllowed] NSData tagData, string itemIdentifier, Action completionHandler); + void SetTagData ([NullAllowed] NSData tagData, string itemIdentifier, Action completionHandler); [iOS (11,0)] [Async] [Export ("setFavoriteRank:forItemIdentifier:completionHandler:")] - void SetFavoriteRank ([NullAllowed] NSNumber favoriteRank, string itemIdentifier, Action completionHandler); + void SetFavoriteRank ([NullAllowed] NSNumber favoriteRank, string itemIdentifier, Action completionHandler); [iOS (11,0)] [Export ("enumeratorForContainerItemIdentifier:error:")] @@ -408,6 +408,7 @@ partial interface NSFileProviderExtension { // From NSFileProviderExtension (NSFileProviderMessaging) + // Missing members -> https://bugzilla.xamarin.com/show_bug.cgi?id=58222 // TODO: NSFileProviderMessageInterfaceName is not bound yet, comes from Foundation //[iOS (11,0)] //[Internal]