Beispiel #1
1
        public void HandleMultiple1(object sender, RoutedEventArgs e)
        {
            try
            {
                // run...
                var conn = this.GetConnection();
                conn.CreateTableAsync<Customer>().ContinueWith(async (r) =>
                {
                    // go...
                    Customer customer = new Customer("foo", "bar", "1");
                    await customer.InsertAsync(conn);
                    int result1 = customer.CustomerId;

                    // go...
                    customer = new Customer("foo", "bar", "2");
                    await customer.InsertAsync(conn);
                    int result2 = customer.CustomerId;

                    // go...
                    customer = new Customer("foo", "bar", "3");
                    await customer.InsertAsync(conn);
                    int result3 = customer.CustomerId;

                    // get all...
                    var all = await conn.TableAsync<Customer>();
                    await this.ShowAlertAsync(string.Format("Results: {0}, {1}, {2}, count: {3}", result1, result2, result3, all.Count()));

                });
            }
            catch (Exception ex)
            {
                this.ShowAlertAsync(ex);
            }
        }
Beispiel #2
0
        public void HandleInsertAsync(object sender, RoutedEventArgs e)
        {
            try
            {
                // run...
                Customer customer = new Customer()
                {
                    FirstName = "Foo",
                    LastName = "Bar",
                    Email = "*****@*****.**"
                };

                var conn = GetConnection();
                conn.InsertAsync(customer).ContinueWith(async (tResult) =>
                 {
                     await this.ShowAlertAsync("Insert called OK. New ID: " + tResult.Result.ToString());

                 }).ChainFailureHandler(this);
            }
            catch (Exception ex)
            {
                this.ShowAlertAsync(ex);
            }
        }
Beispiel #3
0
        public void HandleMultiple2(object sender, RoutedEventArgs e)
        {
            try
            {
                // run...
                var conn = this.GetConnection();
                conn.CreateTableAsync<Customer>().ContinueWith(async (r) =>
                {
                    // go...
                    List<Customer> customers = new List<Customer>();
                    List<Task> tasks = new List<Task>();
                    for (int index = 0; index < 100; index++)
                    {
                        Customer customer = new Customer("foo", "bar", index.ToString());
                        customers.Add(customer);

                        // run...
                        tasks.Add(customer.InsertAsync(conn));
                    }

                    // walk...
                    Task.WaitAll(tasks.ToArray());

                    // get all...
                    var all = await conn.TableAsync<Customer>();

                    // show...
                    StringBuilder builder = new StringBuilder();
                    builder.Append("Count: ");
                    builder.Append(all.Count());
                    builder.Append("\r\n--> ");
                    for (int index = 0; index < customers.Count; index++)
                    {
                        if (index > 0)
                            builder.Append(", ");
                        builder.Append(customers[index].CustomerId);
                    }
                    await this.ShowAlertAsync(builder.ToString());

                });
            }
            catch (Exception ex)
            {
                this.ShowAlertAsync(ex);
            }
        }