From 3f2fcf8c4493c2711628399daf70f6a469f89133 Mon Sep 17 00:00:00 2001 From: LGTM Migrator Date: Wed, 9 Nov 2022 19:34:31 +0000 Subject: [PATCH 1/9] Add CodeQL workflow for GitHub code scanning --- .github/workflows/codeql.yml | 41 ++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 .github/workflows/codeql.yml diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml new file mode 100644 index 0000000..f9afc6d --- /dev/null +++ b/.github/workflows/codeql.yml @@ -0,0 +1,41 @@ +name: "CodeQL" + +on: + push: + branches: [ "main" ] + pull_request: + branches: [ "main" ] + schedule: + - cron: "59 14 * * 2" + +jobs: + analyze: + name: Analyze + runs-on: ubuntu-latest + permissions: + actions: read + contents: read + security-events: write + + strategy: + fail-fast: false + matrix: + language: [ csharp ] + + steps: + - name: Checkout + uses: actions/checkout@v3 + + - name: Initialize CodeQL + uses: github/codeql-action/init@v2 + with: + languages: ${{ matrix.language }} + queries: +security-and-quality + + - name: Autobuild + uses: github/codeql-action/autobuild@v2 + + - name: Perform CodeQL Analysis + uses: github/codeql-action/analyze@v2 + with: + category: "/language:${{ matrix.language }}" From ca202dcaa1058bd47386dc1ca565eedbd838e932 Mon Sep 17 00:00:00 2001 From: James A Sutherland <> Date: Mon, 21 Nov 2022 13:53:04 -0600 Subject: [PATCH 2/9] Use .Net 6 for tests not EOL 5 --- DicomTypeTranslation.Tests/DicomTypeTranslation.Tests.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DicomTypeTranslation.Tests/DicomTypeTranslation.Tests.csproj b/DicomTypeTranslation.Tests/DicomTypeTranslation.Tests.csproj index 5fb4b9b..0ed323d 100644 --- a/DicomTypeTranslation.Tests/DicomTypeTranslation.Tests.csproj +++ b/DicomTypeTranslation.Tests/DicomTypeTranslation.Tests.csproj @@ -1,6 +1,6 @@  - net5.0 + net6.0 9.0 DicomTypeTranslation.Tests DicomTypeTranslation.Tests From 254d122db4a465679b4a65e3da1de2ddb081f646 Mon Sep 17 00:00:00 2001 From: James A Sutherland <> Date: Mon, 21 Nov 2022 13:53:46 -0600 Subject: [PATCH 3/9] CodeQL fixups --- .../DatabaseExamples.cs | 4 +- .../Helpers/DicomDatasetHelpers.cs | 46 +++++++++---------- .../Helpers/DictionaryHelperMethods.cs | 2 +- .../Helpers/FlexibleEquality.cs | 6 +-- 4 files changed, 29 insertions(+), 29 deletions(-) diff --git a/DicomTypeTranslation.Tests/DatabaseExamples.cs b/DicomTypeTranslation.Tests/DatabaseExamples.cs index 89a3f87..0040636 100644 --- a/DicomTypeTranslation.Tests/DatabaseExamples.cs +++ b/DicomTypeTranslation.Tests/DatabaseExamples.cs @@ -37,7 +37,7 @@ public void WorkedExampleTest(FAnsi.DatabaseType dbType) tbl.AddColumn("FileLocation", new DatabaseTypeRequest(typeof(string), 500), true, 500); //Create a DataTable in memory for the data we read from disk - DataTable dt = new DataTable(); + using var dt = new DataTable(); dt.Columns.Add("SOPInstanceUID"); dt.Columns.Add("Modality"); dt.Columns.Add("PatientID"); @@ -101,7 +101,7 @@ public void TestGetDataTable() new DicomDate(DicomTag.PatientBirthDate,new DateTime(2001,1,1)) }); - var dt = new DataTable(); + using var dt = new DataTable(); var row = ds.ToRow(dt); Assert.AreEqual("Frank", row["PatientName"]); diff --git a/DicomTypeTranslation/Helpers/DicomDatasetHelpers.cs b/DicomTypeTranslation/Helpers/DicomDatasetHelpers.cs index 9cf7162..44a60ea 100644 --- a/DicomTypeTranslation/Helpers/DicomDatasetHelpers.cs +++ b/DicomTypeTranslation/Helpers/DicomDatasetHelpers.cs @@ -86,40 +86,40 @@ public static bool ValueEquals(DicomItem a, DicomItem b) private static bool ValueEquals(IByteBuffer a, IByteBuffer b) { if (a == null || b == null) - return a == b; + return ReferenceEquals(a,b); - if (a == b) + if (ReferenceEquals(a, b)) return true; if (a.IsMemory) return b.IsMemory && a.Data.SequenceEqual(b.Data); - if (a is IBulkDataUriByteBuffer abuff) + switch (a) { - if (!(b is IBulkDataUriByteBuffer bbuff)) - return false; - - return abuff.BulkDataUri == bbuff.BulkDataUri; - } - - if (a is EmptyBuffer && b is EmptyBuffer) - return true; + case IBulkDataUriByteBuffer abuff: + { + if (b is not IBulkDataUriByteBuffer bbuff) + return false; - if (a is StreamByteBuffer && b is StreamByteBuffer) - { - var asbb = (StreamByteBuffer)a; - var bsbb = (StreamByteBuffer)b; + return abuff.BulkDataUri == bbuff.BulkDataUri; + } + case EmptyBuffer when b is EmptyBuffer: + return true; + case StreamByteBuffer buffer when b is StreamByteBuffer: + { + var asbb = buffer; + var bsbb = (StreamByteBuffer)b; - if (asbb.Stream == null || bsbb.Stream == null) - return asbb.Stream == bsbb.Stream; + if (asbb.Stream == null || bsbb.Stream == null) + return asbb.Stream == bsbb.Stream; - return asbb.Position == bsbb.Position && asbb.Size == bsbb.Size && asbb.Stream.Equals(bsbb.Stream); + return asbb.Position == bsbb.Position && asbb.Size == bsbb.Size && asbb.Stream.Equals(bsbb.Stream); + } + case CompositeByteBuffer buffer when b is CompositeByteBuffer: + return buffer.Buffers.Zip(((CompositeByteBuffer)b).Buffers, ValueEquals).All(x => x); + default: + return a.Equals(b); } - - if (a is CompositeByteBuffer && b is CompositeByteBuffer) - return ((CompositeByteBuffer)a).Buffers.Zip(((CompositeByteBuffer)b).Buffers, ValueEquals).All(x => x); - - return a.Equals(b); } /// diff --git a/DicomTypeTranslation/Helpers/DictionaryHelperMethods.cs b/DicomTypeTranslation/Helpers/DictionaryHelperMethods.cs index f09daf2..2881da4 100644 --- a/DicomTypeTranslation/Helpers/DictionaryHelperMethods.cs +++ b/DicomTypeTranslation/Helpers/DictionaryHelperMethods.cs @@ -43,7 +43,7 @@ public static bool DictionaryEquals(IDictionary dict1, IDictionary dict2) { //if either is null if (dict1 == null || dict2 == null) - return dict1 == dict2; //they are only equal if they are both null + return Object.ReferenceEquals(dict1,dict2); //they are only equal if they are both null var keys1 = new HashSet(); diff --git a/DicomTypeTranslation/Helpers/FlexibleEquality.cs b/DicomTypeTranslation/Helpers/FlexibleEquality.cs index ddf7698..ec925b0 100644 --- a/DicomTypeTranslation/Helpers/FlexibleEquality.cs +++ b/DicomTypeTranslation/Helpers/FlexibleEquality.cs @@ -19,7 +19,7 @@ public static class FlexibleEquality public static bool FlexibleEquals(object a, object b) { if (a == null || b == null) - return a == b; + return ReferenceEquals(a,b); //types are different so most likely we are not equipped to deal with this problem let a decide if it is equal or not if (a.GetType() != b.GetType()) @@ -31,8 +31,8 @@ public static bool FlexibleEquals(object a, object b) return DictionaryHelperMethods.DictionaryEquals((IDictionary)a, (IDictionary)b); //if they are both arrays - if (a is Array) - return ArrayHelperMethods.ArrayEquals((Array)a, (Array)b); + if (a is Array array) + return ArrayHelperMethods.ArrayEquals(array, (Array)b); //they are not dictionaries or arrays return Equals(a, b); From cceb21b063f6b71c2af38084f505711eacf591af Mon Sep 17 00:00:00 2001 From: James A Sutherland <> Date: Mon, 21 Nov 2022 13:58:26 -0600 Subject: [PATCH 4/9] Run with .Net 6 on Ubuntu 20.04, not 5 on 18.04 --- .github/workflows/dotnet-core.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/dotnet-core.yml b/.github/workflows/dotnet-core.yml index edd8070..7954696 100644 --- a/.github/workflows/dotnet-core.yml +++ b/.github/workflows/dotnet-core.yml @@ -11,14 +11,14 @@ env: jobs: build: - runs-on: ubuntu-18.04 + runs-on: ubuntu-20.04 steps: - uses: actions/checkout@v3 - name: Setup .NET Core uses: actions/setup-dotnet@v2 with: - dotnet-version: 5.x + dotnet-version: 6.x - uses: actions/cache@v3 with: path: ~/.nuget/packages @@ -28,7 +28,7 @@ jobs: - name: Add MSFT code signing key run: wget -qO- https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add - - name: Add MSFT package repo - run: sudo add-apt-repository "$(wget -qO- https://packages.microsoft.com/config/ubuntu/18.04/mssql-server-2019.list)" + run: sudo add-apt-repository "$(wget -qO- https://packages.microsoft.com/config/ubuntu/20.04/mssql-server-2019.list)" - name: MySQL run: | sudo mkdir -p /var/run/mysqld From 154b8c55eca8ee265a9c52973b9f81999deb1cc2 Mon Sep 17 00:00:00 2001 From: James A Sutherland <> Date: Mon, 21 Nov 2022 14:10:00 -0600 Subject: [PATCH 5/9] Adjust MySQL handling in CI --- .github/workflows/dotnet-core.yml | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/.github/workflows/dotnet-core.yml b/.github/workflows/dotnet-core.yml index 7954696..f0d84a2 100644 --- a/.github/workflows/dotnet-core.yml +++ b/.github/workflows/dotnet-core.yml @@ -29,15 +29,11 @@ jobs: run: wget -qO- https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add - - name: Add MSFT package repo run: sudo add-apt-repository "$(wget -qO- https://packages.microsoft.com/config/ubuntu/20.04/mssql-server-2019.list)" - - name: MySQL + - name: Install MS SQL Server and Postgresql, start existing MySQL run: | - sudo mkdir -p /var/run/mysqld - sudo chown mysql:mysql /var/run/mysqld - sudo mysqld_safe --port=3306 --skip-grant-tables & - - name: Install Sql Server - run: sudo apt-get install -y --no-install-recommends postgresql mssql-tools mssql-server - - name: Configure Sql Server - run: sudo -E /opt/mssql/bin/mssql-conf -n setup accept-eula + sudo apt-get install -y --no-install-recommends postgresql mssql-tools mssql-server + sudo -E /opt/mssql/bin/mssql-conf -n setup accept-eula + sudo service mysql start - name: Install dependencies run: dotnet restore - name: Build From 9c0483dc8697afe1373e2b1c66166d1ffaeb1a9a Mon Sep 17 00:00:00 2001 From: James A Sutherland <> Date: Mon, 21 Nov 2022 14:15:36 -0600 Subject: [PATCH 6/9] Add MySQL password for CI runs --- .github/workflows/dotnet-core.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/dotnet-core.yml b/.github/workflows/dotnet-core.yml index f0d84a2..16a9d63 100644 --- a/.github/workflows/dotnet-core.yml +++ b/.github/workflows/dotnet-core.yml @@ -31,6 +31,7 @@ jobs: run: sudo add-apt-repository "$(wget -qO- https://packages.microsoft.com/config/ubuntu/20.04/mssql-server-2019.list)" - name: Install MS SQL Server and Postgresql, start existing MySQL run: | + sed -i -e 's/Pwd=;/Pwd=root;/' DicomTypeTranslation.Tests/TestDatabases.xml sudo apt-get install -y --no-install-recommends postgresql mssql-tools mssql-server sudo -E /opt/mssql/bin/mssql-conf -n setup accept-eula sudo service mysql start From c706c14b6c34e01c1d2c08a9a3f7894663ff22be Mon Sep 17 00:00:00 2001 From: James A Sutherland <> Date: Mon, 21 Nov 2022 14:19:18 -0600 Subject: [PATCH 7/9] Streamline, add AllowPublicKeyRetrieval=True for MySQL security --- .github/workflows/dotnet-core.yml | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/.github/workflows/dotnet-core.yml b/.github/workflows/dotnet-core.yml index 16a9d63..744f018 100644 --- a/.github/workflows/dotnet-core.yml +++ b/.github/workflows/dotnet-core.yml @@ -19,26 +19,16 @@ jobs: uses: actions/setup-dotnet@v2 with: dotnet-version: 6.x - - uses: actions/cache@v3 - with: - path: ~/.nuget/packages - key: ${{ runner.os }}-nuget-${{ hashFiles('**/*.csproj') }} - restore-keys: | - ${{ runner.os }}-nuget - - name: Add MSFT code signing key - run: wget -qO- https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add - - - name: Add MSFT package repo - run: sudo add-apt-repository "$(wget -qO- https://packages.microsoft.com/config/ubuntu/20.04/mssql-server-2019.list)" - name: Install MS SQL Server and Postgresql, start existing MySQL run: | - sed -i -e 's/Pwd=;/Pwd=root;/' DicomTypeTranslation.Tests/TestDatabases.xml + sudo wget -qO/etc/apt/trusted.gpg.d/microsoft.asc https://packages.microsoft.com/keys/microsoft.asc + sudo add-apt-repository "$(wget -qO- https://packages.microsoft.com/config/ubuntu/20.04/mssql-server-2019.list)" + sed -i -e 's/Pwd=;/Pwd=root;AllowPublicKeyRetrieval=True;/' DicomTypeTranslation.Tests/TestDatabases.xml sudo apt-get install -y --no-install-recommends postgresql mssql-tools mssql-server sudo -E /opt/mssql/bin/mssql-conf -n setup accept-eula sudo service mysql start - - name: Install dependencies - run: dotnet restore - name: Build - run: dotnet build --configuration Release --no-restore + run: dotnet build --configuration Release - name: Test run: dotnet test --no-restore --verbosity normal - name: Pack and push From 2d6349b318fce871928f854e581ebeb40cef7386 Mon Sep 17 00:00:00 2001 From: James A Sutherland <> Date: Mon, 21 Nov 2022 15:20:16 -0600 Subject: [PATCH 8/9] Remove legacy Rake and Travis files --- .travis.yml | 38 ------------------------ .travisignore | 5 ---- rakeconfig.rb | 11 ------- rakefile.rb | 80 --------------------------------------------------- 4 files changed, 134 deletions(-) delete mode 100644 .travis.yml delete mode 100644 .travisignore delete mode 100644 rakeconfig.rb delete mode 100644 rakefile.rb diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index dc6f4e4..0000000 --- a/.travis.yml +++ /dev/null @@ -1,38 +0,0 @@ -language: generic -mono: none -dist: bionic -os: linux - -addons: - postgresql: "10" - apt: - packages: - sources: - - sourceline: 'deb [arch=amd64] https://packages.microsoft.com/ubuntu/18.04/prod bionic main' - key_url: 'https://packages.microsoft.com/keys/microsoft.asc' - - sourceline: 'deb [arch=amd64,arm64,armhf] https://packages.microsoft.com/ubuntu/16.04/mssql-server-2017 xenial main' - -services: -- postgresql -- mysql -env: - global: - - MSSQL_SA_PASSWORD="YourStrong!Passw0rd" - - ACCEPT_EULA=Y - - MSSQL_PID='developer' -cache: - directories: - - $HOME/.local/share/NuGet/ - - $HOME/.nuget - -before_script: -- sudo apt-get install -y --no-install-recommends mssql-tools mssql-server dotnet-runtime-2.2 dotnet-sdk-3.1 -- sudo /opt/mssql/bin/mssql-conf -n setup accept-eula - -script: - - dotnet restore - - dotnet build - - dotnet test - - cd DicomTypeTranslation && dotnet pack -p:Version=$(fgrep Version ../SharedAssemblyInfo.cs|cut -d'"' -f2|head -n1) -c Release --include-symbols --include-source - - if [ ! -z "$TRAVIS_TAG" ]; then dotnet nuget push bin/Release/HIC.DicomTypeTranslation.$TRAVIS_TAG.nupkg -s https://api.nuget.org/v3/index.json -k $NUGET_KEY; fi - diff --git a/.travisignore b/.travisignore deleted file mode 100644 index f1e35f5..0000000 --- a/.travisignore +++ /dev/null @@ -1,5 +0,0 @@ - -.gitignore -*.md -*.png -*.rb \ No newline at end of file diff --git a/rakeconfig.rb b/rakeconfig.rb deleted file mode 100644 index 7d3e85c..0000000 --- a/rakeconfig.rb +++ /dev/null @@ -1,11 +0,0 @@ -PUBLISH_DIR = ENV['PUBLISH_DIR'] || "Release" -SOLUTION = ENV['SOLUTION'] || "DicomTypeTranslation.sln" -DBSERVER = ENV['DBSERVER'] || "SQL-ADP-02\\hiccitests" -MYSQLDB = ENV['MYSQLDB'] || "adp-hicci-03" -MYSQLUSR = ENV['MYSQLUSR'] || "hicci" -MYSQLPASS= ENV['MYSQLPASS'] || "killerzombie" -PRERELEASE = ENV['PRERELEASE'] || "false" -CANDIDATE = ENV['CANDIDATE'] || "false" -SUFFIX = ENV['SUFFIX'] || "develop" -NUGETKEY = ENV['NUGETKEY'] || "blahblahblahbroken!" -MSBUILD15CMD = ENV['MSBUILD15CMD'] || "C:/Program Files (x86)/Microsoft Visual Studio/2017/BuildTools/MSBuild/15.0/Bin/msbuild.exe" \ No newline at end of file diff --git a/rakefile.rb b/rakefile.rb deleted file mode 100644 index 1449ccf..0000000 --- a/rakefile.rb +++ /dev/null @@ -1,80 +0,0 @@ -load 'rakeconfig.rb' -$MSBUILD15CMD = MSBUILD15CMD.gsub(/\\/,"/") - -task :continuous, [:config] => [:setup_connection,:assemblyinfo, :build, :tests] - -task :release, [:config] => [:setup_connection,:assemblyinfo, :deploy, :pack] - -task :restorepackages do - sh "nuget restore #{SOLUTION}" -end - -task :setup_connection do - File.open("DicomTypeTranslation.Tests/TestDatabases.xml", "w") do |f| - f.write(" - - True - FAnsiTests - - - MicrosoftSQLServer - server=#{DBSERVER};Trusted_Connection=True; - - - MySql - Server=#{MYSQLDB};Uid=#{MYSQLUSR};Pwd=#{MYSQLPASS};sslmode=Required - - - ") - end -end - -task :build, [:config] => :restorepackages do |msb, args| - sh "\"#{$MSBUILD15CMD}\" #{SOLUTION} \/t:Clean;Build \/p:Configuration=#{args.config}" -end - -task :tests do - sh 'dotnet test --logger:"nunit;LogFilePath=test-result.xml"' -end - -task :deploy, [:config] => :restorepackages do |msb, args| - args.with_defaults(:config => :Release) - sh "\"#{$MSBUILD15CMD}\" #{SOLUTION} \/t:Clean;Build \/p:Configuration=#{args.config}" -end - -desc "Sets the version number from SharedAssemblyInfo file" -task :assemblyinfo do - asminfoversion = File.read("SharedAssemblyInfo.cs").match(/AssemblyInformationalVersion\("(\d+)\.(\d+)\.(\d+)(-.*)?"/) - - puts asminfoversion.inspect - - major = asminfoversion[1] - minor = asminfoversion[2] - patch = asminfoversion[3] - suffix = asminfoversion[4] - - version = "#{major}.#{minor}.#{patch}" - puts "version: #{version}#{suffix}" - - # DO NOT REMOVE! needed by build script! - f = File.new('version', 'w') - f.write "#{version}#{suffix}" - f.close - # ---- -end - -desc "Pushes the plugin packages into the specified folder" -task :pack, [:config] do |t, args| - args.with_defaults(:config => :Release) - - version = File.open('version') {|f| f.readline} - puts "version: #{version}" - - Dir.chdir('DicomTypeTranslation') do - sh "nuget pack HIC.DicomTypeTranslation.nuspec -Properties Configuration=#{args.config} -IncludeReferencedProjects -Symbols -Version #{version}" - sh "nuget push HIC.DicomTypeTranslation.#{version}.nupkg -Source https://api.nuget.org/v3/index.json -ApiKey #{NUGETKEY}" - end -end From ee016d52dfd440ebff35cfee9590e1d4316a3610 Mon Sep 17 00:00:00 2001 From: James A Sutherland <> Date: Mon, 21 Nov 2022 15:21:06 -0600 Subject: [PATCH 9/9] Force .Net 6 for LGTM builds --- .lgtm.yml | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .lgtm.yml diff --git a/.lgtm.yml b/.lgtm.yml new file mode 100644 index 0000000..5d99e70 --- /dev/null +++ b/.lgtm.yml @@ -0,0 +1,5 @@ +extraction: + csharp: + index: + dotnet: + version: 6.0.103