Exemplo n.º 1
0
        /// <summary>
        /// Loads the document.
        /// </summary>
        /// <param name="query">Query.</param>
        private void LoadDocument(NSMetadataQuery query)
        {
            Console.WriteLine("Loading Document...");

            // Take action based on the returned record count
            switch (query.ResultCount)
            {
            case 0:
                // Create a new document
                CreateNewDocument();
                break;

            case 1:
                // Gain access to the url and create a new document from
                // that instance
                NSMetadataItem item = (NSMetadataItem)query.ResultAtIndex(0);
                var            url  = (NSUrl)item.ValueForAttribute(NSMetadataQuery.ItemURLKey);

                // Load the document
                OpenDocument(url);
                break;

            default:
                // There has been an issue
                Console.WriteLine("Issue: More than one document found...");
                break;
            }
        }
 void PrintMetadataItem(NSMetadataItem item)
 {
     Console.WriteLine("path={0}, display={1}, url={2}, name={3}, downloaded={4}, downloading={5}, uploaded={6}, uploading={7}, createData={8}, updateDate={9},",
                       item.Path, item.DisplayName, item.Url, item.FileSystemName, item.UbiquitousItemIsUploaded,
                       item.UbiquitousItemIsUploading, item.UbiquitousItemIsUploaded, item.UbiquitousItemIsUploading,
                       item.FileSystemCreationDate, item.FileSystemContentChangeDate);
 }
Exemplo n.º 3
0
        public CloudFile(NSMetadataItem item, NSUrl documentsUrl)
        {
            this.documentsUrl = documentsUrl;

            LocalPath = item.ValueForKey(NSMetadataQuery.ItemPathKey).ToString();

            var docsPath    = documentsUrl.Path;
            var docsPathLen = docsPath.Length;

            if (!docsPath.EndsWith("/", StringComparison.Ordinal))
            {
                docsPathLen++;
            }

            Path = LocalPath.Substring(docsPathLen);

            LocalUrl = NSUrl.FromFilename(LocalPath);

            var t = item.FileSystemContentChangeDate;

            if (t != null)
            {
                ModifiedTime = new DateTime(2001, 1, 1).AddSeconds(t.SecondsSinceReferenceDate);
            }
            else
            {
                ModifiedTime = DateTime.MinValue;
            }

            var isDownloading = item.UbiquitousItemIsDownloading;

            if (UIDevice.CurrentDevice.CheckSystemVersion(7, 0))
            {
                IsDownloaded = item.DownloadingStatus == NSItemDownloadingStatus.Downloaded;
            }
            else
            {
                try {
                    IsDownloaded = ((NSNumber)item.ValueForKey(NSMetadataQuery.UbiquitousItemIsDownloadedKey)).BoolValue;
                } catch (Exception) {
                    IsDownloaded = false;
                }
            }
            DownloadProgress = isDownloading ? item.UbiquitousItemPercentDownloaded / 100.0 : 1;
        }
Exemplo n.º 4
0
        void PrintMetadataItem(NSMetadataItem item)
        {
            // TODO: https://trello.com/c/3Uw6WFkC
            NSString path        = (NSString)item.ValueForAttribute(NSMetadataQuery.ItemPathKey);
            NSString display     = (NSString)item.ValueForAttribute(NSMetadataQuery.ItemDisplayNameKey);
            NSUrl    url         = (NSUrl)item.ValueForAttribute(NSMetadataQuery.ItemURLKey);
            NSString name        = (NSString)item.ValueForAttribute(NSMetadataQuery.ItemFSNameKey);
            NSNumber downloaded  = (NSNumber)item.ValueForAttribute(NSMetadataQuery.UbiquitousItemIsDownloadedKey);
            NSNumber downloading = (NSNumber)item.ValueForAttribute(NSMetadataQuery.UbiquitousItemIsDownloadingKey);
            NSNumber uploaded    = (NSNumber)item.ValueForAttribute(NSMetadataQuery.UbiquitousItemIsUploadedKey);
            NSNumber uploading   = (NSNumber)item.ValueForAttribute(NSMetadataQuery.UbiquitousItemIsUploadingKey);
            NSDate   createData  = (NSDate)item.ValueForAttribute(NSMetadataQuery.ItemFSCreationDateKey);
            NSDate   updateDate  = (NSDate)item.ValueForAttribute(NSMetadataQuery.ItemFSContentChangeDateKey);

//			NSNumber hasConflicts = item.ValueForAttribute (NSMetadataQuery.UbiquitousItemHasUnresolvedConflictsKey);

            Console.WriteLine("path={0}, display={1}, url={2}, name={3}, downloaded={4}, downloading={5}, uploaded={6}, uploading={7}, createData={8}, updateDate={9},",
                              path, display, url, name, downloaded, downloading, uploaded, uploading, createData, updateDate);
        }
Exemplo n.º 5
0
        public void CtorUrl()
        {
            // 10.9 for NSMetadataItem initWithURL:
            TestRuntime.AssertXcodeVersion(5, 1);

            var url = NSBundle.MainBundle.BundleUrl;

            using (var mi = new NSMetadataItem(url)) {
                Assert.That(mi.DisplayName.ToString(), Is.EqualTo("apitest"), "DisplayName");
                Assert.NotNull(mi.FileSystemContentChangeDate, "FileSystemContentChangeDate");
                Assert.NotNull(mi.FileSystemCreationDate, "FileSystemCreationDate");
                Assert.That(mi.FileSystemName.ToString(), Is.EqualTo("apitest.app"), "FileSystemName");
                Assert.That(mi.FileSystemSize.UInt64Value, Is.GreaterThan(0), "FileSystemSize");
                Assert.False(mi.IsUbiquitous, "IsUbiquitous");
                Assert.That(mi.Path.ToString(), Does.EndWith("/apitest.app"), "Path");
                Assert.False(mi.UbiquitousItemHasUnresolvedConflicts, "UbiquitousItemHasUnresolvedConflicts");
                Assert.False(mi.UbiquitousItemIsDownloading, "UbiquitousItemIsDownloading");
                Assert.False(mi.UbiquitousItemIsUploaded, "UbiquitousItemIsUploaded");
                Assert.False(mi.UbiquitousItemIsUploading, "UbiquitousItemIsUploading");
                Assert.That(mi.UbiquitousItemPercentDownloaded, Is.EqualTo(0), "UbiquitousItemPercentDownloaded");
                Assert.That(mi.UbiquitousItemPercentUploaded, Is.EqualTo(0), "UbiquitousItemPercentUploaded");
                Assert.Null(mi.Url, "Url");

                Assert.That(mi.ContentType.ToString(), Is.EqualTo("com.apple.application-bundle"), "ContentType");
                Assert.That(mi.ContentTypeTree.Length, Is.GreaterThan(1), "ContentTypeTree");
#if NET
                Assert.That(mi.UbiquitousItemDownloadingStatus, Is.EqualTo(NSItemDownloadingStatus.Unknown), "UbiquitousItemDownloadingStatus");
#else
                Assert.That(mi.DownloadingStatus, Is.EqualTo(NSItemDownloadingStatus.Unknown), "DownloadingStatus");
#endif
                Assert.Null(mi.UbiquitousItemDownloadingError, "UbiquitousItemDownloadingError");
                Assert.Null(mi.UbiquitousItemUploadingError, "UbiquitousItemUploadingError");
                Assert.Null(mi.UbiquitousItemContainerDisplayName, "UbiquitousItemContainerDisplayName");
                Assert.Null(mi.UbiquitousItemUrlInLocalContainer, "UbiquitousItemUrlInLocalContainer");

                // 10.10
                if (TestRuntime.CheckXcodeVersion(6, 0))
                {
                    Assert.False(mi.UbiquitousItemDownloadRequested, "UbiquitousItemDownloadRequested");
                    Assert.False(mi.UbiquitousItemIsExternalDocument, "UbiquitousItemIsExternalDocument");
                }
            }
        }
 // ListInfo objects may originate from local URLs or NSMetadataItems representing document in the cloud.
 void InsertListInfoWithProvider(NSMetadataItem item, Action <int> completionHandler)
 {
     InsertListInfoWithProvider((NSUrl)item.ValueForAttribute(NSMetadataQuery.ItemURLKey), completionHandler);
 }
Exemplo n.º 7
0
 //  Not used in the program was just a test for the Delegate Class
 public NSObject MetadataQueryReplacementObjectForResultObject(NSMetadataQuery query, NSMetadataItem result)
 {
     Console.WriteLine("delegate object");
     return(null);
 }
Exemplo n.º 8
0
        void LoadDocument(NSMetadataQuery query)
        {
            Console.WriteLine("LoadDocument");

            if (query.ResultCount == 1)
            {
                NSMetadataItem item = (NSMetadataItem)query.ResultAtIndex(0);
                var            url  = (NSUrl)item.ValueForAttribute(NSMetadataQuery.ItemURLKey);
                doc = new MonkeyDocument(url);

                doc.Open((success) => {
                    if (success)
                    {
                        Console.WriteLine("iCloud document opened");
                        Console.WriteLine(" -- " + doc.DocumentString);
                        viewController.DisplayDocument(doc);
                    }
                    else
                    {
                        Console.WriteLine("failed to open iCloud document");
                    }
                });
            }
            else if (query.ResultCount == 0)
            {
                // no document exists, CREATE the first one
                // for a more realistic iCloud application the user will probably
                // create documents as needed, so this bit of code wouldn't be necessary
                var docsFolder = Path.Combine(iCloudUrl.Path, "Documents");                 // NOTE: Documents folder is user-accessible in Settings
                var docPath    = Path.Combine(docsFolder, monkeyDocFilename);
                var ubiq       = new NSUrl(docPath, false);

                Console.WriteLine("ubiq:" + ubiq.AbsoluteString);

                var doc = new MonkeyDocument(ubiq);

                doc.Save(doc.FileUrl, UIDocumentSaveOperation.ForCreating
                         , (saveSuccess) => {
                    Console.WriteLine("Save completion:" + saveSuccess);
                    if (saveSuccess)
                    {
                        doc.Open((openSuccess) => {
                            Console.WriteLine("Open completion:" + openSuccess);
                            if (openSuccess)
                            {
                                Console.WriteLine("new document for iCloud");
                                Console.WriteLine(" == " + doc.DocumentString);
                                viewController.DisplayDocument(doc);
                            }
                            else
                            {
                                Console.WriteLine("couldn't open");
                            }
                        });
                    }
                    else
                    {
                        Console.WriteLine("couldn't save");
                    }
                });
            }
            else
            {
                Console.WriteLine("Who put all these other UIDocuments here?");
            }
        }
Exemplo n.º 9
0
		//  Not used in the program was just a test for the Delegate Class
		public NSObject MetadataQueryReplacementObjectForResultObject (NSMetadataQuery query, NSMetadataItem result)
		{
			Console.WriteLine ("delegate object");
			return null;
		}
Exemplo n.º 10
0
		public CloudFile (NSMetadataItem item, NSUrl documentsUrl)
		{
			this.documentsUrl = documentsUrl;

			LocalPath = item.ValueForKey (NSMetadataQuery.ItemPathKey).ToString ();

			var docsPath = documentsUrl.Path;
			var docsPathLen = docsPath.Length;
			if (!docsPath.EndsWith ("/", StringComparison.Ordinal))
				docsPathLen++;

			Path = LocalPath.Substring (docsPathLen);

			LocalUrl = NSUrl.FromFilename (LocalPath);

			var t = item.FileSystemContentChangeDate;
			if (t != null) {
				ModifiedTime = new DateTime (2001, 1, 1).AddSeconds (t.SecondsSinceReferenceDate);
			} else {
				ModifiedTime = DateTime.MinValue;
			}

			var isDownloading = item.UbiquitousItemIsDownloading;
			if (UIDevice.CurrentDevice.CheckSystemVersion (7, 0)) {
				IsDownloaded = item.DownloadingStatus == NSItemDownloadingStatus.Downloaded;
			} else {
				try {
					IsDownloaded = ((NSNumber)item.ValueForKey (NSMetadataQuery.UbiquitousItemIsDownloadedKey)).BoolValue;
				} catch (Exception) {
					IsDownloaded = false;
				}
			}
			DownloadProgress = isDownloading ? item.UbiquitousItemPercentDownloaded / 100.0 : 1;
		}
		// ListInfo objects may originate from local URLs or NSMetadataItems representing document in the cloud.
		void InsertListInfoWithProvider(NSMetadataItem item, Action<int> completionHandler)
		{
			InsertListInfoWithProvider ((NSUrl)item.ValueForAttribute (NSMetadataQuery.ItemURLKey), completionHandler);
		}
		void PrintMetadataItem(NSMetadataItem item)
		{
			// TODO: https://trello.com/c/3Uw6WFkC
			NSString path = (NSString)item.ValueForAttribute (NSMetadataQuery.ItemPathKey);
			NSString display = (NSString)item.ValueForAttribute (NSMetadataQuery.ItemDisplayNameKey);
			NSUrl url = (NSUrl)item.ValueForAttribute(NSMetadataQuery.ItemURLKey);
			NSString name = (NSString)item.ValueForAttribute (NSMetadataQuery.ItemFSNameKey);
			NSNumber downloaded = (NSNumber)item.ValueForAttribute (NSMetadataQuery.UbiquitousItemIsDownloadedKey);
			NSNumber downloading = (NSNumber)item.ValueForAttribute (NSMetadataQuery.UbiquitousItemIsDownloadingKey);
			NSNumber uploaded = (NSNumber)item.ValueForAttribute (NSMetadataQuery.UbiquitousItemIsUploadedKey);
			NSNumber uploading = (NSNumber)item.ValueForAttribute (NSMetadataQuery.UbiquitousItemIsUploadingKey);
			NSDate createData = (NSDate)item.ValueForAttribute (NSMetadataQuery.ItemFSCreationDateKey);
			NSDate updateDate = (NSDate)item.ValueForAttribute (NSMetadataQuery.ItemFSContentChangeDateKey);
//			NSNumber hasConflicts = item.ValueForAttribute (NSMetadataQuery.UbiquitousItemHasUnresolvedConflictsKey);

			Console.WriteLine ("path={0}, display={1}, url={2}, name={3}, downloaded={4}, downloading={5}, uploaded={6}, uploading={7}, createData={8}, updateDate={9},",
				path, display, url, name, downloaded, downloading, uploaded, uploading, createData, updateDate);
		}