예제 #1
0
        public async Task <DomainTrackingUrl> AddAsync(DomainTrackingUrl trackingUrl)
        {
            // Get subscription
            CompanySubscription subscription = await _subscriptionService.GetAsync(trackingUrl.SubscriptionId);

            // Check redirect url
            if (trackingUrl.RedirectUrl == null)
            {
                throw new ArgumentException("RedirectUrl required");
            }

            if (!string.Equals(trackingUrl.RedirectUrl.Host, subscription.SiteHostname, StringComparison.InvariantCultureIgnoreCase))
            {
                throw new BadRequestException(
                          string.Format("Client subscription {0} allows only URLs starting with {1}: {2}",
                                        subscription.Id, subscription.SiteHostname, trackingUrl.RedirectUrl));
            }

            // Add tracking url
            TrackingUrlEntity entity = _mappingEngine.Map <DomainTrackingUrl, TrackingUrlEntity>(trackingUrl);

            entity = await _trackingUrlRepository.AddAsync(entity);

            DomainTrackingUrl result = _mappingEngine.Map <TrackingUrlEntity, DomainTrackingUrl>(entity);

            result.Key = _urlShortenerService.Encode(Int64.Parse(result.Id));

            return(result);
        }
예제 #2
0
        public void Run(string[] args)
        {
            if (args is null)
            {
                throw new ArgumentNullException();
            }

            else if (args.Length != 1)
            {
                throw new ArgumentException("The number of arguments must be only one");
            }

            if (!int.TryParse(args[0], out int urlId))
            {
                Console.WriteLine("Attempted conversion of '{0}' failed.",
                                  args[0] ?? "<null>");
            }
            var encodedUrl = _urlShortenerService.Encode(urlId);

            Console.WriteLine($"Encoded URL: {encodedUrl}");
            var decodedUrl = _urlShortenerService.Decode(encodedUrl);

            Console.WriteLine($"Decoded URL : {decodedUrl}");
        }