Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

closes:#260 #261

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
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
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<UserSecretsId>1e4848b5-b05b-4295-9890-853a993c210c</UserSecretsId>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ private ActionResult<RenderResponseDto> RenderZpl(RenderRequestDto request)
var pdfs = new List<RenderLabelDto>();
foreach (var labelInfo in analyzeInfo.LabelInfos)
{
if (labelInfo.ZplElements?.Length <= 0)
{
continue;
}
if (request.Type == "image")
{
var imageData = drawer.Draw(labelInfo.ZplElements, request.LabelWidth, request.LabelHeight, request.PrintDensityDpmm);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:2019",
"applicationUrl": "http://localhost:8019",
"sslPort": 44301
}
},
Expand All @@ -21,8 +21,7 @@
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"applicationUrl": "https://localhost:5001;http://localhost:5000"
}
},
"WSL": {
"commandName": "WSL2",
Expand Down
60 changes: 60 additions & 0 deletions src/BinaryKits.Zpl.Viewer.WebApi/ServiceInstall.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
@ECHO OFF
setlocal enabledelayedexpansion
color 00
title NSSM�����Զ���װ��������(��Ҫϵͳ����ԱȨ�޲�������)
::��������װ����
@echo ������������������NSSM.exe�����д�������,�뽫��Ҫ��װ��exe����NSSM.exe�������������������ͬһ���ļ��С�


PUSHD %~DP0 & cd /d "%~dp0"
%1 %2
mshta vbscript:createobject("shell.application").shellexecute("%~s0","goto :runas","","runas",1)(window.close)&goto :eof
:runas


echo.
echo.
echo ######################��ѡ��Ҫִ�еIJ���######################
echo ----------------------1.��װ������Ŀ���Զ�����----------------------
echo ----------------------2.ж�ظ÷���----------------------------------
echo.
echo.
echo ��ѡ��Ҫִ�еIJ���
set /p sel=
@set clientname=BinaryKitsZPL
@set clientexe=D:\Program Files (x86)\BinaryKits\BinaryKits.Zpl.Viewer.WebApi.exe
::@set clientDescript=ZPLԤ������������ͽӿڿ�ͨ��http://localhost:8019��ַ����-- Description=%clientDescript%

@echo on
if %sel% equ 1 (
::for /f "tokens=* delims=" %%a in ('sc query %clientname% | findstr /i "δ��װ"') do set output=%%a
::if %output% equ ''(
nssm install %clientname% %clientexe%
if %ERRORLEVEL% equ 1 (
ECHO ִ��nssm install�������
pause>nul
exit 0
)


nssm start %clientname%
)

if %sel% equ 2 (
nssm stop %clientname%
echo %ERRORLEVEL%
if %ERRORLEVEL% equ 1 (
ECHO ִ��nssm stop�������
pause>nul
exit 0
)
nssm remove %clientname% confirm
if %ERRORLEVEL% NEQ 1 (
ECHO ִ��nssm remove�������
pause>nul
exit 0
)
)
echo ִ�����,������˳�...
pause>nul
exit 0
3 changes: 1 addition & 2 deletions src/BinaryKits.Zpl.Viewer.WebApi/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public void ConfigureServices(IServiceCollection services)
builder.WithOrigins(allowedOrigins.Split(","))
.AllowAnyHeader()
.AllowAnyMethod();

});
});
}
Expand All @@ -50,14 +51,12 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
app.UseDeveloperExceptionPage();
}

app.UseCors();

app.UseSwagger();
app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "BinaryKits.Zpl.Viewer.WebApi v1"));

app.UseRouting();

app.UseDefaultFiles();
app.UseStaticFiles();

Expand Down
3 changes: 2 additions & 1 deletion src/BinaryKits.Zpl.Viewer.WebApi/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@
"Microsoft.Hosting.Lifetime": "Information"
}
},
"AllowedHosts": "*"
"AllowedHosts": "*",
"Urls": "http://localhost:8019"
}
Binary file added src/BinaryKits.Zpl.Viewer.WebApi/nssm.exe
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace BinaryKits.Zpl.Viewer.CommandAnalyzers
{
public class DownloadGraphicsZplCommandAnalyzer : ZplCommandAnalyzerBase
{
private static readonly Regex commandRegex = new Regex( @"^~DG(\w:)?(.*?\..+?),(\d+),(\d+),(.+)$",RegexOptions.Compiled);
private static readonly Regex commandRegex = new Regex( @"^~DG(\w:)?(.*?|\..+?),(\d+),(\d+),(.+)$",RegexOptions.Compiled);

private readonly IPrinterStorage _printerStorage;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace BinaryKits.Zpl.Viewer.CommandAnalyzers
{
public class RecallGraphicZplCommandAnalyzer : ZplCommandAnalyzerBase
{
private static readonly Regex commandRegex = new Regex(@"^\^XG(\w:)?(.*?\..+?)(?:,(\d*))?(?:,(\d*))?$", RegexOptions.Compiled);
private static readonly Regex commandRegex = new Regex(@"^\^XG(\w:)?(.*?|\..+?)(?:,(\d*))?(?:,(\d*))?$", RegexOptions.Compiled);

public RecallGraphicZplCommandAnalyzer(VirtualPrinter virtualPrinter) : base("^XG", virtualPrinter) { }

Expand Down
96 changes: 53 additions & 43 deletions src/BinaryKits.Zpl.Viewer/ZplAnalyzer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public AnalyzeInfo Analyze(string zplData)
var elements = new List<ZplElementBase>();
for (var i = 0; i < zplCommands.Length; i++)
{
var currentCommand = zplCommands[i];
var currentCommand = zplCommands[i].Trim();//any command can not end with white-space

if (this._labelStartCommand.Equals(currentCommand.Trim(), StringComparison.OrdinalIgnoreCase))
{
Expand Down Expand Up @@ -134,61 +134,71 @@ public AnalyzeInfo Analyze(string zplData)

private string[] SplitZplCommands(string zplData)
{
if (string.IsNullOrWhiteSpace(zplData))
try
{
return Array.Empty<string>();
}

var cleanZpl = verticalWhitespaceRegex.Replace(zplData, string.Empty);
char caret = '^';
char tilde = '~';
List<string> results = new(200);
StringBuilder buffer = new(2000);
HashSet<string> ignoredCommandsHS = new HashSet<string>(ignoredCommands);
for (int i = 0; i < cleanZpl.Length; i++)
{
char c = cleanZpl[i];
if (c == caret || c == tilde)
if (string.IsNullOrWhiteSpace(zplData))
{
string command = buffer.ToString();
buffer.Clear();

// all commands have at least 3 chars, even ^A because of required font parameter
if (command.Length > 2)
return Array.Empty<string>();
}
zplData = zplData.Replace("\u0010CT~", "~CT").Replace("~CD", "^CD").Replace("~CC^", "^CC").Replace("~CT~", "");

var cleanZpl = verticalWhitespaceRegex.Replace(zplData, string.Empty);
char caret = '^';
char tilde = '~';
List<string> results = new(200);
StringBuilder buffer = new(2000);
HashSet<string> ignoredCommandsHS = new HashSet<string>(ignoredCommands);
for (int i = 0; i < cleanZpl.Length; i++)
{
char c = cleanZpl[i];
if (c == caret || c == tilde)
{
PatchCommand(ref command, ref caret, ref tilde);

var commandLetters = command.Substring(1, 2).ToUpper();
string command = buffer.ToString();
buffer.Clear();

if (commandLetters == "CT")
// all commands have at least 3 chars, even ^A because of required font parameter
if (command.Length > 2)
{
tilde = command[3];
PatchCommand(ref command, ref caret, ref tilde);

var commandLetters = command.Substring(1, 2).ToUpper();

if (commandLetters == "CT")
{
tilde = command.Length > 3 ? command[3] : command[0];
}
else if (commandLetters == "CC")
{
caret = command.Length > 3 ? command[3] : command[0];
}
else if (!ignoredCommandsHS.Contains(commandLetters))
{
results.Add(command);
}
}
else if (commandLetters == "CC")
// likely invalid command
else if (command.Trim().Length > 0)
{
caret = command[3];
results.Add(command.Trim());
}
else if (!ignoredCommandsHS.Contains(commandLetters))
{
results.Add(command);
}
}
// likely invalid command
else if (command.Trim().Length > 0)
{
results.Add(command.Trim());
// no else case, multiple ^ or ~ in a row should not be valid commands to be processed
}
// no else case, multiple ^ or ~ in a row should not be valid commands to be processed
buffer.Append(c);
}
buffer.Append(c);
string lastCommand = buffer.ToString();
if (lastCommand.Length > 0)
{
PatchCommand(ref lastCommand, ref caret, ref tilde);
results.Add(lastCommand);
}
return results.ToArray();

}
string lastCommand = buffer.ToString();
if (lastCommand.Length > 0)
catch (Exception exception)
{
PatchCommand(ref lastCommand, ref caret, ref tilde);
results.Add(lastCommand);
Console.WriteLine(exception.ToString());
return new string[0];
}
return results.ToArray();
}

private void PatchCommand(ref string command, ref char caret, ref char tilde)
Expand Down