public async Task <IEnumerable <CalendarTable> > GetCalendarAsync() { if (!initialized) { Init(); } List <CalendarTable> calendarTables = new List <CalendarTable>(); try { IFolder folder = await rootFolder.CreateFolderAsync("Library", CreationCollisionOption.OpenIfExists); // create a file, overwriting any existing fileMySubFolder IFile Calendarfile = await folder.CreateFileAsync("Calendar.json", CreationCollisionOption.OpenIfExists); var json = await Calendarfile.ReadAllTextAsync(); // populate the file with some text CalendarTable = JsonConvert.DeserializeObject <CalendarInfo.RootObject>(json); if (CalendarTable.items != null) { foreach (var item in CalendarTable.items) { CalendarTable calendar = new CalendarTable(item); calendarTables.Add(calendar); } } } catch (Exception) { } return(await Task.Run(() => calendarTables)); //sqlite.GetCalendarItems()); }
public Task AddCalendarItems(CalendarInfo.RootObject rootObject) { if (rootObject.items.Count > 100) { _connection.DeleteAll <CalendarTable>(); } foreach (var items in rootObject.items) { if (items != null) { var Citem = new CalendarTable(items); { if (!_connection.Table <CalendarTable>().Any(x => x.id == Citem.id)) { _connection.Insert(Citem); } else { _connection.Update(Citem); } } } } return(Task.Run(() => rootObject)); }
public async Task SyncCalendarAsync(string Url) { try { if (!CrossConnectivity.Current.IsConnected) { return; } using (var clients = new HttpClient()) { var CalendarString = await clients.GetStringAsync(Url); IFolder folder = await rootFolder.CreateFolderAsync("Library", CreationCollisionOption.OpenIfExists); // create a file, overwriting any existing fileMySubFolder IFile file = await folder.CreateFileAsync("Calendar.json", CreationCollisionOption.OpenIfExists); var json = await file.ReadAllTextAsync(); // populate the file with some text if (json != CalendarString && !string.IsNullOrEmpty(CalendarString)) { await file.WriteAllTextAsync(CalendarString); CalendarTable = JsonConvert.DeserializeObject <CalendarInfo.RootObject>(CalendarString); //await sqlite.AddCalendarItems(JsonConvert.DeserializeObject<CalendarInfo.RootObject>(CalendarString)); } } Settings.LastSync = DateTime.Now; } catch (Exception ex) { Debug.WriteLine("Sync Failed:" + ex.Message); } }