/// <summary> /// Override to provide custom Model refresh behavior /// </summary> /// <param name="parameters">Parameters passed to data portal</param> /// <returns></returns> protected virtual async Task <T> DoRefreshAsync(params object[] parameters) { if (typeof(Core.IReadOnlyObject).IsAssignableFrom(typeof(T)) || typeof(Core.IReadOnlyCollection).IsAssignableFrom(typeof(T)) || typeof(Core.IEditableCollection).IsAssignableFrom(typeof(T))) { if (Server.DataPortal.GetCriteriaFromArray(parameters) is Server.EmptyCriteria) { return(await DataPortal.FetchAsync()); } else { return(await DataPortal.FetchAsync(parameters)); } } else { if (Server.DataPortal.GetCriteriaFromArray(parameters) is Server.EmptyCriteria) { return(await DataPortal.CreateAsync()); } else { return(await DataPortal.FetchAsync(parameters)); } } }
public async Task TestSaveWhileBusy() { IDataPortal <ItemWithAsynchRule> dataPortal = _testDIContext.CreateDataPortal <ItemWithAsynchRule>(); TestResults.Reinitialise(); UnitTestContext context = GetContext(); var item = await dataPortal.FetchAsync("an id"); item.RuleField = "some value"; context.Assert.IsTrue(item.IsBusy); context.Assert.IsFalse(item.IsSavable); try { await item.SaveAsync(); } catch (Exception ex) { var error = ex as InvalidOperationException; context.Assert.IsNotNull(error); context.Assert.IsTrue(error.Message.ToLower().Contains("busy")); context.Assert.IsTrue(error.Message.ToLower().Contains("save")); context.Assert.Success(); } context.Complete(); }
public async Task FetchAsync_WithCriteria() { IDataPortal <Single2> dataPortal = _testDIContext.CreateDataPortal <Single2>(); var result = await dataPortal.FetchAsync(123); Assert.IsNotNull(result); Assert.AreEqual(123, result.Id); }
public async Task OnGet(int id) { if (id == -1) { Item = await _portal.CreateAsync(); } else { Item = await _portal.FetchAsync(id); } }
public ItemEditViewModel(IDataPortal <PersonEdit> portal, int id) { PersonPortal = portal; Initialize(); if (id == -1) { RefreshAsync <PersonEdit>(() => PersonPortal.CreateAsync()); } else { RefreshAsync <PersonEdit>(() => PersonPortal.FetchAsync(id)); } }
public async Task TestBusy() { IDataPortal <ItemWithAsynchRule> dataPortal = _noCloneOnUpdateDIContext.CreateDataPortal <ItemWithAsynchRule>(); UnitTestContext context = GetContext(); var item = await dataPortal.FetchAsync("an id"); item.RuleField = "some value"; context.Assert.IsTrue(item.IsBusy, "Should be busy"); context.Assert.IsFalse(item.IsSavable, "Should not be savable"); context.Assert.Success(); context.Complete(); }
public async Task FetchAsync_Parrallel() { IDataPortal <SingleWithFactory> dataPortal = _testDIContext.CreateDataPortal <SingleWithFactory>(); var list = new List <int>(500); for (var i = 0; i < 500; i++) { list.Add(i); } var tasks = list.AsParallel().Select(x => dataPortal.FetchAsync()); await Task.WhenAll(tasks); }
public async Task TestSaveWhileBusyNetOnly() { IDataPortal <ItemWithAsynchRule> dataPortal = _testDIContext.CreateDataPortal <ItemWithAsynchRule>(); UnitTestContext context = GetContext(); var item = await dataPortal.FetchAsync("an id"); item.RuleField = "some value"; context.Assert.IsTrue(item.IsBusy); context.Assert.IsFalse(item.IsSavable); item.Save(); context.Assert.Success(); context.Complete(); }
public async Task TestSaveWhileNotBusyNoActiveRuleNetOnly() { IDataPortal <ItemWithAsynchRule> dataPortal = _noCloneOnUpdateDIContext.CreateDataPortal <ItemWithAsynchRule>(); UnitTestContext context = GetContext(); var item = await dataPortal.FetchAsync("an id"); item.OperationResult = "something"; context.Assert.IsFalse(item.IsBusy); context.Assert.IsTrue(item.IsSavable); item = item.Save(); context.Assert.AreEqual("DataPortal_Update", item.OperationResult); context.Assert.Success(); context.Complete(); }
private async void PersonEditPage_Load(object sender, EventArgs e) { var personInfo = (PersonInfo)Context; PersonEdit personEdit; if (personInfo == null) { personEdit = await _portal.CreateAsync(); } else { personEdit = await _portal.FetchAsync(personInfo.Id); } nameTextBox.DataBindings.Add(nameof(nameTextBox.Text), personEdit, nameof(personEdit.Name)); saveButton.DataBindings.Add(nameof(saveButton.Enabled), personEdit, nameof(personEdit.IsSavable)); errorProvider1.DataSource = personEdit; }
public async Task TestNotBusy() { IDataPortal <ItemWithAsynchRule> dataPortal = _testDIContext.CreateDataPortal <ItemWithAsynchRule>(); UnitTestContext context = GetContext(); var item = await dataPortal.FetchAsync("an id"); item.ValidationComplete += (o2, e2) => { context.Assert.IsFalse(item.IsBusy); context.Assert.IsTrue(item.IsSavable); context.Assert.Success(); }; item.RuleField = "some value"; context.Assert.IsTrue(item.IsBusy); context.Assert.IsFalse(item.IsSavable); context.Complete(); }
private async void UserControl_Loaded(object sender, RoutedEventArgs e) { var context = Context as PersonInfo; ViewModel.Model = await ViewModel.RefreshAsync <PersonEdit>(async() => { if (context == null) { return(await _portal.CreateAsync()); } else { return(await _portal.FetchAsync(context.Id)); } }); DataContext = ViewModel; }
public async Task TestSaveWhileNotBusyNetOnly() { IDataPortal <ItemWithAsynchRule> dataPortal = _noCloneOnUpdateDIContext.CreateDataPortal <ItemWithAsynchRule>(); TestResults.Reinitialise(); UnitTestContext context = GetContext(); var item = await dataPortal.FetchAsync("an id"); item.ValidationComplete += (o2, e2) => { context.Assert.IsFalse(item.IsBusy); context.Assert.IsTrue(item.IsSavable); item = item.Save(); context.Assert.AreEqual("DataPortal_Update", item.OperationResult); context.Assert.Success(); }; item.RuleField = "some value"; context.Assert.IsTrue(item.IsBusy); context.Assert.IsFalse(item.IsSavable); context.Complete(); }
public void FetchAsync_WithException() { var lck = new AutoResetEvent(false); new Action(async() => { IDataPortal <Single2> dataPortal = _testDIContext.CreateDataPortal <Single2>(); try { var result = await dataPortal.FetchAsync(9999); Assert.Fail("Expected exception not thrown"); } catch (Exception ex) { Assert.IsInstanceOfType(ex, typeof(Csla.DataPortalException)); } finally { lck.Set(); } }).Invoke(); lck.WaitOne(); }
// GET: Person/Edit/5 public async Task <ActionResult> Edit(int id) { var obj = await PersonEditPortal.FetchAsync(id); return(View(obj)); }
private async void UserControl_Loaded(object sender, RoutedEventArgs e) { ViewModel.Model = await _portal.FetchAsync(); DataContext = ViewModel; }
private async void PersonListPage_Load(object sender, EventArgs e) { var personList = await _portal.FetchAsync(); personListBox.DataSource = personList; }
public async Task OnGetAsync() { await Portal.FetchAsync(123); }
public async Task OnGet(int id) { Item = await _portal.FetchAsync(id); }
public async Task OnGet() { PersonList = await _portal.FetchAsync(); }
// GET: Person public async Task <ActionResult> Index() { var list = await PersonListPortal.FetchAsync(); return(View(list)); }
// GET: Person/Details/5 public async Task <ActionResult> Details(int id) { var obj = await PersonInfoPortal.FetchAsync(id); return(View(obj)); }