コード例 #1
0
        public async Task <IHttpActionResult> Get(string name)
        {
            if (String.IsNullOrWhiteSpace(name))
            {
                return(BadRequest("Missing name argument"));
            }

            //var cached = Cache.GetItem(name);
            //if (cached != null) { return Ok(cached); }

            //var rateLimit = await TwitterApiManager.GetRateLimit();
            //if (rateLimit != null && rateLimit.Content != null && rateLimit.Content.Remaining == 0)
            //{
            //    return Content((HttpStatusCode)429, rateLimit);
            //}


            NameCheckModel model = null;

            try
            {
                model = await Provider.NameCheckAsync(name, EndpointType.Api, Request.GetClientIpAddress());

                await DataService.SaveAsync(model);
            }
            catch
            {
                // TODO : Log it
                return(InternalServerError());
            }
            return(Ok(model));
        }
コード例 #2
0
        public async Task <ActionResult> Index(NameCheckViewModel viewModel)
        {
            if (viewModel == null)
            {
                return(RedirectToAction("index"));
            }

            viewModel.History = ReadOrCreateSessionItem <List <NameCheckModel> >(Constants.SessionKeys.NameCheckHistory);

            if (ModelState.IsValid)
            {
                NameCheckModel model = await Provider.NameCheckAsync(viewModel.Name, EndpointType.Website, Request.UserHostAddress);

                await NameCheckDataService.SaveAsync(model);

                viewModel.History.Add(model);
                SaveOrCreateSessionItem(Constants.SessionKeys.NameCheckHistory, viewModel.History);
                viewModel.Name = null;
                ModelState.Clear();
            }

            return(View(viewModel));
        }
コード例 #3
0
        public async Task <NameCheckModel> NameCheckAsync(string name, EndpointType endpointType = EndpointType.NotSet, string userIp = null)
        {
            Guard.ArgumentNotNullOrWhiteSpace(name, "name");
            Stopwatch timer = new Stopwatch();

            timer.Start();

            var key    = NameCheckHelper.FormatKey(name);
            var result = Cache.GetItem(key);

            if (result != null)
            {
                return(result);
            }

            result              = new NameCheckModel();
            result.Id           = DescendingSortedGuid.NewSortedGuid();
            result.Key          = key;
            result.DateUtc      = DateTime.UtcNow;
            result.EndpointType = endpointType;
            result.Name         = NameCheckHelper.FormatName(name);
            result.Query        = NameCheckHelper.FormatQuery(name);
            result.UserIp       = userIp;

            var twitterResult = await TwitterApiManager.IsNameAvailable(result.Query);

            var gandiResult = GandiApiManager.CheckDomains(result.Query, new string[] { "com", "net", "org" });

            result.SocialNetworks = new Dictionary <string, bool>();
            result.SocialNetworks.Add("twitter", twitterResult.Content);
            result.Domains = gandiResult;

            timer.Stop();
            result.QueryDurationMs = timer.ElapsedMilliseconds;
            Cache.AddItem(key, result);
            return(result);
        }