Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FileProvider] Add Xcode 9 Beta 1, 2 & 3 Bindings #2279

Merged
merged 5 commits into from
Jul 20, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/Constants.iOS.cs.in
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}
}
29 changes: 29 additions & 0 deletions src/FileProvider/NSFileProviderItemIdentifierExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
//
// NSFileProviderItemIdentifierExtensions.cs
//
// Authors:
// Alex Soto <[email protected]>
//
// 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
307 changes: 307 additions & 0 deletions src/fileprovider.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,307 @@
//
// FileProvider C# bindings
//
// Authors:
// Alex Soto <[email protected]>
//
// 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 NSFileProviderError : nint {
NotAuthenticated = -1000,
FilenameCollision = -1001,
SyncAnchorExpired = -1002,
PageExpired = SyncAnchorExpired,
InsufficientQuota = -1003,
ServerUnreachable = -1004,
NoSuchItem = -1005,
}

[iOS (11,0)]
enum NSFileProviderItemIdentifier {

[Field ("NSFileProviderRootContainerItemIdentifier")]
RootContainer,

[Field ("NSFileProviderWorkingSetContainerItemIdentifier")]
WorkingSetContainer,
}

[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 upToPage);

[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 startPage);

[Export ("enumerateChangesForObserver:fromSyncAnchor:")]
void EnumerateChanges (INSFileProviderChangeObserver observer, NSData syncAnchor);

[Export ("currentSyncAnchorWithCompletionHandler:")]
void CurrentSyncAnchor (Action<NSData> completionHandler);
}

interface INSFileProviderItem { }

[iOS (11,0)]
[Protocol]
interface NSFileProviderItem {

[Advice ("Use 'NSFileProviderItemIdentifierExtensions.GetValue (ItemIdentifier)' to get a 'NSFileProviderItemIdentifier' enum.")]
[Abstract]
[Export ("itemIdentifier")]
NSString Identifier { get; }

[Advice ("Use 'NSFileProviderItemIdentifierExtensions.GetValue (ParentItemIdentifier)' to get a 'NSFileProviderItemIdentifier' enum.")]
[Abstract]
[Export ("parentItemIdentifier")]
NSString ParentIdentifier { get; }

[Abstract]
[Export ("filename")]
string Filename { get; }

[Abstract]
[Export ("typeIdentifier")]
string TypeIdentifier { get; }

[Export ("capabilities")]
NSFileProviderItemCapabilities GetCapabilities ();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a mix of properties and GetX methods in this type, any particular reason for using one or the other? Most seems like they'd make more sense as properties.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a protocol we cant use optional properties, can we?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right, I didn't notice that the properties were required and the methods optional.


[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; }

[Protected]
[Export ("signalEnumeratorForContainerItemIdentifier:completionHandler:")]
// Not Async'ified on purpose, because this can switch from app to extension.
void SignalEnumerator (NSString containerItemIdentifier, Action<NSError> completion);

[Wrap ("SignalEnumerator (containerItemIdentifier.GetConstant (), completion)")]
void SignalEnumerator (NSFileProviderItemIdentifier containerItemIdentifier, Action<NSError> 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, NSString identifier, Action<NSError> completion);

[Wrap ("Register (task, identifier.GetConstant (), completion)")]
void Register (NSUrlSessionTask task, NSFileProviderItemIdentifier identifier, Action<NSError> 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<NSError> completionHandler);

[Static]
[Async]
[Export ("removeDomain:completionHandler:")]
void RemoveDomain (NSFileProviderDomain domain, Action<NSError> completionHandler);

[Static]
[Async]
[Export ("getDomainsWithCompletionHandler:")]
void GetDomains (Action<NSFileProviderDomain [], NSError> completionHandler);

[Static]
[Async]
[Export ("removeAllDomainsWithCompletionHandler:")]
void RemoveAllDomains (Action<NSError> completionHandler);

[Static]
[Export ("managerForDomain:")]
[return: NullAllowed]
NSFileProviderManager FromDomain (NSFileProviderDomain domain);
}
}
#endif
18 changes: 18 additions & 0 deletions src/foundation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@
using XamCore.Security;
#if IOS
using XamCore.CoreSpotlight;
#if XAMCORE_2_0
using XamCore.FileProvider;
#endif
#endif

#if MONOMAC
Expand Down Expand Up @@ -3180,6 +3183,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 GetFileProviderError (string nonExistentItemIdentifier);
#endif

#if false
// FIXME that value is present in the header (7.0 DP 6) files but returns NULL (i.e. unusable)
Expand Down
6 changes: 6 additions & 0 deletions src/frameworks.sources
Original file line number Diff line number Diff line change
Expand Up @@ -599,6 +599,11 @@ EVENTKITUI_SOURCES = \
EXTERNALACCESSORY_API_SOURCES = \
ExternalAccessory/EAEnums.cs \

# FileProvider

FILEPROVIDER_SOURCES = \
FileProvider/NSFileProviderItemIdentifierExtensions.cs \

# FinderSync

FINDERSYNC_CORE_SOURCES = \
Expand Down Expand Up @@ -1652,6 +1657,7 @@ IOS_FRAMEWORKS = \
EventKit \
EventKitUI \
ExternalAccessory \
FileProvider \
GLKit \
GameController \
GameplayKit \
Expand Down
Loading