Example #1
0
        public void InsertOrUpdateReport(ExpenseReport item)
        {
            //Need to check if iOS 9 for CoreSpotlight
            if (UIDevice.CurrentDevice.CheckSystemVersion(9, 0))
            {
                var attributes = new CSSearchableItemAttributeSet(itemContentType: "");
                attributes.Title = "Expense Report: " + item.ReportName;
                attributes.ContentDescription =
                    "Status: " + item.StatusString
                    + "\nTotal: " + item.Total
                    + "\nCreated On:  " + item.CreatedOnString;

                // Create item
                var itemToAdd = new CSSearchableItem(item.ID.ToString(), item.ExpenseReportIdentifier, attributes);

                // Index item
                CSSearchableIndex.DefaultSearchableIndex.Index(new CSSearchableItem[] { itemToAdd }, (error) => {
                    // Successful?
                    if (error != null)
                    {
                        Console.WriteLine(error.LocalizedDescription);
                    }
                });
            }
        }
		public SpotlightHelper (List<Restaurant> restaurants)
		{
			this.restaurants = restaurants;
			var dataItems = new List<CSSearchableItem>();
			foreach (var r in restaurants) {
				var attributeSet = new CSSearchableItemAttributeSet (UTType.Text);
				attributeSet.Title = r.Name;
				attributeSet.ContentDescription = r.Cuisine;
				attributeSet.TextContent = r.Chef;

				var dataItem = new CSSearchableItem (r.Number.ToString(), "com.xamarin.restguide", attributeSet);
				dataItems.Add (dataItem);
			}

			// HACK: index should be 'managed' rather than deleted/created each time - keep track of what's indexed?
			// see the "To9o" sample for a better user-input search indexing strategy
			CSSearchableIndex.DefaultSearchableIndex.DeleteAll(null);

			CSSearchableIndex.DefaultSearchableIndex.Index (dataItems.ToArray<CSSearchableItem> (), err => {
				if (err != null) {
					Console.WriteLine (err);
				} else {
					Console.WriteLine ("Indexed items successfully");
				}
			});
		}
Example #3
0
        static async Task <CSSearchableItemAttributeSet> GetAttributeSet(IAppLinkEntry deepLinkUri, string contentType, string id)
        {
            var searchableAttributeSet = new CSSearchableItemAttributeSet(contentType)
            {
                RelatedUniqueIdentifier = id,
                Title = deepLinkUri.Title,
                ContentDescription = deepLinkUri.Description,
                Url = new NSUrl(deepLinkUri.AppLinkUri.ToString())
            };

            var source = deepLinkUri.Thumbnail;
            IImageSourceHandler handler;

            if (source != null && (handler = Registrar.Registered.GetHandler <IImageSourceHandler>(source.GetType())) != null)
            {
                UIImage uiimage;
                try
                {
                    uiimage = await handler.LoadImageAsync(source);
                }
                catch (OperationCanceledException)
                {
                    uiimage = null;
                }
                searchableAttributeSet.ThumbnailData = uiimage.AsPNG();
                uiimage.Dispose();
            }

            return(searchableAttributeSet);
        }
Example #4
0
        void ReIndexSearchItems(List <TodoItem> items)
        {
            var searchableItems = new List <CSSearchableItem> ();

            foreach (var item in todoItems)
            {
                // Create attributes to describe item
                var attributes = new CSSearchableItemAttributeSet(UTType.Text);
                attributes.Title = item.Name;
                attributes.ContentDescription = item.Notes;

                // Create item
                var searchableItem = new CSSearchableItem(item.ID, "com.companyname.corespotlightsearch", attributes);
                searchableItems.Add(searchableItem);
            }

            // Index items
            CSSearchableIndex.DefaultSearchableIndex.Index(searchableItems.ToArray <CSSearchableItem> (), error => {
                if (error != null)
                {
                    Debug.WriteLine(error);
                }
                else
                {
                    Debug.WriteLine("Successfully indexed items");
                }
            });
        }
Example #5
0
        void SetupSearch()
        {
            var activity = new NSUserActivity("com.micjames.beerdrinkin.beerdetails");

            if (!string.IsNullOrEmpty(beer.Description))
            {
                var info = new NSMutableDictionary();
                info.Add(new NSString("id"), new NSString(beer.BreweryDbId));
                info.Add(new NSString("name"), new NSString(beer.Name));
                info.Add(new NSString("description"), new NSString(beer.Description));
                info.Add(new NSString("imageUrl"), new NSString(beer.ImageMedium));
                info.Add(new NSString("abv"), new NSString(beer?.ABV.ToString()));
                info.Add(new NSString("breweryDbId"), new NSString(beer.BreweryDbId));

                var attributes = new CSSearchableItemAttributeSet();
                attributes.DisplayName        = beer.Name;
                attributes.ContentDescription = beer.Description;

                var keywords = new NSString[] { new NSString(beer.Name), new NSString("beerName") };
                activity.Keywords            = new NSSet <NSString>(keywords);
                activity.ContentAttributeSet = attributes;

                activity.Title    = beer.Name;
                activity.UserInfo = info;

                activity.EligibleForSearch         = true;
                activity.EligibleForPublicIndexing = true;
                activity.BecomeCurrent();
            }
        }
        public SpotlightHelper(List <Restaurant> restaurants)
        {
            this.restaurants = restaurants;
            var dataItems = new List <CSSearchableItem>();

            foreach (var r in restaurants)
            {
                var attributeSet = new CSSearchableItemAttributeSet(UTType.Text);
                attributeSet.Title = r.Name;
                attributeSet.ContentDescription = r.Cuisine;
                attributeSet.TextContent        = r.Chef;

                var dataItem = new CSSearchableItem(r.Number.ToString(), "com.xamarin.restguide", attributeSet);
                dataItems.Add(dataItem);
            }

            // HACK: index should be 'managed' rather than deleted/created each time - keep track of what's indexed?
            // see the "To9o" sample for a better user-input search indexing strategy
            CSSearchableIndex.DefaultSearchableIndex.DeleteAll(null);

            CSSearchableIndex.DefaultSearchableIndex.Index(dataItems.ToArray <CSSearchableItem> (), err => {
                if (err != null)
                {
                    Console.WriteLine(err);
                }
                else
                {
                    Console.WriteLine("Indexed items successfully");
                }
            });
        }
Example #7
0
        void RegisterHandoff(Speaker speaker)
        {
            var userInfo = new NSMutableDictionary();

            userInfo.Add(new NSString("Url"), new NSString(speaker.GetAppLink().AppLinkUri.AbsoluteUri));

            var keywords = new NSMutableSet <NSString>(new NSString(speaker.FirstName), new NSString(speaker.LastName));

            if (speaker.Sessions != null)
            {
                foreach (var session in speaker.Sessions)
                {
                    keywords.Add(new NSString(session.Title));
                }
            }

            _activity.Keywords   = new NSSet <NSString>(keywords);
            _activity.WebPageUrl = NSUrl.FromString(speaker.GetWebUrl());

            _activity.EligibleForHandoff = false;

            _activity.AddUserInfoEntries(userInfo);

            // Provide context
            var attributes = new CSSearchableItemAttributeSet($"{AboutThisApp.PackageName}.speaker");

            attributes.Keywords           = keywords.ToArray().Select(k => k.ToString()).ToArray();
            attributes.Url                = NSUrl.FromString(speaker.GetAppLink().AppLinkUri.AbsoluteUri);
            _activity.ContentAttributeSet = attributes;
        }
        /// <summary>
        /// Add the restaurant collection to the CoreSpotlight index
        /// </summary>
        public SpotlightHelper(List<Restaurant> restaurants)
        {
            this.restaurants = restaurants;
            var dataItems = new List<CSSearchableItem>();
            foreach (var r in restaurants) {
                var attributeSet = new CSSearchableItemAttributeSet (UTType.Text);
                attributeSet.Title = r.Name;
                attributeSet.ContentDescription = r.Cuisine;
                attributeSet.TextContent = r.Chef; // also allow search by chef's name

                var dataItem = new CSSearchableItem (r.Number.ToString(), "com.xamarin.restguide", attributeSet);
                dataItems.Add (dataItem);
            }

            // HACK: index could be 'managed' rather than deleted/created each time - keep track of what's indexed?
            // see the "To9o" sample for a better user-input search indexing strategy
            CSSearchableIndex.DefaultSearchableIndex.DeleteAll(deletErr =>
            {
                // Start the new index only after the old one is completely deleted;
                // important for larger indexes, where DeleteAll might take time to finish (thanks @jamesmontemagno)
                CSSearchableIndex.DefaultSearchableIndex.Index (dataItems.ToArray<CSSearchableItem> (), err => {
                    if (err != null) {
                        Console.WriteLine ("Index failed " + err);
                        Xamarin.Insights.Report(new Exception("CoreSpotlight Index Failed"), new Dictionary <string, string> {
                            {"Message", err.ToString()}
                        }, Xamarin.Insights.Severity.Error);
                    } else {
                        Console.WriteLine ("Indexed items successfully");
                        Xamarin.Insights.Track("CoreSpotlight", new Dictionary<string, string> {
                            {"Type", "Indexed successfully"}
                        });
                    }
                });
            });
        }
Example #9
0
        static async Task <CSSearchableItemAttributeSet> GetAttributeSet(IAppLinkEntry deepLinkUri, string contentType, string id)
        {
#pragma warning disable CA1416 // TODO: 'CSSearchableItemAttributeSet' is unsupported on: 'ios' 14.0 and later
            var searchableAttributeSet = new CSSearchableItemAttributeSet(contentType)
            {
                RelatedUniqueIdentifier = id,
                Title = deepLinkUri.Title,
                ContentDescription = deepLinkUri.Description,
                Url = new NSUrl(deepLinkUri.AppLinkUri.ToString())
            };
#pragma warning restore CA1416

            if (deepLinkUri.Thumbnail != null)
            {
                using (var uiimage = await deepLinkUri.Thumbnail.GetNativeImageAsync())
                {
                    if (uiimage == null)
                    {
                        throw new InvalidOperationException("AppLinkEntry Thumbnail must be set to a valid source");
                    }

                    searchableAttributeSet.ThumbnailData = uiimage.AsPNG();
                }
            }

            return(searchableAttributeSet);
        }
Example #10
0
        async Task <CSSearchableItem> AddConferenceToSearch(Conference conference)
        {
            var attributes = new CSSearchableItemAttributeSet(itemContentType: MobileCoreServices.UTType.DelimitedText.ToString());

            attributes.Title = conference.Name;
            attributes.ContentDescription = conference.Description;
            if (!string.IsNullOrWhiteSpace(conference.ImageUrl))
            {
                try {
                    var imageService = ServiceLocator.Current.GetInstance <IImageService> ();
                    var localPath    = await imageService.GetConferenceImagePath(conference);

                    UIImage image = null;
                    await Task.Run(() => {
                        var uiImage = UIImage.FromFile(localPath);
                        if (uiImage != null)
                        {
                            attributes.ThumbnailData = uiImage.AsPNG();
                        }
                    });
                } catch (Exception e) {
                    Insights.Report(e);
                }
            }
            var searchableConference = new CSSearchableItem(conference.Slug, "tekconf", attributes);

            return(searchableConference);
        }
        public static void BulkIndex(List<Task> tasks)
        {
            // HACK: generating fake GUID keys
            var searchIndexMap2 = new Dictionary<string, Task> ();
            foreach (var r in tasks) {
                searchIndexMap2.Add (Guid.NewGuid ().ToString(), r);
            }
            // mapping keys to objects
            var dataItems = searchIndexMap2.Select (keyValuePair => {
                var guid = keyValuePair.Key;
                var t = keyValuePair.Value;

                var attributeSet = new CSSearchableItemAttributeSet (UTType.Text);
                attributeSet.Title = t.Name;
                attributeSet.ContentDescription = t.Notes;
                attributeSet.TextContent = t.Notes;

                var dataItem = new CSSearchableItem (t.Id.ToString(), Spotlight.SearchDomain, attributeSet);
                return dataItem;

            });

            // Delete everything before doing bulk index
            CSSearchableIndex.DefaultSearchableIndex.DeleteAll(null);

            // Bulk index
            CSSearchableIndex.DefaultSearchableIndex.Index (dataItems.ToArray<CSSearchableItem> (), err => {
                if (err != null) {
                    Console.WriteLine (err);
                } else {
                    Console.WriteLine ("Indexed items successfully");
                }
            });
        }
        public void AddBeerToIndex(Beer beer)
        {
            var activity = new NSUserActivity("com.micjames.beerdrinkin.beerdetails");

            if (!string.IsNullOrEmpty(beer.Description))
            {
                var info = new NSMutableDictionary();
                info.Add(new NSString("name"), new NSString(beer.Name));
                info.Add(new NSString("description"), new NSString(beer.Description));

                if (beer?.Image?.MediumUrl != null)
                {
                    info.Add(new NSString("imageUrl"), new NSString(beer.Image.LargeUrl));
                }

                var attributes = new CSSearchableItemAttributeSet();
                attributes.DisplayName = beer.Name;
                attributes.ContentDescription = beer.Description;

                var keywords = new NSString[] { new NSString(beer.Name), new NSString("beerName") };
                activity.Keywords = new NSSet<NSString>(keywords);
                activity.ContentAttributeSet = attributes;

                activity.Title = beer.Name;
                activity.UserInfo = info;

                activity.EligibleForSearch = true;
                activity.EligibleForPublicIndexing = true;
                activity.BecomeCurrent();
            }

        }
Example #13
0
        public void AddBeerToIndex(Beer beer)
        {
            var activity = new NSUserActivity("com.micjames.beerdrinkin.beerdetails");

            if (!string.IsNullOrEmpty(beer.Description))
            {
                var info = new NSMutableDictionary();
                info.Add(new NSString("name"), new NSString(beer.Name));
                info.Add(new NSString("description"), new NSString(beer.Description));

                if (beer?.Image?.MediumUrl != null)
                {
                    info.Add(new NSString("imageUrl"), new NSString(beer.Image.LargeUrl));
                }

                var attributes = new CSSearchableItemAttributeSet();
                attributes.DisplayName        = beer.Name;
                attributes.ContentDescription = beer.Description;

                var keywords = new NSString[] { new NSString(beer.Name), new NSString("beerName") };
                activity.Keywords            = new NSSet <NSString>(keywords);
                activity.ContentAttributeSet = attributes;

                activity.Title    = beer.Name;
                activity.UserInfo = info;

                activity.EligibleForSearch         = true;
                activity.EligibleForPublicIndexing = true;
                activity.BecomeCurrent();
            }
        }
Example #14
0
		static async Task<CSSearchableItemAttributeSet> GetAttributeSet(IAppLinkEntry deepLinkUri, string contentType, string id)
		{
			var searchableAttributeSet = new CSSearchableItemAttributeSet(contentType)
			{
				RelatedUniqueIdentifier = id,
				Title = deepLinkUri.Title,
				ContentDescription = deepLinkUri.Description,
				Url = new NSUrl(deepLinkUri.AppLinkUri.ToString())
			};
Example #15
0
        private void RegisterHandoff(TalkModel talkModel)
        {
            var userInfo = new NSMutableDictionary();
            var uri      = new NSString(talkModel.GetAppLink().AppLinkUri.AbsoluteUri);

            userInfo.Add(new NSString("link"), uri);
            userInfo.Add(new NSString("Url"), uri);

            var keywords = new NSMutableSet <NSString>(new NSString(talkModel.Title));

            foreach (var speaker in talkModel.Speakers)
            {
                keywords.Add(new NSString(speaker.FullName));
            }

            foreach (var category in talkModel.Categories)
            {
                keywords.Add(new NSString(category.Name));
            }

            this.activity.Keywords   = new NSSet <NSString>(keywords);
            this.activity.WebPageUrl = NSUrl.FromString(talkModel.GetWebUrl());
            this.activity.UserInfo   = userInfo;

            // Provide context
            var attributes =
                new CSSearchableItemAttributeSet($"{AboutThisApp.PackageName}.session")
            {
                Keywords =
                    keywords.ToArray()
                    .Select(
                        k =>
                        k.ToString())
                    .ToArray(),
                Url = NSUrl.FromString(
                    talkModel.GetAppLink()
                    .AppLinkUri
                    .AbsoluteUri)
            };

            if (talkModel.StartTime.HasValue && talkModel.StartTime > DateTime.MinValue)
            {
                attributes.DueDate   = talkModel.StartTime.Value.ToNSDate();
                attributes.StartDate = talkModel.StartTime.Value.ToNSDate();
                attributes.EndDate   = talkModel.EndTime?.ToNSDate();

                attributes.ImportantDates = new[] { attributes.StartDate, attributes.EndDate };
            }

            this.activity.ContentAttributeSet = attributes;
            this.activity.EligibleForHandoff  = true;
        }
		public iOS9SearchModel (List<Restaurant> restaurants)
		{
			searchIndexMap2 = new Dictionary<Guid, Restaurant> ();
			foreach (var r in restaurants) {
				searchIndexMap2.Add (Guid.NewGuid (), r);
			}
			var dataItems = searchIndexMap2.Select (keyValuePair => {
				var guid = keyValuePair.Key;
				var restaurant = keyValuePair.Value;

				var attributeSet = new CSSearchableItemAttributeSet (UTType.Text);
				attributeSet.Title = restaurant.Name;
				attributeSet.ContentDescription = restaurant.Text;
				attributeSet.TextContent = restaurant.Text;

				var dataItem = new CSSearchableItem (guid.ToString (), "com.xamarin.restguide", attributeSet);
				return dataItem;

			});

//			searchIndexMap = new Dictionary<Guid, string> ();
//			foreach (var r in restaurants) {
//				searchIndexMap.Add (Guid.NewGuid (), r.Name);
//			}
//
//			//CoreSpotlight initialization
//			var dataItems = searchIndexMap.Select (keyValuePair => {
//				var guid = keyValuePair.Key;
//				var restaurant = keyValuePair.Value;
//
//				var attributeSet = new CSSearchableItemAttributeSet (UTType.Text);
//				attributeSet.Title = restaurant;
//				attributeSet.ContentDescription = "My app's data relating to " + restaurant;
//				attributeSet.TextContent = restaurant;
//
//				var dataItem = new CSSearchableItem (guid.ToString (), "com.xamarin.restguide", attributeSet);
//				return dataItem;
//			
//			});

			// HACK: index should be 'managed' rather than deleted/created each time
			CSSearchableIndex.DefaultSearchableIndex.DeleteAll(null);

			CSSearchableIndex.DefaultSearchableIndex.Index (dataItems.ToArray<CSSearchableItem> (), err => {
				if (err != null) {
					Console.WriteLine (err);
				} else {
					Console.WriteLine ("Indexed items successfully");
				}
			});
		}
Example #17
0
        private void RegisterHandoff(SpeakerModel speakerModel)
        {
            var userInfo = new NSMutableDictionary
            {
                {
                    new NSString("Url"),
                    new NSString(
                        speakerModel.GetAppLink().AppLinkUri.AbsoluteUri)
                }
            };

            var keywords = new NSMutableSet <NSString>(
                new NSString(speakerModel.FullName));

            if (speakerModel.Talks != null)
            {
                foreach (var session in speakerModel.Talks)
                {
                    keywords.Add(new NSString(session.Title));
                }
            }

            this.activity.Keywords   = new NSSet <NSString>(keywords);
            this.activity.WebPageUrl = NSUrl.FromString(speakerModel.GetWebUrl());

            this.activity.EligibleForHandoff = false;

            this.activity.AddUserInfoEntries(userInfo);

            // Provide context
            var attributes =
                new CSSearchableItemAttributeSet($"{AboutThisApp.PackageName}.speaker")
            {
                Keywords =
                    keywords.ToArray()
                    .Select(
                        k =>
                        k.ToString())
                    .ToArray(),
                Url = NSUrl.FromString(
                    speakerModel
                    .GetAppLink()
                    .AppLinkUri
                    .AbsoluteUri)
            };

            this.activity.ContentAttributeSet = attributes;
        }
Example #18
0
 CSSearchableItem CreateSearchItem(Song song)
 {
     try{
         var attributes = new CSSearchableItemAttributeSet();
         attributes.Album         = song.Album;
         attributes.ContentType   = UTType.Audio;
         attributes.Title         = song.Name;
         attributes.Artist        = song.Artist;
         attributes.ContentRating = song.Rating;
         attributes.MusicalGenre  = song.Genre;
         attributes.Identifier    = song.Id;
         var item = new CSSearchableItem(song.Id, "songdata", attributes);
         return(item);
     }
     catch (Exception ex) {
         return(null);
     }
 }
Example #19
0
        public void CreateSearchItem(TodoItem item)
        {
            // Create attributes to describe item
            var attributes = new CSSearchableItemAttributeSet (UTType.Text);
            attributes.Title = item.Name;
            attributes.ContentDescription = item.Notes;

            // Create item
            var searchableItem = new CSSearchableItem (item.ID, "com.companyname.corespotlightsearch", attributes);

            // Index item
            CSSearchableIndex.DefaultSearchableIndex.Index (new CSSearchableItem[]{ searchableItem }, error => {
                if (error != null) {
                    Debug.WriteLine (error);
                } else {
                    Debug.WriteLine ("Successfully indexed item");
                }
            });
        }
        public static Task IndexTrips(IEnumerable <Trip> trips)
        {
            return(Task.Run(() =>
            {
                CSSearchableIndex.DefaultSearchableIndex.DeleteAll(deleteError =>
                {
                    if (deleteError != null)
                    {
                        Logger.Instance.Report(new System.Exception("CoreSpotlight Index Deletion Failed"), new Dictionary <string, string>
                        {
                            { "Message", deleteError.ToString() }
                        });
                    }
                });

                var i = 0;
                var dataItems = new List <CSSearchableItem>();
                foreach (var trip in trips)
                {
                    var attributeSet = new CSSearchableItemAttributeSet(UTType.Text);
                    attributeSet.Title = trip.Name;
                    attributeSet.ContentDescription = $"{trip.Name} was on {trip.TimeAgo} and lasted {trip.TotalDistance}.";

                    var dataItem = new CSSearchableItem(i.ToString(), "com.microsoft.MyDriving.trip", attributeSet);
                    dataItems.Add(dataItem);

                    i++;
                }

                CSSearchableIndex.DefaultSearchableIndex.Index(dataItems.ToArray(), insertionError =>
                {
                    if (insertionError != null)
                    {
                        Logger.Instance.Report(new System.Exception("CoreSpotlight Indexing Failed"), new Dictionary <string, string>
                        {
                            { "Message", insertionError.ToString() }
                        });
                    }
                });
            }));
        }
		public static Task IndexTrips(IEnumerable<Trip> trips)
		{
			return Task.Run(() =>
			{
				CSSearchableIndex.DefaultSearchableIndex.DeleteAll(deleteError =>
				{
					if (deleteError != null)
					{
						Logger.Instance.Report(new System.Exception("CoreSpotlight Index Deletion Failed"), new Dictionary<string, string>
						{
							{ "Message", deleteError.ToString () }
						});
					}
				});

				var i = 0;
				var dataItems = new List<CSSearchableItem>();
				foreach (var trip in trips)
				{
					var attributeSet = new CSSearchableItemAttributeSet(UTType.Text);
					attributeSet.Title = trip.Name;
					attributeSet.ContentDescription = $"{trip.Name} was on {trip.TimeAgo} and lasted {trip.TotalDistance}.";

					var dataItem = new CSSearchableItem(i.ToString(), "com.microsoft.MyDriving.trip", attributeSet);
					dataItems.Add(dataItem);

					i++;
				}

				CSSearchableIndex.DefaultSearchableIndex.Index (dataItems.ToArray (), insertionError =>
				{
					if (insertionError != null)
					{
						Logger.Instance.Report(new System.Exception("CoreSpotlight Indexing Failed"), new Dictionary<string, string>
						{
							{ "Message", insertionError.ToString () }
						});
					}
				});
			});
		}
        private void SetupCoreSpotlightSearch()
        {
            // Create attributes to describe an item
            var attributes = new CSSearchableItemAttributeSet(UTType.Data);

            attributes.Title = "Test Cloud";
            attributes.ContentDescription = "Automatically test your app on 1,000 devices in the cloud.";

            // Create item
            var item = new CSSearchableItem("1", "products", attributes);

            // Index item
            CSSearchableIndex.DefaultSearchableIndex.Index(new CSSearchableItem[] { item }, (error) =>
            {
                // Successful?
                if (error != null)
                {
                    Console.WriteLine(error.LocalizedDescription);
                }
            });
        }
        public static void Index(TodoItem t)
        {
            var attributeSet = new CSSearchableItemAttributeSet(UTType.Text);

            attributeSet.Title = t.Name;
            attributeSet.ContentDescription = t.Notes;
            attributeSet.TextContent        = t.Notes;

            var dataItem = new CSSearchableItem(t.Id.ToString(), Spotlight.SearchDomain, attributeSet);

            CSSearchableIndex.DefaultSearchableIndex.Index(new CSSearchableItem[] { dataItem }, err => {
                if (err != null)
                {
                    Console.WriteLine(err);
                }
                else
                {
                    Console.WriteLine("Indexed inividual item successfully");
                }
            });
        }
Example #24
0
        /// <summary>
        /// Add the restaurant collection to the CoreSpotlight index
        /// </summary>
        public SpotlightHelper(List <Restaurant> restaurants)
        {
            this.restaurants = restaurants;
            var dataItems = new List <CSSearchableItem>();

            foreach (var r in restaurants)
            {
                var attributeSet = new CSSearchableItemAttributeSet(UTType.Text);
                attributeSet.Title = r.Name;
                attributeSet.ContentDescription = r.Cuisine;
                attributeSet.TextContent        = r.Chef;          // also allow search by chef's name

                var dataItem = new CSSearchableItem(r.Number.ToString(), "com.xamarin.restguide", attributeSet);
                dataItems.Add(dataItem);
            }

            // HACK: index could be 'managed' rather than deleted/created each time - keep track of what's indexed?
            // see the "To9o" sample for a better user-input search indexing strategy
            CSSearchableIndex.DefaultSearchableIndex.DeleteAll(deletErr =>
            {
                // Start the new index only after the old one is completely deleted;
                // important for larger indexes, where DeleteAll might take time to finish (thanks @jamesmontemagno)
                CSSearchableIndex.DefaultSearchableIndex.Index(dataItems.ToArray <CSSearchableItem> (), err => {
                    if (err != null)
                    {
                        Console.WriteLine("Index failed " + err);
                        Xamarin.Insights.Report(new Exception("CoreSpotlight Index Failed"), new Dictionary <string, string> {
                            { "Message", err.ToString() }
                        }, Xamarin.Insights.Severity.Error);
                    }
                    else
                    {
                        Console.WriteLine("Indexed items successfully");
                        Xamarin.Insights.Track("CoreSpotlight", new Dictionary <string, string> {
                            { "Type", "Indexed successfully" }
                        });
                    }
                });
            });
        }
        void RegisterHandoff(MiniHack entity)
        {
            var userInfo = new NSMutableDictionary();
            var uri      = new NSString(entity.GetAppLink().AppLinkUri.AbsoluteUri);

            userInfo.Add(new NSString("link"), uri);
            userInfo.Add(new NSString("Url"), uri);

            var keywords = new NSMutableSet <NSString>(new NSString(entity.Name));

            _activity.Keywords = new NSSet <NSString>(keywords);
            _activity.UserInfo = userInfo;

            // Provide context
            var attributes = new CSSearchableItemAttributeSet($"{AboutThisApp.PackageName}.minihack");

            attributes.Keywords = keywords.ToArray().Select(k => k.ToString()).ToArray();
            attributes.Url      = NSUrl.FromString(entity.GetAppLink().AppLinkUri.AbsoluteUri);

            _activity.ContentAttributeSet = attributes;
            _activity.EligibleForHandoff  = false;
        }
Example #26
0
        static async Task <CSSearchableItemAttributeSet> GetAttributeSet(IAppLinkEntry deepLinkUri, string contentType, string id)
        {
            var searchableAttributeSet = new CSSearchableItemAttributeSet(contentType)
            {
                RelatedUniqueIdentifier = id,
                Title = deepLinkUri.Title,
                ContentDescription = deepLinkUri.Description,
                Url = new NSUrl(deepLinkUri.AppLinkUri.ToString())
            };

            using (var uiimage = await deepLinkUri.Thumbnail.GetNativeImageAsync())
            {
                if (uiimage == null)
                {
                    throw new InvalidOperationException("AppLinkEntry Thumbnail must be set to a valid source");
                }

                searchableAttributeSet.ThumbnailData = uiimage.AsPNG();
            }

            return(searchableAttributeSet);
        }
Example #27
0
        NSUserActivity CreateActivity(TodoItem item)
        {
            // Create app search activity
            var activity = new NSUserActivity (ActivityTypes.View);

            // Populate activity
            activity.Title = item.Name;

            // Add additional data
            var attributes = new CSSearchableItemAttributeSet ();
            attributes.DisplayName = item.Name;
            attributes.ContentDescription = item.Notes;

            activity.ContentAttributeSet = attributes;
            activity.AddUserInfoEntries (NSDictionary.FromObjectAndKey (new NSString (item.ID), new NSString ("Id")));

            // Add app search ability
            activity.EligibleForSearch = true;
            activity.BecomeCurrent ();	// Don't forget to ResignCurrent() later

            return activity;
        }
        public static void BulkIndex(List <TodoItem> todoItems)
        {
            // HACK: generating fake GUID keys
            var searchIndexMap2 = new Dictionary <string, TodoItem> ();

            foreach (var r in todoItems)
            {
                searchIndexMap2.Add(Guid.NewGuid().ToString(), r);
            }
            // mapping keys to objects
            var dataItems = searchIndexMap2.Select(keyValuePair => {
                var guid = keyValuePair.Key;
                var t    = keyValuePair.Value;

                var attributeSet   = new CSSearchableItemAttributeSet(UTType.Text);
                attributeSet.Title = t.Name;
                attributeSet.ContentDescription = t.Notes;
                attributeSet.TextContent        = t.Notes;

                var dataItem = new CSSearchableItem(t.Id.ToString(), Spotlight.SearchDomain, attributeSet);
                return(dataItem);
            });

            // Delete everything before doing bulk index
            CSSearchableIndex.DefaultSearchableIndex.DeleteAll(null);

            // Bulk index
            CSSearchableIndex.DefaultSearchableIndex.Index(dataItems.ToArray <CSSearchableItem> (), err => {
                if (err != null)
                {
                    Console.WriteLine(err);
                }
                else
                {
                    Console.WriteLine("Indexed items successfully");
                }
            });
        }
        public static void Index(Task t)
        {
            var attributeSet = new CSSearchableItemAttributeSet (UTType.Text);
            attributeSet.Title = t.Name;
            attributeSet.ContentDescription = t.Notes;
            attributeSet.TextContent = t.Notes;

            var dataItem = new CSSearchableItem (t.Id.ToString(), Spotlight.SearchDomain, attributeSet);

            CSSearchableIndex.DefaultSearchableIndex.Index (new CSSearchableItem[] {dataItem}, err => {
                if (err != null) {
                    Console.WriteLine (err);
                    Insights.Report(new Exception("CoreSpotlight Index Failed"), new Dictionary <string, string> {
                        {"Message", err.ToString()}
                    }, Xamarin.Insights.Severity.Error);
                } else {
                    Console.WriteLine ("Indexed inividual item successfully");
                    Insights.Track("CoreSpotlight", new Dictionary<string, string> {
                        {"Type", "Indexed successfully"}
                    });
                }
            });
        }
Example #30
0
        NSUserActivity CreateActivity(TodoItem item)
        {
            // Create app search activity
            var activity = new NSUserActivity(ActivityTypes.View);

            // Populate activity
            activity.Title = item.Name;

            // Add additional data
            var attributes = new CSSearchableItemAttributeSet();

            attributes.DisplayName        = item.Name;
            attributes.ContentDescription = item.Notes;

            activity.ContentAttributeSet = attributes;
            activity.AddUserInfoEntries(NSDictionary.FromObjectAndKey(new NSString(item.ID), new NSString("Id")));

            // Add app search ability
            activity.EligibleForSearch = true;
            activity.BecomeCurrent();                   // Don't forget to ResignCurrent() later

            return(activity);
        }
Example #31
0
        public void CreateSearchItem(TodoItem item)
        {
            // Create attributes to describe item
            var attributes = new CSSearchableItemAttributeSet(UTType.Text);

            attributes.Title = item.Name;
            attributes.ContentDescription = item.Notes;

            // Create item
            var searchableItem = new CSSearchableItem(item.ID, "com.companyname.corespotlightsearch", attributes);

            // Index item
            CSSearchableIndex.DefaultSearchableIndex.Index(new CSSearchableItem[] { searchableItem }, error => {
                if (error != null)
                {
                    Debug.WriteLine(error);
                }
                else
                {
                    Debug.WriteLine("Successfully indexed item");
                }
            });
        }
Example #32
0
        void ReIndexSearchItems(List<TodoItem> items)
        {
            var searchableItems = new List<CSSearchableItem> ();
            foreach (var item in todoItems) {
                // Create attributes to describe item
                var attributes = new CSSearchableItemAttributeSet (UTType.Text);
                attributes.Title = item.Name;
                attributes.ContentDescription = item.Notes;

                // Create item
                var searchableItem = new CSSearchableItem (item.ID, "com.companyname.corespotlightsearch", attributes);
                searchableItems.Add (searchableItem);
            }

            // Index items
            CSSearchableIndex.DefaultSearchableIndex.Index (searchableItems.ToArray<CSSearchableItem> (), error => {
                if (error != null) {
                    Debug.WriteLine (error);
                } else {
                    Debug.WriteLine ("Successfully indexed items");
                }
            });
        }
Example #33
0
		static async Task<CSSearchableItemAttributeSet> GetAttributeSet(IAppLinkEntry deepLinkUri, string contentType, string id)
		{
			var searchableAttributeSet = new CSSearchableItemAttributeSet(contentType)
			{
				RelatedUniqueIdentifier = id,
				Title = deepLinkUri.Title,
				ContentDescription = deepLinkUri.Description,
				Url = new NSUrl(deepLinkUri.AppLinkUri.ToString())
			};

			var source = deepLinkUri.Thumbnail;
			IImageSourceHandler handler;
			if (source != null && (handler = Registrar.Registered.GetHandler<IImageSourceHandler>(source.GetType())) != null)
			{
				UIImage uiimage;
				try
				{
					uiimage = await handler.LoadImageAsync(source);
				}
				catch (OperationCanceledException)
				{
					uiimage = null;
				}
				searchableAttributeSet.ThumbnailData = uiimage.AsPNG();
				uiimage.Dispose();
			}

			return searchableAttributeSet;
		}
		async Task<CSSearchableItem> AddConferenceToSearch (Conference conference)
		{
			var attributes = new CSSearchableItemAttributeSet (itemContentType: MobileCoreServices.UTType.DelimitedText.ToString ());
			attributes.Title = conference.Name;
			attributes.ContentDescription = conference.Description;
			if (!string.IsNullOrWhiteSpace (conference.ImageUrl)) {
				try {
					var imageService = ServiceLocator.Current.GetInstance<IImageService> ();
					var localPath = await imageService.GetConferenceImagePath (conference);
					UIImage image = null;
					await Task.Run (() => {
						var uiImage = UIImage.FromFile (localPath);
						if (uiImage != null) {
							attributes.ThumbnailData = uiImage.AsPNG ();
						}
					});
				} catch (Exception e) {
					Insights.Report (e);
				}
			}
			var searchableConference = new CSSearchableItem (conference.Slug, "tekconf", attributes);
			return searchableConference;
		}
		void SetupSearch()
		{
			var activity = new NSUserActivity("com.micjames.beerdrinkin.beerdetails");

			if (!string.IsNullOrEmpty(beer.Description))
			{
				var info = new NSMutableDictionary();
				info.Add(new NSString("id"), new NSString(beer.BreweryDbId));
				info.Add(new NSString("name"), new NSString(beer.Name));
				info.Add(new NSString("description"), new NSString(beer.Description));
				info.Add(new NSString("imageUrl"), new NSString(beer.ImageMedium));
				info.Add(new NSString("abv"), new NSString(beer?.ABV.ToString()));
				info.Add(new NSString("breweryDbId"), new NSString(beer.BreweryDbId));
			
				var attributes = new CSSearchableItemAttributeSet();
				attributes.DisplayName = beer.Name;
				attributes.ContentDescription = beer.Description;

				var keywords = new NSString[] { new NSString(beer.Name), new NSString("beerName") };
				activity.Keywords = new NSSet<NSString>(keywords);
				activity.ContentAttributeSet = attributes;

				activity.Title = beer.Name;
				activity.UserInfo = info;

				activity.EligibleForSearch = true;
				activity.EligibleForPublicIndexing = true;
				activity.BecomeCurrent();
			}

        }