public void ClientSerializeGeographyTest_BindingAddChangeShouldBeDetected()
 {
     DataServiceContext ctx = new DataServiceContext(new Uri("http://localhost"));
     DataServiceCollection<SpatialEntityType> dsc = new DataServiceCollection<SpatialEntityType>(ctx, null, TrackingMode.AutoChangeTracking, "Entities", null, null);
     dsc.Add(testEntity);
     ClientSerializeGeographyTest_Validate(ctx);
 }
Example #2
0
        public async Task SaveChangesTest()
        {
            var context = this.CreateWrappedContext<DefaultContainer>().Context;
            context.MergeOption = MergeOption.OverwriteChanges;
            int expectedPropertyCount = 1;
            Action<WritingEntryArgs> onEntryEnding = args =>
            {
                Assert.Equal(expectedPropertyCount, args.Entry.Properties.Count());
            };
            context.Configurations.RequestPipeline.OnEntryEnding(onEntryEnding);
            DataServiceCollection<Customer> customers = new DataServiceCollection<Customer>(context, "Customer", null, null);
            Customer c1 = new Customer();
            customers.Add(c1);
            c1.CustomerId = 1;
            c1.Name = "testName";

            //Partial Post an Entity
            expectedPropertyCount = 2;
            var response = await context.SaveChangesAsync(SaveChangesOptions.PostOnlySetProperties);
            Assert.True((response.First() as ChangeOperationResponse).StatusCode == 201, "StatusCode == 201");

            Order o1 = new Order { OrderId = 1000, CustomerId = 1, Concurrency = new ConcurrencyInfo() { Token = "token1" } };
            context.AddToOrder(o1);
            context.AddLink(c1, "Orders", o1);

            //Post with batch
            expectedPropertyCount = 3;
            await context.SaveChangesAsync(SaveChangesOptions.BatchWithSingleChangeset);

            List<Order> orders = new List<Order>();
            for (int i = 1; i <= 9; i++)
            {
                Order order = new Order { OrderId = 1000 + i };
                context.AddToOrder(order);
                orders.Add(order);
            }

            //Post with batch
            await context.SaveChangesAsync(SaveChangesOptions.BatchWithIndependentOperations);

            //Post $ref
            foreach (var order in orders)
            {
                context.AddLink(c1, "Orders", order);
            }
            await context.SaveChangesAsync();

            //Load property
            await context.LoadPropertyAsync(c1, "Orders");

            //Partial Update an Entity
            expectedPropertyCount = 1;
            c1.Orders[0].Concurrency.Token = "UpdatedToken";
            await context.SaveChangesAsync(SaveChangesOptions.None);

            this.EnqueueTestComplete();
        }
Example #3
0
        public void OnlySetComplexPropertiesShouldBeSentOnPost()
        {
            DataServiceCollection <EntityType> collection = new DataServiceCollection <EntityType>(context, "EntitySet", null, null);
            EntityType entity = new EntityType();

            collection.Add(entity);
            entity.Complex = new ComplexType
            {
                Name = "July",
                Home = new Address("Jiaotong", 16)
            };
            Assert.Equal(EntityStates.Added, context.Entities.FirstOrDefault().State);
            ValidateBodyContent(context, "{\"Complex\":{\"Name\":\"July\",\"Home\":{\"Code\":16,\"Street\":\"Jiaotong\"}}}", SaveChangesOptions.PostOnlySetProperties);
        }
Example #4
0
        private Order GetTrackedOrder()
        {
            var order = GetUntrackedOrder();

            // Add the entity to a DataServiceCollection to track it.
            var collection = new DataServiceCollection <Order>(dsc, "Orders", null, null);

            collection.Add(order);

            // Change some property intentionally.
            order.OrderID = 100;

            return(order);
        }
Example #5
0
        public void AddDeleteEntitySave()
        {
            var ctxwrap = this.CreateWrappedContext<DefaultContainer>();
            var context = ctxwrap.Context;
            DataServiceCollection<Customer> dsc = new DataServiceCollection<Customer>(context);
            Customer c = new Customer { CustomerId = 1002 };
            dsc.Add(c);
            dsc.Remove(c);
            Assert.True(VerifyCtxCount(context, 0, 0));
            this.SaveChanges(context);
            Assert.True(VerifyCtxCount(context, 0, 0));

            this.EnqueueTestComplete();
        }
Example #6
0
        public async Task <JsonResult> CreateAccount([FromBody] ViewModels.Account item)
        {
            // create a new account
            Contexts.Microsoft.Dynamics.CRM.Account account = new Contexts.Microsoft.Dynamics.CRM.Account();

            DataServiceCollection <Contexts.Microsoft.Dynamics.CRM.Account> AccountCollection = new DataServiceCollection <Contexts.Microsoft.Dynamics.CRM.Account>(_system);
            DataServiceCollection <Contexts.Microsoft.Dynamics.CRM.Contact> ContactCollection = new DataServiceCollection <Contexts.Microsoft.Dynamics.CRM.Contact>(_system);

            AccountCollection.Add(account);
            account.Name        = item.name;
            account.Description = item.description;

            if (item.primarycontact != null)
            {
                // get the contact.
                Contexts.Microsoft.Dynamics.CRM.Contact contact = new Contexts.Microsoft.Dynamics.CRM.Contact();
                contact.Fullname         = item.primarycontact.name;
                contact.Contactid        = new Guid(item.primarycontact.id);
                account.Primarycontactid = contact;
            }


            await _system.SaveChangesAsync(SaveChangesOptions.PostOnlySetProperties | SaveChangesOptions.BatchWithSingleChangeset);

            // if we have not yet authenticated, then this is the new record for the user.
            string       temp         = _httpContextAccessor.HttpContext.Session.GetString("UserSettings");
            UserSettings userSettings = JsonConvert.DeserializeObject <UserSettings>(temp);

            if (userSettings.IsNewUserRegistration)
            {
                // we can now authenticate.
                if (userSettings.AuthenticatedUser == null)
                {
                    Models.User user = new Models.User();
                    user.Active   = true;
                    user.Guid     = userSettings.ContactId;
                    user.SmUserId = userSettings.UserId;
                    userSettings.AuthenticatedUser = user;
                }

                userSettings.IsNewUserRegistration = false;

                string userSettingsString = JsonConvert.SerializeObject(userSettings);
                // add the user to the session.
                _httpContextAccessor.HttpContext.Session.SetString("UserSettings", userSettingsString);
            }

            return(Json(account));
        }
        public static void createAndDeleteWithSingleEntity(Resources context,
                                                           string filePath,
                                                           TestType testType,
                                                           TestWorkload testWorkload,
                                                           string DataAreaId,
                                                           string customerAccount)
        {
            Stopwatch sw = new Stopwatch();
            string    SalesOrderNumber;

            Entity = "AAXSalesOrderHeaderV2EntityOnlySalesOrderNumber";

            DataServiceCollection <SalesOrderHeaderV2EntityOnlySalesTable> SalesOrderCollection = new DataServiceCollection <SalesOrderHeaderV2EntityOnlySalesTable>(context);

            SalesOrderHeaderV2EntityOnlySalesTable SalesOrderHeaderV2EntityOnlySalesTable = new SalesOrderHeaderV2EntityOnlySalesTable();

            SalesOrderCollection.Add(SalesOrderHeaderV2EntityOnlySalesTable);

            //Required Fields
            SalesOrderHeaderV2EntityOnlySalesTable.OrderingCustomerAccountNumber = customerAccount;
            SalesOrderHeaderV2EntityOnlySalesTable.InvoiceCustomerAccountNumber  = customerAccount;
            SalesOrderHeaderV2EntityOnlySalesTable.dataAreaId   = DataAreaId;
            SalesOrderHeaderV2EntityOnlySalesTable.CurrencyCode = "USD";
            SalesOrderHeaderV2EntityOnlySalesTable.LanguageId   = "en-us";

            context.SaveChanges(SaveChangesOptions.PostOnlySetProperties | SaveChangesOptions.BatchWithSingleChangeset);
            SalesOrderNumber = SalesOrderHeaderV2EntityOnlySalesTable.SalesOrderNumber;
            SalesOrderHeaderV2EntityOnlySalesTable = null;

            context.AAXSalesOrderHeaderV2EntityOnlySalesOrderNumbers.FirstOrDefault();

            sw.Start();

            var AAXSalesOrderHeaderV2EntityOnlySalesOrderNumbers = context.AAXSalesOrderHeaderV2EntityOnlySalesOrderNumbers.Where(x => x.SalesOrderNumber == SalesOrderNumber && x.dataAreaId == DataAreaId).First();

            context.DeleteObject(AAXSalesOrderHeaderV2EntityOnlySalesOrderNumbers);
            context.SaveChanges(SaveChangesOptions.PostOnlySetProperties | SaveChangesOptions.BatchWithSingleChangeset);

            sw.Stop();

            Console.WriteLine("Created and Deleted Sales Order " + SalesOrderNumber);

            StreamWriter stream = File.AppendText(filePath);

            stream.WriteLine(Entity + "," + testType + "," + testWorkload + "," + sw.Elapsed.TotalMilliseconds.ToString());

            stream.Flush();
            stream.Close();
        }
        public static void insertIntoDataBase(Resources context)
        {
            string connectionString, Name = null, Email = null;

            string bankAccountNumber = null;

            SqlConnection  con;
            SqlDataAdapter adapter = new SqlDataAdapter();
            SqlCommand     cmd;

            connectionString = "Data Source = MININT - 5REKJI3; Initial Catalog = WebServices; Integrated Security = True";

            con = new SqlConnection(connectionString);
            try
            {
                con.Open();

                Customer customer = new Customer();
                DataServiceCollection <Customer> customerDetailCollection = new DataServiceCollection <Customer>(context);

                customerDetailCollection.Add(customer);

                var CustomerDetailsnew = context.Customers.Where(x => x.DataAreaId == "USMF");

                foreach (var Customer in customerDetailCollection)
                {
                    bankAccountNumber = Customer.PaymentBankAccount;
                    Name  = Customer.Name;
                    Email = Customer.PrimaryContactEmail;
                    cmd   = new SqlCommand("insert into ax.CustTable (bankAccountNumber,Name,Email) values (@bankAccountNumber,@Name,@Email)");
                    cmd.Parameters.AddWithValue("@bankAccountNumber", bankAccountNumber);
                    cmd.Parameters.AddWithValue("@Name", Name);
                    cmd.Parameters.AddWithValue("@Email", Email);
                    cmd.Connection = con;
                    cmd.ExecuteNonQuery();

                    Console.WriteLine("BackAccount", Customer.PaymentBankAccount);
                }
                con.Close();
                //console.ReadLine();

                //MessageBox.Show("Rows inserted");
            }
            catch (Exception ex)
            {
                //MessageBox.Show(ex.ToString());
            }
        }
        public void CreateIndividualSampleCode1()
        {
            try
            {
                //Create an individual Customer with 1 address linked to employer and another individual address
                var a = new DataServiceCollection <SaveAddressInput>(null, TrackingMode.None);

                //Address linked to a company
                SaveAddressInput a1 = new SaveAddressInput()
                {
                    AddressTypeCode = "WORK",
                    //Address1 = "One DesCombes Drive",
                    City        = "Broomfield",
                    State       = "CO",
                    PostalCode  = "80020",
                    CountryCode = "USA",
                    OverrideAddressValidation     = false,
                    SetRelationshipAsPrimary      = true,
                    PrimaryAddress                = true,
                    CreateNewAddressIfOrdersExist = true,
                    EndOldPrimaryRelationship     = true,
                    WebMobileDirectory            = true,
                };

                a.Add(a1);


                SaveCustomerInput s = new SaveCustomerInput()
                {
                    FirstName         = "Troy_New_Member",
                    LastName          = "Fulton",
                    CustomerClassCode = "INDIV",

                    Addresses = a,
                };

                SaveCustomerOutput op = SvcClient.Post <SaveCustomerOutput>("CreateIndividual", s);
                op.Equals(op);
            }
            catch (Exception ex)
            {
                var message = ex.Message;

                var messages = message.ParseXML <Messages>();

                throw ex;
            }
        }
        public void OnlyChangedPropertiesInDerivedEntityTypeShouldBeSentOnPost()
        {
            EntityType entity = new DerivedEntityType();
            DataServiceCollection <DerivedEntityType> collection = new DataServiceCollection <DerivedEntityType>(context, "EntitySet", null, null);

            collection.Add((DerivedEntityType)entity);
            entity.ID      = 71;
            entity.Complex = new ComplexType
            {
                Name = "June",
                Home = new Address("Xiadu", 17)
            };
            ((DerivedEntityType)entity).Home = new HomeAddress("Xingang", 17, "Guangzhou");
            Assert.AreEqual(EntityStates.Added, context.Entities.FirstOrDefault().State);
            ValidateBodyContent(context, "{\"ID\":71,\"Complex\":{\"Name\":\"June\",\"Home\":{\"Code\":17,\"Street\":\"Xiadu\"}},\"Home\":{\"City\":\"Guangzhou\",\"Code\":17,\"Street\":\"Xingang\"}}", SaveChangesOptions.PostOnlySetProperties);
        }
        public static void InsertIntoDataBase(Resources context)
        {
            string connectionString, custgroupid = null;

            string identificationnumber = null;

            SqlConnection  con;
            SqlDataAdapter adapter = new SqlDataAdapter();
            SqlCommand     cmd;

            connectionString = "Data Source = MININT - 5REKJI3; Initial Catalog = WebServices; Integrated Security = True";

            con = new SqlConnection(connectionString);
            try
            {
                con.Open();

                Customer customer = new Customer();
                DataServiceCollection <Customer> customerDetailCollection = new DataServiceCollection <Customer>(context);

                customerDetailCollection.Add(customer);

                var CustomerDetailsnew = context.Customers.Where(x => x.DataAreaId == "USMF");

                foreach (var Customer in customerDetailCollection)
                {
                    custgroupid          = Customer.CustomerGroupId;
                    identificationnumber = Customer.IdentificationNumber;
                    cmd = new SqlCommand("insert into ax.CustTable (custgroupid,identificationnumber) values (@custgroupid,@IdentificationNumber)");
                    cmd.Parameters.AddWithValue("@custgroupid", custgroupid);
                    cmd.Parameters.AddWithValue("@identificationnumber", identificationnumber);
                    cmd.Connection = con;
                    cmd.ExecuteNonQuery();

                    Console.WriteLine("identificationNumber", Customer.IdentificationNumber);
                }
                con.Close();
                //console.ReadLine();

                //MessageBox.Show("Rows inserted");
            }
            catch (Exception ex)
            {
                //MessageBox.Show(ex.ToString());
            }
        }
Example #12
0
        private static SVC_ODataPersonView_DE CreateExchange()
        {
            DataServiceCollection <SVC_ODataPersonView_DE> svcOdata = new DataServiceCollection <SVC_ODataPersonView_DE>(context);

            var newExchange = new SVC_ODataPersonView_DE();

            svcOdata.Add(newExchange);

            newExchange.Name  = "foo bar";
            newExchange.Email = "kuntal-test";

            context.SaveChanges(SaveChangesOptions.PostOnlySetProperties);

            //context.SaveChanges();

            return(newExchange);
        }
Example #13
0
        public void AddDeleteEntitySave()
        {
            var ctxwrap = this.CreateWrappedContext <DefaultContainer>();
            var context = ctxwrap.Context;
            DataServiceCollection <Customer> DSC = new DataServiceCollection <Customer>(context);
            Customer c = new Customer {
                CustomerId = 1002
            };

            DSC.Add(c);
            DSC.Remove(c);
            Assert.True(VerifyCtxCount(context, 0, 0));
            this.SaveChanges(context);
            Assert.True(VerifyCtxCount(context, 0, 0));

            this.EnqueueTestComplete();
        }
        public async Task <IActionResult> CreateContact([FromBody] ViewModels.Contact viewModel)
        {
            Interfaces.Microsoft.Dynamics.CRM.Contact item = viewModel.ToModel();

            // create a new contact.
            Interfaces.Microsoft.Dynamics.CRM.Contact contact = new Interfaces.Microsoft.Dynamics.CRM.Contact();

            // create a DataServiceCollection to add the record
            DataServiceCollection <Interfaces.Microsoft.Dynamics.CRM.Contact> ContactCollection = new DataServiceCollection <Interfaces.Microsoft.Dynamics.CRM.Contact>(_system);

            // add a new contact.
            ContactCollection.Add(contact);

            // changes need to made after the add in order for them to be saved.
            contact.CopyValues(item);

            // PostOnlySetProperties is used so that settings such as owner will get set properly by the dynamics server.

            DataServiceResponse dsr = await _system.SaveChangesAsync(SaveChangesOptions.PostOnlySetProperties | SaveChangesOptions.BatchWithSingleChangeset);

            foreach (OperationResponse result in dsr)
            {
                if (result.StatusCode == 500) // error
                {
                    return(StatusCode(500, result.Error.Message));
                }
            }
            contact.Contactid = dsr.GetAssignedId();
            // if we have not yet authenticated, then this is the new record for the user.
            string       temp         = _httpContextAccessor.HttpContext.Session.GetString("UserSettings");
            UserSettings userSettings = JsonConvert.DeserializeObject <UserSettings>(temp);

            if (userSettings.IsNewUserRegistration)
            {
                if (string.IsNullOrEmpty(userSettings.ContactId))
                {
                    userSettings.ContactId = contact.Contactid.ToString();
                    string userSettingsString = JsonConvert.SerializeObject(userSettings);
                    // add the user to the session.
                    _httpContextAccessor.HttpContext.Session.SetString("UserSettings", userSettingsString);
                }
            }

            return(Json(contact.ToViewModel()));
        }
Example #15
0
        public void DeletingInUnchangedState()
        {
            var ctxwrap = this.CreateWrappedContext <DefaultContainer>();
            var context = ctxwrap.Context;
            DataServiceCollection <Customer> DSC = new DataServiceCollection <Customer>(context);
            Customer unchanged = new Customer {
                CustomerId = 1002
            };

            DSC.Add(unchanged);
            VerifyCtxCount(context, 1, 0);
            this.SaveChanges(context);
            this.CheckState(context, EntityStates.Unchanged, unchanged);
            VerifyCtxCount(context, 1, 0);
            DSC.Remove(unchanged);
            VerifyCtxCount(context, 0, 0);

            this.EnqueueTestComplete();
        }
Example #16
0
        private void OnAddMenu(object sender, RoutedEventArgs e)
        {
            var category = CategoriesComboBox.SelectedItem as R.Category;

            if (category != null)
            {
                var newMenu = new R.Menu
                {
                    Category    = category,
                    CategoryId  = category.Id,
                    Name        = "[Please Add Name]",
                    Description = "[Please Add Description]",
                    Price       = 0m,
                    Active      = true
                };

                _trackedMenus.Add(newMenu);
            }
        }
Example #17
0
        public void LoadPropertyCollection()
        {
            var ctxwrap = this.CreateWrappedContext <DefaultContainer>();
            var context = ctxwrap.Context;
            var querry  = (from c in context.Customer
                           where c.CustomerId == -10
                           select c) as DataServiceQuery <Customer>;

            var ar  = querry.BeginExecute(null, null).EnqueueWait(this);
            var cus = querry.EndExecute(ar).First();
            DataServiceCollection <Customer> DSC = new DataServiceCollection <Customer>(context);

            DSC.Add(cus);
            var ar02 = context.BeginLoadProperty(cus, "Orders", null, null).EnqueueWait(this);

            context.EndLoadProperty(ar02);
            foreach (Order o in cus.Orders)
            {
                o.OrderId = (134);
            }

            int fristCount = context.Entities.Count();

            foreach (var ed in context.Entities)
            {
                if (ed.Entity.GetType().Equals(cus.Orders.First().GetType()))
                {
                    Assert.Equal(EntityStates.Modified, ed.State);
                }
            }

            var o1 = new Order {
                OrderId = 1220
            };

            cus.Orders.Add(o1);
            Assert.Equal(fristCount + 1, context.Entities.Count());
            cus.Orders.Remove(o1);
            Assert.Equal(fristCount, context.Entities.Count());

            this.EnqueueTestComplete();
        }
Example #18
0
        public void DeletingInDeletedState()
        {
            var ctxwrap = this.CreateWrappedContext <DefaultContainer>();
            var context = ctxwrap.Context;
            DataServiceCollection <Customer> dsc = new DataServiceCollection <Customer>(context);
            Customer deleted = new Customer {
                CustomerId = 1004
            };

            dsc.Add(deleted);
            VerifyCtxCount(context, 1, 0);
            this.SaveChanges(context);
            context.DeleteObject(deleted);
            this.CheckState(context, EntityStates.Deleted, deleted);
            VerifyCtxCount(context, 1, 0);
            dsc.Remove(deleted);
            VerifyCtxCount(context, 0, 0);

            this.EnqueueTestComplete();
        }
Example #19
0
        public static void CreateSalesOrderWithoutChangeset(Resources context)
        {
            string salesOrderNumber = "100006";

            try
            {
                RetailStore retailStore = new RetailStore();
                DataServiceCollection <RetailStore> retailStoreCollection = new DataServiceCollection <RetailStore>(context);
                retailStoreCollection.Add(retailStore);

                //retailStore.
                //SalesOrderHeader salesOrder = new SalesOrderHeader();
                //DataServiceCollection<SalesOrderHeader> salesOrderCollection = new DataServiceCollection<SalesOrderHeader>(context);
                //salesOrderCollection.Add(salesOrder);

                //salesOrder.SalesOrderNumber = salesOrderNumber; // Change number sequence setting in AX to allow user to set values.
                //salesOrder.CurrencyCode = "USD";
                //salesOrder.InvoiceCustomerAccountNumber = "US-001";
                //salesOrder.OrderingCustomerAccountNumber = "US-001";
                //salesOrder.LanguageId = "en-us";
                //salesOrder.DataAreaId = "USMF";

                //SalesOrderLine salesOrderLine = new SalesOrderLine();
                //DataServiceCollection<SalesOrderLine> salesOrderLineCollection = new DataServiceCollection<SalesOrderLine>(context);
                //salesOrderLineCollection.Add(salesOrderLine);

                //salesOrderLine.SalesOrderNumber = salesOrder.SalesOrderNumber;
                //salesOrderLine.ItemNumber = "1000";
                //salesOrderLine.OrderedSalesQuantity = 1;
                //salesOrderLine.ShippingSiteId = "ABC"; // Error in line.
                //salesOrderLine.ShippingWarehouseId = "24";
                //salesOrderLine.DataAreaId = "USMF";

                context.SaveChanges(SaveChangesOptions.PostOnlySetProperties | SaveChangesOptions.BatchWithIndependentOperations); // The changes within the branch are treated as independent operation. Failure in one will not roll back others.
                Console.WriteLine(string.Format("Invoice {0} - Saved !", salesOrderNumber));
            }
            catch (DataServiceRequestException e)
            {
                Console.WriteLine(string.Format("Invoice {0} - Save Failed !", salesOrderNumber));
            }
        }
Example #20
0
        public void UpdateCollectionPropertyShouldOnlySerializeChangedProperties()
        {
            EntityType entity = new EntityType
            {
                ID      = 1,
                Complex = new ComplexType
                {
                    Name = "June",
                    Home = new Address("Dongchuan", 200)
                },
                StringCollection = new ObservableCollection <string>(new string[] { "first", "second" })
            };
            DataServiceCollection <EntityType> collection = new DataServiceCollection <EntityType>(context, null, TrackingMode.AutoChangeTracking, "EntitySet", null, null);

            collection.Add(entity);

            context.Entities.FirstOrDefault().State = EntityStates.Unchanged;
            entity.StringCollection.Add("third");
            Assert.Equal(EntityStates.Modified, context.Entities.FirstOrDefault().State);
            ValidateBodyContent(context, "{\"[email protected]\":\"#Collection(String)\",\"StringCollection\":[\"first\",\"second\",\"third\"]}");
        }
Example #21
0
        private void PostPropertiesOfEntityParameterToAction(EntityParameterSendOption option)
        {
            TestClientContext.EntityParameterSendOption = option;

            var customer = TestClientContext.CustomersPlus.First();

            OrderPlus order = new OrderPlus();

            var collection = new DataServiceCollection <OrderPlus>(TestClientContext, "OrdersPlus", null, null);

            collection.Add(order);

            int orderId = (new Random()).Next();

            order.OrderIDPlus         = orderId;
            order.OrderShelfLifesPlus = new ObservableCollection <TimeSpan>();

            OrderPlus orderCreated = customer.PlaceOrderPlus(order).GetValue();

            Assert.Equal(orderId, orderCreated.OrderIDPlus);
        }
        public static void CreateSalesOrderInSingleChangeset(Resources context)
        {
            string paymentBankAccount = "KGS123456789";

            try
            {
                Customer customer = new Customer();
                DataServiceCollection <Customer> customerCollection = new DataServiceCollection <Customer>(context);
                customerCollection.Add(customer);

                customer.PaymentBankAccount  = paymentBankAccount;
                customer.DataAreaId          = "USMF";
                customer.PrimaryContactEmail = "*****@*****.**";
                context.SaveChanges(SaveChangesOptions.PostOnlySetProperties | SaveChangesOptions.BatchWithSingleChangeset); // Batch with Single Changeset ensure the saved changed runs in all-or-nothing mode.
                Console.WriteLine(string.Format("Invoice {0} - Saved !", paymentBankAccount));
            }
            catch (DataServiceRequestException e)
            {
                Console.WriteLine(string.Format("Invoice {0} - Save Failed !", paymentBankAccount));
            }
        }
Example #23
0
        //public static string ODataEntityPath = ClientConfiguration.Default.UriString + "data";



        //public ClienteBE conect(ClienteBE pCustomer, string pAplicacionId)
        //{
        //    ClienteBE vResul = new ClienteBE();
        //    Uri oDataUri = new Uri(ODataEntityPath, UriKind.Absolute);
        //    var context = new Resources(oDataUri);

        //    context.SendingRequest2 += new EventHandler<SendingRequest2EventArgs>(delegate (object sender, SendingRequest2EventArgs e)
        //    {
        //        var authenticationHeader = OAuthHelper.GetAuthenticationHeader();
        //        e.RequestMessage.SetHeader(OAuthHelper.OAuthHeader, authenticationHeader);
        //    });
        //    CreateCustomer(context, pCustomer);
        //    return vResul;
        //}


        public static void CreateCustomer(ClienteBE pCustomer)
        {
            try
            {
                Resources context      = ConexionD365.conect();
                Customer  vendorEntity = new Customer();

                DataServiceCollection <Customer> vendorEntityCollection = new DataServiceCollection <Customer>(context);
                vendorEntityCollection.Add(vendorEntity);
                vendorEntity.CustomerAccount   = pCustomer.ClienteID;
                vendorEntity.Name              = pCustomer.Name;
                vendorEntity.CustomerGroupId   = "Sales";
                vendorEntity.SalesCurrencyCode = "USD";
                //DataServiceCollection<Customer> vend = new DataServiceCollection<Customer>(context.Customers.Where(p => p.CustomerAccount == "C0000000049"));
                context.SaveChanges(SaveChangesOptions.PostOnlySetProperties | SaveChangesOptions.BatchWithSingleChangeset);
            }
            catch (Exception msj)
            {
                string mensaje = msj.InnerException.Message;
            }
        }
        public void UpdateComplexPropertyInComplexPropertyShouldOnlySerializeChangedProperties()
        {
            EntityType entity = new EntityType
            {
                ID      = 1,
                Complex = new ComplexType
                {
                    Name = "June",
                    Home = new Address("Dongchuan", 200)
                },
                StringCollection = new ObservableCollection <string>(new string[] { "first", "second" })
            };
            DataServiceCollection <EntityType> collection = new DataServiceCollection <EntityType>(context, null, TrackingMode.AutoChangeTracking, "EntitySet", null, null);

            collection.Add(entity);

            context.Entities.FirstOrDefault().State = EntityStates.Unchanged;
            entity.Complex.Home.Code = 17;
            Assert.AreEqual(EntityStates.Modified, context.Entities.FirstOrDefault().State);
            ValidateBodyContent(context, "{\"Complex\":{\"Name\":\"June\",\"Home\":{\"Code\":17,\"Street\":\"Dongchuan\"}}}");
        }
        public static void updateWithSimpleEntityMinimum(Resources context,
                                                         string filePath,
                                                         TestType testType,
                                                         TestWorkload testWorkload,
                                                         string DataAreaId,
                                                         string SalesOrderNumber)
        {
            Stopwatch sw = new Stopwatch();

            Entity = "SalesOrderHeadersV2EntityOnlySalesTable";

            context.SalesOrderHeadersV2EntityOnlySalesTable.FirstOrDefault();

            var SalesOrderHeadersV2EntityOnlySalesTable = context.SalesOrderHeadersV2EntityOnlySalesTable.Where(x => x.SalesOrderNumber == SalesOrderNumber && x.dataAreaId == DataAreaId).First();

            if (SalesOrderHeadersV2EntityOnlySalesTable.SalesOrderNumber != null)
            {
                DataServiceCollection <SalesOrderHeaderV2EntityOnlySalesTable> SalesOrderCollection = new DataServiceCollection <SalesOrderHeaderV2EntityOnlySalesTable>(context);
                string salesURL = SalesOrderHeadersV2EntityOnlySalesTable.URL;

                // replace whatever is there with this trash
                salesURL = "http://www." + Guid.NewGuid().ToString() + ".com";

                sw.Start();
                SalesOrderCollection.Add(SalesOrderHeadersV2EntityOnlySalesTable);

                SalesOrderHeadersV2EntityOnlySalesTable.URL = salesURL;

                context.SaveChanges(SaveChangesOptions.PostOnlySetProperties | SaveChangesOptions.BatchWithSingleChangeset);

                sw.Stop();


                StreamWriter stream = File.AppendText(filePath);

                stream.WriteLine(Entity + "," + testType + "," + testWorkload + "," + sw.Elapsed.TotalMilliseconds.ToString());
                stream.Flush();
                stream.Close();
            }
        }
Example #26
0
        public static void CreateSalesOrderInSingleChangeset(Resources context)
        {
            string salesOrderNumber = "100005";

            try
            {
                RetailStore retailStore = new RetailStore();
                DataServiceCollection <RetailStore> retailStoreCollection = new DataServiceCollection <RetailStore>(context);


                SalesOrderHeader salesOrder = new SalesOrderHeader();
                DataServiceCollection <SalesOrderHeader> salesOrderCollection = new DataServiceCollection <SalesOrderHeader>(context);
                salesOrderCollection.Add(salesOrder);

                salesOrder.SalesOrderNumber              = salesOrderNumber; // Change number sequence setting in AX to allow user to set values.
                salesOrder.CurrencyCode                  = "USD";
                salesOrder.InvoiceCustomerAccountNumber  = "US-001";
                salesOrder.OrderingCustomerAccountNumber = "US-001";
                salesOrder.LanguageId = "en-us";
                salesOrder.DataAreaId = "USMF";

                SalesOrderLine salesOrderLine = new SalesOrderLine();
                DataServiceCollection <SalesOrderLine> salesOrderLineCollection = new DataServiceCollection <SalesOrderLine>(context);
                salesOrderLineCollection.Add(salesOrderLine);

                salesOrderLine.SalesOrderNumber     = salesOrder.SalesOrderNumber;
                salesOrderLine.ItemNumber           = "1000";
                salesOrderLine.OrderedSalesQuantity = 1;
                salesOrderLine.ShippingSiteId       = "2";
                salesOrderLine.ShippingWarehouseId  = "24";
                salesOrderLine.DataAreaId           = "USMF";

                context.SaveChanges(SaveChangesOptions.PostOnlySetProperties | SaveChangesOptions.BatchWithSingleChangeset); // Batch with Single Changeset ensure the saved changed runs in all-or-nothing mode.
                Console.WriteLine(string.Format("Invoice {0} - Saved !", salesOrderNumber));
            }
            catch (DataServiceRequestException e)
            {
                Console.WriteLine(string.Format("Invoice {0} - Save Failed !", salesOrderNumber));
            }
        }
Example #27
0
        public static void CreateCustomer2(Resources context)
        {
            Customer myCustomer = new Customer();
            DataServiceCollection <Customer> customersCollection = new DataServiceCollection <Customer>(context);

            customersCollection.Add(myCustomer);

            myCustomer.CustomerAccount   = "US-X11111";
            myCustomer.Name              = "ABC Trees  111";
            myCustomer.CustomerGroupId   = "01";
            myCustomer.SalesCurrencyCode = "USD";
            //myCustomer.CreditRating = "Excellent";
            // myCustomer.AddressCountryRegionId = "USA";

            #region Create multiple customers

            //Customer myCustomer2 = new Customer();

            //customersCollection.Add(myCustomer2);

            //myCustomer2.CustomerAccount = "US-X22222";
            //myCustomer2.Name = "ABC Rains vb";
            //myCustomer2.CustomerGroupId = "01";
            //myCustomer2.SalesCurrencyCode = "USD";
            //myCustomer2.CreditRating = "Excellent";
            //myCustomer2.AddressCountryRegionId = "USA";

            #endregion

            DataServiceResponse response = null;
            try
            {
                response = context.SaveChanges(SaveChangesOptions.PostOnlySetProperties | SaveChangesOptions.BatchWithSingleChangeset);
                Console.WriteLine("created ok");
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message + ex.InnerException);
            }
        }
Example #28
0
        public void AddSaveUpdateSaveEntity()
        {
            var ctxwrap = this.CreateWrappedContext <DefaultContainer>();
            var context = ctxwrap.Context;
            DataServiceCollection <Customer> dsc = new DataServiceCollection <Customer>(context);
            Customer c = new Customer {
                CustomerId = 1002
            };

            dsc.Add(c);
            this.CheckState(context, EntityStates.Added, c);
            Assert.True(VerifyCtxCount(context, 1, 0));
            this.SaveChanges(context);
            Assert.True(VerifyCtxCount(context, 1, 0));
            c.CustomerId = 1003;
            this.CheckState(context, EntityStates.Modified, c);
            Assert.True(VerifyCtxCount(context, 1, 0));
            this.SaveChanges(context);
            Assert.True(VerifyCtxCount(context, 1, 0));

            this.EnqueueTestComplete();
        }
Example #29
0
        public void AddSaveDetachedSaveEntity()
        {
            var ctxwrap = this.CreateWrappedContext <DefaultContainer>();
            var context = ctxwrap.Context;
            DataServiceCollection <Customer> DSC = new DataServiceCollection <Customer>(context);
            Customer c = new Customer {
                CustomerId = 1002
            };

            DSC.Add(c);
            this.CheckState(context, EntityStates.Added, c);
            Assert.True(VerifyCtxCount(context, 1, 0));
            this.SaveChanges(context);
            Assert.True(VerifyCtxCount(context, 1, 0));
            context.Detach(c);
            this.CheckState(context, EntityStates.Detached, DSC);
            Assert.True(VerifyCtxCount(context, 0, 0));
            this.SaveChanges(context);
            Assert.True(VerifyCtxCount(context, 0, 0));

            this.EnqueueTestComplete();
        }
        public void DerivedComplexTypeShouldOnlySerializeChangedProperties()
        {
            EntityType entity = new EntityType
            {
                ID      = 1,
                Complex = new ComplexType
                {
                    Name = "June",
                    Home = new HomeAddress("Xiadu", 200, "Guangzhou")
                },
                StringCollection = new ObservableCollection <string>(new string[] { "first", "second" })
            };
            DataServiceCollection <EntityType> collection = new DataServiceCollection <EntityType>(context, null, TrackingMode.AutoChangeTracking, "EntitySet", null, null);

            collection.Add(entity);

            context.Entities.FirstOrDefault().State = EntityStates.Unchanged;
            entity.ID = 71;
            entity.Complex.Home.Code = 17;
            ((HomeAddress)entity.Complex.Home).City = "Guangzhou";
            Assert.AreEqual(EntityStates.Modified, context.Entities.FirstOrDefault().State);
            ValidateBodyContent(context, "{\"ID\":71,\"Complex\":{\"Name\":\"June\",\"Home\":{\"City\":\"Guangzhou\",\"Code\":17,\"Street\":\"Xiadu\"}}}");
        }
        public static void CreateVendorInSigleChangeset(Resources context)
        {
            string vendorId = "VEND00001";

            try
            {
                Vendor vendor = new Vendor();
                DataServiceCollection <Vendor> salesOrderCollection = new DataServiceCollection <Vendor>(context);
                salesOrderCollection.Add(vendor);

                vendor.VendorAccountNumber = vendorId;
                vendor.VendorGroupId       = "VENDGROUP01";
                vendor.VendorPartyType     = "Organization";
                vendor.VendorName          = "Name of the vendor";

                context.SaveChanges(SaveChangesOptions.PostOnlySetProperties | SaveChangesOptions.BatchWithSingleChangeset); // Batch with Single Changeset ensure the saved changed runs in all-or-nothing mode.
                Console.WriteLine(string.Format("Vendor {0} - Saved !", vendorId));
            }
            catch (DataServiceRequestException e)
            {
                Console.WriteLine(string.Format("Vendor {0} - Save Failed !", vendorId));
            }
        }
Example #32
0
        public void RemoveParentEntityWithLinks()
        {
            var ctxwrap = this.CreateWrappedContext <DefaultContainer>();
            var context = ctxwrap.Context;
            DataServiceCollection <Customer> DSC = new DataServiceCollection <Customer>(context);
            Customer c = new Customer {
                CustomerId = 1002
            };

            DSC.Add(c);
            Order o = new Order {
                OrderId = 2001, Customer = c, CustomerId = 1002
            };

            c.Orders.Add(o);
            VerifyCtxCount(context, 2, 1);
            DSC.Remove(c);
            VerifyCtxCount(context, 0, 0);
            SaveChanges(context);
            VerifyCtxCount(context, 0, 0);

            this.EnqueueTestComplete();
        }
Example #33
0
        public void AddRemoveNullEntity()
        {
            var ctxwrap = this.CreateWrappedContext <DefaultContainer>();
            var context = ctxwrap.Context;
            DataServiceCollection <Customer> DSC = new DataServiceCollection <Customer>(context);

            try
            {
                DSC.Add(null);
                Assert.True(false, "Expected error not thrown");
            }
            catch (InvalidOperationException e)
            {
#if !PORTABLELIB && !SILVERLIGHT
                StringResourceUtil.VerifyDataServicesClientString(e.Message, "DataBinding_BindingOperation_ArrayItemNull", "Add");
#else
                Assert.NotNull(e);
#endif
            }

            try
            {
                DSC.Remove(null);
                Assert.True(false, "Expected error not thrown");
            }
            catch (InvalidOperationException e)
            {
#if !PORTABLELIB && !SILVERLIGHT
                StringResourceUtil.VerifyDataServicesClientString(e.Message, "DataBinding_BindingOperation_ArrayItemNull", "Remove");
#else
                Assert.NotNull(e);
#endif
            }

            this.EnqueueTestComplete();
        }
Example #34
0
        public void LoadPropertyCollection()
        {
            var ctxwrap = this.CreateWrappedContext<DefaultContainer>();
            var context = ctxwrap.Context;
            var querry = (from c in context.Customer
                          where c.CustomerId == -10
                          select c) as DataServiceQuery<Customer>;

            var ar = querry.BeginExecute(null, null).EnqueueWait(this);
            var cus = querry.EndExecute(ar).First();
            DataServiceCollection<Customer> DSC = new DataServiceCollection<Customer>(context);
            DSC.Add(cus);
            var ar02 = context.BeginLoadProperty(cus, "Orders", null, null).EnqueueWait(this);
            context.EndLoadProperty(ar02);
            foreach (Order o in cus.Orders)
            {
                o.OrderId = (134);
            }

            int fristCount = context.Entities.Count();
            foreach (var ed in context.Entities)
            {
                if (ed.Entity.GetType().Equals(cus.Orders.First().GetType()))
                {
                    Assert.AreEqual(EntityStates.Modified, ed.State);
                }
            }

            var o1 = new Order { OrderId = 1220 };
            cus.Orders.Add(o1);
            Assert.AreEqual(fristCount + 1, context.Entities.Count());
            cus.Orders.Remove(o1);
            Assert.AreEqual(fristCount, context.Entities.Count());

            this.EnqueueTestComplete();
        }
Example #35
0
        public void AddSaveUpdateSaveEntity()
        {
            var ctxwrap = this.CreateWrappedContext<DefaultContainer>();
            var context = ctxwrap.Context;
            DataServiceCollection<Customer> DSC = new DataServiceCollection<Customer>(context);
            Customer c = new Customer { CustomerId = 1002 };
            DSC.Add(c);
            this.CheckState(context, EntityStates.Added, c);
            Assert.IsTrue(VerifyCtxCount(context, 1, 0));
            this.SaveChanges(context);
            Assert.IsTrue(VerifyCtxCount(context, 1, 0));
            c.CustomerId = 1003;
            this.CheckState(context, EntityStates.Modified, c);
            Assert.IsTrue(VerifyCtxCount(context, 1, 0));
            this.SaveChanges(context);
            Assert.IsTrue(VerifyCtxCount(context, 1, 0));

            this.EnqueueTestComplete();
        }
        private Order GetTrackedOrder()
        {
            var order = GetUntrackedOrder();

            // Add the entity to a DataServiceCollection to track it.
            var collection = new DataServiceCollection<Order>(dsc, "Orders", null, null);
            collection.Add(order);

            // Change some property intentionally.
            order.OrderID = 100;

            return order;
        }
Example #37
0
        public void ClearListTest()
        {
            var ctxwrap = this.CreateWrappedContext<DefaultContainer>();
            var context = ctxwrap.Context;
            DataServiceCollection<Customer> dsc = new DataServiceCollection<Customer>(context);
            Customer c = new Customer { CustomerId = 1002 };
            Customer c2 = new Customer { CustomerId = 1003 };
            Customer c3 = new Customer { CustomerId = 1004 };
            dsc.Add(c);
            dsc.Add(c2);
            dsc.Add(c3);
            Order o = new Order { OrderId = 2001, Customer = c, CustomerId = 1002 };
            c.Orders.Add(o);
            VerifyCtxCount(context, 4, 1);
            dsc.Clear();
            VerifyCtxCount(context, 0, 0);

            this.EnqueueTestComplete();
        }
Example #38
0
        public void AddRemoveNullEntity()
        {
            var ctxwrap = this.CreateWrappedContext<DefaultContainer>();
            var context = ctxwrap.Context;
            DataServiceCollection<Customer> DSC = new DataServiceCollection<Customer>(context);
            try
            {
                DSC.Add(null);
                Assert.Fail("Expected error not thrown");
            }
            catch (InvalidOperationException e)
            {
#if !PORTABLELIB && !SILVERLIGHT
                 StringResourceUtil.VerifyDataServicesClientString(e.Message, "DataBinding_BindingOperation_ArrayItemNull", "Add" );
#else
                Assert.IsNotNull(e);
#endif

            }

            try
            {
                DSC.Remove(null);
                Assert.Fail("Expected error not thrown");
            }
            catch (InvalidOperationException e)
            {
#if !PORTABLELIB && !SILVERLIGHT
                StringResourceUtil.VerifyDataServicesClientString(e.Message, "DataBinding_BindingOperation_ArrayItemNull", "Remove");
#else
                Assert.IsNotNull(e);
#endif
                
                }

            this.EnqueueTestComplete();
        }
Example #39
0
        public void RemoveEntityTwice()
        {
            var ctxwrap = this.CreateWrappedContext<DefaultContainer>();
            var context = ctxwrap.Context;
            DataServiceCollection<Customer> dsc = new DataServiceCollection<Customer>(context);
            Customer c = new Customer { CustomerId = 1002 };
            Customer c2 = new Customer { CustomerId = 1003 };
            dsc.Add(c);
            dsc.Add(c2);
            dsc.Remove(c);
            this.CheckState(context, EntityStates.Deleted, c);
            Assert.True(VerifyCtxCount(context, 1, 0));
            dsc.Remove(c);
            this.CheckState(context, EntityStates.Deleted, c);
            Assert.True(VerifyCtxCount(context, 1, 0));

            this.EnqueueTestComplete();
        }
Example #40
0
        public void RemoveChildEntityWithLinks()
        {
            var ctxwrap = this.CreateWrappedContext<DefaultContainer>();
            var context = ctxwrap.Context;
            DataServiceCollection<Customer> dsc = new DataServiceCollection<Customer>(context);
            DataServiceCollection<Order> dscOrder = new DataServiceCollection<Order>(context);
            Customer c = new Customer { CustomerId = 1002 };
            dsc.Add(c);
            Order o = new Order { OrderId = 2001, Customer = c, CustomerId = 1002 };
            c.Orders.Add(o);
            VerifyCtxCount(context, 2, 1);
            dscOrder.Remove(o);
            VerifyCtxCount(context, 1, 0);
            SaveChanges(context);
            VerifyCtxCount(context, 1, 0);

            this.EnqueueTestComplete();
        }
Example #41
0
        public void DeletingInDeletedState()
        {
            var ctxwrap = this.CreateWrappedContext<DefaultContainer>();
            var context = ctxwrap.Context;
            DataServiceCollection<Customer> DSC = new DataServiceCollection<Customer>(context);
            Customer deleted = new Customer { CustomerId = 1004 };
            DSC.Add(deleted);
            VerifyCtxCount(context, 1, 0);
            this.SaveChanges(context);
            context.DeleteObject(deleted);
            this.CheckState(context, EntityStates.Deleted, deleted);
            VerifyCtxCount(context, 1, 0);
            DSC.Remove(deleted);
            VerifyCtxCount(context, 0, 0);

            this.EnqueueTestComplete();
        }
Example #42
0
        public void AddSaveDetachedSaveEntity()
        {
            var ctxwrap = this.CreateWrappedContext<DefaultContainer>();
            var context = ctxwrap.Context;
            DataServiceCollection<Customer> dsc = new DataServiceCollection<Customer>(context);
            Customer c = new Customer { CustomerId = 1002 };
            dsc.Add(c);
            this.CheckState(context, EntityStates.Added, c);
            Assert.True(VerifyCtxCount(context, 1, 0));
            this.SaveChanges(context);
            Assert.True(VerifyCtxCount(context, 1, 0));
            context.Detach(c);
            this.CheckState(context, EntityStates.Detached, dsc);
            Assert.True(VerifyCtxCount(context, 0, 0));
            this.SaveChanges(context);
            Assert.True(VerifyCtxCount(context, 0, 0));

            this.EnqueueTestComplete();
        }
Example #43
0
        public void DeletingInUnchangedState()
        {
            var ctxwrap = this.CreateWrappedContext<DefaultContainer>();
            var context = ctxwrap.Context;
            DataServiceCollection<Customer> dsc = new DataServiceCollection<Customer>(context);
            Customer unchanged = new Customer { CustomerId = 1002 };
            dsc.Add(unchanged);
            VerifyCtxCount(context, 1, 0);
            this.SaveChanges(context);
            this.CheckState(context, EntityStates.Unchanged, unchanged);
            VerifyCtxCount(context, 1, 0);
            dsc.Remove(unchanged);
            VerifyCtxCount(context, 0, 0);

            this.EnqueueTestComplete();
        }
        public void CreateNewCompositionForPanel()
        {
            _repository = ServiceLocator.Current.GetInstance<DataServiceRepository<Repository.DataService.Composition>>();
            var staffgroups = new DataServiceCollection<Staffgroup>(null, TrackingMode.None);

            int staffDensity = ((short)_staffConfiguration == (short)_Enum.StaffConfiguration.Grand) ?
                Infrastructure.Constants.Defaults.NewCompositionPanelGrandStaffConfigurationStaffDensity : Infrastructure.Constants.Defaults.NewCompositionPanelSimpleStaffConfigurationStaffDensity;

            Repository.DataService.Composition composition = CompositionManager.Create();
            for (int n = 0; n < Infrastructure.Constants.Defaults.NewCompositionPanelStaffgroupDensity; n++)
            {
                var staffgroup = StaffgroupManager.Create(composition.Id, _staffgroupSequence);
                _staffgroupSequence += Defaults.SequenceIncrement;
                var staffs = new DataServiceCollection<Staff>(null, TrackingMode.None);
                _staffSequence = 0;
                for (var j = 0; j < staffDensity; j++)
                {
                    var staff = StaffManager.Create(staffgroup.Id, _staffSequence);
                    _staffSequence += Defaults.SequenceIncrement;

                    //set clef to default grand staff clef, so the next time through this loop, the grand staff gets the correct clef.
                    Preferences.DefaultClefId = 0;

                    var measures = new DataServiceCollection<Repository.DataService.Measure>(null, TrackingMode.None);
                    _measureSequence = 0;
                    for (var k = 0; k < Infrastructure.Constants.Defaults.NewCompositionPanelMeasureDensity; k++)
                    {
                        var measure = MeasureManager.Create(staff.Id, _measureSequence);

                        _measureSequence += Defaults.SequenceIncrement;
                        measure.Index = _measureIndex;
                        _measureIndex++;
                        _repository.Context.AddLink(staff, "Measures", measure);
                        measures.Add(measure);
                    }
                    staff.Measures = measures;
                    _repository.Context.AddLink(staffgroup, "Staffs", staff);
                    staffs.Add(staff);
                }
                staffgroup.Staffs = staffs;
                _repository.Context.AddLink(composition, "Staffgroups", staffgroup);
                staffgroups.Add(staffgroup);
            }
            composition.Staffgroups = staffgroups;
            composition = CompositionManager.Flatten(composition);
            Composition = composition;
        }
        public void ClientSerializeGeographyTest_BindingUpdateChangeShouldBeDetected()
        {
            DataServiceContext ctx = new DataServiceContext(new Uri("http://localhost"));
            DataServiceCollection<SpatialEntityType> dsc = new DataServiceCollection<SpatialEntityType>(ctx, null, TrackingMode.AutoChangeTracking, "Entities", null, null);
            dsc.Add(testEntity);
            Assert.AreEqual(1, ctx.Entities.Count);

            ctx.Entities.FirstOrDefault().State = EntityStates.Unchanged;
            testEntity.Prop1 = testEntity.Prop1;
            Assert.AreEqual(EntityStates.Modified, ctx.Entities.FirstOrDefault().State);

            ClientSerializeGeographyTest_ValidateUpdate(ctx);
        }
Example #46
0
        public void OnCloneComposition(object obj)
        {
            Repository.DataService.Composition sourceComposition = CompositionManager.Composition;

            SetDimensions(sourceComposition);

            var verses = new DataServiceCollection<Repository.DataService.Verse>(null, TrackingMode.None);
            var staffgroups = new DataServiceCollection<Repository.DataService.Staffgroup>(null, TrackingMode.None);
            var arcs = new DataServiceCollection<Repository.DataService.Arc>(null, TrackingMode.None);

            var composition = CompositionManager.Create();
            Cache.Clear();

            foreach (var sourceStaffgroup in sourceComposition.Staffgroups)
            {
                var staffgroup = StaffgroupManager.Clone(composition.Id, sourceStaffgroup);

                var staffs = new DataServiceCollection<Repository.DataService.Staff>(null, TrackingMode.None);
                foreach (var sourceStaff in sourceStaffgroup.Staffs)
                {
                    var staff = StaffManager.Clone(staffgroup.Id, sourceStaff);
                    var measures = new DataServiceCollection<Repository.DataService.Measure>(null, TrackingMode.None);
                    foreach (var sourceMeasure in sourceStaff.Measures)
                    {
                        var measure = MeasureManager.Clone(staff.Id, sourceMeasure);
                        var chords = new DataServiceCollection<Repository.DataService.Chord>(null, TrackingMode.None);
                        foreach (var sourceChord in sourceMeasure.Chords)
                        {
                            ChordManager.Measure = measure;
                            var chord = ChordManager.Clone(measure, sourceChord);
                            var notes = new DataServiceCollection<Repository.DataService.Note>(null, TrackingMode.None);
                            foreach (var sourceNote in sourceChord.Notes)
                            {
                                var note = NoteController.Clone(chord.Id, sourceChord, measure, sourceNote.Location_X, sourceNote.Location_Y, sourceNote);
                                if (note != null)
                                {
                                    _repository.Context.AddLink(chord, "Notes", note);
                                    notes.Add(note);
                                }
                            }
                            chord.Notes = notes;
                            _repository.Context.AddLink(measure, "Chords", chord);
                            chords.Add(chord);
                        }
                        measure.Chords = chords;
                        _repository.Context.AddLink(staff, "Measures", measure);
                        measures.Add(measure);
                    }
                    staff.Measures = measures;
                    _repository.Context.AddLink(staffgroup, "Staffs", staff);
                    staffs.Add(staff);
                }
                staffgroup.Staffs = staffs;
                _repository.Context.AddLink(composition, "Staffgroups", staffgroup);
                staffgroups.Add(staffgroup);
            }
            int s;
            for (s = 0; s < sourceComposition.Arcs.Count; s++)
            {
                var arc = ArcManager.Clone(sourceComposition.Arcs[s]);
                _repository.Context.AddLink(composition, "Arcs", arc);
                arcs.Add(arc);
            }

            for (s = 0; s < sourceComposition.Verses.Count; s++)
            {
                var verse = VerseManager.Clone(composition.Id, sourceComposition.Verses[s]);
                Cache.Verses.Add(verse);
                _repository.Context.AddLink(composition, "Verses", verse);
                verses.Add(verse);
            }
            composition.Instrument_Id = sourceComposition.Instrument_Id;
            composition.Key_Id = sourceComposition.Key_Id;
            composition.Provenance = sourceComposition.Provenance;
            composition.Arcs = arcs;
            composition.Verses = verses;
            composition.Staffgroups = staffgroups;

            _ea.GetEvent<NewComposition>().Publish(composition);
        }
Example #47
0
        public static void OnCreateNewComposition(object obj)
        {
            var payload = (Tuple<string, List<string>, _Enum.StaffConfiguration, List<short>>)obj;
            _repository = ServiceLocator.Current.GetInstance<DataServiceRepository<Repository.DataService.Composition>>();

            var verses = new DataServiceCollection<Repository.DataService.Verse>(null, TrackingMode.None);
            var staffgroups = new DataServiceCollection<Staffgroup>(null, TrackingMode.None);
            var collaborations = new DataServiceCollection<Repository.DataService.Collaboration>(null, TrackingMode.None);

            var composition = Create();
            composition.Provenance.TitleLine = payload.Item1;
            composition.StaffConfiguration = (short)payload.Item3;
            ClefIds = payload.Item4;
            for (int sgIndex = 0; sgIndex < Infrastructure.Support.Densities.StaffgroupDensity; sgIndex++)
            {
                var staffgroup = StaffgroupManager.Create(composition.Id, _staffgroupSequence);
                _staffgroupSequence += Defaults.SequenceIncrement;
                var staffs = new DataServiceCollection<Staff>(null, TrackingMode.None);
                _staffSequence = 0;
                for (int sIndex = 0; sIndex < Infrastructure.Support.Densities.StaffDensity; sIndex++)
                {
                    var staff = StaffManager.Create(staffgroup.Id, _staffSequence);

                    //clefIds was populated in NewCompositionPanel. it's a list of selected staff clef Ids top to bottom.
                    //if Dimensions.StaffDensity > then in multi instrument staffconfiguration - each staff clef is the
                    //same as the first staff clef. otherwise the staff clefs are whatever was specified in the newcompositionpanel
                    staff.Clef_Id = (Infrastructure.Support.Densities.StaffDensity > 2) ? ClefIds[0] : ClefIds[sIndex % 2];

                    _staffSequence += Defaults.SequenceIncrement;
                    var measures = new DataServiceCollection<Repository.DataService.Measure>(null, TrackingMode.None);
                    _measureSequence = 0;
                    for (int mIndex = 0; mIndex < Infrastructure.Support.Densities.MeasureDensity; mIndex++)
                    {
                        var measure = MeasureManager.Create(staff.Id, _measureSequence);

                        _measureSequence += Defaults.SequenceIncrement;
                        measure.Index = _measureIndex;
                        _measureIndex++;
                        _repository.Context.AddLink(staff, "Measures", measure);
                        //if this is the last measure on the last staff then measure.bar is the EndBar.
                        if (mIndex == Infrastructure.Support.Densities.MeasureDensity - 1)
                        {
                            if (sgIndex == Infrastructure.Support.Densities.StaffgroupDensity - 1)
                            {
                                if (sIndex == Infrastructure.Support.Densities.StaffDensity - 1)
                                {
                                    measure.Bar_Id = 1;
                                }
                            }
                        }
                        measures.Add(measure);
                    }
                    staff.Measures = measures;
                    _repository.Context.AddLink(staffgroup, "Staffs", staff);
                    staffs.Add(staff);
                }
                staffgroup.Staffs = staffs;
                _repository.Context.AddLink(composition, "Staffgroups", staffgroup);
                staffgroups.Add(staffgroup);
            }

            composition.Staffgroups = staffgroups;
            Repository.DataService.Collaboration collaboration = CollaborationManager.Create(composition, 0);
            _repository.Context.AddLink(composition, "Collaborations", collaboration);
            collaborations.Add(collaboration);
            composition.Collaborations = collaborations;
            composition.Verses = verses;
            Ea.GetEvent<NewComposition>().Publish(composition);
        }
        private ICollection<Order> GetTrackedOrders()
        {
            var order1 = GetUntrackedOrder();
            var order2 = GetUntrackedOrder();

            // Add the entities to a DataServiceCollection to track them.
            var collection = new DataServiceCollection<Order>(dsc, "Orders", null, null);
            collection.Add(order1);
            collection.Add(order2);

            // Change some properties intentionally.
            order1.OrderID = 100;
            order2.OrderID = 101;

            return new List<Order> { order1, order2 };
        }
Example #49
0
        public void AddRemoveNullEntity()
        {
            var ctxwrap = this.CreateWrappedContext<DefaultContainer>();
            var context = ctxwrap.Context;
            DataServiceCollection<Customer> dsc = new DataServiceCollection<Customer>(context);
            try
            {
                dsc.Add(null);
                Assert.True(false, "Expected error not thrown");
            }
            catch (InvalidOperationException e)
            {
                Assert.NotNull(e);
            }

            try
            {
                dsc.Remove(null);
                Assert.True(false, "Expected error not thrown");
            }
            catch (InvalidOperationException e)
            {
                Assert.NotNull(e);
            }

            this.EnqueueTestComplete();
        }