public override List <ContentProviderOperation> Parse(XDocument input, ContentResolver resolver) { List <ContentProviderOperation> batch = new List <ContentProviderOperation>(); // Clear any existing static blocks, as they may have been updated. String selection = ScheduleContract.Blocks.BLOCK_TYPE + "=? OR " + ScheduleContract.Blocks.BLOCK_TYPE + "=?"; String[] selectionArgs = { ParserUtils.BlockTypeFood, ParserUtils.BlockTypeOfficeHours }; batch.Add(ContentProviderOperation.NewDelete(ScheduleContract.Blocks.CONTENT_URI).WithSelection(selection, selectionArgs).Build()); var blocks = from x in input.Descendants("block") select new BlocksXml { StartTime = ParserUtils.ParseTime(x.Element("start").Value), EndTime = ParserUtils.ParseTime(x.Element("end").Value), Title = x.Element("title").Value, BlockType = x.Element("type") != null?x.Element("type").Value : "" }; foreach (var item in blocks) { batch.Add(ParseBlock(item)); } return(batch); }
private static void CleanupPlaylist(Context context, long playlistId, ICursor cursor) { var idCol = cursor.GetColumnIndexOrThrow(Playlists.Members.AudioId); var uri = Uri.Parse($"content://media/external/audio/playlists/{playlistId}/members"); var ops = new List <ContentProviderOperation> { ContentProviderOperation.NewDelete(uri).Build() }; var f = 100; if (cursor.MoveToFirst() && cursor.Count > 0) { do { var builder = ContentProviderOperation.NewInsert(uri) .WithValue(Playlists.Members.PlayOrder, cursor.Position) .WithValue(Playlists.Members.AudioId, cursor.GetLong(idCol)); if ((cursor.Position + 1) % f == 0) { builder.WithYieldAllowed(true); } ops.Add(builder.Build()); } while (cursor.MoveToNext()); } context.ContentResolver.ApplyBatch(MediaStore.Authority, ops); }
/// <summary> /// Builds ContentProviderOperations for adding/removing reminders. /// Specifically intended for use by AddOrUpdateEvent, as if existingEvent is omitted, /// this requires that the operations are added to a batch in which the first operation /// inserts the event. /// </summary> /// <param name="reminders">New reminders (replacing existing reminders, if any)</param> /// <param name="existingEvent">(optional) Existing event to update reminders for</param> /// <returns>List of ContentProviderOperations for applying reminder updates as part of a batched update</returns> private static IList <ContentProviderOperation> BuildReminderUpdateOperations(IList <CalendarEventReminder> reminders, CalendarEvent existingEvent = null) { var operations = new List <ContentProviderOperation>(); // If reminders haven't changed, do nothing // if (reminders == existingEvent?.Reminders || (reminders != null && existingEvent?.Reminders != null && reminders.SequenceEqual(existingEvent.Reminders))) { return(operations); } // Build operations that remove all existing reminders and add new ones if (existingEvent?.Reminders != null) { operations.AddRange(existingEvent.Reminders.Select(reminder => ContentProviderOperation.NewDelete(_remindersUri) .WithSelection($"{CalendarContract.Reminders.InterfaceConsts.EventId} = {existingEvent.ExternalID}", null) .Build())); } if (reminders != null) { if (existingEvent != null) { operations.AddRange(reminders.Select(reminder => ContentProviderOperation.NewInsert(_remindersUri) .WithValues(reminder.ToContentValues(existingEvent.ExternalID)) .Build())); } else { // This assumes that these operations are being added to a batch in which the first operation // is the event insertion operation // operations.AddRange(reminders.Select(reminder => ContentProviderOperation.NewInsert(_remindersUri) .WithValues(reminder.ToContentValues()) .WithValueBackReference(CalendarContract.Reminders.InterfaceConsts.EventId, 0) .Build())); } } return(operations); }
public override List <ContentProviderOperation> Parse(XDocument input, ContentResolver resolver) { List <ContentProviderOperation> batch = new List <ContentProviderOperation>(); batch.Add(ContentProviderOperation.NewDelete(ScheduleContract.Tracks.CONTENT_URI).Build()); var tracks = from x in input.Descendants("track") select new TrackXml { Name = x.Element("name").Value, Color = Color.ParseColor(x.Element("color").Value), Abstract = x.Element("abstract").Value }; foreach (var item in tracks) { batch.Add(ParseTracks(item)); } return(batch); }
public override List <ContentProviderOperation> Parse(XDocument input, ContentResolver resolver) { List <ContentProviderOperation> batch = new List <ContentProviderOperation>(); // Clear any existing suggestion words batch.Add(ContentProviderOperation.NewDelete(ScheduleContract.SearchSuggest.CONTENT_URI).Build()); var suggestions = from x in input.Descendants("word") select new TagXml { Word = x.Value }; foreach (var item in suggestions) { batch.Add(ContentProviderOperation.NewInsert(ScheduleContract.SearchSuggest.CONTENT_URI).WithValue(SearchManager.SuggestColumnText1, item.Word).Build()); } return(batch); }