Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 0 additions & 7 deletions AlarmSources/Fax/Fax.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,6 @@
<Reference Include="AlarmWorkflow.BackendService.SettingsContracts">
<HintPath>..\..\Build\AlarmWorkflow.BackendService.SettingsContracts.dll</HintPath>
</Reference>
<Reference Include="Ghostscript.NET, Version=1.2.0.0, Culture=neutral, PublicKeyToken=f85051de34525b59, processorArchitecture=MSIL">
<HintPath>..\packages\Ghostscript.NET.1.2.0\lib\net40\Ghostscript.NET.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Drawing" />
Expand Down Expand Up @@ -82,9 +78,6 @@
<ItemGroup>
<EmbeddedResource Include="settings.info.xml" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
Expand Down
33 changes: 19 additions & 14 deletions AlarmSources/Fax/FaxAlarmSource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
using AlarmWorkflow.Shared.Diagnostics;
using AlarmWorkflow.Shared.Extensibility;
using AlarmWorkflow.Shared.Specialized;
using Ghostscript.NET;
using AlarmWorkflow.Shared.Specialized.Pdf;
using AlarmWorkflow.Shared.Specialized.Tiff;

namespace AlarmWorkflow.AlarmSource.Fax
{
Expand Down Expand Up @@ -56,6 +57,7 @@ sealed class FaxAlarmSource : IAlarmSource
private DirectoryInfo _faxPath;
private DirectoryInfo _archivePath;
private DirectoryInfo _analysisPath;
private bool _convertToPdf;

private IOcrSoftware _ocrSoftware;
private IParser _parser;
Expand Down Expand Up @@ -140,20 +142,11 @@ private void ProcessNewPdf(FileInfo file)

try
{
GhostscriptImageDevice dev = new GhostscriptImageDevice();
dev.Device = "tiffgray";
dev.GraphicsAlphaBits = GhostscriptImageDeviceAlphaBits.V_4;
dev.TextAlphaBits = GhostscriptImageDeviceAlphaBits.V_4;
dev.Resolution = 300;
dev.InputFiles.Add(file.FullName);
dev.OutputPath = tiffFilePath;
dev.Process();

PdfHelper.ConvertToTiff(file.FullName, tiffFilePath);
ProcessNewImage(new FileInfo(tiffFilePath));

file.Delete();
}
catch (GhostscriptException ex)
catch (PdfConvertException ex)
{
Logger.Instance.LogFormat(LogType.Error, this, Properties.Resources.GhostscriptConvertError);
Logger.Instance.LogException(this, ex);
Expand Down Expand Up @@ -232,9 +225,20 @@ private void ProcessNewImage(FileInfo file)
}

IDictionary<string, object> ctxParameters = new Dictionary<string, object>();
ctxParameters[ContextParameterKeys.ArchivedFilePath] = archivedFilePath;
ctxParameters[ContextParameterKeys.ImagePath] = file.FullName;

if(_convertToPdf)
{
Logger.Instance.LogFormat(LogType.Trace, this, Properties.Resources.ConvertImageToPdf, archivedFilePath);
string pdfPath = TiffHelper.ConvertToPdf(archivedFilePath);
ctxParameters[ContextParameterKeys.ArchivedFilePath] = pdfPath;
File.Delete(archivedFilePath);
}
else
{
ctxParameters[ContextParameterKeys.ArchivedFilePath] = archivedFilePath;
ctxParameters[ContextParameterKeys.ImagePath] = file.FullName;
}

AlarmSourceEventArgs args = new AlarmSourceEventArgs(operation);
args.Parameters = ctxParameters;

Expand Down Expand Up @@ -282,6 +286,7 @@ private void InitializeFaxPaths()
_faxPath = new DirectoryInfo(_configuration.FaxPath);
_archivePath = new DirectoryInfo(_configuration.ArchivePath);
_analysisPath = new DirectoryInfo(_configuration.AnalysisPath);
_convertToPdf = _configuration.ConvertToPdf;

Logger.Instance.LogFormat(LogType.Trace, this, Properties.Resources.UsingIncomingFaxDirectory, _faxPath.FullName);
Logger.Instance.LogFormat(LogType.Trace, this, Properties.Resources.UsingAnalyzedFaxDirectory, _analysisPath.FullName);
Expand Down
7 changes: 6 additions & 1 deletion AlarmSources/Fax/FaxConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ internal string AnalysisPath
get { return _settings.GetSetting(FaxSettingKeys.AnalysisPath).GetValue<string>(); }
}

internal bool ConvertToPdf
{
get { return _settings.GetSetting(FaxSettingKeys.ConvertToPdf).GetValue<bool>(); }
}

internal string OCRSoftwarePath
{
get { return _settings.GetSetting(FaxSettingKeys.OcrPath).GetValue<string>(); }
Expand Down Expand Up @@ -102,7 +107,7 @@ private void _settings_SettingChanged(object sender, SettingChangedEventArgs e)
{
changedKeys.Add("OCR.Path");
}
else if ((key.Equals(FaxSettingKeys.FaxPath) || key.Equals(FaxSettingKeys.AnalysisPath) || key.Equals(FaxSettingKeys.ArchivePath)) && !changedKeys.Contains("FaxPaths"))
else if ((key.Equals(FaxSettingKeys.FaxPath) || key.Equals(FaxSettingKeys.AnalysisPath) || key.Equals(FaxSettingKeys.ArchivePath) || key.Equals(FaxSettingKeys.ConvertToPdf)) && !changedKeys.Contains("FaxPaths"))
{
changedKeys.Add("FaxPaths");
}
Expand Down
1 change: 1 addition & 0 deletions AlarmSources/Fax/FaxSettingKeys.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ static class FaxSettingKeys
internal static readonly SettingKey FaxPath = SettingKey.Create(Identifier, "FaxPath");
internal static readonly SettingKey ArchivePath = SettingKey.Create(Identifier, "ArchivePath");
internal static readonly SettingKey AnalysisPath = SettingKey.Create(Identifier, "AnalysisPath");
internal static readonly SettingKey ConvertToPdf = SettingKey.Create(Identifier, "ConvertToPdf");
internal static readonly SettingKey AlarmFaxParserAlias = SettingKey.Create(Identifier, "AlarmfaxParser");
internal static readonly SettingKey OcrPath = SettingKey.Create(Identifier, "OCR.Path");
}
Expand Down
9 changes: 9 additions & 0 deletions AlarmSources/Fax/Properties/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions AlarmSources/Fax/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -201,4 +201,7 @@
<data name="GhostscriptConvertError" xml:space="preserve">
<value>Error using Ghostscript. Maybe it's not installed.</value>
</data>
<data name="ConvertImageToPdf" xml:space="preserve">
<value>Convert analysed image '{0}' to PDF-Document</value>
</data>
</root>
4 changes: 0 additions & 4 deletions AlarmSources/Fax/packages.config

This file was deleted.

2 changes: 2 additions & 0 deletions AlarmSources/Fax/settings.info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
Description="Verzeichnis für verarbeitete Faxe." IsDynamic="true"/>
<Setting Name="AnalysisPath" DisplayText="Analyse-Verzeichnis" Category="Verzeichnisse" Editor="DirectoryTypeEditor"
Description="Verzeichnis für analysierte Faxe." IsDynamic="true"/>
<Setting Name="ConvertToPdf" DisplayText="Konvertieren zu PDF" Category="Verzeichnisse" IsDynamic="true"
Description="Gibt an ob das analysierte Fax in eine PDF-Datei umgewandelt werden soll."/>

<Setting Name="OCR.Path" DisplayText="Pfad (Verzeichnis)" Category="Tesseract OCR-Software" Editor="DirectoryTypeEditor"
Description="Wenn leer gelassen, wird das Standardverzeichnis (innerhalb des Programmverzeichnisses) genommen." IsDynamic="true"/>
Expand Down
1 change: 1 addition & 0 deletions AlarmSources/Fax/settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<Setting Name="FaxPath" Type="System.String" IsNull="False">C:\Fax</Setting>
<Setting Name="ArchivePath" Type="System.String" IsNull="False">C:\Fax\Archive\</Setting>
<Setting Name="AnalysisPath" Type="System.String" IsNull="False">C:\Fax\Analysis\</Setting>
<Setting Name="ConvertToPdf" Type="System.Boolean" IsNull="False">False</Setting>
<Setting Name="OCR.Path" Type="System.String" IsNull="False"></Setting>
<Setting Name="AlarmfaxParser" Type="System.String" IsNull="False">NoParser</Setting>
</SettingsConfiguration>
57 changes: 23 additions & 34 deletions Jobs/Engine/AlarmSourcePrinter/AlarmSourcePrinterJob.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
using AlarmWorkflow.Shared.Core;
using AlarmWorkflow.Shared.Diagnostics;
using AlarmWorkflow.Shared.Specialized.Printing;
using AlarmWorkflow.Shared.Specialized.Pdf;
using AlarmWorkflow.Shared.Specialized.Tiff;

namespace AlarmWorkflow.Job.AlarmSourcePrinterJob
{
Expand All @@ -44,21 +46,19 @@ class AlarmSourcePrinterJob : IJob

private void PrintFaxes(IJobContext context, Operation operation)
{
if (!context.Parameters.ContainsKey("ArchivedFilePath") || !context.Parameters.ContainsKey("ImagePath"))
if (!context.Parameters.ContainsKey("ArchivedFilePath"))
{
Logger.Instance.LogFormat(LogType.Trace, this, Resources.NoPrintingPossible);
return;
}

FileInfo sourceImageFile = new FileInfo((string)context.Parameters["ImagePath"]);
if (!sourceImageFile.Exists)
FileInfo archivedFile = new FileInfo((string)context.Parameters["ArchivedFilePath"]);
if (!archivedFile.Exists)
{
Logger.Instance.LogFormat(LogType.Error, this, Resources.FileNotFound, sourceImageFile.FullName);
Logger.Instance.LogFormat(LogType.Error, this, Resources.FileNotFound, archivedFile.FullName);
return;
}

string imagePath = (string)context.Parameters["ImagePath"];

foreach (string queueName in _settings.GetSetting("AlarmSourcePrinterJob", "PrintingQueueNames").GetStringArray())
{
var queues = _settings.GetSetting(SettingKeys.PrintingQueuesConfiguration).GetValue<PrintingQueuesConfiguration>();
Expand All @@ -69,7 +69,7 @@ private void PrintFaxes(IJobContext context, Operation operation)
}

PrintFaxTask task = new PrintFaxTask();
task.ImagePath = imagePath;
task.ArchivedFile = archivedFile.FullName;
task.Print(pq);
}
}
Expand Down Expand Up @@ -123,11 +123,25 @@ class PrintFaxTask
{
private IList<Image> _pages;

internal string ImagePath { private get; set; }
internal string ArchivedFile { private get; set; }

internal void Print(PrintingQueue queue)
{
_pages = SplitMultipageTiff(ImagePath);
switch (Path.GetExtension(ArchivedFile))
{
case ".pdf":
_pages = PdfHelper.ExtractImages(ArchivedFile);
break;

case ".tif":
_pages = TiffHelper.SplitMultipage(ArchivedFile);
break;

default:
Logger.Instance.LogFormat(LogType.Error, this, Resources.ArchivedFileWrongFormat, ArchivedFile);
return;
}


ThreadPool.QueueUserWorkItem(w => GdiPrinter.Print(queue, GdiPrinterPrintAction));
}
Expand All @@ -148,31 +162,6 @@ private bool GdiPrinterPrintAction(int pageIndex, Graphics graphics, Rectangle m

return pageIndex < _pages.Count;
}

private static IList<Image> SplitMultipageTiff(string tiffFileName)
{
List<Image> images = new List<Image>();

using (Image tiffImage = Image.FromFile(tiffFileName))
{
Guid objGuid = tiffImage.FrameDimensionsList[0];
FrameDimension dimension = new FrameDimension(objGuid);
int noOfPages = tiffImage.GetFrameCount(dimension);

foreach (Guid guid in tiffImage.FrameDimensionsList)
{
for (int index = 0; index < noOfPages; index++)
{
FrameDimension currentFrame = new FrameDimension(guid);
tiffImage.SelectActiveFrame(currentFrame, index);
images.Add((Image)tiffImage.Clone());
}
}
}

return images;
}

}

#endregion
Expand Down
11 changes: 10 additions & 1 deletion Jobs/Engine/AlarmSourcePrinter/Properties/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions Jobs/Engine/AlarmSourcePrinter/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -153,4 +153,8 @@
<data name="ExportJobDisplayName" xml:space="preserve">
<value>Alarmquellendruck</value>
</data>
<data name="ArchivedFileWrongFormat" xml:space="preserve">
<value>The archived file '{0}' has no printable format</value>
<comment> </comment>
</data>
</root>
30 changes: 1 addition & 29 deletions Jobs/Engine/Mailing/Helpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,35 +39,7 @@ internal static Stream ToStream(this Image image, ImageFormat format)
stream.Position = 0;
return stream;
}

internal static string[] ConvertTiffToJpegAndSplit(string fileName)
{
using (Image imageFile = Image.FromFile(fileName))
{
FrameDimension frameDimensions = new FrameDimension(imageFile.FrameDimensionsList[0]);
int frameNum = imageFile.GetFrameCount(frameDimensions);
string[] jpegPaths = new string[frameNum];

for (int frame = 0; frame < frameNum; frame++)
{
imageFile.SelectActiveFrame(frameDimensions, frame);
using (Bitmap bmp = new Bitmap(imageFile))
{
string tempFileName = Path.GetTempFileName();

FileInfo fileInfo = new FileInfo(tempFileName);
fileInfo.Attributes = FileAttributes.Temporary;

jpegPaths[frame] = tempFileName;

bmp.Save(jpegPaths[frame], ImageFormat.Jpeg);
}
}

return jpegPaths;
}
}


internal static Bitmap CombineBitmap(string[] files)
{
List<Bitmap> images = new List<Bitmap>();
Expand Down
26 changes: 17 additions & 9 deletions Jobs/Engine/Mailing/MailingJob.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
using AlarmWorkflow.Shared.Core;
using AlarmWorkflow.Shared.Diagnostics;
using AlarmWorkflow.Shared.ObjectExpressions;
using AlarmWorkflow.Shared.Specialized.Tiff;

namespace AlarmWorkflow.Job.MailingJob
{
Expand Down Expand Up @@ -185,21 +186,28 @@ private void SendMail(Operation operation, IJobContext context)

private void AttachImage(IJobContext context, MailMessage message)
{
if (context.Parameters.Keys.Contains("ImagePath"))
if (context.Parameters.Keys.Contains("ArchivedFilePath"))
{
string imagePath = (string)context.Parameters["ImagePath"];
if (!string.IsNullOrWhiteSpace(imagePath))
string filePath = (string)context.Parameters["ArchivedFilePath"];
if (!string.IsNullOrWhiteSpace(filePath))
{
if (File.Exists(imagePath))
if (File.Exists(filePath))
{
string[] splitFiles = Helpers.ConvertTiffToJpegAndSplit(imagePath);
Stream stream = Helpers.CombineBitmap(splitFiles).ToStream(ImageFormat.Jpeg);
if(Path.GetExtension(filePath) == ".tif")
{
string[] splitFiles = TiffHelper.ConvertToJpegAndSplit(filePath);
Stream stream = Helpers.CombineBitmap(splitFiles).ToStream(ImageFormat.Jpeg);

message.Attachments.Add(new Attachment(stream, ImageAttachmentFileName));
message.Attachments.Add(new Attachment(stream, ImageAttachmentFileName));

foreach (string s in splitFiles)
foreach (string s in splitFiles)
{
File.Delete(s);
}
}
else
{
File.Delete(s);
message.Attachments.Add(new Attachment(filePath));
}
}
}
Expand Down
1 change: 1 addition & 0 deletions Resources/Documentation/RelNotes/0.9.9.0.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Generelles
* ConfEd: Im Adressbuch sind die Einträge nun nach Nachname/Vorname sortiert.
* Als benutzerdefinierte Objektausdrücke sind nun auch Skripte in JavaScript möglich, siehe Anhang #2.
* Die Faxauswertung erkennt nun auch PDF-Dateien.
* Ausgerwertete Faxe können optional als PDF-Dokumente gespeichert werden.

Anhänge
-------
Expand Down
Loading