Esempio n. 1
0
        public async Task UseDataServiceCollectionToTrackAllPages()
        {
            var context       = this.CreateWrappedContext <DefaultContainer>().Context;
            var customerCount = ((await context.Customer.IncludeCount().ExecuteAsync()) as QueryOperationResponse <Customer>).Count;

            var customers = new DataServiceCollection <Customer>(context, await context.Customer.GetAllPagesAsync(), TrackingMode.AutoChangeTracking, null, null, null);

            Assert.Equal(customerCount, customers.Count());
            context.Configurations.RequestPipeline.OnEntryEnding((args) =>
            {
                Assert.Single(args.Entry.Properties);
            });
            for (int i = 0; i < customers.Count(); i++)
            {
                customers[i].Name = "Customer" + i.ToString();
            }
            await context.SaveChangesAsync();

            //customers = new DataServiceCollection<Customer>(await ((DataServiceQuery<Customer>)context.Customer.Take(1)).ExecuteAsync());
            //context.Configurations.RequestPipeline.OnEntryEnding((args) =>
            //{
            //    Assert.Equal(1, args.Entry.Properties.Count());
            //});
            //await context.LoadPropertyAllPagesAsync(customers[0], "Orders");
            //for (int i = 0; i < customers[0].Orders.Count(); i++)
            //{
            //    if (customers[0].Orders[i].Concurrency == null)
            //    {
            //        customers[0].Orders[i].Concurrency = new ConcurrencyInfo();
            //    }
            //    customers[0].Orders[i].Concurrency.Token = "Order_ConCurrency_" + i.ToString();

            //}
            //await context.SaveChangesAsync();

            //context.MergeOption = MergeOption.OverwriteChanges;
            //await context.LoadPropertyAllPagesAsync(customers[0], "Orders");
            //for (int i = 0; i < customers[0].Orders.Count(); i++)
            //{
            //    Assert.Equal(customers[0].Orders[i].Concurrency.Token, "Order_ConCurrency_" + i.ToString());
            //}
            this.EnqueueTestComplete();
        }
Esempio n. 2
0
        public void TrackEntitiesInAllPages()
        {
            var context       = this.CreateWrappedContext().Context;
            var customerCount = context.Customer.Count();

            var customers = new DataServiceCollection <Customer>(context, context.Customer.GetAllPages(), TrackingMode.AutoChangeTracking, null, null, null);

            Assert.AreEqual(customerCount, customers.Count());
            context.Configurations.RequestPipeline.OnEntryEnding((args) =>
            {
                Assert.AreEqual(1, args.Entry.Properties.Count());
            });
            for (int i = 0; i < customers.Count(); i++)
            {
                customers[i].Name = "Customer" + i.ToString();
            }
            context.SaveChanges();

            //customers = new DataServiceCollection<Customer>(context.Customer.Take(1));
            //context.Configurations.RequestPipeline.OnEntryEnding((args) =>
            //{
            //    Assert.AreEqual(1, args.Entry.Properties.Count());
            //});
            //context.LoadPropertyAllPages(customers[0], "Orders");
            //for (int i = 0; i < customers[0].Orders.Count(); i++)
            //{
            //    if (customers[0].Orders[i].Concurrency == null)
            //    {
            //        customers[0].Orders[i].Concurrency = new ConcurrencyInfo();
            //    }
            //    customers[0].Orders[i].Concurrency.Token = "Order_ConCurrency_" + i.ToString();

            //}
            //context.SaveChanges();

            //context.MergeOption = MergeOption.OverwriteChanges;
            //context.LoadPropertyAllPages(customers[0], "Orders");
            //for (int i = 0; i < customers[0].Orders.Count(); i++)
            //{
            //    Assert.AreEqual(customers[0].Orders[i].Concurrency.Token, "Order_ConCurrency_" + i.ToString());
            //}
        }
Esempio n. 3
0
        public static void UpdateCustomer(Resources context)
        {
            //var customersToUpdate= context.Customers.Where(x => x.CustomerAccount == "US-X11111");
            var query = from Customer
                        in context.Customers
                        where Customer.CustomerAccount == "US-X11111" &&
                        Customer.CustomerGroupId == "01"
                        select Customer;
            DataServiceCollection <Customer> customersToUpdate = new DataServiceCollection <Customer>(query);

            foreach (var customer in customersToUpdate)
            {
                //customer.DefaultDimensionDisplayValue = DefaultDimesnionHelper::createDefaultDimension(conAttribute, conAttributeValue);
                //customer.DimensionSet = new
                //customer.PaymentMethod = "Check";
                customer.Name = "test 03";
                //customer.DefaultDimensionDisplayValue = "Boys Campus"; // "BNE";
                customer.DefaultDimensionDisplayValue = "10000000-Boys Campus-BIM-G10";
                context.UpdateObject(customer);
            }


            if (customersToUpdate.Count() > 0)
            {
                DataServiceResponse response = null;
                try
                {
                    response = context.SaveChanges(SaveChangesOptions.BatchWithSingleChangeset);
                    Console.WriteLine("Updated ok");
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message + ex.InnerException);
                }
            }
        }
Esempio n. 4
0
        public async Task UseDataServiceCollectionToTrackAllPages()
        {
            var context = this.CreateWrappedContext<DefaultContainer>().Context;
            var customerCount = ((await context.Customer.IncludeTotalCount().ExecuteAsync()) as QueryOperationResponse<Customer>).TotalCount;

            var customers = new DataServiceCollection<Customer>(context, await context.Customer.GetAllPagesAsync(), TrackingMode.AutoChangeTracking, null, null, null);
            Assert.AreEqual(customerCount, customers.Count());
            context.Configurations.RequestPipeline.OnEntryEnding((args) =>
            {
                Assert.AreEqual(1, args.Entry.Properties.Count());
            });
            for (int i = 0; i < customers.Count(); i++)
            {
                customers[i].Name = "Customer" + i.ToString();
            }
            await context.SaveChangesAsync();

            //customers = new DataServiceCollection<Customer>(await ((DataServiceQuery<Customer>)context.Customer.Take(1)).ExecuteAsync());
            //context.Configurations.RequestPipeline.OnEntryEnding((args) =>
            //{
            //    Assert.AreEqual(1, args.Entry.Properties.Count());
            //});
            //await context.LoadPropertyAllPagesAsync(customers[0], "Orders");
            //for (int i = 0; i < customers[0].Orders.Count(); i++)
            //{
            //    if (customers[0].Orders[i].Concurrency == null)
            //    {
            //        customers[0].Orders[i].Concurrency = new ConcurrencyInfo();
            //    }
            //    customers[0].Orders[i].Concurrency.Token = "Order_ConCurrency_" + i.ToString();

            //}
            //await context.SaveChangesAsync();

            //context.MergeOption = MergeOption.OverwriteChanges;
            //await context.LoadPropertyAllPagesAsync(customers[0], "Orders");
            //for (int i = 0; i < customers[0].Orders.Count(); i++)
            //{
            //    Assert.AreEqual(customers[0].Orders[i].Concurrency.Token, "Order_ConCurrency_" + i.ToString());
            //}
            this.EnqueueTestComplete();
        }
Esempio n. 5
0
        public void TrackEntitiesInAllPages()
        {
            var context = this.CreateWrappedContext().Context;
            var customerCount = context.Customer.Count();

            var customers = new DataServiceCollection<Customer>(context, context.Customer.GetAllPages(), TrackingMode.AutoChangeTracking, null, null, null);
            Assert.AreEqual(customerCount, customers.Count());
            context.Configurations.RequestPipeline.OnEntryEnding((args) =>
            {
                Assert.AreEqual(1, args.Entry.Properties.Count());
            });
            for (int i = 0; i < customers.Count(); i++)
            {
                customers[i].Name = "Customer" + i.ToString();
            }
            context.SaveChanges();

            //customers = new DataServiceCollection<Customer>(context.Customer.Take(1));
            //context.Configurations.RequestPipeline.OnEntryEnding((args) =>
            //{
            //    Assert.AreEqual(1, args.Entry.Properties.Count());
            //});
            //context.LoadPropertyAllPages(customers[0], "Orders");
            //for (int i = 0; i < customers[0].Orders.Count(); i++)
            //{
            //    if (customers[0].Orders[i].Concurrency == null)
            //    {
            //        customers[0].Orders[i].Concurrency = new ConcurrencyInfo();
            //    }
            //    customers[0].Orders[i].Concurrency.Token = "Order_ConCurrency_" + i.ToString();

            //}
            //context.SaveChanges();

            //context.MergeOption = MergeOption.OverwriteChanges;
            //context.LoadPropertyAllPages(customers[0], "Orders");
            //for (int i = 0; i < customers[0].Orders.Count(); i++)
            //{
            //    Assert.AreEqual(customers[0].Orders[i].Concurrency.Token, "Order_ConCurrency_" + i.ToString());
            //}
        }
Esempio n. 6
0
        static void Main(string[] args)
        {
            var endPoint      = new Uri("https://app.inlooxnow.com/");
            var endPointOdata = new Uri(endPoint, "odata/");

            var username = "******";
            var password = "";

            var tokenResponse = ODataBasics.GetToken(endPoint, username, password).Result;

            // in case multiple accounts exists
            if (tokenResponse.Error != null)
            {
                var accounts = tokenResponse.GetAccounts();

                // filter correct account by name
                var myAccount = accounts.FirstOrDefault(k => k.Name.StartsWith("000000"));
                tokenResponse = ODataBasics.GetToken(endPoint, username, password, myAccount.Id).Result;
            }

            if (tokenResponse == null)
            {
                Console.WriteLine("Login invalid");
                return;
            }

            var context = ODataBasics.GetInLooxContext(endPointOdata, tokenResponse.AccessToken);
            // lookup custom field "DocTest" id
            var ceDefaults  = context.customexpanddefaultextend.ToList();
            var cedDocument = ceDefaults.FirstOrDefault(k => k.DisplayName == "DocTest");

            if (cedDocument == null)
            {
                Console.WriteLine("Custom field 'DocTest' not found");
                return;
            }

            // build query for all documents with custom field 'DocTest' set to true.
            var query = context.documentview
                        .Where(k => k.CustomExpand.Any(ce => ce.CustomExpandDefaultId == cedDocument.CustomExpandDefaultId && ce.BoolValue == true))
                        .OrderBy(k => k.FileName)
                        .Skip(0)
                        .Take(10);

            // need to use DataServiceCollection to use the PostOnlySetProperties feature
            // if you only need to read from the query a ToList() is ok.
            var docs = new DataServiceCollection <DocumentView>(query);

            Console.WriteLine(docs.Count());

            foreach (var d in docs)
            {
                Console.WriteLine(d.FileName);
            }

            // change document state
            if (docs.Count > 0)
            {
                var doc = docs.FirstOrDefault();
                doc.State = "Updated " + DateTime.Now;

                // only update the modfied properties
                context.SaveChangesDefaultOptions = SaveChangesOptions.PostOnlySetProperties;

                context.UpdateObject(doc);
                context.SaveChanges();
            }
        }