public void CreateLink()
        {
            using (var context = TestDwhDbContext.CreateDWHDbContext()) {
                var keyCache = new BasePrimaryKeyCache();
                var hubRepo  = new HubRepository <H_TestHub_Default>(context, HashFunctions.MD5, null);
                var linkRepo = new LinkRepository <L_TestLink_Default>(context, HashFunctions.MD5, keyCache, DVKeyCaching.Enabled);
                var loadDate = DateTime.Now;

                hubRepo.Insert(hubs, loadDate);

                linkRepo.Insert(new L_TestLink_Default(hub1.PrimaryKey, hub2.PrimaryKey), loadDate);
                linkRepo.Insert(new L_TestLink_Default(hub1.PrimaryKey, hub2.PrimaryKey), loadDate);
            }
        }
        public void TestQueriesAndInsert()
        {
            using (var context = TestDwhDbContext.CreateDWHDbContext()) {
                var hubRepo       = new HubRepository <H_TestHub_Stores>(context, HashFunctions.MD5, null);
                var satelliteRepo = new SatelliteRepository <S_TestSatellite_Stores>(context, HashFunctions.MD5);
                var linkRepo      = new LinkRepository <L_TestLink_Stores>(context, HashFunctions.MD5, null, DVKeyCaching.Disabled);

                var loadDate = DateTime.Now;

                // HUB - storing info
                hubRepo.Insert(TestHub1, loadDate, loadInformation: LoadInfo1);

                var hub = hubRepo.GetByKey(TestHub1.PrimaryKey);

                Assert.Equal(LoadInfo1.RecordSource, hub.RecordSource);
                Assert.Equal(LoadInfo1.LoadedBy, hub.LoadedBy);

                // SATELLITE - storing info
                Hub1Satellite1 = satelliteRepo.Insert(Hub1Satellite1, loadDate, loadInformation: LoadInfo1);

                var sat = satelliteRepo.GetCurrent(s => s.Reference == TestHub1.PrimaryKey).Single();

                Assert.Equal(LoadInfo1.RecordSource, sat.RecordSource);
                Assert.Equal(LoadInfo1.LoadedBy, sat.LoadedBy);

                // LINK - storing info
                Link1 = linkRepo.Insert(Link1, loadDate, loadInformation: LoadInfo1);

                var link = linkRepo.GetByKey(Link1.PrimaryKey);

                Assert.Equal(LoadInfo1.RecordSource, link.RecordSource);
                Assert.Equal(LoadInfo1.LoadedBy, link.LoadedBy);
            }
        }
        public void KeyCachingIsSharedByAllInstances()
        {
            using (var context = TestDwhDbContext.CreateDWHDbContext()) {
                var keyCache = new BasePrimaryKeyCache();
                var hubRepo  = new HubRepository <H_TestHub_Default>(context, HashFunctions.MD5, null);
                var linkRepo = new LinkRepository <L_TestLink_Default>(context, HashFunctions.MD5, keyCache, DVKeyCaching.Enabled);
                var loadDate = DateTime.Now;

                hubRepo.Insert(hubs, loadDate);

                //single insert
                var insertedLink = linkRepo.Insert(new L_TestLink_Default(hub1.PrimaryKey, hub2.PrimaryKey), loadDate);

                //new repository created -> cache is initialized from memory context
                // -> cache already kontains the key
                linkRepo = new LinkRepository <L_TestLink_Default>(context, HashFunctions.MD5, keyCache, DVKeyCaching.Enabled);

                // same key again -> insert prevented
                var insertedLink2 = linkRepo.Insert(new L_TestLink_Default(hub1.PrimaryKey, hub2.PrimaryKey), loadDate);

                var list = linkRepo.Get();
                Assert.NotNull(list);
                Assert.Single(list);
            }
        }
        public void TestQueriesAndInsert()
        {
            using (var context = TestDwhDbContext.CreateDWHDbContext()) {
                var referenceRepo = new CRUDRepository <LoadInformation, long>(context);

                var hubRepo       = new HubRepository <H_TestHub_References>(context, HashFunctions.MD5, null);
                var satelliteRepo = new SatelliteRepository <S_TestSatellite_References>(context, HashFunctions.MD5);
                var linkRepo      = new LinkRepository <L_TestLink_References>(context, HashFunctions.MD5, null, DVKeyCaching.Disabled);

                var loadDate = DateTime.Now;

                // REFERENCE ENTRY - inserting and data persistence tests
                var load1Key = referenceRepo.Insert(LoadInfo1);
                var load2Key = referenceRepo.Insert(LoadInfo2);

                var hubList = referenceRepo.Get();
                Assert.NotEmpty(hubList);
                Assert.Equal(2, hubList.Count());
                Assert.False(load1Key == default);
                Assert.False(load2Key == default);

                var loadInfo = referenceRepo.Get(x => x.PrimaryKey == load2Key).Single();

                Assert.Equal(LoadInfo2.RecordSource, loadInfo.RecordSource);
                Assert.Equal(LoadInfo2.LoadedBy, loadInfo.LoadedBy);

                // HUB - referencing
                TestHub1 = hubRepo.Insert(TestHub1, loadDate, loadReference: LoadInfo1);
                TestHub2 = hubRepo.Insert(TestHub2, loadDate, loadReference: LoadInfo2);
                Assert.Equal(load1Key, TestHub1.LoadReference);
                Assert.Equal(load2Key, TestHub2.LoadReference);

                // SATELLITE - referencing
                Hub1Satellite1 = satelliteRepo.Insert(Hub1Satellite1, loadDate, loadReference: LoadInfo1);
                Hub2Satellite1 = satelliteRepo.Insert(Hub2Satellite1, loadDate, loadReference: LoadInfo2);

                Assert.Equal(load1Key, Hub1Satellite1.LoadReference);
                Assert.Equal(load2Key, Hub2Satellite1.LoadReference);

                var satelliteList = satelliteRepo.GetCurrent();
                Assert.NotEmpty(satelliteList);
                Assert.Equal(2, satelliteList.Count());


                // LINK - referencing
                Link1 = linkRepo.Insert(Link1, loadDate, loadReference: LoadInfo1);

                Assert.Equal(load1Key, Link1.LoadReference);

                Link1 = linkRepo.Get().Single();
                Assert.Equal(load1Key, Link1.LoadReference);
            }
        }
        public void LinkKeyCaching()
        {
            //Caching enabled -> same key is ignored
            using (var context = TestDwhDbContext.CreateDWHDbContext()) {
                var keyCache = new BasePrimaryKeyCache();
                var hubRepo  = new HubRepository <H_TestHub_Default>(context, HashFunctions.MD5, null);
                var linkRepo = new LinkRepository <L_TestLink_Default>(context, HashFunctions.MD5, keyCache, DVKeyCaching.Enabled);
                var loadDate = DateTime.Now;

                hubRepo.Insert(hubs, loadDate);

                //single insert
                var insertedLink = linkRepo.Insert(new L_TestLink_Default(hub1.PrimaryKey, hub2.PrimaryKey), loadDate);
                // same key again
                var insertedLink2 = linkRepo.Insert(new L_TestLink_Default(hub1.PrimaryKey, hub2.PrimaryKey), loadDate);

                Assert.Equal(insertedLink.PrimaryKey, insertedLink2.PrimaryKey);

                var queriedLinks = linkRepo.Get();

                Assert.NotNull(queriedLinks);
                Assert.Single(queriedLinks);
            }

            //caching disabled -> insert throws exception
            using (var context = TestDwhDbContext.CreateDWHDbContext()) {
                var hubRepo  = new HubRepository <H_TestHub_Default>(context, HashFunctions.MD5, null);
                var linkRepo = new LinkRepository <L_TestLink_Default>(context, HashFunctions.MD5, null, DVKeyCaching.Disabled);
                var loadDate = DateTime.Now;

                hubRepo.Insert(hubs, loadDate);

                //single insert
                var insertedLink = linkRepo.Insert(new L_TestLink_Default(hub1.PrimaryKey, hub2.PrimaryKey), loadDate);
                // same key again
                Assert.Throws <InvalidOperationException>(() => linkRepo.Insert(new L_TestLink_Default(hub1.PrimaryKey, hub2.PrimaryKey), loadDate));
            }
        }
        public void KeyCalculation()
        {
            using (var context = TestDwhDbContext.CreateDWHDbContext()) {
                var keyCache = new BasePrimaryKeyCache();
                var hubRepo  = new HubRepository <H_TestHub_Default>(context, HashFunctions.MD5, null);
                var linkRepo = new LinkRepository <L_TestLink_Default>(context, HashFunctions.MD5, keyCache, DVKeyCaching.Enabled);
                var loadDate = DateTime.Now;

                hubRepo.Insert(hubs, loadDate);

                L_TestLink_Default link = new L_TestLink_Default(hub1.PrimaryKey, hub2.PrimaryKey);
                //single insert
                var insertedLink = linkRepo.Insert(link, loadDate);
                Assert.Equal(HashFunctions.MD5(link.GetBusinessKeyString()), insertedLink.PrimaryKey);
            }
        }
Beispiel #7
0
        private async void gridView1_RowUpdated(object sender, DevExpress.XtraGrid.Views.Base.RowObjectEventArgs e)
        {
            tblLink link = e.Row as tblLink;

            if (link == null)
            {
                return;
            }
            link.Type = UserManagement.UserSession.Type;
            if (link.Id > 0)
            {
                await rpLink.Update(link);
            }
            else
            {
                await rpLink.Insert(link);
            }
        }
Beispiel #8
0
 public ActionResult LinkFormPost()
 {
     try
     {
         CreateRepos();
         string url = Request["url"];
         LinkRepo.Insert(Request["url"], int.Parse(Session["UserId"].ToString()), Request["source"], Request["taget"], Request["name"], Request["summary"]);
         return(Redirect("/link"));
     }
     catch (Exception ex)
     {
         Console.Write(ex);
         return(Content("Xảy ra lỗi hệ thống ! Vui lòng thử lại."));
     }
     finally
     {
         DisposeRepos();
     }
 }
Beispiel #9
0
        public bool CreateDefaults()
        {
            bool aboutIsEmpty = AboutRepository.IsEmpty().GetAwaiter().GetResult();

            //aboutIsEmpty = false;
            if (aboutIsEmpty == false)
            {
                return(false);
            }
            if (aboutIsEmpty)
            {
                try
                {
                    var newAbout = new About
                    {
                        created_at = DateTime.Now,
                        updated_at = DateTime.Now,
                        photo      = $@"http://res.cloudinary.com/djqq6o8su/image/upload/mkvg51472rnjves4etg0",
                        title      = "Mr Photographer",
                        desc       = "Photographer based in Somewhere"
                    };
                    AboutRepository.Insert(newAbout);
                    SaveAsync().GetAwaiter().GetResult();
                }
                catch (Exception e)
                {
                    Console.WriteLine("{0} Exception caught.", e);
                }
            }
            bool galleryIsEmpty = GalleryRepository.IsEmpty().GetAwaiter().GetResult();

            //galleryIsEmpty = false;
            if (galleryIsEmpty)
            {
                try
                {
                    string[] names = new string[] { "People", "Landscape" };
                    foreach (var name in names)
                    {
                        var newItem = new Gallery
                        {
                            created_at = DateTime.Now,
                            updated_at = DateTime.Now,
                            name       = name
                        };
                        GalleryRepository.Insert(newItem);
                    }
                    SaveAsync().GetAwaiter().GetResult();
                }
                catch (Exception e)
                {
                    Console.WriteLine("{0} Exception caught.", e);
                }
            }
            bool linkIsEmpty = LinkRepository.IsEmpty().GetAwaiter().GetResult();

            //linkIsEmpty = false;
            if (linkIsEmpty)
            {
                try
                {
                    string[] names = new string[] { "yourfacebookname", "yourinsntagramname", "yourtwittername", "youryourtubename" };
                    foreach (var name in names)
                    {
                        var newItem = new Link
                        {
                            created_at = DateTime.Now,
                            updated_at = DateTime.Now,
                            name       = name
                        };
                        LinkRepository.Insert(newItem);
                    }
                    SaveAsync().GetAwaiter().GetResult();
                }
                catch (Exception e)
                {
                    Console.WriteLine("{0} Exception caught.", e);
                }
            }
            bool logoIsEmpty = LogoRepository.IsEmpty().GetAwaiter().GetResult();

            //logoIsEmpty = false;
            if (logoIsEmpty)
            {
                try
                {
                    string[] photos = new string[] { "http://res.cloudinary.com/djqq6o8su/image/upload/iwrwnlkuxlbypgdn05kp" };
                    foreach (var photo in photos)
                    {
                        var newItem = new Logo
                        {
                            created_at = DateTime.Now,
                            updated_at = DateTime.Now,
                            photo      = photo
                        };
                        LogoRepository.Insert(newItem);
                    }
                    SaveAsync().GetAwaiter().GetResult();
                }
                catch (Exception e)
                {
                    Console.WriteLine("{0} Exception caught.", e);
                }
            }
            bool slideIsEmpty = SlideRepository.IsEmpty().GetAwaiter().GetResult();

            //slideIsEmpty = false;
            if (slideIsEmpty)
            {
                try
                {
                    string[] names = new string[]
                    {
                        "http://res.cloudinary.com/djqq6o8su/image/upload/rrcbpzjxm5mesjptu9lc",
                        "http://res.cloudinary.com/djqq6o8su/image/upload/iib9veyowj3wpyirbmlo",
                        "http://res.cloudinary.com/djqq6o8su/image/upload/qgo6zbmwwd0kyanaoynz"
                    };
                    foreach (var name in names)
                    {
                        var newItem = new Slide
                        {
                            created_at = DateTime.Now,
                            updated_at = DateTime.Now,
                            name       = name
                        };
                        SlideRepository.Insert(newItem);
                    }
                    SaveAsync().GetAwaiter().GetResult();
                }
                catch (Exception e)
                {
                    Console.WriteLine("{0} Exception caught.", e);
                }
            }
            bool photoIsEmpty = PhotoRepository.IsEmpty().GetAwaiter().GetResult();

            //photoIsEmpty = false;
            if (photoIsEmpty)
            {
                try
                {
                    string[] names = new string[]
                    {
                        "http://res.cloudinary.com/djqq6o8su/image/upload/tub2v7olse0lwbq9vzrv",
                        "http://res.cloudinary.com/djqq6o8su/image/upload/hvxogea37wkzqv5o6kkv",
                        "http://res.cloudinary.com/djqq6o8su/image/upload/dp62d2vwochkoy2y82ee",
                        "http://res.cloudinary.com/djqq6o8su/image/upload/lifml3ceohhebylxgue6",
                        "http://res.cloudinary.com/djqq6o8su/image/upload/ki6pdlhihsvaakimfnml",
                        "http://res.cloudinary.com/djqq6o8su/image/upload/itwquw92jfpht6yi1ilk",
                        "http://res.cloudinary.com/djqq6o8su/image/upload/jplpld8tp4bxvskdpdzr"
                    };
                    string[] names2 = new string[]
                    {
                        "http://res.cloudinary.com/djqq6o8su/image/upload/vp8ahga7g1h8f6zx2d0x",
                        "http://res.cloudinary.com/djqq6o8su/image/upload/ozljewvxh83ahvob1aml",
                        "http://res.cloudinary.com/djqq6o8su/image/upload/tgrcyaoqx8jwi7mksakd",
                        "http://res.cloudinary.com/djqq6o8su/image/upload/nnsii3wvw6gn40qcldwf",
                        "http://res.cloudinary.com/djqq6o8su/image/upload/e23tgxmvw8jkeje3apjk",
                        "http://res.cloudinary.com/djqq6o8su/image/upload/tb0rpo4gvhxv0cyyb31z",
                        "http://res.cloudinary.com/djqq6o8su/image/upload/k90gojfb903m7hoknvs5",
                        "http://res.cloudinary.com/djqq6o8su/image/upload/yqmqqvltyfgt6wbza9zg",
                        "http://res.cloudinary.com/djqq6o8su/image/upload/vrlwiz6u8gcrygbruzw3",
                        "http://res.cloudinary.com/djqq6o8su/image/upload/xapqjqz9vs5kwhqh0cr5"
                    };
                    var galleryPeople    = GalleryRepository.GetAsync(item => item.name == "People").GetAwaiter().GetResult().FirstOrDefault();
                    var galleryLandscape = GalleryRepository.GetAsync(item => item.name == "Landscape").GetAwaiter().GetResult().FirstOrDefault();
                    foreach (var name in names)
                    {
                        var newItem = new Photo
                        {
                            created_at = DateTime.Now,
                            updated_at = DateTime.Now,
                            name       = name,
                            Gallery    = galleryPeople
                        };
                        PhotoRepository.Insert(newItem);
                    }
                    foreach (var name in names2)
                    {
                        var newItem = new Photo
                        {
                            created_at = DateTime.Now,
                            updated_at = DateTime.Now,
                            name       = name,
                            Gallery    = galleryLandscape
                        };
                        PhotoRepository.Insert(newItem);
                    }
                    SaveAsync().GetAwaiter().GetResult();
                }
                catch (Exception e)
                {
                    Console.WriteLine("{0} Exception caught.", e);
                }
            }

            bool userIsEmpty = UserManager.Users.Count() == 0;

            if (userIsEmpty)
            {
                //var user = new ApplicationUser
                //{
                //    ApiToken = "some",
                //    UserName = "******",
                //    Email = "*****@*****.**",
                //    EmailConfirmed = true,
                //    DateAdd = DateTime.Now,
                //    DateUpd = DateTime.Now
                //};
                //await UserManager.CreateAsync(user, "admin");
                ApplicationDbInitializer.SeedRoles(RoleManager);
                ApplicationDbInitializer.SeedUsers(UserManager, appSettings);
                //await SaveAsync();
                //new SignInManager<User>().SignInAsync
                //UserManager.Users.ToList().ForEach( async(user)=> {
                //    await _userManager.DeleteAsync(user);
                //});
            }

            if (aboutIsEmpty || galleryIsEmpty || linkIsEmpty || logoIsEmpty || photoIsEmpty || slideIsEmpty || userIsEmpty)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }