private void OnListTasks(LazyResult <Tasks.v1.Data.Tasks> response) { Tasks.v1.Data.Tasks result = null; try { result = response.GetResult(); } catch (Exception ex) { AppDelegate.FinishActivity(); ReloadComplete(); ShowError(ex); return; } BeginInvokeOnMainThread(() => { var section = Root.First(); section.Clear(); if (result.Items != null) { section.AddAll(result.Items.Select(t => new StyledStringElement(t.Title, () => OnTap(t)) { Accessory = (t.Status == "completed") ? UITableViewCellAccessory.Checkmark : UITableViewCellAccessory.None } ).Cast <Element>()); } ReloadComplete(); AppDelegate.FinishActivity(); }); }
public void IsLazyTest() { bool hasBeenFetched = false; Func<bool> fetchFunction = () => (hasBeenFetched = true); // Try fetching the result. var result = new LazyResult<bool>(fetchFunction); Assert.IsFalse(hasBeenFetched); Assert.IsTrue(result.GetResult()); Assert.IsTrue(hasBeenFetched); // Try a second fetch. Confirm that a cached result will be used. hasBeenFetched = false; Assert.IsTrue(result.GetResult()); Assert.IsFalse(hasBeenFetched); }
/// <summary> /// Executes the request asynchronously without parsing the response, /// and calls the specified method once finished. /// </summary> /// <remarks>The returned stream is encoded in UTF-8.</remarks> public void FetchAsyncAsStream([Optional] ExecuteRequestDelegate <Stream> methodToCall) { GetAsyncResponse( (IAsyncRequestResult state) => { var result = new LazyResult <Stream>( () => { // Retrieve and convert the response. IResponse response = state.GetResponse(); response.ThrowIfNull("response"); return(response.Stream); }); // Only invoke the method if it was set. if (methodToCall != null) { methodToCall(result); } else { result.GetResult(); // Resolve the result in any case. } }); }
private void OnEventResponse(LazyResult <Event> _event) { var realEvent = _event.GetResult(); ViewModel.EventTitle = realEvent.Summary; ViewModel.StartDate = DateTime.Parse(realEvent.Start.DateTime); ViewModel.EndDate = DateTime.Parse(realEvent.End.DateTime); }
public void IsLazyTest() { bool hasBeenFetched = false; Func <bool> fetchFunction = () => (hasBeenFetched = true); // Try fetching the result. var result = new LazyResult <bool>(fetchFunction); Assert.IsFalse(hasBeenFetched); Assert.IsTrue(result.GetResult()); Assert.IsTrue(hasBeenFetched); // Try a second fetch. Confirm that a cached result will be used. hasBeenFetched = false; Assert.IsTrue(result.GetResult()); Assert.IsFalse(hasBeenFetched); }
/// <summary> /// Executes the request asynchronously and optionally calls the specified method once finished. /// </summary> public void FetchAsync([Optional] ExecuteRequestDelegate <TResponse> methodToCall) { GetAsyncResponse( (IAsyncRequestResult state) => { var result = new LazyResult <TResponse>(() => { // Retrieve and convert the response. IResponse response = state.GetResponse(); return(FetchObject(response)); }); // Only invoke the method if it was set. if (methodToCall != null) { methodToCall(result); } else { result.GetResult(); } }); }
private void OnTaskListResponse(LazyResult <TaskLists> response) { TaskLists lists = null; try { lists = response.GetResult(); } catch (Exception ex) { BeginInvokeOnMainThread(ReloadComplete); AppDelegate.FinishActivity(); ShowError(ex); } if (lists == null || lists.Items == null) { AppDelegate.FinishActivity(); return; } Section section = new Section(); section.AddAll(lists.Items.Select(l => new StringElement(l.Title, () => { var tasks = new TasksViewController(this.service, l); NavigationController.PushViewController(tasks, true); }) ).Cast <Element>()); BeginInvokeOnMainThread(() => { Root.Clear(); Root.Add(section); ReloadComplete(); AppDelegate.FinishActivity(); }); }
private void OnTaskListResponse(LazyResult<TaskLists> response) { TaskLists lists = null; try { lists = response.GetResult(); } catch (Exception ex) { BeginInvokeOnMainThread (ReloadComplete); AppDelegate.FinishActivity(); ShowError (ex); } if (lists == null || lists.Items == null) { AppDelegate.FinishActivity(); return; } Section section = new Section(); section.AddAll (lists.Items.Select (l => new StringElement (l.Title, () => { var tasks = new TasksViewController (this.service, l); NavigationController.PushViewController (tasks, true); }) ).Cast<Element>()); BeginInvokeOnMainThread (() => { Root.Clear(); Root.Add (section); ReloadComplete(); AppDelegate.FinishActivity(); }); }
private void OnListTasks(LazyResult<Tasks.v1.Data.Tasks> response) { Tasks.v1.Data.Tasks result = null; try { result = response.GetResult(); } catch (Exception ex) { AppDelegate.FinishActivity(); ReloadComplete(); ShowError (ex); return; } BeginInvokeOnMainThread (() => { var section = Root.First(); section.Clear(); if (result.Items != null) { section.AddAll (result.Items.Select (t => new StyledStringElement (t.Title, () => OnTap (t)) { Accessory = (t.Status == "completed") ? UITableViewCellAccessory.Checkmark : UITableViewCellAccessory.None } ).Cast<Element>()); } ReloadComplete(); AppDelegate.FinishActivity(); }); }