예제 #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;
            }
        }
예제 #2
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);
        }
 // 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);
 }
예제 #4
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?");
            }
        }
		// 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);
		}