/// <summary> /// Hooks the manager screenshot. /// </summary> private void HookManager_Screenshot() { Int32 hwnd = 0; hwnd = GetForegroundWindow(); var sessionID = _contextDB.GetLoginSession().SessionId; if (hwnd == 0) { return; } string appProcessName = Process.GetProcessById(GetWindowProcessID(hwnd)).ProcessName; var capture = new ScreenshotLogModel { SessionId = sessionID, ActivityName = appProcessName, ActivityType = "Application", //Sementara dipantek! Image = new ScreenCapture().CaptureScreenByteArrayString(System.Drawing.Imaging.ImageFormat.Jpeg), CaptureScreenDate = loginTime.AddTicks(stopwatch.ElapsedTicks) }; _contextDB.CreateImageData(capture); }
/// <summary> /// Gets the screenshot log list send to server. /// </summary> /// <returns></returns> public List <ScreenshotLogModel> GetScreenshotLogListSendToServer() { List <ScreenshotLogModel> result = new List <ScreenshotLogModel>(); string retrieveQuery = "SELECT * FROM ScreenshotLogModel WHERE IsSuccessSendToServer = 'False'"; using (var connection = PrivateConnection()) { connection.Open(); using (var transaction = connection.BeginTransaction()) { DateTime dateTimeResult = new DateTime(1900, 1, 1); ScreenshotLogModel recordData = new ScreenshotLogModel(); 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.ScreenshotLogModelId = reader["ScreenshotLogModelId"] != DBNull.Value ? Convert.ToInt32(reader["ScreenshotLogModelId"]) : 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.Image = reader["Image"] != DBNull.Value ? Convert.FromBase64String(reader["Image"].ToString()) : new byte[0]; if (reader["CaptureScreenDate"] != DBNull.Value) // &&(DateTime.TryParseExact(reader["CaptureScreenDate"].ToString(), "yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture, DateTimeStyles.None, out dateTimeResult))) { recordData.CaptureScreenDate = Convert.ToDateTime(reader["CaptureScreenDate"]); // dateTimeResult; } recordData.IsSuccessSendToServer = reader["IsSuccessSendToServer"] != DBNull.Value ? Convert.ToBoolean(reader["IsSuccessSendToServer"].ToString()) : 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; result.Add(recordData); } } transaction.Commit(); } } return(result); }
private void HookManager_Screenshot() { Int32 hwnd = 0; hwnd = GetForegroundWindow(); string appProcessName = Process.GetProcessById(GetWindowProcessID(hwnd)).ProcessName; var capture = new ScreenshotLogModel(); capture.ScreenshotLogModelId = Guid.NewGuid().ToString(); capture.SessionID = 0; capture.ActivityName = appProcessName; capture.Image = new ScreenCapture().CaptureScreenByteArrayString(System.Drawing.Imaging.ImageFormat.Jpeg); capture.CaptureScreenDate = DateTime.Now; capture.IsSuccessSendToServer = false; //screenCaptureList.Add(capture); //SendScreenCapture(screenCaptureList); //screenCaptureList = new List<amCapture>(); }
/// <summary> /// Updates the image data. /// </summary> /// <param name="item">The item.</param> public void UpdateImageData(ScreenshotLogModel item) { string updateQuery = string.Empty; updateQuery = string.Format("UPDATE ScreenshotLogModel SET IsSuccessSendToServer = '{0}' " + "WHERE ScreenshotLogModelId = '{1}'", item.IsSuccessSendToServer, item.ScreenshotLogModelId); 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(); } } }
/// <summary> /// Creates the image data. /// </summary> /// <param name="item">The item.</param> public void CreateImageData(ScreenshotLogModel item) { string insertQuery = string.Empty; insertQuery = string.Format("INSERT INTO ScreenshotLogModel ( ScreenshotLogModelId, SessionId, ActivityName, ActivityType, Image, CaptureScreenDate, IsSuccessSendToServer, CreatedDate, RowStatus ) " + "VALUES ('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}')", item.ScreenshotLogModelId, item.SessionId, item.ActivityName, item.ActivityType, Convert.ToBase64String(item.Image), item.CaptureScreenDate, item.IsSuccessSendToServer, DateTime.Now.ToString(DATE_FORMAT), 0); 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(); } } }