Beispiel #1
0
        public override void RunAction(Message incomingChatMessage, Room chatRoom)
        {
            using (var db = new DatabaseContext())
            {
                var reviewItemId = GetRegexMatchingObject()
                                   .Match(incomingChatMessage.Content)
                                   .Groups[1]
                                   .Value
                                   .Parse <int>();

                var reviewerId = GetRegexMatchingObject()
                                 .Match(incomingChatMessage.Content)
                                 .Groups[2]
                                 .Value
                                 .Parse <int>();

                if (!ChatExchangeDotNet.User.Exists(chatRoom.Meta, reviewerId))
                {
                    chatRoom.PostReplyOrThrow(incomingChatMessage, "Sorry, I couldn't find a user with that ID.");
                    return;
                }

                db.EnsureUserExists(reviewerId);

                var parsedReviewItem = UserTracking.GetUserReviewedItem(reviewItemId, reviewerId);

                db.ReviewedItems.Add(parsedReviewItem);
                db.SaveChanges();

                chatRoom.PostReplyOrThrow(incomingChatMessage, "Review entered.");
            }
        }
Beispiel #2
0
        static void Main(string[] args)
        {
            WriteToConsole("Starting program");

            // dispose our RoomManager
            using (mng = new RoomManager())
            {
                mng.ShutdownOrderGiven            += mng_ShutdownOrderGiven;
                mng.InformationMessageBroadcasted += mng_InformationMessageBroadcasted;

                WriteToConsole("Joining room");
                mng.JoinRoom();

                InitializeDatbase();

                WriteToConsole("Connecting chat event listeners");
                mng.ConnectEventDelegates();

                WriteToConsole("Starting user tracker");
                var rm = mng.CvChatRoom;
                using (watcher = new UserTracking(ref rm))
                {
                    mng.PostStartupMessage();

                    WriteToConsole("Running wait loop");

                    // wait to get signaled
                    // we do it this way because this is cross-thread
                    shutdownEvent.WaitOne();
                }
            }
        }
Beispiel #3
0
        public async Task StopTracker(Guid trackerId)
        {
            Tracker trackerDb = _trackerContext.Trackers.FirstOrDefault(t => t.TrackerId == trackerId);

            trackerDb.IsActiveTracker = false;
            UserTracking userTrackingDb = _trackerContext.UserTrackings.FirstOrDefault(ut => ut.Tracker == trackerDb && ut.TrackerStopTime == null);

            userTrackingDb.TrackerStopTime = DateTime.Now;
            _trackerContext.SaveChanges();
        }
Beispiel #4
0
        public static void PublishUserMessage(String message, Boolean ignoreReturningUsers)
        {
            if (ignoreReturningUsers && UserTracking.IsReturningUser(CurrentHttpContext))
            {
                return;
            }

            var context = GetContext();

            context.Clients[UserTracking.UserConnectionId].sendUserMessage(message);
        }
Beispiel #5
0
        public async Task <object> DeleteTracker(Guid trackerId)
        {
            Tracker      trackerDb      = _trackerContext.Trackers.FirstOrDefault(t => t.TrackerId == trackerId);
            UserTracking userTrackingDb = _trackerContext.UserTrackings.FirstOrDefault(ut => ut.Tracker == trackerDb);

            if (userTrackingDb != null)
            {
                _trackerContext.UserTrackings.Remove(userTrackingDb);
            }
            _trackerContext.Trackers.Remove(trackerDb);
            _trackerContext.SaveChanges();
            return(true);
        }
Beispiel #6
0
    /// <summary>
    /// Page_Load:Page load Event handler
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void Page_Load(object sender, EventArgs e)
    {
        SystemCheck systemCheck = new SystemCheck();

        systemCheck.SessionCheck();
        UserTracking userTracking = new UserTracking();

        userTracking.TrackPageEntry("50045");
        Session["ChartType"]    = "Pie";
        Session["ChartPalette"] = "WarmEarth";
        Session["CustomerType"] = "PFC Employee";
        GetCustomerName();
    }
Beispiel #7
0
        public System.Threading.Tasks.Task AckServer()
        {
            UserTracking.UserConnectionId = Context.ConnectionId;
            var context = new HttpContextWrapper(HttpContext.Current);

            return(Task.Factory.StartNew(() =>
            {
                if (UserTracking.IsReturningUser(context))
                {
                    return;
                }

                Caller.sendUserMessage(UserMessages.Welcome);
            }));
        }
Beispiel #8
0
        public async Task StartTracker(Guid trackerId, string userName)
        {
            Tracker trackerDb = _trackerContext.Trackers.FirstOrDefault(t => t.TrackerId == trackerId);

            trackerDb.IsActiveTracker = true;
            UserTracking userTracking = new UserTracking
            {
                UserTrackingId   = Guid.NewGuid(),
                Tracker          = trackerDb,
                TrackerStartTime = DateTime.Now,
                User             = await _userManager.FindByNameAsync(userName)
            };

            _trackerContext.UserTrackings.Add(userTracking);
            _trackerContext.SaveChanges();
        }
Beispiel #9
0
 public bool InsertSessionTracker(string UserName, string SystemIp, string SystemName)
 {
     try
     {
         int SessionId = GetLoginSequence();
         var track     = new UserTracking();
         track.Username   = UserName;
         track.Sessionid  = new EncryptionManager().EncryptValue(SessionId.ToString());
         track.Systemip   = SystemIp;
         track.Systemname = SystemName;
         track.Logindate  = DateTime.Now;
         _db.Insert(track);
         return(true);
     }
     catch (Exception ex)
     {
         return(false);
     }
 }
Beispiel #10
0
        /// <summary>
        /// Page Load Event handler
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (Request.QueryString["DestPage"] != null && Request.QueryString["ModuleID"] != null)
                {
                    try
                    {
                        UserTracking userTracking = new UserTracking();
                        userTracking.TrackPageEntry(Request.QueryString["ModuleID"].ToString());

                        Response.Redirect(Cryptor.Decrypt(Request.QueryString["DestPage"].ToString()).ToString());
                    }
                    catch (Exception ex)
                    {
                        Response.Write(ex);
                    }
                }
            }
        }
        public async Task Invoke(HttpContext context)
        {
            now = DateTime.Now;
            userTrackingGuid = Guid.NewGuid();
            //CookieManager.SetVisitorIdentity();
            //new System.Threading.ThreadLocal<string>().Values[]
            await _next(context);

            UserTracking ut = new UserTracking
            {
                Guid        = userTrackingGuid,
                StartTime   = now,
                Request     = context.Request.Path,
                QueryString = context.Request.QueryString.ToString(),
                UserAgent   = context.Request.Headers["UserAgnet"],
                ElapsedSecs = (DateTime.Now - now).TotalSeconds,
                ServerBy    = Environment.MachineName,
                IsHttps     = context.Request.IsHttps,
                RequestType = context.Request.Method,
                UserIp      = context.Connection.RemoteIpAddress.MapToIPv4().ToString()
            };
        }
Beispiel #12
0
            public async Task <Result <Unit> > Handle(Command request, CancellationToken cancellationToken)
            {
                var observer = await _context.Users.FirstOrDefaultAsync(x => x.UserName == _userAccessor.GetUsername());

                var target = await _context.Users.FirstAsync(t => t.UserName == request.TargetUsername);

                if (null == target)
                {
                    return(null);
                }

                var tracking = await _context.UserTrackings.FindAsync(observer.Id, target.Id);

                if (null == tracking)
                {
                    tracking = new UserTracking
                    {
                        Observer = observer,
                        Target   = target
                    };
                    _context.UserTrackings.Add(tracking);
                }
                else
                {
                    _context.UserTrackings.Remove(tracking);
                }

                var success = await _context.SaveChangesAsync() > 0;

                if (success)
                {
                    return(Result <Unit> .Success(Unit.Value));
                }

                return(Result <Unit> .Failure("Failed to update tracker"));
            }
Beispiel #13
0
 public void AddUserTracking(string userId, UserTracking info)
 {
     throw new NotImplementedException();
 }
        public async Task Seed()
        {
            _context.Database.EnsureCreated();

            var user = await this._userManager.FindByEmailAsync("*****@*****.**");

            if (user == null)
            {
                user = new ApplicationUser()
                {
                    FirstName = "first",
                    LastName  = "user",
                    UserName  = "******",
                    Email     = "*****@*****.**",
                };

                var trackedUser = new ApplicationUser()
                {
                    FirstName = "second",
                    LastName  = "user",
                    UserName  = "******",
                    Email     = "*****@*****.**"
                };

                var result1 = await this._userManager.CreateAsync(user, "123456aB!");

                var result2 = await this._userManager.CreateAsync(trackedUser, "123456aB!");

                if (result1 != IdentityResult.Success || result2 != IdentityResult.Success)
                {
                    throw new InvalidOperationException("Failed to create default users");
                }
            }

            user = await this._userManager.FindByEmailAsync("*****@*****.**");

            if (user == null)
            {
                var adminUser = new ApplicationUser()
                {
                    FirstName = "admin",
                    LastName  = "user",
                    UserName  = "******",
                    Email     = "*****@*****.**",
                };
                var result3 = await this._userManager.CreateAsync(adminUser, "123456aB!");

                if (result3 != IdentityResult.Success)
                {
                    throw new InvalidOperationException("Failed to create default users");
                }

                var role = new ApplicationRole()
                {
                    Name = "Admin", Description = "Administrator role"
                };
                var result4 = await this._roleManager.CreateAsync(role);

                if (result4 != IdentityResult.Success)
                {
                    throw new InvalidOperationException("Failed to create admin roles");
                }

                var result5 = await this._userManager.AddToRoleAsync(adminUser, "Admin");

                if (result5 != IdentityResult.Success)
                {
                    throw new InvalidOperationException("Failed to create admin roles");
                }
            }


            if (!_context.UserTrackings.Any())
            {
                var firstUser = await this._userManager.FindByEmailAsync("*****@*****.**");

                var profileFirst = new UserProfile()
                {
                    UserName   = firstUser.UserName,
                    AvatarType = Shared.Avatar.meh.ToString(),
                    Created    = DateTime.Now,
                    Gender     = true,
                    ImageUrl   = string.Empty
                };

                _context.UserProfiles.Add(profileFirst);
                //_context.UserProfiles.Add(profileFirst);
                var secondtUser = await this._userManager.FindByEmailAsync("*****@*****.**");

                var profileSecond = new UserProfile()
                {
                    UserName   = secondtUser.UserName,
                    AvatarType = Shared.Avatar.poo.ToString(),
                    Created    = DateTime.Now,
                    Gender     = true,
                    ImageUrl   = string.Empty
                };

                _context.UserProfiles.Add(profileSecond);
                _context.SaveChanges();

                var trackedProfile = _context.UserProfiles.Where(up => up.UserName == secondtUser.UserName).FirstOrDefault();
                var trackerProfile = _context.UserProfiles.Where(up => up.UserName == firstUser.UserName).FirstOrDefault();

                UserTracking ut = new UserTracking()
                {
                    OnlinePresence = new UserOnlinePresence()
                    {
                        IsActive  = false,
                        Location  = "somewhere in te mediratenean",
                        ProfileId = trackedProfile.Id
                    },
                    UserProfile   = trackedProfile,
                    UserProfileId = trackedProfile.Id,
                    //                    Tracker = profileFirst,
                    TrackerId = trackerProfile.Id
                };


                _context.UserTrackings.Add(ut);
                _context.SaveChanges();
            }

            user = await this._userManager.FindByEmailAsync("*****@*****.**");

            if (user == null)
            {
                user = new ApplicationUser()
                {
                    FirstName = "third",
                    LastName  = "user",
                    UserName  = "******",
                    Email     = "*****@*****.**",
                };

                var result1 = await this._userManager.CreateAsync(user, "123456aB!");

                if (result1 != IdentityResult.Success)
                {
                    throw new InvalidOperationException("Failed to create third user");
                }


                var profileThird = new UserProfile()
                {
                    UserName   = user.UserName,
                    AvatarType = Shared.Avatar.female.ToString(),
                    Created    = DateTime.Now,
                    Gender     = true,
                    ImageUrl   = string.Empty
                };

                _context.UserProfiles.Add(profileThird);
                _context.SaveChanges();
            }

            user = await this._userManager.FindByEmailAsync("*****@*****.**");

            if (user == null)
            {
                // this will a user created fro invitation without actual application user
                var profileFourth = new UserProfile()
                {
                    UserName = "******",
                    Created  = DateTime.MinValue
                };

                _context.UserProfiles.Add(profileFourth);
                _context.SaveChanges();
            }


            if (!_context.TrackingInvitations.Any())
            {
                var trackingProfile     = _context.UserProfiles.Where(up => up.UserName == "firstuser").FirstOrDefault();
                var trackedProfile      = _context.UserProfiles.Where(up => up.UserName == "thirduser").FirstOrDefault();
                var trackedProfileEmail = _context.UserProfiles.Where(up => up.UserName == "*****@*****.**").FirstOrDefault();

                if (trackingProfile == null || trackedProfile == null || trackedProfileEmail == null)
                {
                    throw new InvalidOperationException("Expected profiles are missing");
                }


                var invitation = new TrackingInvitation()
                {
                    TrackerId = trackingProfile.Id,
                    TrackeeId = trackedProfile.Id
                };

                var invitationViaEmail = new TrackingInvitation()
                {
                    TrackerId = trackingProfile.Id,
                    TrackeeId = trackedProfileEmail.Id,
                    email     = trackedProfileEmail.UserName
                };

                _context.TrackingInvitations.Add(invitation);
                _context.TrackingInvitations.Add(invitationViaEmail);
                _context.SaveChanges();
            }
        }
        public ActionResult Index()
        {
            UserTracking.TrackUserVisit(HttpContext);

            return(View());
        }