/// <summary> /// Retrieves informations on a PSTĀ file from the clientId and the localPath. /// </summary> /// <param name="clientId"></param> /// <param name="localPath"></param> /// <returns></returns> public PstFile GetPstFile(string clientId, string localPath) { PstFile pstFile = new PstFile(); using (var _sqlCommand = new SqlCommand("SELECT * FROM tbPstFiles WHERE ClientId LIKE @clientId AND LocalPath LIKE @localPath;", _dbConnection)) { AddParameter(_sqlCommand, "@clientId", System.Data.SqlDbType.UniqueIdentifier, new Guid(clientId)); AddParameter(_sqlCommand, "@localPath", System.Data.SqlDbType.NVarChar, localPath.Substring(0, System.Math.Min(300, localPath.Length))); using (SqlDataReader reader = _sqlCommand.ExecuteReader()) { if (reader.HasRows) { if (reader.Read()) { pstFile.LocalPath = reader.GetString(1); pstFile.Id = reader.GetGuid(2); pstFile.IsSetToBackup = reader.GetBoolean(3); pstFile.Size = reader.GetInt64(4); object lastSuccessfulBackup = reader[5]; pstFile.LastSuccessfulBackup = (lastSuccessfulBackup == System.DBNull.Value) ? (DateTime?)null : Convert.ToDateTime(lastSuccessfulBackup); } } } } return(pstFile); }
private void RegisterNewPstFile(string clientId, PstFile pstFile) { var _sqlCommand = new SqlCommand($"INSERT INTO tbPstFiles VALUES (@clientId,@localPath,'{Guid.NewGuid()}',@isSetToBackup,@size,null);", _dbConnection); AddParameter(_sqlCommand, "@clientId", System.Data.SqlDbType.UniqueIdentifier, new Guid(clientId)); AddParameter(_sqlCommand, "@localPath", System.Data.SqlDbType.NVarChar, pstFile.LocalPath.Substring(0, System.Math.Min(300, pstFile.LocalPath.Length))); AddParameter(_sqlCommand, "@isSetToBackup", System.Data.SqlDbType.Bit, pstFile.IsSetToBackup); AddParameter(_sqlCommand, "@size", System.Data.SqlDbType.BigInt, pstFile.Size); _sqlCommand.ExecuteNonQuery(); }
/// <summary> /// Insert the PST file into the database if the PST file do not already exists, otherwise, update informations /// </summary> /// <param name="clientId">Unique ID of the client that own the PST file.</param> /// <param name="pstFile">Informations on the PST file.</param> /// <param name="bckSession">Informations on the backup session.</param> public void RegisterPstFile(string clientId, PstFile pstFile) { if (IsPstFileExists(clientId, pstFile.LocalPath)) { UpdatePstFileInfo(clientId, pstFile); } else { RegisterNewPstFile(clientId, pstFile); } }
private void UpdatePstFileInfo(string clientId, PstFile pstFile) { var _sqlCommand = new SqlCommand("UPDATE tbPstFiles SET " + "IsSetToBackup=@isSetToBackup," + "Size=@size," + "LastSuccessfulBackup=@lastSuccessfulBackup " + "WHERE ClientId LIKE @clientId AND LocalPath LIKE @localPath;", _dbConnection); AddParameter(_sqlCommand, "@isSetToBackup", System.Data.SqlDbType.Bit, pstFile.IsSetToBackup); AddParameter(_sqlCommand, "@size", System.Data.SqlDbType.BigInt, pstFile.Size); AddParameter(_sqlCommand, "@lastSuccessfulBackup", System.Data.SqlDbType.DateTime, ((object)pstFile.LastSuccessfulBackup ?? DBNull.Value)); AddParameter(_sqlCommand, "@clientId", System.Data.SqlDbType.UniqueIdentifier, new Guid(clientId)); AddParameter(_sqlCommand, "@localPath", System.Data.SqlDbType.NVarChar, pstFile.LocalPath.Substring(0, System.Math.Min(300, pstFile.LocalPath.Length))); _sqlCommand.ExecuteNonQuery(); }
/// <summary> /// Register, in the database, all informations on the PST file mounted in Outlook /// </summary> /// <param name="clientId">Unique Id of the client that own the PST file</param> /// <param name="backupSession">Informations on the backup session</param> public void RegisterPstFile(string clientId, PstFile pstFile) { Logger.Write(30021, $"Registering the PST file {pstFile.LocalPath}", Logger.MessageSeverity.Debug); _reportServerDb.RegisterPstFile(clientId, pstFile); }