Skip to content

Commit fa90d3b

Browse files
committed
Compile into single exe and support named DICOM tags
1 parent f378945 commit fa90d3b

File tree

5 files changed

+156
-8
lines changed

5 files changed

+156
-8
lines changed

dcmfind/FodyWeavers.xml

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Weavers xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="FodyWeavers.xsd">
3+
<Costura />
4+
</Weavers>

dcmfind/FodyWeavers.xsd

+111
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
3+
<!-- This file was generated by Fody. Manual changes to this file will be lost when your project is rebuilt. -->
4+
<xs:element name="Weavers">
5+
<xs:complexType>
6+
<xs:all>
7+
<xs:element name="Costura" minOccurs="0" maxOccurs="1">
8+
<xs:complexType>
9+
<xs:all>
10+
<xs:element minOccurs="0" maxOccurs="1" name="ExcludeAssemblies" type="xs:string">
11+
<xs:annotation>
12+
<xs:documentation>A list of assembly names to exclude from the default action of "embed all Copy Local references", delimited with line breaks</xs:documentation>
13+
</xs:annotation>
14+
</xs:element>
15+
<xs:element minOccurs="0" maxOccurs="1" name="IncludeAssemblies" type="xs:string">
16+
<xs:annotation>
17+
<xs:documentation>A list of assembly names to include from the default action of "embed all Copy Local references", delimited with line breaks.</xs:documentation>
18+
</xs:annotation>
19+
</xs:element>
20+
<xs:element minOccurs="0" maxOccurs="1" name="Unmanaged32Assemblies" type="xs:string">
21+
<xs:annotation>
22+
<xs:documentation>A list of unmanaged 32 bit assembly names to include, delimited with line breaks.</xs:documentation>
23+
</xs:annotation>
24+
</xs:element>
25+
<xs:element minOccurs="0" maxOccurs="1" name="Unmanaged64Assemblies" type="xs:string">
26+
<xs:annotation>
27+
<xs:documentation>A list of unmanaged 64 bit assembly names to include, delimited with line breaks.</xs:documentation>
28+
</xs:annotation>
29+
</xs:element>
30+
<xs:element minOccurs="0" maxOccurs="1" name="PreloadOrder" type="xs:string">
31+
<xs:annotation>
32+
<xs:documentation>The order of preloaded assemblies, delimited with line breaks.</xs:documentation>
33+
</xs:annotation>
34+
</xs:element>
35+
</xs:all>
36+
<xs:attribute name="CreateTemporaryAssemblies" type="xs:boolean">
37+
<xs:annotation>
38+
<xs:documentation>This will copy embedded files to disk before loading them into memory. This is helpful for some scenarios that expected an assembly to be loaded from a physical file.</xs:documentation>
39+
</xs:annotation>
40+
</xs:attribute>
41+
<xs:attribute name="IncludeDebugSymbols" type="xs:boolean">
42+
<xs:annotation>
43+
<xs:documentation>Controls if .pdbs for reference assemblies are also embedded.</xs:documentation>
44+
</xs:annotation>
45+
</xs:attribute>
46+
<xs:attribute name="DisableCompression" type="xs:boolean">
47+
<xs:annotation>
48+
<xs:documentation>Embedded assemblies are compressed by default, and uncompressed when they are loaded. You can turn compression off with this option.</xs:documentation>
49+
</xs:annotation>
50+
</xs:attribute>
51+
<xs:attribute name="DisableCleanup" type="xs:boolean">
52+
<xs:annotation>
53+
<xs:documentation>As part of Costura, embedded assemblies are no longer included as part of the build. This cleanup can be turned off.</xs:documentation>
54+
</xs:annotation>
55+
</xs:attribute>
56+
<xs:attribute name="LoadAtModuleInit" type="xs:boolean">
57+
<xs:annotation>
58+
<xs:documentation>Costura by default will load as part of the module initialization. This flag disables that behavior. Make sure you call CosturaUtility.Initialize() somewhere in your code.</xs:documentation>
59+
</xs:annotation>
60+
</xs:attribute>
61+
<xs:attribute name="IgnoreSatelliteAssemblies" type="xs:boolean">
62+
<xs:annotation>
63+
<xs:documentation>Costura will by default use assemblies with a name like 'resources.dll' as a satellite resource and prepend the output path. This flag disables that behavior.</xs:documentation>
64+
</xs:annotation>
65+
</xs:attribute>
66+
<xs:attribute name="ExcludeAssemblies" type="xs:string">
67+
<xs:annotation>
68+
<xs:documentation>A list of assembly names to exclude from the default action of "embed all Copy Local references", delimited with |</xs:documentation>
69+
</xs:annotation>
70+
</xs:attribute>
71+
<xs:attribute name="IncludeAssemblies" type="xs:string">
72+
<xs:annotation>
73+
<xs:documentation>A list of assembly names to include from the default action of "embed all Copy Local references", delimited with |.</xs:documentation>
74+
</xs:annotation>
75+
</xs:attribute>
76+
<xs:attribute name="Unmanaged32Assemblies" type="xs:string">
77+
<xs:annotation>
78+
<xs:documentation>A list of unmanaged 32 bit assembly names to include, delimited with |.</xs:documentation>
79+
</xs:annotation>
80+
</xs:attribute>
81+
<xs:attribute name="Unmanaged64Assemblies" type="xs:string">
82+
<xs:annotation>
83+
<xs:documentation>A list of unmanaged 64 bit assembly names to include, delimited with |.</xs:documentation>
84+
</xs:annotation>
85+
</xs:attribute>
86+
<xs:attribute name="PreloadOrder" type="xs:string">
87+
<xs:annotation>
88+
<xs:documentation>The order of preloaded assemblies, delimited with |.</xs:documentation>
89+
</xs:annotation>
90+
</xs:attribute>
91+
</xs:complexType>
92+
</xs:element>
93+
</xs:all>
94+
<xs:attribute name="VerifyAssembly" type="xs:boolean">
95+
<xs:annotation>
96+
<xs:documentation>'true' to run assembly verification (PEVerify) on the target assembly after all weavers have been executed.</xs:documentation>
97+
</xs:annotation>
98+
</xs:attribute>
99+
<xs:attribute name="VerifyIgnoreCodes" type="xs:string">
100+
<xs:annotation>
101+
<xs:documentation>A comma-separated list of error codes that can be safely ignored in assembly verification.</xs:documentation>
102+
</xs:annotation>
103+
</xs:attribute>
104+
<xs:attribute name="GenerateXsd" type="xs:boolean">
105+
<xs:annotation>
106+
<xs:documentation>'false' to turn off automatic generation of the XML Schema file.</xs:documentation>
107+
</xs:annotation>
108+
</xs:attribute>
109+
</xs:complexType>
110+
</xs:element>
111+
</xs:schema>

dcmfind/Program.cs

+28-8
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.Collections.Generic;
33
using System.IO;
44
using System.Linq;
5+
using System.Reflection;
56
using CommandLine;
67
using Dicom;
78

@@ -76,15 +77,9 @@ private static void Query(Options options)
7677
return;
7778
}
7879

79-
DicomTag queryDicomTag;
80-
try
80+
DicomTag queryDicomTag = ToDicomTag(queryParts[0]);
81+
if (queryDicomTag == null)
8182
{
82-
queryDicomTag = DicomTag.Parse(queryParts[0]);
83-
}
84-
catch (DicomDataException e)
85-
{
86-
Console.Error.WriteLine($"Invalid DICOM tag in query '{query}': " + e.Message);
87-
Console.Error.WriteLine(e);
8883
return;
8984
}
9085

@@ -100,6 +95,31 @@ private static IEnumerable<string> Files(string directory, string filePattern, b
10095
return Directory.EnumerateFiles(directory, filePattern, recursive ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly);
10196
}
10297

98+
private static DicomTag ToDicomTag(string dicomTag)
99+
{
100+
try
101+
{
102+
if(dicomTag[0] == '(' || char.IsDigit(dicomTag[0]))
103+
return DicomTag.Parse(dicomTag);
104+
105+
var field = typeof(DicomTag).GetFields(BindingFlags.Static | BindingFlags.Public)
106+
.Where(f => f.FieldType == typeof(DicomTag))
107+
.FirstOrDefault(f => string.Equals(f.Name, dicomTag));
108+
if (field != null)
109+
{
110+
return (DicomTag) field.GetValue(null);
111+
}
112+
113+
return DicomTag.Parse(dicomTag);
114+
}
115+
catch (DicomDataException e)
116+
{
117+
Console.Error.WriteLine($"Invalid DICOM tag in query '{dicomTag}': " + e.Message);
118+
Console.Error.WriteLine(e);
119+
return null;
120+
}
121+
}
122+
103123
private static DicomFile ToDicomFile(string file)
104124
{
105125
try

dcmfind/dcmfind.csproj

+11
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<Import Project="..\packages\Costura.Fody.4.1.0\build\Costura.Fody.props" Condition="Exists('..\packages\Costura.Fody.4.1.0\build\Costura.Fody.props')" />
34
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
45
<PropertyGroup>
56
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
@@ -36,6 +37,10 @@
3637
<HintPath>..\packages\CommandLineParser.2.6.0\lib\net461\CommandLine.dll</HintPath>
3738
<Private>True</Private>
3839
</Reference>
40+
<Reference Include="Costura, Version=4.1.0.0, Culture=neutral, PublicKeyToken=9919ef960d84173d">
41+
<HintPath>..\packages\Costura.Fody.4.1.0\lib\net40\Costura.dll</HintPath>
42+
<Private>True</Private>
43+
</Reference>
3944
<Reference Include="Dicom.Core, Version=4.0.3.0, Culture=neutral, PublicKeyToken=3a13f649e28eb09a">
4045
<HintPath>..\packages\fo-dicom.Desktop.4.0.3\lib\net45\Dicom.Core.dll</HintPath>
4146
<Private>True</Private>
@@ -52,14 +57,20 @@
5257
<ItemGroup>
5358
<None Include="packages.config" />
5459
</ItemGroup>
60+
<ItemGroup>
61+
<Content Include="FodyWeavers.xml" />
62+
</ItemGroup>
5563
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
5664
<Import Project="..\packages\fo-dicom.Desktop.4.0.3\build\net45\fo-dicom.Desktop.targets" Condition="Exists('..\packages\fo-dicom.Desktop.4.0.3\build\net45\fo-dicom.Desktop.targets')" />
5765
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
5866
<PropertyGroup>
5967
<ErrorText>This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105.The missing file is {0}.</ErrorText>
6068
</PropertyGroup>
6169
<Error Condition="!Exists('..\packages\fo-dicom.Desktop.4.0.3\build\net45\fo-dicom.Desktop.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\fo-dicom.Desktop.4.0.3\build\net45\fo-dicom.Desktop.targets'))" />
70+
<Error Condition="!Exists('..\packages\Fody.6.0.5\build\Fody.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Fody.6.0.5\build\Fody.targets'))" />
71+
<Error Condition="!Exists('..\packages\Costura.Fody.4.1.0\build\Costura.Fody.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Costura.Fody.4.1.0\build\Costura.Fody.props'))" />
6272
</Target>
73+
<Import Project="..\packages\Fody.6.0.5\build\Fody.targets" Condition="Exists('..\packages\Fody.6.0.5\build\Fody.targets')" />
6374
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
6475
Other similar extension points exist, see Microsoft.Common.targets.
6576
<Target Name="BeforeBuild">

dcmfind/packages.config

+2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<packages>
33
<package id="CommandLineParser" version="2.6.0" targetFramework="net48" />
4+
<package id="Costura.Fody" version="4.1.0" targetFramework="net48" />
45
<package id="fo-dicom" version="4.0.3" targetFramework="net48" />
56
<package id="fo-dicom.Desktop" version="4.0.3" targetFramework="net48" />
7+
<package id="Fody" version="6.0.5" targetFramework="net48" developmentDependency="true" />
68
</packages>

0 commit comments

Comments
 (0)