Esempio n. 1
0
        public void SimleTransformerTest()
        {
            var userLogin = new UserLogin("admin", "admin");
            var result    = SimpleTransformer.Transform <UserLogin, User>(userLogin);

            Assert.AreEqual(userLogin.Login, result.Login);
        }
Esempio n. 2
0
        /// <summary>
        /// Simple transform just builds the SsaGraph from all the identifiers.
        /// </summary>
        /// <param name="proc"></param>
        public SsaTransform(Procedure proc)
        {
            this.proc     = proc;
            this.SsaState = new SsaState(proc, null);
            var str = new SimpleTransformer(SsaState);

            str.Transform();
        }
Esempio n. 3
0
        public void CanUseTransformerInStreamDocs_Session()
        {
            using (var store = NewRemoteDocumentStore())
            {
                using (var session = store.OpenSession())
                {
                    session.Store(new Person {
                        Name = "John"
                    });
                    session.Store(new Person {
                        Name = "George"
                    });

                    session.SaveChanges();
                }

                var transformer = new SimpleTransformer();
                transformer.Execute(store);

                using (var session = store.OpenSession())
                {
                    using (var enumerator = session.Advanced.Stream <SimpleTransformer.Result>("people/", transformer: transformer.TransformerName, transformerParameters: new Dictionary <string, RavenJToken> {
                        { "Name", "Test" }
                    }))
                    {
                        var count = 0;
                        while (enumerator.MoveNext())
                        {
                            var result = enumerator.Current;

                            Assert.Equal("Test", result.Document.Name);

                            count++;
                        }

                        Assert.Equal(2, count);
                    }

                    using (var enumerator = session.Advanced.Stream <SimpleTransformer.Result>(Etag.Empty, transformer: transformer.TransformerName, transformerParameters: new Dictionary <string, RavenJToken> {
                        { "Name", "Test" }
                    }))
                    {
                        var count = 0;
                        while (enumerator.MoveNext())
                        {
                            var result = enumerator.Current;

                            Assert.Equal("Test", result.Document.Name);

                            count++;
                        }

                        Assert.Equal(2 + 1, count); // +1 for HiLo
                    }
                }
            }
        }
Esempio n. 4
0
        /// <inheritdoc />
        /// <summary>
        /// The registration.
        /// </summary>
        /// <param name="userRegistration">
        /// The user registration.
        /// </param>
        /// <exception cref="T:System.Exception">
        /// </exception>
        public void Registration(UserRegistration userRegistration)
        {
            var validator        = DIContainer.Resolve <IValidator <UserRegistration> >("UserRegistration");
            var resultValidation = validator.Validate(userRegistration);

            switch (resultValidation.ValidationStatus)
            {
            case ValidationStatus.Success:
                break;

            case ValidationStatus.Fail:
                throw new Exception(resultValidation.AttachedInfo);
            }

            var user = SimpleTransformer.Transform <UserRegistration, User>(userRegistration);

            this.userRepository.Insert(user);
        }
Esempio n. 5
0
        /// <inheritdoc />
        /// <summary>
        /// The system enter.
        /// </summary>
        /// <param name="userLogin">
        /// The user login.
        /// </param>
        /// <returns>
        /// The <see cref="T:System.Int32" />.
        /// </returns>
        /// <exception cref="T:System.Exception">
        /// </exception>
        public int SystemEnter(UserLogin userLogin)
        {
            var validator        = DIContainer.Resolve <IValidator <UserLogin> >("UserLogin");
            var resultValidation = validator.Validate(userLogin);

            switch (resultValidation.ValidationStatus)
            {
            case ValidationStatus.Success:
                break;

            case ValidationStatus.Fail:
                throw new Exception(resultValidation.AttachedInfo);
            }

            var user     = SimpleTransformer.Transform <UserLogin, User>(userLogin);
            var userList = this.userRepository.SelectAll();

            return(userList.First(x => x.Login == user.Login && x.Password == user.Password).UserId);
        }
Esempio n. 6
0
        public void StreamWithTransformer()
        {
            var store = new DocumentStore();

            #region stream_3

            var transformer = new SimpleTransformer();
            transformer.Execute(store);

            using (IEnumerator<RavenJObject> enumerator = store.DatabaseCommands.StreamDocs(startsWith: "people/", transformer: transformer.TransformerName, transformerParameters: new Dictionary<string, RavenJToken> {{"Name", "Bill"}}))
            {
                while (enumerator.MoveNext())
                {
                    RavenJObject result = enumerator.Current;
                    string name = result.Value<string>("Name");
                    Assert.Equal("Bill", name); // Should be true
                }
            }
            #endregion
        }
Esempio n. 7
0
        /// <inheritdoc />
        /// <summary>
        /// The get all warehouse goods.
        /// </summary>
        /// <returns>
        /// The <see cref="T:System.Collections.Generic.IEnumerable`1" />.
        /// </returns>
        public IEnumerable <WarehouseGoods> GetAllWarehouseGoods()
        {
            var warehouseCollection       = this.warehouseRepository.SelectAll();
            var goodsOfDeliveryCollection = this.goodsOfDeliveryRepository.SelectAll();
            var deliveryCollection        = this.deliveryRepository.SelectAll();
            var goodsCollection           = this.goodsRepository.SelectAll();
            var providerCollection        = this.providerRepository.SelectAll();
            var goodsCategoryCollection   = this.goodsCategoryRepository.SelectAll();
            var goodsClassCollection      = this.goodsClassRepository.SelectAll();
            var goodsStateCollection      = this.stateRepository.SelectAll();

            var result = from warehouse in warehouseCollection
                         from goodsOfDelivery in goodsOfDeliveryCollection
                         from delivery in deliveryCollection
                         from goods in goodsCollection
                         from provider in providerCollection
                         from goodsCategory in goodsCategoryCollection
                         from goodsClass in goodsClassCollection
                         from state in goodsStateCollection
                         where warehouse.GoodsOfDeliveryId == goodsOfDelivery.GoodsOfDeliveryId
                         where goodsOfDelivery.DeliveryId == delivery.DeliveryId
                         where goodsOfDelivery.GoodsId == goods.GoodsId
                         where goods.ProviderId == provider.ProviderId
                         where goods.GoodsCategoryId == goodsCategory.GoodsCategoryId
                         where goods.GoodsClassId == goodsClass.GoodsClassId
                         where warehouse.StateId == state.StateId
                         select new WarehouseGoods
            {
                GoodsId          = goods.GoodsId,
                Title            = goods.Title,
                Provider         = SimpleTransformer.Transform <Provider, ProviderDto>(provider),
                GoodsCategory    = SimpleTransformer.Transform <GoodsCategory, GoodsCategoryDto>(goodsCategory),
                GoodsClass       = SimpleTransformer.Transform <GoodsClass, GoodsClassDto>(goodsClass),
                Amount           = goodsOfDelivery.Amount,
                DateTimeDelivery = delivery.DateTimeDelivery,
                State            = state.Title
            };

            return(result);
        }
Esempio n. 8
0
        public void StreamWithTransformer()
        {
            var store = new DocumentStore();

            #region stream_3

            var transformer = new SimpleTransformer();
            transformer.Execute(store);

            using (IEnumerator <RavenJObject> enumerator = store.DatabaseCommands.StreamDocs(startsWith: "people/", transformer: transformer.TransformerName, transformerParameters: new Dictionary <string, RavenJToken> {
                { "Name", "Bill" }
            }))
            {
                while (enumerator.MoveNext())
                {
                    RavenJObject result = enumerator.Current;
                    string       name   = result.Value <string>("Name");
                    Assert.Equal("Bill", name); // Should be true
                }
            }
            #endregion
        }
Esempio n. 9
0
        public LoadingEntities()
        {
            using (var store = new DocumentStore())
            {
                using (var session = store.OpenSession())
                {
                    #region loading_entities_1_1
                    Employee employee = session.Load <Employee>("employees/1");
                    #endregion
                }

                using (var session = store.OpenSession())
                {
                    #region loading_entities_1_2
                    // loading 'employees/1'
                    // and transforming result using 'Employees_NoLastName' transformer
                    // which returns 'LastName' as 'null'
                    Employee employee = session.Load <Employees_NoLastName, Employee>("employees/1");
                    #endregion
                }

                using (var session = store.OpenSession())
                {
                    #region loading_entities_1_3
                    EntityWithIntegerId entity = session.Load <EntityWithIntegerId>(1);
                    #endregion
                }

                using (var session = store.OpenSession())
                {
                    #region loading_entities_1_4
                    Employee employee = session.Load <Employee>(1);
                    #endregion
                }


                using (var session = store.OpenSession())
                {
                    #region loading_entities_2_1
                    // loading 'products/1'
                    // including document found in 'Supplier' property
                    Product product = session
                                      .Include <Product>(x => x.Supplier)
                                      .Load <Product>("products/1");

                    Supplier supplier = session.Load <Supplier>(product.Supplier);                    // this will not make server call
                    #endregion
                }

                using (var session = store.OpenSession())
                {
                    #region loading_entities_2_2
                    // loading 'products/1'
                    // including document found in 'Supplier' property
                    Product product = session
                                      .Include("Supplier")
                                      .Load <Product>("products/1");

                    Supplier supplier = session.Load <Supplier>(product.Supplier);                    // this will not make server call
                    #endregion
                }

                using (var session = store.OpenSession())
                {
                    #region loading_entities_2_3
                    // loading 'products/1'
                    // including document found in 'Supplier' property
                    // transforming loaded product according to Products_Transformer
                    Product product = session
                                      .Include <Product>(x => x.Supplier)
                                      .Load <Products_Transformer, Product>("products/1");

                    Supplier supplier = session.Load <Supplier>(product.Supplier);                    // this will not make server call
                    #endregion
                }

                using (var session = store.OpenSession())
                {
                    #region loading_entities_3_1
                    Employee[] employees = session.Load <Employee>(new List <string> {
                        "employees/1", "employees/2"
                    });
                    Employee employee1 = employees[0];
                    Employee employee2 = employees[1];
                    #endregion
                }

                using (var session = store.OpenSession())
                {
                    #region loading_entities_3_2
                    // loading 'employees/1' and 'employees/2'
                    // and transforming results using 'Employees_NoLastName' transformer
                    // which returns 'LastName' as 'null'
                    Employee[] employees = session
                                           .Load <Employees_NoLastName, Employee>(new List <string> {
                        "employees/1", "employees/2"
                    });
                    Employee employee1 = employees[0];
                    Employee employee2 = employees[1];
                    #endregion
                }

                using (var session = store.OpenSession())
                {
                    #region loading_entities_4_1
                    // return up to 128 entities with Id that starts with 'employees'
                    Employee[] result = session
                                        .Advanced
                                        .LoadStartingWith <Employee>("employees", null, 0, 128);
                    #endregion
                }

                using (var session = store.OpenSession())
                {
                    #region loading_entities_4_2
                    // return up to 128 entities with Id that starts with 'employees/'
                    // and rest of the key begins with "1" or "2" e.g. employees/10, employees/25
                    Employee[] result = session
                                        .Advanced
                                        .LoadStartingWith <Employee>("employees/", "1*|2*", 0, 128);
                    #endregion
                }

                using (var session = store.OpenSession())
                {
                    #region loading_entities_4_3
                    // return up to 128 entities with Id that starts with 'employees/'
                    // and rest of the Id have length of 3, begins and ends with "1"
                    // and contains any character at 2nd position e.g. employees/101, employees/1B1
                    // and transform results using 'Employees_NoLastName' transformer
                    Employee[] result = session
                                        .Advanced
                                        .LoadStartingWith <Employees_NoLastName, Employee>("employees/", "1?1", 0, 128);
                    #endregion
                }

                using (var session = store.OpenSession())
                {
                    #region loading_entities_5_1
                    IEnumerator <StreamResult <Employee> > enumerator = session.Advanced.Stream <Employee>("employees/");
                    while (enumerator.MoveNext())
                    {
                        StreamResult <Employee> employee = enumerator.Current;
                    }
                    #endregion
                }

                using (var session = store.OpenSession())
                {
                    #region loading_entities_5_2
                    var transformer = new SimpleTransformer();
                    transformer.Execute(store);

                    using (IEnumerator <StreamResult <SimpleTransformer.Result> > enumerator = session.Advanced.Stream <SimpleTransformer.Result>("people/", transformer: transformer.TransformerName, transformerParameters: new Dictionary <string, RavenJToken> {
                        { "Name", "Bill" }
                    }))
                    {
                        while (enumerator.MoveNext())
                        {
                            StreamResult <SimpleTransformer.Result> result = enumerator.Current;
                            string name = result.Document.Name;
                            Assert.Equal("Bill", name); // Should be true
                        }
                    }
                    #endregion
                }

                using (var session = store.OpenSession())
                {
                    #region loading_entities_6_1
                    bool     isLoaded = session.Advanced.IsLoaded("employees/1");            // false
                    Employee employee = session.Load <Employee>("employees/1");
                    isLoaded = session.Advanced.IsLoaded("employees/1");                     // true
                    #endregion
                }
            }
        }