Ejemplo n.º 1
0
        public IActionResult VisitDetails(int?id)
        {
            // Check valid login:
            if (HttpContext.Session.GetString("UserID") != null)
            {
                try
                {
                    VisitorStats visit = _db.VsVisitors
                                         .Join(_db.VsVisits,
                                               v1 => v1.Id,
                                               v2 => v2.VisitorId,
                                               (v1, v2) => new VisitorStats()
                    {
                        VisitID    = v2.Id,
                        IPAddress  = v1.Ipaddress,
                        VisitTime  = v2.VisitTime,
                        VisitURL   = v2.VisitUrl,
                        RefererURL = v2.RefererUrl,
                        HostName   = v1.HostName,
                        Agent      = v1.Agent
                    })
                                         .Where(v => v.VisitID.Equals(id))
                                         .FirstOrDefault();

                    return(View(visit));
                }
                catch (Exception e)
                {
                    Console.Write(e.Message);
                }

                return(View());
            }
            return(RedirectToAction("Login", "Home"));
        }
Ejemplo n.º 2
0
    public virtual void NPCEnters(Passanger passanger)
    {
        guestInShop = true;
        VisitorStats visitor = VisitorStats(passanger);

        FC.AddShopIncome(visitor.type, visitor.earningGain);
        //FC.UpdateMonthlyRevenue(visitor.earningGain);
        OnSatisfactionGain(visitor.satisfactionGain);
    }
Ejemplo n.º 3
0
    public virtual bool GainCustomer(Passanger pPassanger)
    {
        if (!HasRessources())
        {
            return(false);
        }

        VisitorStats visitor = VisitorStats(pPassanger);

        if (visitor.curAmount < visitor.maxCapacity)
        {
            UseRessources(ResourcesUsedPerCustomer);
            ++visitor.curAmount;
            ++totalGuestCount;
            return(true);
        }
        else
        {
            return(false);
        }
    }
        /// <summary>
        /// This method is called on every new HTTP request to check whether the requested URL matches
        /// a registered application URL. If so, visitor statistics will be saved for this URL.
        /// </summary>
        /// <param name="context"></param>
        /// <param name="handler"></param>
        /// <returns></returns>
        public async Task InvokeAsync(HttpContext context, [FromServices] IVisitorHandler handler)
        {
            string requestedWith = context.Request.Headers["X-Requested-With"];
            string ajaxRequest   = "XMLHttpRequest";

            if (handler.IsRegisteredUrl() && requestedWith != ajaxRequest)
            {
                string   deletionDays = Convert.ToInt32(_config["IpDeletionDays:Days"]) < 1 ? "1" : _config["IpDeletionDays:Days"];
                DateTime deletionDate = DateTime.Now.AddDays(Convert.ToDouble(deletionDays));

                string visitorIP = context.Connection.RemoteIpAddress.ToString();
                var    hostEntry = Dns.GetHostEntry(visitorIP);
                string hostName  = hostEntry.HostName;

                foreach (string url in handler.GetAppUrls(out int appID))
                {
                    if (context.Request.GetDisplayUrl().Equals(url))
                    {
                        VisitorStats item = new VisitorStats
                        {
                            VisitTime    = DateTime.Now,
                            VisitURL     = context.Request.GetDisplayUrl(),
                            RefererURL   = context.Request.Headers["Referer"].ToString(),
                            IPAddress    = visitorIP,
                            HostName     = hostName,
                            Agent        = context.Request.Headers["User-Agent"].ToString(),
                            DeletionDate = deletionDate,
                            AppID        = appID
                        };

                        handler.SaveVisitorStats(item);
                    }
                }
            }

            // Call the next middleware delegate in the pipeline:
            await _next.Invoke(context);
        }
        /// <summary>
        /// Save the visitor statistics passed from the middleware to the DB.
        /// </summary>
        /// <param name="input"></param>
        public void SaveVisitorStats(VisitorStats input)
        {
            try
            {
                VsVisitor visitor = new VsVisitor()
                {
                    Ipaddress  = input.IPAddress,
                    HostName   = input.HostName,
                    Agent      = input.Agent,
                    DeleteDate = input.DeletionDate,
                    AppId      = input.AppID
                };

                // Check if visitor (IP) is to be inserted or updated to DB:
                if (!_db.VsVisitors.Where(i => i.Ipaddress.Equals(input.IPAddress)).Any())
                {
                    _db.VsVisitors.Add(visitor);
                    _db.SaveChanges();
                }
                else
                {
                    visitor          = _db.VsVisitors.Where(v => v.Ipaddress.Equals(input.IPAddress)).Select(v => v).FirstOrDefault();
                    visitor.HostName = input.HostName;
                    visitor.Agent    = input.Agent;

                    _db.VsVisitors.Update(visitor);
                    _db.SaveChanges();
                }

                // Now ensure the visitor ID (to be used as reference key for visit entity) exists in DB:
                int visitorID = _db.VsVisitors.Where(i => i.Ipaddress.Equals(input.IPAddress)).Select(v => v.Id).First();

                if (visitorID > 0)
                {
                    VsVisit visit = new VsVisit
                    {
                        VisitorId  = visitorID,
                        RefererUrl = input.RefererURL,
                        VisitUrl   = input.VisitURL,
                        VisitTime  = input.VisitTime
                    };

                    _db.VsVisits.Add(visit);
                    _db.SaveChanges();

                    // Handle storage of admin visit:
                    if (_context.HttpContext.Session.GetString("AdminIP") != null)
                    {
                        if (_context.HttpContext.Session.GetString("AdminIP").Equals(input.IPAddress))
                        {
                            VsAdminVisit adminVisit = new VsAdminVisit()
                            {
                                // If admin IP session is set, then so is the user ID session (via HomeController > Login):
                                AdminId = Convert.ToInt32(_context.HttpContext.Session.GetString("UserID")),
                                VisitId = visit.Id
                            };

                            _db.VsAdminVisits.Add(adminVisit);
                            _db.SaveChanges();
                        }
                    }
                }
            }
            catch (Exception e)
            {
                Console.Write(e.Message);
            }
        }