Beispiel #1
0
        public async Task AddAsync(StatDbModel statDbModel)
        {
            var date = statDbModel.CreateDate.Date.AddHours(4);

            if (string.IsNullOrEmpty(statDbModel.Id))
            {
                statDbModel.Id = Guid.NewGuid().ToString();
            }

            var update = Builders <StatsDbModel> .Update
                         .Push("Stats", statDbModel);

            var builder = Builders <StatsDbModel> .Filter;
            var filter  = builder.Eq(x => x.SiteId, statDbModel.SiteId) & builder.Eq(x => x.Date, date);
            await _Collection.UpdateOneAsync(filter, update, new UpdateOptions { IsUpsert = true });
        }
Beispiel #2
0
        protected override async Task ActionAsync()
        {
            var client = Input.Client;

            if (!string.IsNullOrEmpty(client.Url) && client.Url.ToLower().Contains("://localhost"))
            {
                return;
            }

            /* if (!string.IsNullOrEmpty(Input.UserAgent) &&
             *   (Input.UserAgent.Contains("bworld") || Input.UserAgent.Contains("seo user-agent")))
             * {
             *   return;
             * }*/

            var statDbModel = new StatDbModel();

            statDbModel.SiteId      = client.SiteId;
            statDbModel.PageName    = client.Name;
            statDbModel.PageParam   = client.Action;
            statDbModel.Url         = UrlHelper.RemoveLastSeparator(client.Url);
            statDbModel.Ip          = Input.IpAdress;
            statDbModel.UserId      = Input.UserId;
            statDbModel.UniversType = Input.Client.Type;
            //var createdDate = DateTime.Now;
            statDbModel.CreateDate = DateTime.Now;
            // new DateTime(createdDate.Year, createdDate.Month, createdDate.Day, createdDate.Hour, createdDate.Minute, createdDate.Second, DateTimeKind.Utc);
            if (string.IsNullOrEmpty(client.ClientSessionId))
            {
                statDbModel.ClientSessionId     = Guid.NewGuid().ToString();
                statDbModel.IsNewClientSesssion = true;
                if (!string.IsNullOrEmpty(client.Referrer))
                {
                    statDbModel.Referrer = UrlHelper.RemoveLastSeparator(client.Referrer);
                }
                statDbModel.UserAgent  = Input.UserAgent;
                statDbModel.TypeDevice = GetDeviceType(Input.UserAgent);
                var data = await _geocodingService.ReverseFromIpAsync(Input.IpAdress);

                if (data != null)
                {
                    var geoDbModel = new GeoDbModel();
                    geoDbModel.As          = data.As;
                    geoDbModel.City        = StringHelper.FirstLetterToUpper(data.City);
                    geoDbModel.Country     = StringHelper.FirstLetterToUpper(data.Country);
                    geoDbModel.CountryCode = data.CountryCode;
                    geoDbModel.Isp         = data.Isp;
                    geoDbModel.Lat         = data.Lat;
                    geoDbModel.Lon         = data.Lon;
                    geoDbModel.Org         = data.Org;
                    geoDbModel.Query       = data.Query;
                    geoDbModel.Region      = data.Region;
                    geoDbModel.RegionName  = StringHelper.FirstLetterToUpper(data.RegionName);
                    geoDbModel.Status      = data.Status;
                    geoDbModel.Timezone    = data.Timezone;
                    geoDbModel.Zip         = data.Zip;

                    statDbModel.Geo = geoDbModel;
                }
            }
            else
            {
                statDbModel.ClientSessionId = client.ClientSessionId;
            }

            if (string.IsNullOrEmpty(client.CookieSessionId))
            {
                statDbModel.CookieSessionId     = Guid.NewGuid().ToString();
                statDbModel.IsNewCookieSesssion = true;
            }
            else
            {
                statDbModel.CookieSessionId = client.CookieSessionId;
            }

            await _statService.AddAsync(statDbModel);

            Result.Data = new SaveStatsResults();

            Result.Data.ClientSessionId = statDbModel.ClientSessionId;
            Result.Data.CookieSessionId = statDbModel.CookieSessionId;
        }