public void DisplayDocument (MonkeyDocument monkeyDoc)
		{
			alertText.Text = string.Empty;
			doc = monkeyDoc;
			docText.Text = doc.DocumentString;
			saveButton.Enabled = true;
		}
		void DataReloaded (NSNotification notification)
		{
			doc = (MonkeyDocument)notification.Object;
			alertText.Text = string.Format ("{0} dataReloaded: notification", DateTime.Now.ToString ("H:mm:ss"));
			// we just overwrite whatever was being typed, no conflict resolution for now
			docText.Text = doc.DocumentString;
		}
 public void DisplayDocument(MonkeyDocument monkeyDoc)
 {
     alertText.Text     = "";
     doc                = monkeyDoc;
     docText.Text       = doc.DocumentString;
     saveButton.Enabled = true;
 }
 void DataReloaded(NSNotification notification)
 {
     doc            = (MonkeyDocument)notification.Object;
     alertText.Text = DateTime.Now.ToString("H:mm:ss") + " dataReloaded: notification";
     // we just overwrite whatever was being typed, no conflict resolution for now
     docText.Text = doc.DocumentString;
 }
Пример #5
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?");
            }
        }
Пример #6
0
		void LoadDocument (NSMetadataQuery metadataQuery)
		{
			Console.WriteLine ("LoadDocument");	

			if (metadataQuery.ResultCount == 1) {
				var item = (NSMetadataItem)metadataQuery.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 (" -- {0}", doc.DocumentString);
						viewController.DisplayDocument (doc);
					} else {
						Console.WriteLine ("failed to open iCloud document");
					}
				});

			} else if (metadataQuery.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 monkeyDoc = new MonkeyDocument (ubiq);
				
				monkeyDoc.Save (monkeyDoc.FileUrl, UIDocumentSaveOperation.ForCreating, saveSuccess => {
					Console.WriteLine ("Save completion:" + saveSuccess);
					if (saveSuccess) {
						monkeyDoc.Open (openSuccess => {
							Console.WriteLine ("Open completion:" + openSuccess);
							if (openSuccess) {
								Console.WriteLine ("new document for iCloud");
								Console.WriteLine (" == " + monkeyDoc.DocumentString);
								viewController.DisplayDocument (monkeyDoc);
							} else {
								Console.WriteLine ("couldn't open");
							}
						});
					} else {
						Console.WriteLine ("couldn't save");
					}
				});
			} else {
				Console.WriteLine ("Who put all these other UIDocuments here?");
			}
		}