Пример #1
0
        internal List <AnalyticsData> GetVistorsForSite(string website, VistorsFilterType filterType, DateTime?fromDate, DateTime?toDate)
        {
            try
            {
                Initialize();

                MySqlCommand command = new MySqlCommand(MySQLStoredProcedures.GetVisitorByDay, _connection);
                command.CommandType = CommandType.StoredProcedure;

                command.Parameters.AddWithValue("?customer_id", website);
                command.Parameters.AddWithValue("?from_date", fromDate);
                command.Parameters.AddWithValue("?to_date", toDate);

                switch (filterType)
                {
                case VistorsFilterType.CITY:
                    command.CommandText = MySQLStoredProcedures.GetVisitorsByCity;
                    return(GetVisitorsByCity(command));

                case VistorsFilterType.COUNTRY:
                    command.CommandText = MySQLStoredProcedures.GetVisitorsByCountry;
                    return(GetVisitorsByCountry(command));

                case VistorsFilterType.DAY:
                    command.CommandText = MySQLStoredProcedures.GetVisitorByDay;
                    return(GetVisitorsByDay(command));

                case VistorsFilterType.HOUR:
                    command.CommandText = MySQLStoredProcedures.GetVisitorByHour;
                    return(GetVisitorsByHour(command));

                default:
                    return(null);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                CleanUp(_connection);
            }
        }
        public IActionResult GetVisitors([FromRoute] VistorsFilterType filterType, [FromQuery] string website, [FromQuery] DateTime?fromDate, [FromQuery] DateTime?toDate)
        {
            try
            {
                #region Auth request
                if (Request.Headers.TryGetValue("Authorization", out StringValues headerValues))
                {
                    // TODO: Validate if valid auth header
                    headerValues.FirstOrDefault();
                }
                else
                {
                    return(BadRequest("Not Authorized"));
                }
                #endregion

                if (String.IsNullOrEmpty(website))
                {
                    return(BadRequest("Param website invalid"));
                }

                if (fromDate == null)
                {
                    fromDate = Kitsune.API2.EnvConstants.Constants.epoch;
                }

                if (toDate == null)
                {
                    toDate = DateTime.UtcNow;
                }

                website = website.Trim().ToLower();

                return(Json(new MySQLConnector().GetVistorsForSite(website, filterType, fromDate, toDate)));
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }
        public IActionResult GetVisitors(VistorsFilterType filterType, DateTime fromDate, DateTime toDate)
        {
            try
            {
                var authId  = User.Claims.FirstOrDefault(x => x.Type == "UserAuthId")?.Value;
                var website = User.Claims.FirstOrDefault(x => x.Type == "CustomerId")?.Value;

                var request = (HttpWebRequest)WebRequest.Create(new Uri(string.Format(Constants.AnalyticsEndpoints.GetVisitorsEndpoint, Constants.KitsuneServerUrl, Convert.ToInt32(filterType), website, fromDate.ToString("yyyy-MM-dd"), toDate.ToString("yyyy-MM-dd"))));
                request.Method      = "GET";
                request.ContentType = "application/json";
                request.Headers.Add(HttpRequestHeader.Authorization, authId);

                var ws       = request.GetResponse();
                var sr       = new StreamReader(ws.GetResponseStream());
                var response = sr.ReadToEnd().ToString();
                return(new JsonResult(response));
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.ToString()));
            }
        }