Implemented VirtualPrinterDriver project

This commit is contained in:
Marco Batzinger 2020-10-19 17:44:50 +02:00
parent f29c84821b
commit 5c87967c3f
125 changed files with 8191 additions and 0 deletions

View file

@ -0,0 +1,20 @@
using JetBrains.Annotations;
namespace VirtualPrinter.Agent.Core
{
public interface IConfig
{
/// <summary>
/// The mask for the filename.
/// </summary>
/// <remarks>The mask can be look like {yyyy}{MM}{DD}{hh}{mm}{ss}{job05}{page03}</remarks>
[NotNull]
string FileNameMask { get; }
/// <summary>
/// The port of the printer.
/// </summary>
/// <remarks>E.g. 9101</remarks>
short PrinterPort { get; }
}
}

View file

@ -0,0 +1,7 @@
namespace VirtualPrinter.Agent.Core
{
public interface IDirectoryHelper
{
string GetOutputDirectory(IExConfig config);
}
}

View file

@ -0,0 +1,36 @@
using System;
using JetBrains.Annotations;
using VirtualPrinter.Agent.Core.Enums;
namespace VirtualPrinter.Agent.Core
{
public interface IExConfig : IConfig
{
/// <summary>
/// Splits a preconverter into two strings.
/// </summary>
/// <remarks>e.g. "C:\Program Files (x86)\MySoftware\MySoftware.exe PRINT" now becomes: string 1 = "C:\Program Files (x86)\MySoftware\MySoftware.exe" and string 2 = "PRINT"</remarks>
[NotNull]
Tuple<string, string> ResolvedPreconverter { get; }
/// <summary>
/// Splits a postconverter into two strings.
/// </summary>
/// <remarks>e.g. "C:\Program Files (x86)\MySoftware\MySoftware.exe PRINTCOMPLETE" now becomes: string 1 = "C:\Program Files (x86)\MySoftware\MySoftware.exe" and string 2 = "PRINTCOMPLETE"</remarks>
[NotNull]
Tuple<string, string> ResolvedPostconverter { get; }
/// <summary>
/// The full path of the output directory.
/// </summary>
[NotNull]
string ResolvedOutputDirectory { get; }
/// <summary>
/// An intermediate format which is read by the printer or similar.
/// </summary>
IntermediateFormat IntermediateFormat { get; }
}
}

View file

@ -0,0 +1,34 @@
using JetBrains.Annotations;
namespace VirtualPrinter.Agent.Core
{
/// <summary>
/// The information of the job.
/// </summary>
public interface IJob
{
/// <summary>
/// The path to the file containing the data.
/// </summary>
[NotNull]
string RawDataPath { get; }
/// <summary>
/// The path to the ini file.
/// </summary>
[NotNull]
string IniDataPath { get; }
/// <summary>
/// Several job infos.
/// </summary>
[NotNull]
IJobInfo JobInfo { get; }
/// <summary>
/// Information about the session.
/// </summary>
[NotNull]
ISessionInfo SessionInfo { get; }
}
}

View file

@ -0,0 +1,15 @@
using System.IO;
using JetBrains.Annotations;
namespace VirtualPrinter.Agent.Core
{
public interface IJobFactory
{
[CanBeNull]
IJob Create([NotNull]string printerName, [NotNull]Stream stream);
[NotNull]
IJob Create([NotNull]string iniPath, [NotNull]string rawPath, IJobInfo jobInfo, ISessionInfo sessionInfo);
}
}

View file

@ -0,0 +1,15 @@
using System.Printing;
namespace VirtualPrinter.Agent.Core
{
public interface IJobInfo
{
int JobId { get; set; }
string Name { get; set; }
string DomainName { get; set; }
string MachineName { get; set; }
string UserName { get; set; }
PrintJobStatus Status { get; set; }
string DeviceName { get; set; }
}
}

View file

@ -0,0 +1,18 @@
using System;
using JetBrains.Annotations;
namespace VirtualPrinter.Agent.Core
{
public interface IJobProcessor
{
/// <summary>
/// Processes an <see cref="IJob"/> passed to it with the information from the <see cref="IUserConfig"/>.
/// </summary>
/// <param name="job"></param>
/// <param name="userConfig"></param>
/// <exception cref="ArgumentNullException">Throws when the <param name="job">job</param> or the <param name="userConfig"> is null.</param></exception>
/// <exception cref="PostScriptConversionException">The job cannot be converted. There is no redirect to a printer. Will not be thrown.</exception>
void Process([NotNull]IJob job, [NotNull]IUserConfig userConfig);
}
}

View file

@ -0,0 +1,17 @@
using System;
using JetBrains.Annotations;
namespace VirtualPrinter.Agent.Core
{
public interface IJobRedirector
{
/// <summary>
/// Redirects the information from the <param name="job">job</param> and the <param name="userConfig">config</param> to an Process to be executed.
/// </summary>
/// <param name="job"></param>
/// <param name="userConfig"></param>
/// <exception cref="ArgumentNullException">Throws when the <see cref="IJob"/> or the <see cref="IUserConfig"/> is null.</exception>
void Redirect([NotNull]IJob job, [NotNull]IUserConfig userConfig);
}
}

View file

@ -0,0 +1,47 @@
using System;
using JetBrains.Annotations;
namespace VirtualPrinter.Agent.Core
{
public interface IJobService
{
/// <summary>
/// Starts the <see cref="IJob"/> in a new Process.
/// </summary>
/// <param name="job"></param>
/// <exception cref="ArgumentNullException">Throws when the <see cref="IJob"/> is null.</exception>
void Start([NotNull]IJob job);
/// <summary>
/// Creates an new <see cref="IJob"/> from the <param name="iniPath">ini file</param> and the <param name="rawPath">raw path</param>.
/// </summary>
/// <param name="iniPath"></param>
/// <param name="rawPath"></param>
/// <returns>An new <see cref="IJob"/> object.</returns>
/// <exception cref="ArgumentException">Throws when the <paramref name="iniPath"/> or the <paramref name="rawPath"/> is null or empty.</exception>
[NotNull]
IJob CreateJob([NotNull]string iniPath, [NotNull]string rawPath);
/// <summary>
/// Reads the <see cref="PrintStatus"/> from the <paramref name="iniPath"/>
/// </summary>
/// <param name="iniPath"></param>
/// <returns>A <see cref="PrintStatus"/></returns>
/// <exception cref="ArgumentException">Throws when the <paramref name="iniPath"/> is null or empty.</exception>
PrintStatus ReadStatus([NotNull]string iniPath);
/// <summary>
/// Starts a new process to finish the <see cref="IJob"/>.
/// </summary>
/// <param name="job"></param>
void Finish([NotNull]IJob job);
/// <summary>
/// Gets the <see cref="JobStatus"/> from the ini file.
/// </summary>
/// <param name="iniPath">The path to the ini file</param>
/// <returns><see cref="JobStatus"/></returns>
JobStatus ReadJobStatus(string iniPath);
}
}

View file

@ -0,0 +1,15 @@
using System;
using VirtualPrinter.Agent.Lib.Model;
namespace VirtualPrinter.Agent.Core
{
public interface IPostScriptConverter
{
event EventHandler<IJob> ProgressInitialized;
event EventHandler<IJob> ProgressFinished;
event EventHandler<ProgressUpdateArgs> ProgressUpdate;
void Convert(IJob job, string target, PostScriptRenderOptions options);
}
}

View file

@ -0,0 +1,29 @@
using JetBrains.Annotations;
namespace VirtualPrinter.Agent.Core
{
public interface IRegistryRepository
{
/// <summary>
/// Try to get the ghostscript path from.
/// </summary>
/// <returns>True if the path exists.</returns>
[ContractAnnotation("=>true,path:notnull; =>false,path:null")]
bool TryGetGhostscriptPath(out string path);
/// <summary>
/// Get the <see cref="IExConfig"/> from the registry.
/// </summary>
/// <returns>The configuration that was read from the registry in HKEY_LOCAL_MACHINE\SOFTWARE.</returns>
[NotNull]
IExConfig GetRegistryConfig();
/// <summary>
/// Get the <see cref="IUserConfig"/> from the registry.
/// </summary>
/// <param name="sid">The security identifier with which each Windows user can be clearly identified in the network.</param>
/// <returns>The configuration that was read from the registry in HKEY_USERS</returns>
[NotNull]
IUserConfig GetUserRegistryConfig([NotNull]string sid);
}
}

View file

@ -0,0 +1,11 @@
namespace VirtualPrinter.Agent.Core
{
public interface ISessionInfo
{
int Id { get; set; }
string Desktop { get; set; }
string Sid { get; set; }
}
}

View file

@ -0,0 +1,16 @@
using JetBrains.Annotations;
namespace VirtualPrinter.Agent.Core
{
public interface IShell
{
void WriteIniEntry(string section, string key, string value, string iniFilePath);
[NotNull]
T ReadIniEntry<T>(string section, string key, string iniFilePath);
void Execute(IJobInfo job, ISessionInfo session, string exe, string args);
bool FileExists([NotNull]string path);
}
}

View file

@ -0,0 +1,26 @@
using JetBrains.Annotations;
namespace VirtualPrinter.Agent.Core
{
public interface IUserConfig
{
/// <summary>
/// The printer stored in the registry.
/// </summary>
[CanBeNull]
string RedirectPrinter { get; }
/// <summary>
/// The DPI value stored in the registry.
/// </summary>
/// <remarks>Initial value is null.</remarks>
double? UserRenderDpi { get; }
/// <summary>
/// The format that you choose on your client side stored in the registry.
/// </summary>
/// <remarks>Intital value is PDF</remarks>
[NotNull]
string Format { get; }
}
}

View file

@ -0,0 +1,12 @@
using System;
namespace VirtualPrinter.Agent.Core
{
public interface IVirtualPrinter : IDisposable
{
/// <summary>
/// Initialize the virtual printer.
/// </summary>
void Init();
}
}

View file

@ -0,0 +1,8 @@
namespace VirtualPrinter.Agent.Core
{
public interface IVirtualPrinterService
{
void Start();
void Stop();
}
}

View file

@ -0,0 +1,9 @@
namespace VirtualPrinter.Agent.Core
{
public enum JobStatus
{
Completed,
Failed,
InProgress
}
}