From 0ad43bc44c072dd9fa50c8d812cbecb6a918f762 Mon Sep 17 00:00:00 2001 From: karronoli Date: Fri, 2 Oct 2020 23:56:45 +0900 Subject: [PATCH 1/7] Create codacy-analysis.yml --- .github/workflows/codacy-analysis.yml | 44 +++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 .github/workflows/codacy-analysis.yml diff --git a/.github/workflows/codacy-analysis.yml b/.github/workflows/codacy-analysis.yml new file mode 100644 index 0000000..c9e3e9c --- /dev/null +++ b/.github/workflows/codacy-analysis.yml @@ -0,0 +1,44 @@ +# This workflow checks out code, performs a Codacy security scan +# and integrates the results with the +# GitHub Advanced Security code scanning feature. For more information on +# the Codacy security scan action usage and parameters, see +# https://github.com/codacy/codacy-analysis-cli-action. +# For more information on Codacy Analysis CLI in general, see +# https://github.com/codacy/codacy-analysis-cli. + +name: Codacy Security Scan + +on: + push: + branches: [ "master", "main" ] + pull_request: + branches: [ "master", "main" ] + +jobs: + codacy-security-scan: + name: Codacy Security Scan + runs-on: ubuntu-latest + steps: + # Checkout the repository to the GitHub Actions runner + - name: Checkout code + uses: actions/checkout@v2 + + # Execute Codacy Analysis CLI and generate a SARIF output with the security issues identified during the analysis + - name: Run Codacy Analysis CLI + uses: codacy/codacy-analysis-cli-action@1.0.0 + with: + # Check https://github.com/codacy/codacy-analysis-cli#project-token to get your project token from your Codacy repository + # You can also omit the token and run the tools that support default configurations + project-token: ${{ secrets.CODACY_PROJECT_TOKEN }} + verbose: true + output: results.sarif + format: sarif + # Force 0 exit code to allow SARIF file generation + # This will handover control about PR rejection to the GitHub side + max-allowed-issues: 2147483647 + + # Upload the SARIF file generated in the previous step + - name: Upload SARIF results file + uses: github/codeql-action/upload-sarif@v1 + with: + sarif_file: results.sarif From 71e19c730b23e8f9ca7fda369970e39a8ae81039 Mon Sep 17 00:00:00 2001 From: karronoli Date: Mon, 12 Oct 2020 14:48:04 +0900 Subject: [PATCH 2/7] test: Check code128 barcode size --- UnitTestProject/UnitTest1.cs | 73 ++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) diff --git a/UnitTestProject/UnitTest1.cs b/UnitTestProject/UnitTest1.cs index 8f4387e..d613fa2 100644 --- a/UnitTestProject/UnitTest1.cs +++ b/UnitTestProject/UnitTest1.cs @@ -301,5 +301,78 @@ public async Task ExampleGraphic() CollectionAssert.AreEqual(expected, actual); } } + + [TestMethod] + public async Task AddCODE128() + { + var task = ResponseForPrint(); + int bar_width = 1, symbol_height = 2, X = 3, Y = 4; + // start B + data1 + shift C + data2 + check + stop + var print_data = "AaBbCc123456789"; + var symbol_width = 11 + 11 * 7 + 11 + 11 * 8 / 2 + 11 + 13; + var operation = new byte[] { ESC }.Concat(Encoding.ASCII.GetBytes( + "BG" + $"{bar_width:D2}" + $"{symbol_height:D3}" + + ">HAaBbCc1>C23456789")); + + using (var printer = new Printer(printEP)) + { + var size_codeBC = printer.Barcode.AddCODE128(bar_width, symbol_height, print_data, + (Size size) => + { + Assert.AreEqual(symbol_width, size.Width); + Assert.AreEqual(symbol_height, size.Height); + + printer.MoveToX(X); + printer.MoveToY(Y); + }); + Assert.AreEqual(symbol_width, size_codeBC.Width); + Assert.AreEqual(symbol_height, size_codeBC.Height); + + var dummy = Encoding.ASCII.GetBytes("dummy"); + printer.PushOperation(dummy); + CollectionAssert.AreEqual(dummy, printer.PopOperation()); + + // start B + data + check + stop + var symbol_width_codeB = 11 + 11 * 8 + 11 + 13; + var size_codeB = printer.Barcode.AddCODE128(bar_width, symbol_height, + "ABC12345", + (Size size) => + { + Assert.AreEqual(symbol_width_codeB, size.Width); + Assert.AreEqual(symbol_height, size.Height); + }); + Assert.AreEqual(symbol_width_codeB, size_codeB.Width); + Assert.AreEqual(symbol_height, size_codeB.Height); + printer.PopOperation(); + + try + { + // Explicitly passing the start code throws an exception. + _ = printer.Barcode.AddCODE128(1, 1, ">G", (Size _) => { }); + Assert.Fail(); + } + catch (Exception e) + { + Assert.IsInstanceOfType(e, typeof(TinySatoArgumentException)); + } + + printer.Send(); + } + + var expected = (new byte[] { ENQ, STX }).Concat(new string[] + { + "A", + $"H{X:D4}", + $"V{Y:D4}", + }.SelectMany(x => (new byte[] { ESC }).Concat(Encoding.ASCII.GetBytes(x)))) + .Concat(operation) + .Concat(new byte[] { ESC, ASCII_Z, ETX }); + + using (task) + { + var actual = await task; + CollectionAssert.AreEqual(expected.ToArray(), actual); + } + } } } From 3aef94b5e6dc41c21dfb2200938b6e71dcbcf53a Mon Sep 17 00:00:00 2001 From: karronoli Date: Mon, 12 Oct 2020 14:51:29 +0900 Subject: [PATCH 3/7] feat: Add PopOperation for tuning operations --- TinySato/Printer.cs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/TinySato/Printer.cs b/TinySato/Printer.cs index de1791b..5eea86d 100644 --- a/TinySato/Printer.cs +++ b/TinySato/Printer.cs @@ -117,6 +117,14 @@ internal void Add(byte[] raw_operation) operations.Add(raw_operation); } + public byte[] PopOperation() + { + var last = operations.Last(); + operations.RemoveAt(operations.Count - 1); + + return last; + } + protected void Insert(int index, string operation) { operations.Insert( From 160772e938403834d7d0596945b169f88bf42434 Mon Sep 17 00:00:00 2001 From: karronoli Date: Mon, 12 Oct 2020 14:52:37 +0900 Subject: [PATCH 4/7] feat: Change `Add(string)` to `PushOperation(IEnumerable)`. pairing for PopOperation & PushOperation --- TinySato/Printer.cs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/TinySato/Printer.cs b/TinySato/Printer.cs index 5eea86d..19685aa 100644 --- a/TinySato/Printer.cs +++ b/TinySato/Printer.cs @@ -107,7 +107,7 @@ public Printer(IPEndPoint endpoint) throw new TinySatoIOException($"Printer is busy. endpoint: {endpoint}, status: {this.status}"); } - public void Add(string operation) + internal void Add(string operation) { operations.Add(Encoding.ASCII.GetBytes(ESC + operation)); } @@ -117,6 +117,11 @@ internal void Add(byte[] raw_operation) operations.Add(raw_operation); } + public void PushOperation(IEnumerable operation) + { + operations.Add(operation.ToArray()); + } + public byte[] PopOperation() { var last = operations.Last(); From ba810ca2cb2ea7f0b90d8e6448d3c1d2d89edd9b Mon Sep 17 00:00:00 2001 From: karronoli Date: Mon, 12 Oct 2020 14:55:22 +0900 Subject: [PATCH 5/7] feat: Return CODE128 barcode size --- TinySato/Barcode.cs | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/TinySato/Barcode.cs b/TinySato/Barcode.cs index 935fa66..70b6c72 100644 --- a/TinySato/Barcode.cs +++ b/TinySato/Barcode.cs @@ -32,12 +32,17 @@ public void AddCODE128(int narrow_bar_width, int barcode_height, string print_da this.printer.Add(string.Format("BG{0:D2}{1:D3}{2}", narrow_bar_width, barcode_height, print_data)); } - public void AddCODE128(int narrow_bar_width, int barcode_height, string print_data, Action set_position_by_size) + public Size AddCODE128(int narrow_bar_width, int barcode_height, string print_data, Action set_position_by_size) { if (!(1 <= narrow_bar_width && narrow_bar_width <= 12)) throw new TinySatoArgumentException("Specify 1-12 dot for Narrow Bar Width."); if (!(1 <= barcode_height && barcode_height <= 600)) throw new TinySatoArgumentException("Specify 1-600 dot for Barcode Height."); + var print_data_head = print_data.Substring(0, 2); + if (print_data_head == ">G" // Start Code A + || print_data_head == ">H" // Start Code B + || print_data_head == ">I") // Start Code C + throw new TinySatoArgumentException($"Remove Start Code from the beginning of print_data. head:{print_data_head}"); var m = (new Regex(@"(\d{6,})$")).Match(print_data); var index = m.Success ? @@ -50,23 +55,29 @@ public void AddCODE128(int narrow_bar_width, int barcode_height, string print_da + 11 * front.Length * narrow_bar_width // front + 11 * narrow_bar_width // check + 13 * narrow_bar_width; // stop + + Size symbol_size; if (back.Length > 0) { var width_set_c = 11 * narrow_bar_width // shift + 11 * back.Length / 2 * narrow_bar_width; // back - set_position_by_size(new Size(width + width_set_c, barcode_height)); + symbol_size = new Size(width + width_set_c, barcode_height); + set_position_by_size(symbol_size); this.printer.Add(string.Format("BG{0:D2}{1:D3}{2}", narrow_bar_width, barcode_height, ">H" + front + ">C" + back)); } else { - set_position_by_size(new Size(width, barcode_height)); + symbol_size = new Size(width, barcode_height); + set_position_by_size(symbol_size); this.printer.Add(string.Format("BG{0:D2}{1:D3}{2}", narrow_bar_width, barcode_height, ">H" + front)); } + + return symbol_size; } public void AddJAN13(int thin_bar_width, int barcode_top, string print_data) From 0e8229f01e43c8834581e492e36dcc841db079fe Mon Sep 17 00:00:00 2001 From: karronoli Date: Tue, 20 Oct 2020 21:36:41 +0900 Subject: [PATCH 6/7] Update codacy-analysis.yml --- .github/workflows/codacy-analysis.yml | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/.github/workflows/codacy-analysis.yml b/.github/workflows/codacy-analysis.yml index c9e3e9c..2fabc17 100644 --- a/.github/workflows/codacy-analysis.yml +++ b/.github/workflows/codacy-analysis.yml @@ -8,7 +8,7 @@ name: Codacy Security Scan -on: +on: push: branches: [ "master", "main" ] pull_request: @@ -22,10 +22,10 @@ jobs: # Checkout the repository to the GitHub Actions runner - name: Checkout code uses: actions/checkout@v2 - + # Execute Codacy Analysis CLI and generate a SARIF output with the security issues identified during the analysis - name: Run Codacy Analysis CLI - uses: codacy/codacy-analysis-cli-action@1.0.0 + uses: codacy/codacy-analysis-cli-action@1.1.0 with: # Check https://github.com/codacy/codacy-analysis-cli#project-token to get your project token from your Codacy repository # You can also omit the token and run the tools that support default configurations @@ -33,12 +33,15 @@ jobs: verbose: true output: results.sarif format: sarif + # Adjust severity of non-security issues + gh-code-scanning-compat: true # Force 0 exit code to allow SARIF file generation # This will handover control about PR rejection to the GitHub side max-allowed-issues: 2147483647 - + # Upload the SARIF file generated in the previous step - name: Upload SARIF results file uses: github/codeql-action/upload-sarif@v1 with: sarif_file: results.sarif + From dc08f82cdeffbbc8cef99239f55b9b07c48d9047 Mon Sep 17 00:00:00 2001 From: karronoli Date: Tue, 20 Oct 2020 21:21:28 +0900 Subject: [PATCH 7/7] Bump version v1.1.7 --- TinySato/Properties/AssemblyInfo.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/TinySato/Properties/AssemblyInfo.cs b/TinySato/Properties/AssemblyInfo.cs index df36b09..8c3b665 100644 --- a/TinySato/Properties/AssemblyInfo.cs +++ b/TinySato/Properties/AssemblyInfo.cs @@ -31,5 +31,5 @@ // // すべての値を指定するか、下のように '*' を使ってビルドおよびリビジョン番号を // 既定値にすることができます: -[assembly: AssemblyVersion("1.1.6.*")] -[assembly: AssemblyFileVersion("1.1.6")] +[assembly: AssemblyVersion("1.1.7.*")] +[assembly: AssemblyFileVersion("1.1.7")]