//[Obsolete]
//public void Export2(int scanFileID, string ftpPath)
//{
// //kontrola vstupnich parametru
// if (scanFileID == 0)
// throw new ArgumentException("Neplatný parametr identifikátor souboru.");
// ScanFileRepository repository = new ScanFileRepository();
// //kontrola existence naskenovaneho souboru
// ScanFile result = repository.Select(scanFileID);
// if (result == null)
// throw new ApplicationException(String.Format("Soubor (ID={0}) neexistuje.", scanFileID));
// //kontrola ulozenych parametrov
// if (result.Status != StatusCode.Exported)
// throw new ApplicationException(String.Format("Soubor (ID={0}) nemá status exportováno.", result.ScanFileID));
// //export ALEPH
// TxFileManager fileMgr = new TxFileManager();
// string filePath = null;
// try
// {
// filePath = result.GetScanFilePath();
// string ftpFilePath = null;
// switch (result.PartOfBook)
// {
// case PartOfBook.FrontCover:
// ftpFilePath = Path.Combine(ftpPath, result.FileName);
// fileMgr.Copy(filePath, ftpFilePath, true);
// break;
// case PartOfBook.TableOfContents:
// if (result.UseOCR)
// {
// string txtFilePath = Path.Combine(ftpPath, result.TxtFileName);
// fileMgr.WriteAllText(txtFilePath, result.OcrText);
// }
// string pdfFilePath = result.GetOcrFilePath();
// ftpFilePath = Path.Combine(ftpPath, result.OcrFileName);
// fileMgr.Copy(pdfFilePath, ftpFilePath, true);
// break;
// default:
// break;
// }
// }
// catch (Exception ex)
// {
// throw new ApplicationException(String.Format("Nepodařilo se exportovat soubor '{0}' na FTP: {1}.", filePath, ex.Message));
// }
//}
public void Delete(int scanFileID, string userName)
{
//kontrola vstupnich parametru
if (scanFileID == 0)
throw new ArgumentException("Neplatný parametr identifikátor souboru.");
if (String.IsNullOrEmpty(userName))
throw new ArgumentException("Neplatný parametr jméno uživatele.");
ScanFileRepository repository = new ScanFileRepository();
//kontrola existence naskenovaneho souboru
ScanFile result = repository.Select(scanFileID);
if (result == null)
throw new ApplicationException(String.Format("Soubor (ID={0}) neexistuje.", scanFileID));
//kontrola ulozenych parametrov
if (result.Status == StatusCode.Exported)
throw new ApplicationException(String.Format("Soubor (ID={0}) má status exportován.", result.ScanFileID));
//vymazanie suboru naskenovaneho obrazku
TxFileManager fileMgr = new TxFileManager();
string filePath = null;
//ulozenie operace do databazy
using (TransactionScope ts = new TransactionScope(TransactionScopeOption.Required))
{
try
{
filePath = result.GetScanFilePath();
if (fileMgr.FileExists(filePath)) fileMgr.Delete(filePath);
filePath = result.GetOcrFilePath();
if (fileMgr.FileExists(filePath)) fileMgr.Delete(filePath);
}
catch (Exception ex)
{
throw new ApplicationException(String.Format("Nepodařilo se vymazat soubor '{0}' z disku: {1}.", filePath, ex.Message));
}
try
{
repository.Delete(result);
Book book = BookComponent.Instance.GetByID(result.BookID);
if (book != null && (book.ScanFiles == null || book.ScanFiles.Count == 0))
{
BookComponent.Instance.Delete(result.BookID, userName);
}
ts.Complete();
}
catch (Exception ex)
{
throw new ApplicationException(String.Format("Nepodařilo se vymazat data souboru (ID={0}) z databáze.", scanFileID), ex);
}
}
}