/// <summary> /// Starts a query to look for the sample Test File. /// </summary> private void FindDocument () { Console.WriteLine ("Finding Document..."); // Create a new query and set it's scope Query = new NSMetadataQuery(); Query.SearchScopes = new NSObject [] { NSMetadataQuery.UbiquitousDocumentsScope, NSMetadataQuery.UbiquitousDataScope, NSMetadataQuery.AccessibleUbiquitousExternalDocumentsScope }; // Build a predicate to locate the file by name and attach it to the query var pred = NSPredicate.FromFormat ("%K == %@" , new NSObject[] { NSMetadataQuery.ItemFSNameKey , new NSString(TestFilename)}); Query.Predicate = pred; // Register a notification for when the query returns NSNotificationCenter.DefaultCenter.AddObserver (this , new Selector("queryDidFinishGathering:") , NSMetadataQuery.DidFinishGatheringNotification , Query); // Start looking for the file Query.StartQuery (); Console.WriteLine ("Querying: {0}", Query.IsGathering); }
private Task InstigateDocumentLookupAsync(TaskScheduler synchronizationContextTaskScheduler) => Task.Factory.StartNew( () => { var query = new NSMetadataQuery { SearchScopes = new NSObject[] { NSMetadataQuery.UbiquitousDocumentsScope }, Predicate = NSPredicate.FromFormat( "%K == %@", new NSObject[] { NSMetadataQuery.ItemFSNameKey, new NSString(documentFilename) }) }; NSNotificationCenter.DefaultCenter.AddObserver(NSMetadataQuery.DidFinishGatheringNotification, this.OnQueryFinished, query); query.StartQuery(); }, CancellationToken.None, TaskCreationOptions.None, synchronizationContextTaskScheduler);
/// <summary> /// Starts a query to look for the sample Test File. /// </summary> private void FindDocument() { Console.WriteLine("Finding Document..."); // Create a new query and set it's scope Query = new NSMetadataQuery(); Query.SearchScopes = new NSObject [] { NSMetadataQuery.UbiquitousDocumentsScope, NSMetadataQuery.UbiquitousDataScope, NSMetadataQuery.AccessibleUbiquitousExternalDocumentsScope }; // Build a predicate to locate the file by name and attach it to the query var pred = NSPredicate.FromFormat("%K == %@" , new NSObject[] { NSMetadataQuery.ItemFSNameKey , new NSString(TestFilename) }); Query.Predicate = pred; // Register a notification for when the query returns NSNotificationCenter.DefaultCenter.AddObserver(this , new Selector("queryDidFinishGathering:") , NSMetadataQuery.DidFinishGatheringNotification , Query); // Start looking for the file Query.StartQuery(); Console.WriteLine("Querying: {0}", Query.IsGathering); }
Task BeginQuery() { if (firstQueryResult != null) { var t = firstQueryResult; firstQueryResult = null; if (!t.Task.IsCompleted) { t.SetException(new Exception("Stopped")); } } if (query != null) { query.StopQuery(); } firstQueryResult = new TaskCompletionSource <object> (); if (documentsUrl == null) { firstQueryResult.SetResult(null); return(firstQueryResult.Task); } var queryString = ""; var head = ""; var args = new List <NSObject> (); foreach (var e in FileExtensions) { queryString += head + "(%K LIKE '*." + e + "')"; head = " OR "; args.Add(NSMetadataQuery.ItemFSNameKey); } query = new NSMetadataQuery(); query.SearchScopes = new NSObject[] { NSMetadataQuery.UbiquitousDocumentsScope }; query.Predicate = NSPredicate.FromFormat( queryString, args.ToArray()); Console.WriteLine("START iCLOUD QUERY"); query.StartQuery(); needsRefresh = false; return(firstQueryResult.Task); }
public override void DidFinishLaunching(NSNotification notification) { Console.WriteLine("FinishedLaunching(notification={0})", notification); mainWindowController = new MainWindowController(); InitializeStatusBar(); //InitializeFirebase(); _query = new NSMetadataQuery(); _query.Predicate = NSPredicate.FromFormat("kMDItemIsScreenCapture = 1"); NSNotificationCenter.DefaultCenter.AddObserver(NSMetadataQuery.DidStartGatheringNotification, ScreenCaptureChange, _query); NSNotificationCenter.DefaultCenter.AddObserver(NSMetadataQuery.DidUpdateNotification, ScreenCaptureChange, _query); NSNotificationCenter.DefaultCenter.AddObserver(NSMetadataQuery.DidFinishGatheringNotification, ScreenCaptureChange, _query); _query.StartQuery(); }
void StartQuery() { if (documentMetadataQuery == null) { documentMetadataQuery = new NSMetadataQuery(); documentMetadataQuery.SearchScopes = new NSObject[] { NSMetadataQuery.UbiquitousDocumentsScope }; string todayListName = AppConfig.SharedAppConfiguration.TodayDocumentNameAndExtension; documentMetadataQuery.Predicate = NSPredicate.FromFormat("(%K = %@)", NSMetadataQuery.ItemFSNameKey, (NSString)todayListName); NSNotificationCenter notificationCenter = NSNotificationCenter.DefaultCenter; // TODO: subscribtion https://trello.com/c/1RyX6cJL finishGatheringToken = notificationCenter.AddObserver(NSMetadataQuery.DidFinishGatheringNotification, HandleMetadataQueryUpdates, documentMetadataQuery); } documentMetadataQuery.StartQuery(); }
void FindDocument() { Console.WriteLine("FindDocument"); query = new NSMetadataQuery(); query.SearchScopes = new NSObject [] { NSMetadataQuery.UbiquitousDocumentsScope }; var pred = NSPredicate.FromFormat("%K == %@" , new NSObject[] { NSMetadataQuery.ItemFSNameKey , new NSString(monkeyDocFilename) }); Console.WriteLine("Predicate:" + pred.PredicateFormat); query.Predicate = pred; NSNotificationCenter.DefaultCenter.AddObserver(this , new Selector("queryDidFinishGathering:") , NSMetadataQuery.DidFinishGatheringNotification , query); query.StartQuery(); }
private void LoadFavorites() { var query = new NSMetadataQuery(); query.SearchScopes = new NSObject[] { NSMetadataQuery.UbiquitousDocumentsScope }; var pred = NSPredicate.FromFormat( "%K == %@", new NSObject[] { NSMetadataQuery.ItemFSNameKey, new NSString(FavoritesService.FavoritesFileName) }); query.Predicate = pred; NSNotificationCenter.DefaultCenter.AddObserver( NSMetadataQuery.DidFinishGatheringNotification, OnDidFinishGathering, query); query.StartQuery(); }
void LoadTasks(NSNotification notification) { Console.WriteLine("LoadTasks()"); if (notification != null && notification.UserInfo != null) { var u = notification.UserInfo.ValueForKey(new NSString("HasiCloud")) as NSNumber; if (u != null) { Console.WriteLine("Has iCloud notification:" + u.BoolValue); } } if (AppDelegate.HasiCloud) { query = new NSMetadataQuery(); query.SearchScopes = new NSObject [] { NSMetadataQuery.QueryUbiquitousDocumentsScope }; var pred = NSPredicate.FromFormat("%K like '*.task'" , new NSObject[] { NSMetadataQuery.ItemFSNameKey }); //Console.WriteLine ("Predicate:" + pred.PredicateFormat); query.Predicate = pred; NSNotificationCenter.DefaultCenter.AddObserver(this , new Selector("queryDidFinishGathering:") , NSMetadataQuery.DidFinishGatheringNotification , query); query.StartQuery(); } else { Console.WriteLine("HasiCloud not populated yet"); InvokeOnMainThread(() => { var uia = new UIAlertView("Connecting to iCloud...", "Press the \uE049 button to refresh", null, "OK", null); uia.Show(); }); } }
void StartMetadataQuery() { if (documentMetadataQuery == null) { NSMetadataQuery metadataQuery = new NSMetadataQuery { SearchScopes = new NSObject[] { NSMetadataQuery.UbiquitousDocumentsScope }, Predicate = NSPredicate.FromFormat("(%K.pathExtension = %@)", NSMetadataQuery.ItemFSNameKey, (NSString)AppConfig.ListerFileExtension) }; documentMetadataQuery = metadataQuery; NSNotificationCenter notificationCenter = NSNotificationCenter.DefaultCenter; // TODO: use typed overload https://trello.com/c/1RyX6cJL finishGatheringToken = notificationCenter.AddObserver(NSMetadataQuery.DidFinishGatheringNotification, HandleMetadataQueryUpdates, metadataQuery); updateToken = notificationCenter.AddObserver(NSMetadataQuery.DidUpdateNotification, HandleMetadataQueryUpdates, metadataQuery); } documentMetadataQuery.StartQuery(); }
private void createNewSearchForPredicate(NSPredicate predicate, string title) { if (predicate == null) { return; } // remove the old search results. mySearchResults.Remove(mySearchResults.ArrangedObjects()); // always search for items in the Address Book //NSPredicate addrBookPredicate = NSPredicate.FromFormat (" (kMDItemKind == 'Address Book Person Data')",new NSObject[0]); NSPredicate addrBookPredicate = NSPredicate.FromFormat(" (kMDItemContentType == 'com.apple.addressbook.person')", new NSObject[0]); predicate = NSCompoundPredicate.CreateAndPredicate(new NSPredicate[2] { addrBookPredicate, predicate }); // set the query predicate.... query.Predicate = predicate; // and send it off for processing... query.StartQuery(); }
void LoadTasks(NSNotification notification) { Console.WriteLine ("LoadTasks()"); if (notification != null && notification.UserInfo != null) { var u = notification.UserInfo.ValueForKey(new NSString("HasiCloud")) as NSNumber; if (u != null) Console.WriteLine ("Has iCloud notification:"+ u.BoolValue); } if (AppDelegate.HasiCloud) { query = new NSMetadataQuery(); query.SearchScopes = new NSObject [] {NSMetadataQuery.QueryUbiquitousDocumentsScope}; var pred = NSPredicate.FromFormat ("%K like '*.task'" , new NSObject[] {NSMetadataQuery.ItemFSNameKey}); //Console.WriteLine ("Predicate:" + pred.PredicateFormat); query.Predicate = pred; NSNotificationCenter.DefaultCenter.AddObserver (this , new Selector("queryDidFinishGathering:") ,NSMetadataQuery.DidFinishGatheringNotification , query); query.StartQuery (); } else { Console.WriteLine ("HasiCloud not populated yet"); InvokeOnMainThread(()=>{ var uia = new UIAlertView("Connecting to iCloud...", "Press the \uE049 button to refresh",null, "OK", null); uia.Show (); }); } }
void FindDocument () { Console.WriteLine ("FindDocument"); query = new NSMetadataQuery { SearchScopes = new NSObject [] { NSMetadataQuery.UbiquitousDocumentsScope } }; var pred = NSPredicate.FromFormat ("%K == %@", new NSObject[] { NSMetadataQuery.ItemFSNameKey, new NSString (MonkeyDocFilename) }); Console.WriteLine ("Predicate:{0}", pred.PredicateFormat); query.Predicate = pred; NSNotificationCenter.DefaultCenter.AddObserver ( this, new Selector ("queryDidFinishGathering:"), NSMetadataQuery.DidFinishGatheringNotification, query ); query.StartQuery (); }
Task BeginQuery () { if (firstQueryResult != null) { var t = firstQueryResult; firstQueryResult = null; if (!t.Task.IsCompleted) t.SetException (new Exception ("Stopped")); } if (query != null) { query.StopQuery (); } firstQueryResult = new TaskCompletionSource<object> (); if (documentsUrl == null) { firstQueryResult.SetResult (null); return firstQueryResult.Task; } var queryString = ""; var head = ""; var args = new List<NSObject> (); foreach (var e in FileExtensions) { queryString += head + "(%K LIKE '*." + e + "')"; head = " OR "; args.Add (NSMetadataQuery.ItemFSNameKey); } query = new NSMetadataQuery (); query.SearchScopes = new NSObject[] { NSMetadataQuery.UbiquitousDocumentsScope }; query.Predicate = NSPredicate.FromFormat ( queryString, args.ToArray ()); Console.WriteLine ("START iCLOUD QUERY"); query.StartQuery (); needsRefresh = false; return firstQueryResult.Task; }