我为 Kofax 创建了一个自定义模块。该模块是一个 WinForms 应用程序,具有运行时表单和设置表单(管理模块)。
对于运行时应用程序,我使用此代码
Program.cs - 启动运行时表单
internal static class Program
{
[STAThread]
private static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new FrmMain());
}
}
FrmMain.cs - 初始化 UI 并创建所需的实例
public partial class FrmMain : Form
{
private BatchProcessor batchProcessor;
private BatchManager batchManager;
private SessionManager sessionManager;
public FrmMain()
{
InitializeComponent();
}
private void FrmMain_Load(object sender, EventArgs e)
{
try
{
batchProcessor = new BatchProcessor();
sessionManager = new SessionManager();
batchManager = new BatchManager(batchProcessor, sessionManager);
// UpdateUI();
timerBatchPolling.Enabled = true;
}
catch (Exception exception)
{
throw exception;
}
}
private void FrmMain_FormClosed(object sender, FormClosedEventArgs e)
{
timerBatchPolling.Enabled = false;
try
{
sessionManager.Logout();
}
catch (Exception exception)
{
throw exception;
}
}
private void timerBatchPolling_Tick(object sender, EventArgs e)
{
timerBatchPolling.Enabled = false;
batchManager.BatchPolling();
// UpdateUI();
timerBatchPolling.Enabled = true;
}
}
BatchManager.cs - 要求处理下一批
internal class BatchManager
{
private BatchProcessor batchProcessor;
private SessionManager sessionManager;
public IBatch CurrentActiveBatch { get; private set; }
public BatchManager(BatchProcessor batchProcessor, SessionManager sessionManager)
{
this.batchProcessor = batchProcessor;
this.sessionManager = sessionManager;
this.sessionManager.LoginToRuntimeSession();
}
public void BatchPolling()
{
CurrentActiveBatch = sessionManager.GetNextBatch();
if (CurrentActiveBatch != null)
{
batchProcessor.ProcessBatch(CurrentActiveBatch);
}
else
{
sessionManager.Logout();
}
}
}
BatchProcessor.cs - 处理批处理
internal class BatchProcessor
{
public void ProcessBatch(IBatch batch)
{
// ...
}
}
我刚刚看到也可以将自定义模块作为服务运行。我不知道如何注册它们或如何设置代码,所以我问是否有办法更改我的代码以将模块变成服务而不是表单应用程序。
感谢帮助!