예제 #1
0
        /// <summary>
        /// Checks the is table exist.
        /// </summary>
        /// <param name="tableName">Name of the table.</param>
        /// <returns></returns>
        private bool CheckIsTableExist(string tableName)
        {
            bool tableIsExist = false;

            string checkScript = string.Format("SELECT name FROM sqlite_master WHERE type='table' AND name='{0}' LIMIT 1", tableName);

            using (var connection = PrivateConnection())
            {
                connection.Open();

                using (var transaction = connection.BeginTransaction())
                {
                    DateTime dateTimeResult          = new DateTime(1900, 1, 1);
                    KeyboardMouseLogModel recordData = new KeyboardMouseLogModel();
                    var sqlCommand = connection.CreateCommand();
                    sqlCommand.Transaction = transaction;
                    sqlCommand.CommandText = checkScript;
                    sqlCommand.CommandType = System.Data.CommandType.Text;
                    using (var reader = sqlCommand.ExecuteReader())
                    {
                        tableIsExist = reader.Read();
                        transaction.Commit();
                    }
                }
            }
            return(tableIsExist);
        }
예제 #2
0
        private void HookManager_MouseClick(object sender, MouseEventArgs e)
        {
            Int32 hwnd = 0;

            hwnd = GetForegroundWindow();
            string appProcessName = Process.GetProcessById(GetWindowProcessID(hwnd)).ProcessName;

            if (keyboardMouseLogList.Exists(monitor => monitor.ActivityName == appProcessName))
            {
                var monitor = keyboardMouseLogList.Where(a => a.ActivityName == appProcessName).OrderByDescending(b => b.StartTime).FirstOrDefault();
                monitor.MouseClickCount++;
                monitor.EndTime = DateTime.Now;
            }
            else
            {
                if (keyboardMouseLogList.Count > 0)
                {
                    //SendMonitoringAsync(monitoringList);
                    keyboardMouseLogList = new List <KeyboardMouseLogModel>();
                }

                var monitor = new KeyboardMouseLogModel();
                monitor.KeyboardMouseLogModelId = Guid.NewGuid().ToString();
                monitor.ActivityName            = appProcessName;
                monitor.ActivityType            = ACTIVITY_TYPE_APPLICATION;
                monitor.KeyStrokeCount          = 0;
                monitor.MouseClickCount         = 1;
                monitor.StartTime             = DateTime.Now;
                monitor.EndTime               = DateTime.Now;
                monitor.IsSuccessSendToServer = false;

                keyboardMouseLogList.Add(monitor);
            }
        }
예제 #3
0
        /// <summary>
        /// Handles the KeyPress event of the HookManager control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="KeyPressEventArgs"/> instance containing the event data.</param>
        private void HookManager_KeyPress(object sender, KeyPressEventArgs e)
        {
            try
            {
                Int32 hwnd = 0;
                hwnd = GetForegroundWindow();

                var sessionID = _contextDB.GetLoginSession().SessionId;

                if (hwnd == 0)
                {
                    return;
                }

                string appProcessName = Process.GetProcessById(GetWindowProcessID(hwnd)).ProcessName;

                if (keyboardMouseLogList.Exists(monitor => monitor.ActivityName == appProcessName))
                {
                    var monitor = keyboardMouseLogList.Where(a => a.ActivityName == appProcessName).OrderByDescending(b => b.StartTime).FirstOrDefault();
                    monitor.KeyStrokeCount++;
                    monitor.EndTime = loginTime.AddTicks(stopwatch.ElapsedTicks);
                }
                else
                {
                    if (keyboardMouseLogList.Count > 0)
                    {
                        foreach (var log in keyboardMouseLogList)
                        {
                            _contextDB.CreateData(log);
                        }

                        keyboardMouseLogList = new List <KeyboardMouseLogModel>();
                    }

                    var monitor = new KeyboardMouseLogModel
                    {
                        SessionId             = sessionID,
                        ActivityName          = appProcessName,
                        ActivityType          = ACTIVITY_TYPE_APPLICATION,
                        KeyStrokeCount        = 1,
                        MouseClickCount       = 0,
                        StartTime             = loginTime.AddTicks(stopwatch.ElapsedTicks),
                        EndTime               = loginTime.AddTicks(stopwatch.ElapsedTicks),
                        IsSuccessSendToServer = false
                    };

                    keyboardMouseLogList.Add(monitor);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
예제 #4
0
        /// <summary>
        /// Gets the log list send to server.
        /// </summary>
        /// <returns></returns>
        public List <KeyboardMouseLogModel> GetLogListSendToServer()
        {
            List <KeyboardMouseLogModel> result = new List <KeyboardMouseLogModel>();

            string retrieveQuery = "SELECT * FROM KeyboardMouseLogModel WHERE IsSuccessSendToServer = 'False'";

            using (var connection = PrivateConnection())
            {
                connection.Open();

                using (var transaction = connection.BeginTransaction())
                {
                    DateTime dateTimeResult          = new DateTime(1900, 1, 1);
                    KeyboardMouseLogModel recordData = new KeyboardMouseLogModel();
                    var sqlCommand = connection.CreateCommand();
                    sqlCommand.Transaction = transaction;
                    sqlCommand.CommandText = retrieveQuery;
                    sqlCommand.CommandType = System.Data.CommandType.Text;
                    using (var reader = sqlCommand.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            recordData.KeyboardMouseLogModelId = reader["KeyboardMouseLogModelId"] != DBNull.Value ? Convert.ToInt32(reader["KeyboardMouseLogModelId"]) : 0;
                            recordData.SessionId       = reader["SessionId"] != DBNull.Value ? int.Parse(reader["SessionId"].ToString()) : 0;
                            recordData.ActivityName    = reader["ActivityName"] != DBNull.Value ? reader["ActivityName"].ToString() : string.Empty;
                            recordData.ActivityType    = reader["ActivityType"] != DBNull.Value ? reader["ActivityType"].ToString() : string.Empty;
                            recordData.KeyStrokeCount  = reader["KeyStrokeCount"] != DBNull.Value ? long.Parse(reader["KeyStrokeCount"].ToString()) : 0;
                            recordData.MouseClickCount = reader["MouseClickCount"] != DBNull.Value ? long.Parse(reader["MouseClickCount"].ToString()) : 0;
                            if (reader["CreatedDate"] != DBNull.Value)//&& DateTime.TryParseExact(reader["EndTime"].ToString(), "dd/MM/yyyy HH:mm:ss", CultureInfo.InvariantCulture, DateTimeStyles.None, out dateTimeResult))
                            {
                                recordData.CreatedDate = Convert.ToDateTime(reader["CreatedDate"]);
                            }
                            if (reader["StartTime"] != DBNull.Value)                            //&& DateTime.TryParseExact(reader["StartTime"].ToString(), "dd/MM/yyyy HH:mm:ss", CultureInfo.InvariantCulture, DateTimeStyles.None, out dateTimeResult))
                            {
                                recordData.StartTime = Convert.ToDateTime(reader["StartTime"]); //dateTimeResult;
                            }
                            if (reader["EndTime"] != DBNull.Value)                              // && DateTime.TryParseExact(reader["EndTime"].ToString(), "dd/MM/yyyy HH:mm:ss", CultureInfo.InvariantCulture, DateTimeStyles.None, out dateTimeResult))
                            {
                                recordData.EndTime = Convert.ToDateTime(reader["EndTime"]);     //dateTimeResult;
                            }
                            recordData.IsSuccessSendToServer = reader["IsSuccessSendToServer"] != DBNull.Value ? Convert.ToBoolean(reader["IsSuccessSendToServer"]) : false;

                            recordData.RowStatus = reader["RowStatus"] != DBNull.Value ? Convert.ToInt32(reader["RowStatus"]) : 0;

                            result.Add(recordData);
                        }
                    }
                    transaction.Commit();
                }
            }
            return(result);
        }
예제 #5
0
        /// <summary>
        /// Gets the last active data.
        /// </summary>
        /// <returns></returns>
        public KeyboardMouseLogModel GetLastActiveData()
        {
            KeyboardMouseLogModel result = new KeyboardMouseLogModel();
            string retrieveQuery         = String.Format("SELECT * FROM KeyboardMouseLogModel ORDER BY StartTime DESC LIMIT 1");

            using (var connection = PrivateConnection())
            {
                connection.Open();

                using (var transaction = connection.BeginTransaction())
                {
                    DateTime dateTimeResult          = new DateTime(1900, 1, 1);
                    KeyboardMouseLogModel recordData = new KeyboardMouseLogModel();
                    var sqlCommand = connection.CreateCommand();
                    sqlCommand.Transaction = transaction;
                    sqlCommand.CommandText = retrieveQuery;
                    sqlCommand.CommandType = System.Data.CommandType.Text;
                    using (var reader = sqlCommand.ExecuteReader())
                    {
                        if (reader.Read())
                        {
                            recordData.KeyboardMouseLogModelId = reader["KeyboardMouseLogModelId"] != DBNull.Value ? Convert.ToInt32(reader["KeyboardMouseLogModelId"]) : 0;
                            recordData.SessionId       = reader["SessionId"] != DBNull.Value ? Convert.ToInt32(reader["SessionId"]) : 0;
                            recordData.ActivityName    = reader["ActivityName"] != DBNull.Value ? reader["ActivityName"].ToString() : string.Empty;
                            recordData.ActivityType    = reader["ActivityType"] != DBNull.Value ? reader["ActivityType"].ToString() : string.Empty;
                            recordData.KeyStrokeCount  = reader["KeyStrokeCount"] != DBNull.Value ? Convert.ToInt64(reader["KeyStrokeCount"].ToString()) : 0;
                            recordData.MouseClickCount = reader["MouseClickCount"] != DBNull.Value ? Convert.ToInt64(reader["MouseClickCount"].ToString()) : 0;
                            if (reader["StartTime"] != DBNull.Value)                            // && DateTime.TryParseExact(reader["StartTime"].ToString(), "yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture, DateTimeStyles.None, out dateTimeResult))
                            {
                                recordData.StartTime = Convert.ToDateTime(reader["StartTime"]); // dateTimeResult;
                            }
                            if (reader["EndTime"] != DBNull.Value)                              // && DateTime.TryParseExact(reader["EndTime"].ToString(), "yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture, DateTimeStyles.None, out dateTimeResult))
                            {
                                recordData.EndTime = Convert.ToDateTime(reader["EndTime"]);     // dateTimeResult;
                            }
                            recordData.IsSuccessSendToServer = reader["IsSuccessSendToServer"] != DBNull.Value ? Convert.ToBoolean(reader["IsSuccessSendToServer"]) : false;
                            if (reader["CreatedDate"] != DBNull.Value && DateTime.TryParseExact(reader["EndTime"].ToString(), "yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture, DateTimeStyles.None, out dateTimeResult))
                            {
                                recordData.CreatedDate = Convert.ToDateTime(reader["CreatedDate"]);// dateTimeResult;
                            }
                            recordData.RowStatus = reader["RowStatus"] != DBNull.Value ? Convert.ToInt32(reader["RowStatus"]) : 0;
                        }
                    }
                    transaction.Commit();
                }
            }
            return(result);
        }
예제 #6
0
        /// <summary>
        /// Updates the data.
        /// </summary>
        /// <param name="item">The item.</param>
        public void UpdateData(KeyboardMouseLogModel item)
        {
            string updateQuery = string.Empty;

            updateQuery = string.Format("UPDATE KeyboardMouseLogModel SET KeyStrokeCount = '{0}', MouseClickCount = '{1}', StartTime = '{2}', EndTime = '{3}', IsSuccessSendToServer = '{4}' " +
                                        "WHERE KeyboardMouseLogModelId = '{5}'", item.KeyStrokeCount, item.MouseClickCount, item.StartTime, item.EndTime, item.IsSuccessSendToServer, item.KeyboardMouseLogModelId);

            using (var connection = PrivateConnection())
            {
                connection.Open();

                using (var transaction = connection.BeginTransaction())
                {
                    var updateCommand = connection.CreateCommand();
                    updateCommand.Transaction = transaction;
                    updateCommand.CommandText = updateQuery;
                    updateCommand.CommandType = System.Data.CommandType.Text;
                    updateCommand.ExecuteNonQuery();

                    transaction.Commit();
                }
            }
        }
예제 #7
0
        /// <summary>
        /// Creates the data.
        /// </summary>
        /// <param name="item">The item.</param>
        public void CreateData(KeyboardMouseLogModel item)
        {
            string insertQuery = string.Empty;

            insertQuery = string.Format("INSERT INTO KeyboardMouseLogModel ( SessionId, ActivityName, ActivityType, KeyStrokeCount, MouseClickCount, StartTime, EndTime ) " +
                                        "VALUES ('{0}','{1}','{2}','{3}','{4}','{5}','{6}')",
                                        item.SessionId, item.ActivityName, item.ActivityType, item.KeyStrokeCount, item.MouseClickCount, item.StartTime, item.EndTime);

            using (var connection = PrivateConnection())
            {
                connection.Open();

                using (var transaction = connection.BeginTransaction())
                {
                    var insertCommand = connection.CreateCommand();
                    insertCommand.Transaction = transaction;
                    insertCommand.CommandText = insertQuery;
                    insertCommand.CommandType = System.Data.CommandType.Text;
                    insertCommand.ExecuteNonQuery();

                    transaction.Commit();
                }
            }
        }