示例#1
0
 /// <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));
         }
     }
 }
示例#2
0
        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();
        }
示例#3
0
        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);
        }
示例#4
0
 public async Task OnGet(int id)
 {
     if (id == -1)
     {
         Item = await _portal.CreateAsync();
     }
     else
     {
         Item = await _portal.FetchAsync(id);
     }
 }
示例#5
0
 public ItemEditViewModel(IDataPortal <PersonEdit> portal, int id)
 {
     PersonPortal = portal;
     Initialize();
     if (id == -1)
     {
         RefreshAsync <PersonEdit>(() => PersonPortal.CreateAsync());
     }
     else
     {
         RefreshAsync <PersonEdit>(() => PersonPortal.FetchAsync(id));
     }
 }
示例#6
0
        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();
        }
示例#7
0
        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);
        }
示例#8
0
        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();
        }
示例#9
0
        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();
        }
示例#10
0
        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;
        }
示例#11
0
        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();
        }
示例#12
0
        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;
        }
示例#13
0
        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();
        }
示例#14
0
        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();
        }
示例#15
0
        // GET: Person/Edit/5
        public async Task <ActionResult> Edit(int id)
        {
            var obj = await PersonEditPortal.FetchAsync(id);

            return(View(obj));
        }
示例#16
0
        private async void UserControl_Loaded(object sender, RoutedEventArgs e)
        {
            ViewModel.Model = await _portal.FetchAsync();

            DataContext = ViewModel;
        }
示例#17
0
        private async void PersonListPage_Load(object sender, EventArgs e)
        {
            var personList = await _portal.FetchAsync();

            personListBox.DataSource = personList;
        }
示例#18
0
 public async Task OnGetAsync()
 {
     await Portal.FetchAsync(123);
 }
示例#19
0
 public async Task OnGet(int id)
 {
     Item = await _portal.FetchAsync(id);
 }
示例#20
0
 public async Task OnGet()
 {
     PersonList = await _portal.FetchAsync();
 }
示例#21
0
        // GET: Person
        public async Task <ActionResult> Index()
        {
            var list = await PersonListPortal.FetchAsync();

            return(View(list));
        }
示例#22
0
        // GET: Person/Details/5
        public async Task <ActionResult> Details(int id)
        {
            var obj = await PersonInfoPortal.FetchAsync(id);

            return(View(obj));
        }