ChinhDo.Transactions.TxFileManager.WriteAllText C# (CSharp) Method

WriteAllText() public method

Creates a file, write the specified contents to the file.
public WriteAllText ( string path, string contents ) : void
path string The file to write to.
contents string The string to write to the file.
return void
        public void WriteAllText(string path, string contents)
        {
            GetEnlistment().WriteAllText(path, contents);
        }

Usage Example

Ejemplo n.º 1
0
        public void Export(int scanFileID, string userName, string computer, string comment = null)
        {
            //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.");

            if (String.IsNullOrEmpty(computer))
                throw new ArgumentException("Neplatný parametr název počítače.");

            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.Complete)
                throw new ApplicationException(String.Format("Soubor (ID={0}) nemá status dokončeno.", result.ScanFileID));

            //export ALEPH
            TxFileManager fileMgr = new TxFileManager();
            string filePath = null;
            string ftpPath = null;

            using (TransactionScope ts = new TransactionScope(TransactionScopeOption.Required))
            {
                try
                {
                    filePath = result.GetScanFilePath();

                    switch (result.PartOfBook)
                    {
                        case PartOfBook.FrontCover:
                            ftpPath = Path.Combine(result.Book.Catalogue.GetDirectoryFTP(true), result.FileName);
                            fileMgr.Copy(filePath, ftpPath, true);
                            break;

                        case PartOfBook.TableOfContents:
                            if (result.UseOCR)
                            {
                                string txtFilePath = Path.Combine(result.Book.Catalogue.GetDirectoryFTP(true), result.TxtFileName);
                                fileMgr.WriteAllText(txtFilePath, result.OcrText);
                            }

                            string pdfFilePath = result.GetOcrFilePath();
                            ftpPath = Path.Combine(result.Book.Catalogue.GetDirectoryFTP(true), result.OcrFileName);
                            fileMgr.Copy(pdfFilePath, ftpPath, true);
                            break;

                        default:
                            break;
                    }
                }
                catch (Exception ex)
                {
                    throw new ApplicationException(String.Format("Nepodařilo se exportovat soubor '{0}' na FTP: {1}.", filePath, ex.Message));
                }

                //ulozenie operace do databazy
                try
                {
                    result.Modified = DateTime.Now;
                    result.Comment = (comment != null ? comment.Left(1000) : null);
                    result.Status = StatusCode.Exported;
                    repository.Update(result);

                    LogOperation(result.ScanFileID, userName, computer, result.Modified, result.Comment, result.Status);

                    ts.Complete();
                }
                catch (Exception ex)
                {
                    throw new ApplicationException(String.Format("Nepodařilo se uložit data souboru (ID={0}) do databáze.", scanFileID), ex);
                }
            }
        }