public StatusInfo GetStatusInfo() { StatusInfo info = new StatusInfo(); info.All = new StatsBaseItem(All.All.GetData()); foreach (var item in Items) { UrlStats urlStats = new UrlStats(); urlStats.ID = item.RequestSetting.ID; urlStats.Url = item.RequestSetting.BaseUrl; urlStats.Method = item.RequestSetting.Method; urlStats.Remark = item.RequestSetting.Remark; urlStats.All = new StatsBaseItem(item.Statistics.All.GetData()).PercentWith(info.All.value); urlStats.Codes.Add(new StatsBaseItem(item.Statistics.Status_2xx.GetData(), 1) .PercentWith(urlStats.All.value).AddItems(item.Statistics.GetRegion(200, 300))); urlStats.Codes.Add(new StatsBaseItem(item.Statistics.Status_4xx.GetData(), 3) .PercentWith(urlStats.All.value).AddItems(item.Statistics.GetRegion(400, 500))); urlStats.Codes.Add(new StatsBaseItem(item.Statistics.Status_5xx.GetData(), 4) .PercentWith(urlStats.All.value).AddItems(item.Statistics.GetRegion(500, 600))); foreach (var t in item.Statistics.All.GetData().GetTimeCountStats()) { urlStats.Latency.Add(new StatsBaseItem(t).PercentWith(urlStats.All.value)); } info.Urls.Add(urlStats); } info.Progress = this.Progress; info.Status = this.Status.ToString(); info._1xx = new StatsBaseItem(All.Status_1xx.GetData(), 0); info._2xx = new StatsBaseItem(All.Status_2xx.GetData(), 1); info._3xx = new StatsBaseItem(All.Status_3xx.GetData(), 2); info._4xx = new StatsBaseItem(All.Status_4xx.GetData(), 3); info._5xx = new StatsBaseItem(All.Status_5xx.GetData(), 4); foreach (var item in All.All.GetData().GetTimeCountStats()) { if (item.Count > 0) { info.Latency.Add(new StatsBaseItem(item)); } } return(info); }
public IActionResult GetUrlStats(string ShortURL) { if (string.IsNullOrEmpty(ShortURL)) { return(StatusCode(400)); } string[] splitUrl = ShortURL.Split('/'); string shortenedID = splitUrl[splitUrl.Length - 1]; try { URL url = _urlContext.UrlSet.Single(x => x.ShortenedIdentifier == shortenedID); //Creating the object to return to the user var returnObject = new UrlStats { baseUrl = _urlService.ReturnBaseUrl(_urlContext, shortenedID), shortenedUrl = ShortURL, useCount = _urlService.GetUrlTotalUses(_urlContext, url), countries = _urlService.GetUrlCountries(_urlContext, url), lastTimeAccessed = _urlService.GetLastAccessTime(_urlContext, url), lastCountryAccessed = _urlService.GetLastCountryAccessed(_urlContext, url), }; string returnData = JsonConvert.SerializeObject(returnObject); return(Ok(returnData)); } catch (NullReferenceException) { return(StatusCode(400)); } catch (InvalidOperationException) { return(StatusCode(404)); } }