コード例 #1
0
        public async Task InitializeAsync()
        {
            var filePath = Path.Combine(AppContext.BaseDirectory, DataConstants.DAT_FILE_PATH);

            await using var stream = _readerService.Read(filePath);

            DatInfo = new DatInfo(stream, 1);
            var records = DatInfo.Records;

            var ipIntervalsInformations = new IUserIp[records];
            var coordinateInformations  = new IUserLocation[records];

            for (var index = 0; index < records; index++)
            {
                ipIntervalsInformations[index] = new UserIp(stream, index + 1);
            }

            for (var index = 0; index < records; index++)
            {
                coordinateInformations[index] = new UserLocation(stream, index + 1);
            }

            UserIps       = new ConcurrentQueue <IUserIp>(ipIntervalsInformations);
            UserLocations = new ConcurrentQueue <IUserLocation>(coordinateInformations);
        }
コード例 #2
0
        public async Task <string> CreateShortUrlForIp(string userIp, string url)
        {
            var isExistUserIp = await ShortenURlDbContext.UserIp.FirstOrDefaultAsync(c => c.Ip == userIp);

            var shortUrl    = createShortUrlService.MakeShortURL();
            var newShortUrl = new ShortUrl()
            {
                ShortUrlString = shortUrl,
                Url            = url
            };

            if (isExistUserIp != null)
            {
                isExistUserIp.ShortUrls.Add(newShortUrl);
                await ShortenURlDbContext.SaveChangesAsync();
            }
            else
            {
                var newUserIp = new UserIp()
                {
                    Ip = userIp,
                };
                newUserIp.ShortUrls.Add(newShortUrl);
                ShortenURlDbContext.UserIp.Add(newUserIp);
                await ShortenURlDbContext.SaveChangesAsync();
            }
            return(shortUrl);
        }
 public void AddUserIp(UserIp userIp)
 {
     _dbContext.UserIps.Add(userIp);
     _dbContext.SaveChanges();
 }