Skip to content

Commit d57f784

Browse files
committed
Added Readme and Service installer
1 parent a5dd691 commit d57f784

8 files changed

+177
-8
lines changed

CreateTables.sql

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/****** Object: Table [dbo].[LabelSpooler] Script Date: 03/03/2020 17:02:21 ******/
2+
SET ANSI_NULLS ON
3+
GO
4+
5+
SET QUOTED_IDENTIFIER ON
6+
GO
7+
8+
CREATE TABLE [dbo].[LabelSpooler](
9+
[jobID] [bigint] IDENTITY(1,1) NOT NULL,
10+
[printerName] [varchar](64) NOT NULL,
11+
[printData] [text] NOT NULL,
12+
[jobStatus] [tinyint] NOT NULL,
13+
[jobCreated] [datetime] NOT NULL,
14+
[jobRetries] [int] NOT NULL,
15+
[jobTag] [varchar](128) NULL,
16+
[jobLastSent] [datetime] NULL,
17+
CONSTRAINT [PK_LabelSpooler] PRIMARY KEY CLUSTERED
18+
(
19+
[jobID] ASC
20+
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
21+
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
22+
GO
23+
24+
ALTER TABLE [dbo].[LabelSpooler] ADD CONSTRAINT [DF_LabelSpooler_jobStatus] DEFAULT ((0)) FOR [jobStatus]
25+
GO
26+
27+
ALTER TABLE [dbo].[LabelSpooler] ADD CONSTRAINT [DF_LabelSpooler_jobCreated] DEFAULT (getdate()) FOR [jobCreated]
28+
GO
29+
30+
ALTER TABLE [dbo].[LabelSpooler] ADD CONSTRAINT [DF_LabelSpooler_jobRetries] DEFAULT ((0)) FOR [jobRetries]
31+
GO
32+
33+
ALTER TABLE [dbo].[LabelSpooler] ADD CONSTRAINT [DF_LabelSpooler_lastRetry] DEFAULT (NULL) FOR [jobLastSent]
34+
GO

DB.cs

+6-1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ public static class DB
2222
private static string _dbUsername;
2323
private static string _dbDatabase;
2424
private static string _dbPassword;
25+
private static bool _logAlreadyLogged;
2526

2627
/* Properties */
2728
public static string Server
@@ -114,11 +115,15 @@ public static DataTable GetJobs(int jobStatus = 0)
114115
SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();
115116
dataTable.Load((IDataReader)sqlDataReader);
116117
DB.conn.Close();
118+
_logAlreadyLogged = false;
117119
return dataTable;
118120
}
119121
catch (Exception ex)
120122
{
121-
Globals.eventRecord("Error getting Jobs: " + ex.Message, EventLogEntryType.Error);
123+
if (_logAlreadyLogged==false) {
124+
Globals.eventRecord("Error getting Jobs: " + ex.Message, EventLogEntryType.Error);
125+
_logAlreadyLogged = true;
126+
}
122127
return dataTable;
123128
}
124129
}

Globals.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public static void initialize()
4141
appPath = AppDomain.CurrentDomain.BaseDirectory;
4242
INIFilename = appPath + "config.ini";
4343

44-
string AppVersion = Assembly.GetExecutingAssembly().GetName().Version.ToString();
44+
appVersion = Assembly.GetExecutingAssembly().GetName().Version.ToString();
4545

4646
if (File.Exists(INIFilename))
4747
{

LabelSpooler.csproj

+24
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,21 @@
1111
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
1212
<FileAlignment>512</FileAlignment>
1313
<Deterministic>true</Deterministic>
14+
<PublishUrl>publish\</PublishUrl>
15+
<Install>true</Install>
16+
<InstallFrom>Disk</InstallFrom>
17+
<UpdateEnabled>false</UpdateEnabled>
18+
<UpdateMode>Foreground</UpdateMode>
19+
<UpdateInterval>7</UpdateInterval>
20+
<UpdateIntervalUnits>Days</UpdateIntervalUnits>
21+
<UpdatePeriodically>false</UpdatePeriodically>
22+
<UpdateRequired>false</UpdateRequired>
23+
<MapFileExtensions>true</MapFileExtensions>
24+
<ApplicationRevision>0</ApplicationRevision>
25+
<ApplicationVersion>1.0.0.%2a</ApplicationVersion>
26+
<IsWebBootstrapper>false</IsWebBootstrapper>
27+
<UseApplicationTrust>false</UseApplicationTrust>
28+
<BootstrapperEnabled>true</BootstrapperEnabled>
1429
</PropertyGroup>
1530
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
1631
<PlatformTarget>AnyCPU</PlatformTarget>
@@ -38,7 +53,9 @@
3853
<Reference Include="System" />
3954
<Reference Include="System.Configuration.Install" />
4055
<Reference Include="System.Core" />
56+
<Reference Include="System.Drawing" />
4157
<Reference Include="System.Management" />
58+
<Reference Include="System.Windows.Forms" />
4259
<Reference Include="System.Xml.Linq" />
4360
<Reference Include="System.Data.DataSetExtensions" />
4461
<Reference Include="Microsoft.CSharp" />
@@ -74,5 +91,12 @@
7491
<DependentUpon>ProjectInstaller.cs</DependentUpon>
7592
</EmbeddedResource>
7693
</ItemGroup>
94+
<ItemGroup>
95+
<BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1">
96+
<Visible>False</Visible>
97+
<ProductName>.NET Framework 3.5 SP1</ProductName>
98+
<Install>false</Install>
99+
</BootstrapperPackage>
100+
</ItemGroup>
77101
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
78102
</Project>

LabelSpooler.sln

+5
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ MinimumVisualStudioVersion = 10.0.40219.1
66
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LabelSpooler", "LabelSpooler.csproj", "{64DD8281-590E-46B6-8C6D-2AA4A4BB725F}"
77
EndProject
88
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{EB4CD78B-16A8-4F03-9E73-332FA350508C}"
9+
ProjectSection(SolutionItems) = preProject
10+
config-example.ini = config-example.ini
11+
CreateTables.sql = CreateTables.sql
12+
README.md = README.md
13+
EndProjectSection
914
EndProject
1015
Global
1116
GlobalSection(SolutionConfigurationPlatforms) = preSolution

Program.cs

+31-6
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
using System.Linq;
44
using System.ServiceProcess;
55
using System.Text;
6+
using System.Configuration.Install;
7+
using System.IO;
8+
using System.Reflection;
69

710
namespace LabelSpooler
811
{
@@ -11,14 +14,36 @@ static class Program
1114
/// <summary>
1215
/// Punto di ingresso principale dell'applicazione.
1316
/// </summary>
14-
static void Main()
17+
static void Main(string[] args)
1518
{
16-
ServiceBase[] ServicesToRun;
17-
ServicesToRun = new ServiceBase[]
19+
//AppDomain.CurrentDomain.UnhandledException += CurrentDomainUnhandledException;
20+
21+
22+
if (System.Environment.UserInteractive)
1823
{
19-
new LabelSpoolerService()
20-
};
21-
ServiceBase.Run(ServicesToRun);
24+
string parameter = string.Concat(args);
25+
switch (parameter)
26+
{
27+
case "--install":
28+
ManagedInstallerClass.InstallHelper(new string[] { Assembly.GetExecutingAssembly().Location });
29+
break;
30+
31+
case "--uninstall":
32+
ManagedInstallerClass.InstallHelper(new string[] { "/u", Assembly.GetExecutingAssembly().Location });
33+
break;
34+
}
35+
}
36+
else
37+
{
38+
ServiceBase[] ServicesToRun;
39+
ServicesToRun = new ServiceBase[]
40+
{
41+
new LabelSpoolerService()
42+
};
43+
ServiceBase.Run(ServicesToRun);
44+
}
2245
}
46+
47+
2348
}
2449
}

README.md

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
LabelSpooler
2+
============
3+
4+
This program polls RAW data from a SQL Server database table and sends data to a printer.
5+
It is useful to send RAW ZPL to Zebra printers, for example.
6+
7+
Installation
8+
------------
9+
10+
- Grab the latest release file
11+
- Extract the zip to a folder of your choice (for example c:\LabelSpooler\ )
12+
- Create the LabelSpooler table in the database with file CreateTables.sql
13+
- Create the file config.ini by copying the config-example.ini
14+
- Install service from an elevated command prompt:
15+
```
16+
c:\LabelSpooler\LabelSpooler.exe --install
17+
```
18+
19+
Uninstallation
20+
--------------
21+
22+
- Uninstall service from an elevated command prompt:
23+
24+
```
25+
c:\LabelSpooler\LabelSpooler.exe --uninstall
26+
```
27+
28+
Need Commercial Support?
29+
------------------------
30+
31+
Send me a mail: [email protected]

config-example.ini

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
[database]
2+
; Database Configuration
3+
server = yoursqlserver
4+
database = database
5+
username = user
6+
password = password
7+
8+
[printers]
9+
; Printers Remapping Configuration
10+
; Syntax is:
11+
; SYSTEM_PRINTER_NAME = PRINTER_QUEUE
12+
; where PRINTER_QUEUE can be another system's printer name or a UNC path
13+
; by default program first seek in this remapping and if no remap is
14+
; found it tries keeps the field value as printer queue/name
15+
16+
; Map printer to a prinserver Queue
17+
; PRINTER_1 = \\PRINTSERVER\PRINTER1
18+
19+
; Redirect Printer to another Printer
20+
; PRINTER_2 = PRINTER_1
21+
22+
[print_settings]
23+
; Max Retries
24+
; When a print fails, et the maximum number of Retries
25+
; max_retries = 3
26+
27+
; Retry Interval
28+
; Specify the time between the next retry, in seconds
29+
; retry_interval = 5
30+
31+
[spooler]
32+
; Spooler Polling Interval in milliseconds, default is 250
33+
; poll_interval = 250
34+
35+
; Run Housekeeper:
36+
; Delete printed records.
37+
; if minutes is 0 housekeeper is disabled, otherwise it is invoked at interval
38+
; specified.
39+
; Default is 60 minutes
40+
; housekeeper_run_interval = 1440
41+
42+
; Housekeeping Interval
43+
; How long records can stay in the table?
44+
; default is 1440 minutes (24h)
45+
; housekeeping_interval = 1440

0 commit comments

Comments
 (0)