Esempio n. 1
0
        public static void Run()
        {
            IArrayCollection <Car> carArray = new ArrayCollection <Car>();

            carArray.Insert(new Car("AB 33 108", 12000), 0);
            carArray.Insert(new Car("CD 65 647", 15000), 1);
            carArray.Insert(new Car("EF 23 243", 35000), 2);
            carArray.Insert(new Car("GH 40 393", 24000), 3);
            carArray.Insert(new Car("IJ 82 553", 18000), 4);

            IIndexedCollection <Car> carIC = Configurator.Configure(carArray);

            Console.WriteLine("After Creation");
            PrintContent(carIC);

            carIC.DeleteAt(2);
            Console.WriteLine("After Delete at position 2");
            PrintContent(carIC);

            carIC.InsertAt(new Car("ZX 98 243", 20000), 1);
            Console.WriteLine("After Insert at position 1");
            PrintContent(carIC);

            carIC.Remove();
            Console.WriteLine("After Remove (at end)");
            PrintContent(carIC);

            carIC.Add(new Car("YP 80 626", 13000));
            Console.WriteLine("After Add (at end)");
            PrintContent(carIC);

            Car aCar = carIC.At(3);

            Console.WriteLine($"Car at index 3: {aCar}");
        }
        public void SetUp()
        {
            ctx = new Context(typeof(IDatabase));

            using (var ws = ctx.OpenWorkspace <IDatabase>(IsolationLevel.Exclusive))
            {
                IDatabase database = ws.Data;

                IIndexedCollection <ICity> tempCities = ws.New <IIndexedCollection <ICity> >();
                // Create 100 users
                database.Users = ws.New <IIndexedCollection <IUser> >();
                IUser user;
                ICity city;
                for (int i = 0; i < 100; i++)
                {
                    user          = ws.New <IUser>();
                    user.Username = "******" + i;
                    user.Age      = i;

                    city      = ws.New <ICity>();
                    city.Name = "City" + i;
                    tempCities.Add(city);
                    user.City = city;

                    database.Users.Add(user);
                }

                database.States = ws.New <IIndexedCollection <IState> >();
                IState state;
                for (int i = 0; i < 2; i++)
                {
                    state        = ws.New <IState>();
                    state.Name   = "State" + i;
                    state.Cities = tempCities;
                    database.States.Add(state);
                }

                database.Cities = tempCities;

                //Create 100 products
                database.Products = ws.New <IIndexedCollection <IProduct> >();
                IProduct product;
                for (int i = 0; i < 100; i++)
                {
                    product           = ws.New <IProduct>();
                    product.Name      = "Product" + i;
                    product.ProductID = i;
                    product.Price     = i;

                    database.Products.Add(product);
                }

                // Create 100 orders
                database.Orders = ws.New <IIndexedCollection <IOrder> >();
                for (int i = 0; i < 100; i++)
                {
                    // Use LINQ to find user with appropriate age
                    user = database.Users.Single(u => u.Age == i);

                    // Use LINQ to find product with appropriate price
                    product = database.Products.Single(p => p.Price.Equals(i));

                    var order = ws.New <IOrder>();
                    order.OrderID = i;
                    order.Date    = DateTime.UtcNow;
                    order.Product = product;
                    order.User    = user;

                    database.Orders.Add(order);
                }

                ws.Commit();
            }
        }