Esempio n. 1
0
        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);
            }
        }
Esempio n. 2
0
 public void OnGet(int id)
 {
     if (id > 0)
     {
         LinkRepository lRepository = new LinkRepository(connectionString);
         Link = lRepository.Get(id);
     }
 }
        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 OnGet(Guid id)
 {
     if (id != null)
     {
         LinkRepository linkRepository = new LinkRepository(connectionString);
         Link = linkRepository.Get(id);
         if (Link != null)
         {
             FileRepository fileRepository = new FileRepository(connectionString);
             File = fileRepository.Get(Link.FileId);
         }
     }
 }
Esempio n. 5
0
 public IActionResult OnPostSave(int id, string email)
 {
     if (id > 0)
     {
         LinkRepository lRepository = new LinkRepository(connectionString);
         Link       = lRepository.Get(id);
         Link.Email = email;
         lRepository.Update(Link);
         if (!String.IsNullOrEmpty(email))
         {
             EmailServices eServices = new EmailServices();
             eServices.SendLink(email, $"{Request.Scheme}://{this.Request.Host}{this.Request.PathBase}/{Link.Url}");
         }
         return(RedirectToPage("Index", new { Id = Link.FileId }));
     }
     return(RedirectToPage("/Error"));
 }
        public IActionResult OnPost(Guid id)
        {
            if (id != null)
            {
                LinkRepository linkRepository = new LinkRepository(connectionString);
                Link = linkRepository.Get(id);
                if (Link != null)
                {
                    FileRepository fileRepository = new FileRepository(connectionString);
                    File = fileRepository.Get(Link.FileId);
                    string filePath = env.WebRootPath + File.Path + @"/" + File.Name;
                    string fileName = File.Name;

                    byte[] fileBytes = System.IO.File.ReadAllBytes(filePath);

                    Link.Count++;
                    linkRepository.Update(Link);
                    return(File(fileBytes, "application/force-download", fileName));
                }
            }
            return(NotFound());
        }
Esempio n. 7
0
 public Link GenerateNewLink(LinkRepository lRepository, int fileId)
 {
     if (lRepository != null)
     {
         Link l = new Link();
         l.FileId   = fileId;
         l.Email    = "";
         l.Count    = 0;
         l.PublicId = Guid.NewGuid();
         while (lRepository.Get(l.PublicId) != null)
         {
             l.PublicId = Guid.NewGuid();
         }
         l.Url = "/Files/Download/" + l.PublicId;
         l.Id  = lRepository.Add(l);
         return(l);
     }
     else
     {
         return(null);
     }
 }
Esempio n. 8
0
        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));
            }
        }
Esempio n. 9
0
        public async Task <IActionResult> Get(Guid id)
        {
            var result = await linkRepository.Get(id);

            return(result.HasValue ? (IActionResult)Ok(result.Value) : NotFound());
        }
Esempio n. 10
0
 public LinkDTO Get(int linkId)
 {
     return(repo.Get(linkId));
 }