Esempio n. 1
0
        private async Task SetCacheAsync(string key, Model.IdAndLink idAndLink)
        {
            _logger.LogTrace("Setting cache for {CacheKey}: {Id}, {Link}",
                             key,
                             idAndLink.Id,
                             idAndLink.Link);

            using (var memoryStream = new MemoryStream())
            {
                new BinaryFormatter().Serialize(memoryStream, idAndLink);
                await _cache.SetAsync(key, memoryStream.ToArray(), new DistributedCacheEntryOptions
                {
                    SlidingExpiration = TimeSpan.FromMinutes(360)
                });
            }
        }
Esempio n. 2
0
        private async Task <string> GetRedirectAsync(string domainName,
                                                     string stub)
        {
            string domainNameText = domainName?.Trim();
            string stubText       = stub?.Trim();

            Model.IdAndLink recordIdLink = null;
            Model.IdAndLink groupIdLink  = null;

            if (!string.IsNullOrEmpty(stubText))
            {
                if (!string.IsNullOrEmpty(domainNameText))
                {
                    // domain and stub provided, check group + stub
                    recordIdLink = await _lookup.GetGroupStubAsync(domainNameText, stubText);
                }

                // no match for group + stub or stub provided with no domain
                if (recordIdLink == null)
                {
                    // check for stub independent of domain/group
                    recordIdLink = await _lookup.GetStubNoGroupAsync(stubText);
                }
            }

            if (recordIdLink == null && !string.IsNullOrEmpty(domainNameText))
            {
                // domain provided, no stub or stub not found; check group default
                groupIdLink = await _lookup.GetGroupDefaultAsync(domainNameText);
            }

            string destination;

            if (recordIdLink == null)
            {
                if (groupIdLink == null)
                {
                    groupIdLink = await _lookup.GetSystemDefault();

                    if (groupIdLink != null)
                    {
                        _logger.LogInformation("Group not found for domain {DomainNameText}, using default group: {GroupLink}",
                                               domainNameText, groupIdLink?.Link);
                    }
                }

                if (groupIdLink == null)
                {
                    destination = _config[Program.ConfigurationDefaultLink];
                    _logger.LogInformation("No default URL configured in the database, defaulting to {Destination} from configuration",
                                           destination);
                }
                else
                {
                    if (!string.IsNullOrEmpty(stubText) &&
                        !MuteStubs.Contains(stubText) &&
                        !stubText.EndsWith(MuteExtension))
                    {
                        _logger.LogWarning("Unable to fulfill domain {DomainNameText}, stub {StubText}, sending to {Link}",
                                           domainNameText,
                                           stubText,
                                           groupIdLink.Link);
                    }
                    destination = groupIdLink.Link;
                    await _update.UpdateGroupVisitAsync((int)groupIdLink.Id);
                }
            }
            else
            {
                destination = recordIdLink.Link;
                await _update.UpdateRecordVisitAsync((int)recordIdLink.Id);
            }

            return(destination);
        }