Updated code to save the DocAscii field.

This commit is contained in:
Rich 2010-04-08 17:42:58 +00:00
parent 88fcff5852
commit 24c892b008

View File

@ -6,7 +6,6 @@ using Csla;
using Csla.Data; using Csla.Data;
using System.Data; using System.Data;
using System.Data.SqlClient; using System.Data.SqlClient;
using EPocalipse.IFilter;
namespace VEPROMS.CSLA.Library namespace VEPROMS.CSLA.Library
{ {
@ -20,45 +19,23 @@ namespace VEPROMS.CSLA.Library
return _LibTitle; return _LibTitle;
} }
} }
public void UpdateDocAscii(string fileName)
{
try
{
DocAscii = null;
// Opening the file directly gives a sharing violation.
// Therefore, the file is copied and the copy is used and then deleted.
FileInfo myFile = new FileInfo(fileName);
FileInfo tempFile = new FileInfo(myFile.DirectoryName + "\\tmp_" + myFile.Name);
myFile.CopyTo(tempFile.FullName); // Copy to the temporary file
using (FilterReader reader = new FilterReader(tempFile.FullName)) // Open the IFilter Reader
{
DocAscii = FixString(reader.ReadToEnd()); // Read the ascii text
reader.Close(); // Close the reader
}
tempFile.Delete();
}
catch (Exception ex)
{
Console.WriteLine("Converting Document to ascii, error is {0}", ex.Message);
}
}
/// <summary> /// <summary>
/// FixString processes the string returned and changes any symbols (0xF0??) to normal characters /// FixString processes the string returned and changes any symbols (0xF0??) to normal characters
/// </summary> /// </summary>
/// <param name="str"></param> /// <param name="str"></param>
/// <returns></returns> /// <returns></returns>
private static string FixString(string str) //private static string FixString(string str)
{ //{
StringBuilder results = new StringBuilder(); // StringBuilder results = new StringBuilder();
foreach (char c in str) // foreach (char c in str)
{ // {
if ((c & 0xFF00) == 0xF000) // if ((c & 0xFF00) == 0xF000)
results.Append((char)(c & 0xFF)); // results.Append((char)(c & 0xFF));
else // else
results.Append((char)(c)); // results.Append((char)(c));
} // }
return results.ToString(); // return results.ToString();
} //}
} }
public partial class DocumentInfo public partial class DocumentInfo
{ {
@ -304,7 +281,7 @@ namespace VEPROMS.CSLA.Library
_MyFile = new FileInfo(value); _MyFile = new FileInfo(value);
} }
} }
public void SaveFile(float length) public void SaveFile(float length,string ascii)
{ {
// TODO: Add Try & Catch logic // TODO: Add Try & Catch logic
if (_MyDocument == null) return; if (_MyDocument == null) return;
@ -315,7 +292,8 @@ namespace VEPROMS.CSLA.Library
fs.Close(); fs.Close();
doc.FileExtension = MyFile.Extension; doc.FileExtension = MyFile.Extension;
doc.DocContent = buf; doc.DocContent = buf;
doc.UpdateDocAscii(_MyFile.FullName); doc.DocAscii = ascii;
//doc.UpdateDocAscii(_MyFile.FullName);
DocumentConfig cfg = new DocumentConfig(doc); DocumentConfig cfg = new DocumentConfig(doc);
cfg.Printing_Length = length; cfg.Printing_Length = length;
doc.Config = cfg.ToString(); doc.Config = cfg.ToString();