public void Open( string fileName, string fileExtension, byte[] content )
{
_fileExtension = fileExtension;
_fileName = fileName;
_content = content;
var encoding = new UTF8Encoding();
const String sMSG_NOPREVIEW =
"<h3 style=\"color:red;\" >Preview reader is unavailable for this file type.</h3>";
const String sMSG_CANNOT_PREVIEW = "<h3 style=\"color:red;\" >Unable to preview this document.</h3>";
const String sMSG_NO_LOCAL =
"<h3 style=\"color:red;\" >You must have a local copy of this file to preview it.</h3>";
//Need to use active document
//String extension = fi.Extension.ToLower().Trim();
var sourceTypes = (String) ATMLContext.GetProperty( "environment.source.filetypes" );
var browserTypes = (String) ATMLContext.GetProperty( "environment.browser.filetypes" );
var supportedTypes = (String) ATMLContext.GetProperty( "environment.supported.filetypes" );
try
{
//if( string.IsNullOrEmpty( sourceTypes ) || )
string extension = fileExtension.ToLower();
if (!supportedTypes.Contains( extension ))
{
PreviewHtml(
encoding.GetBytes( sMSG_NOPREVIEW + "<br />" + extension +
" file types are not supported at this time." ) );
}
else
{
String tempFileName = fileName;
if (sourceTypes.Contains( extension ))
{
sourcePreviewer.ConfigurationManager.Language = extension.Substring( 1 );
PreviewSource( encoding.GetString( content ), extension );
}
else
{
if (webBrowser.Document != null)
{
webBrowser.Document.OpenNew( true );
}
webBrowser.Navigate( "about:blank" );
try
{
using (new HourGlass())
{
Guid guid = GetPreviewHandlerGUID( fileName );
if (browserTypes.Contains( extension ))
PreviewHtml( tempFileName );
else if (UTRSOfficeUtils.IsInstalled( UTRSOfficeUtils.MSOfficeApplications.Word )
&& UTRSOfficeUtils.IsWordDocument( extension ))
PreviewHtml( UTRSOfficeUtils.OfficeDocToHtml( fileName,
UTRSOfficeUtils.MSOfficeApplications
.Word ) );
else if (UTRSOfficeUtils.IsInstalled( UTRSOfficeUtils.MSOfficeApplications.Excel )
&& UTRSOfficeUtils.IsExcelDocument( extension ))
PreviewHtml( UTRSOfficeUtils.OfficeDocToHtml( fileName,
UTRSOfficeUtils.MSOfficeApplications
.Excel ) );
else if (UTRSOfficeUtils.IsInstalled( UTRSOfficeUtils.MSOfficeApplications.PowerPoint )
&& UTRSOfficeUtils.IsPowerPointDocument( extension ))
PreviewHtml( UTRSOfficeUtils.OfficeDocToHtml( fileName,
UTRSOfficeUtils.MSOfficeApplications
.PowerPoint ) );
else if (guid != Guid.Empty)
PreView( guid, tempFileName );
else
{
PreviewHtml(
encoding.GetBytes( sMSG_NOPREVIEW +
"<br />Could not find a preview handler for " +
extension ) );
}
}
}
catch (Exception ee)
{
LogManager.Error( ee, sMSG_CANNOT_PREVIEW );
PreviewHtml(
encoding.GetBytes( sMSG_CANNOT_PREVIEW +
"<br />An error has occurred attempting to preview this document: <br />" +
ee.Message ) );
}
}
}
}
catch (Exception e)
{
LogManager.Error( e, "Failed to open preview for file {0} ", fileName );
LogManager.Debug(
"Error opening Preview. Data Dump:\n File Name: {0}{1}\nSource Types:{2}\nBrowser Types:{3}\nSupported Type:{4}\nStack Trace:\n{5}",
fileName, fileExtension, sourceTypes, browserTypes, supportedTypes, e.StackTrace );
}
Cursor = Cursors.Default;
}