Skip to content

Commit

Permalink
Merge pull request #42 from drewnoakes/tidying
Browse files Browse the repository at this point in the history
Tidying
  • Loading branch information
drewnoakes authored Jun 6, 2019
2 parents ab3d7e0 + fbe7016 commit e468149
Show file tree
Hide file tree
Showing 12 changed files with 110 additions and 42 deletions.
60 changes: 60 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
root = true

[*]
indent_style = space

[*.cs]
indent_size = 4
insert_final_newline = true
charset = utf-8

[*.{csproj}]
indent_size = 2

[*.{props,targets,ruleset,config,resx}]
indent_size = 2

[*.json]
indent_size = 2

[*.cs]
dotnet_sort_system_directives_first = true

dotnet_style_qualification_for_field = false:warning
dotnet_style_qualification_for_property = false:warning
dotnet_style_qualification_for_method = false:warning
dotnet_style_qualification_for_event = false:warning

dotnet_style_predefined_type_for_locals_parameters_members = true:warning
dotnet_style_predefined_type_for_member_access = true:warning

dotnet_style_object_initializer = true:suggestion
dotnet_style_collection_initializer = true:suggestion
dotnet_style_coalesce_expression = true:suggestion
dotnet_style_null_propagation = true:suggestion
dotnet_style_explicit_tuple_names = true:suggestion

csharp_style_var_for_built_in_types = false:none
csharp_style_var_when_type_is_apparent = true:none
csharp_style_var_elsewhere = false:none

csharp_style_expression_bodied_methods = false:none
csharp_style_expression_bodied_constructors = false:none
csharp_style_expression_bodied_operators = false:none

csharp_style_expression_bodied_properties = false:none
csharp_style_expression_bodied_indexers = false:none
csharp_style_expression_bodied_accessors = false:none

csharp_style_pattern_matching_over_is_with_cast_check = true:suggestion
csharp_style_pattern_matching_over_as_with_null_check = true:suggestion
csharp_style_inlined_variable_declaration = true:suggestion
csharp_style_throw_expression = true:suggestion
csharp_style_conditional_delegate_call = true:suggestion

csharp_new_line_before_open_brace = all:warning
csharp_new_line_before_else = true:warning
csharp_new_line_before_catch = true:warning
csharp_new_line_before_finally = true:warning
csharp_new_line_before_members_in_object_initializers = true:warning
csharp_new_line_before_members_in_anonymous_types = true:warning
2 changes: 1 addition & 1 deletion Build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,6 @@ if ((test-path $msbuild) -eq $false) {
}

&$msbuild XmpCore\XmpCore.csproj /t:Build,Pack /p:Configuration=Release /p:PackageOutputPath=..\artifacts
&$msbuild XmpCore\XmpCore.csproj /t:Build,Pack /p:Configuration=Release /p:PackageOutputPath=..\artifacts /p:Signed=True
&$msbuild XmpCore\XmpCore.csproj /t:Build,Pack /p:Configuration=Release /p:PackageOutputPath=..\artifacts /p:Signed=True /p:PackageId=XmpCore.StrongName

Pop-Location
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

This library is a port of Adobe's XMP SDK to .NET.

The API should be familiar to users of Adobe's XMPCore 5.1.2, though it has been modified
The API should be familiar to users of Adobe's XMPCore 6.1.10, though it has been modified
in places to better suit .NET development.

## Sample Usage
Expand Down
9 changes: 7 additions & 2 deletions XmpCore.sln
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.26228.4
# Visual Studio Version 16
VisualStudioVersion = 16.0.29001.49
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{06DA73A6-87C5-4772-9A59-534F10530ED6}"
ProjectSection(SolutionItems) = preProject
.editorconfig = .editorconfig
.gitattributes = .gitattributes
.gitignore = .gitignore
appveyor.yml = appveyor.yml
Build.ps1 = Build.ps1
README.md = README.md
EndProjectSection
EndProject
Expand All @@ -33,4 +35,7 @@ Global
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {DD96C38F-B7E1-459C-A3B6-600F0072F51E}
EndGlobalSection
EndGlobal
2 changes: 1 addition & 1 deletion XmpCore/IXmpMeta.cs
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ public interface IXmpMeta
/// Arrays and non-leaf levels of structs do not have values.
/// Must be <c>null</c> if the value is not relevant.<br/>
/// The value is automatically detected: Boolean, Integer, Long, Double, <see cref="IXmpDateTime"/> and
/// byte[] are handled, on all other <see cref="System.Object.ToString"/> is called.
/// byte[] are handled, on all other <see cref="object.ToString"/> is called.
/// </param>
/// <param name="options">Option flags describing the property. See the earlier description.</param>
/// <exception cref="XmpException">Wraps all errors and exceptions that may occur.</exception>
Expand Down
7 changes: 4 additions & 3 deletions XmpCore/Impl/ParseRdf.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Xml;
using System.Xml.Linq;
using XmpCore.Options;
Expand Down Expand Up @@ -565,17 +566,17 @@ private static void Rdf_LiteralPropertyElement(XmpMeta xmp, XmpNode xmpParent, X
}

// FfF: Can there be more than one text node in a row?
var textValue = string.Empty;
var textValue = new StringBuilder();

foreach (var child in xmlNode.Nodes())
{
if (child.NodeType != XmlNodeType.Text)
throw new XmpException("Invalid child of literal property element", XmpErrorCode.BadRdf);

textValue += ((XText)child).Value;
textValue.Append(((XText)child).Value);
}

newChild.Value = textValue;
newChild.Value = textValue.ToString();
}

/// <summary>
Expand Down
13 changes: 7 additions & 6 deletions XmpCore/Impl/XmpSerializerRdf.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

using System.Collections.Generic;
using System.IO;
using System.Text;
using XmpCore.Options;

namespace XmpCore.Impl
Expand Down Expand Up @@ -242,19 +243,19 @@ private string SerializeAsRdf()
}

// Write the packet trailer PI into the tail string as UTF-8.
var tailStr = string.Empty;
var tailStr = new StringBuilder();
if (!_options.OmitPacketWrapper)
{
for (level = _options.BaseIndent; level > 0; level--)
{
tailStr += _options.Indent;
tailStr.Append(_options.Indent);
}
tailStr += PacketTrailer;
tailStr += _options.ReadOnlyPacket ? 'r' : 'w';
tailStr += PacketTrailer2;
tailStr.Append(PacketTrailer);
tailStr.Append(_options.ReadOnlyPacket ? 'r' : 'w');
tailStr.Append(PacketTrailer2);
}

return tailStr;
return tailStr.ToString();
}

/// <summary>Serializes the metadata in pretty-printed manner.</summary>
Expand Down
46 changes: 24 additions & 22 deletions XmpCore/Impl/XmpUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ public static void SeparateArrayItems(IXmpMeta xmp, string schemaNs, string arra
var arrayNode = SeparateFindCreateArray(schemaNs, arrayName, arrayOptions, xmpImpl);

var arrayElementLimit = int.MaxValue;
if (arrayNode != null && arrayOptions != null)
if (arrayOptions != null)
{
arrayElementLimit = arrayOptions.ArrayElementsLimit;
if (arrayElementLimit == -1)
Expand Down Expand Up @@ -1139,7 +1139,7 @@ private static bool IsClosingQuote(char ch, char openQuote, char closeQuote)
/// <param name="schemaURI">Schema of the specified property</param>
/// <param name="propName">Name of the property</param>
/// <returns>true in case of success otherwise false.</returns>
static bool MoveOneProperty(XmpMeta stdXMP, XmpMeta extXMP, string schemaURI, string propName)
private static bool MoveOneProperty(XmpMeta stdXMP, XmpMeta extXMP, string schemaURI, string propName)
{
XmpNode propNode = null;

Expand Down Expand Up @@ -1171,7 +1171,7 @@ static bool MoveOneProperty(XmpMeta stdXMP, XmpMeta extXMP, string schemaURI, st
/// <summary>estimates the size of an xmp node</summary>
/// <param name="xmpNode">XMP Node Object</param>
/// <returns>the estimated size of the node</returns>
static int EstimateSizeForJPEG(XmpNode xmpNode)
private static int EstimateSizeForJPEG(XmpNode xmpNode)
{
int estSize = 0;
int nameSize = xmpNode.Name.Length;
Expand Down Expand Up @@ -1222,14 +1222,14 @@ private static void PutObjectsInMultiMap(SortedDictionary<int, List<List<string>
{
if (multiMap == null)
return;
List<List<string>> tempList; // multiMap[key];
//if (tempList == null)
if (!multiMap.TryGetValue(key, out tempList))

if (!multiMap.TryGetValue(key, out List<List<string>> list))
{
tempList = new List<List<string>>();
multiMap[key] = tempList;
list = new List<List<string>>();
multiMap[key] = list;
}
tempList.Add(stringPair);

list.Add(stringPair);
}

/// <summary>Utility function for retrieving biggest entry in the multimap</summary>
Expand Down Expand Up @@ -1444,23 +1444,25 @@ public static void PackageForJPEG(IXmpMeta origXMPImpl,
extStr.Append(tempStr);

#if NETSTANDARD2_0
var md = MD5.Create();
var hashBytes = md.ComputeHash(Encoding.UTF8.GetBytes(tempStr));

digestStr.Append(ByteArrayToHexString(hashBytes));

string ByteArrayToHexString(byte[] bytes)
using (var md = MD5.Create())
{
var result = new StringBuilder(bytes.Length*2);
const string HexAlphabet = "0123456789ABCDEF";
var hashBytes = md.ComputeHash(Encoding.UTF8.GetBytes(tempStr));

digestStr.Append(ByteArrayToHexString(hashBytes));

foreach (var b in bytes)
string ByteArrayToHexString(byte[] bytes)
{
result.Append(HexAlphabet[b >> 4]);
result.Append(HexAlphabet[b & 0xF]);
}
var result = new StringBuilder(bytes.Length*2);
const string HexAlphabet = "0123456789ABCDEF";

return result.ToString();
foreach (var b in bytes)
{
result.Append(HexAlphabet[b >> 4]);
result.Append(HexAlphabet[b & 0xF]);
}

return result.ToString();
}
}
#endif

Expand Down
2 changes: 1 addition & 1 deletion XmpCore/Options/ParseOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public sealed class ParseOptions : Options
public const int DisallowDoctypeFlag = 0x0040;

/// <summary>Map of nodes whose children are to be limited.</summary>
private Dictionary<string, int> mXMPNodesToLimit = new Dictionary<string, int>();
private readonly Dictionary<string, int> mXMPNodesToLimit = new Dictionary<string, int>();

/// <summary>Sets the options to the default values.</summary>
public ParseOptions()
Expand Down
5 changes: 2 additions & 3 deletions XmpCore/XmpCore.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
<PropertyGroup>
<Description>.NET library for working with the Extensible Metadata Platform (XMP)

This library is a port of Adobe's Java XMP SDK to .NET. It was initially ported by Yakov Danila and Nathanael Jones. Now maintained by Drew Noakes and contributors on GitHub.
This library is a port of Adobe's Java XMP SDK to .NET. It was initially ported by Yakov Danila and Nathanael Jones. Now maintained by Drew Noakes and contributors on GitHub.

The API should be familiar to users of Adobe's XMPCore, though it has been modified in places to better suit .NET development.</Description>
<Copyright>Copyright 2015-2017</Copyright>
<Copyright>Copyright 2015-2019</Copyright>
<AssemblyTitle>XmpCore</AssemblyTitle>
<VersionPrefix>6.1.10.0</VersionPrefix>
<Authors>Drew Noakes</Authors>
Expand Down Expand Up @@ -34,7 +34,6 @@ The API should be familiar to users of Adobe's XMPCore, though it has been modif
<AssemblyOriginatorKeyFile>../XmpCore.snk</AssemblyOriginatorKeyFile>
<SignAssembly>true</SignAssembly>
<PublicSign Condition=" '$(OS)' != 'Windows_NT' ">true</PublicSign>
<PackageId>XmpCore.StrongName</PackageId>
</PropertyGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion XmpCore/XmpUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,7 @@ static public void ApplyTemplate(IXmpMeta workingXMP, IXmpMeta templateXMP, Temp
/// <param name="destRoot">The root location for the destination. May be a general path expression. Defaults to the source location.</param>
/// <param name="options">Option flags to control the separation. (For now, this argument is ignored. 0 should be passed.</param>
/// <exception cref="XmpException">Forwards the Exceptions from the metadata processing</exception>
public static void DuplicateSubtree(IXmpMeta source, IXmpMeta dest, String sourceNS, String sourceRoot, String destNS, String destRoot, PropertyOptions options)
public static void DuplicateSubtree(IXmpMeta source, IXmpMeta dest, string sourceNS, string sourceRoot, string destNS, string destRoot, PropertyOptions options)
{
Impl.XmpUtils.DuplicateSubtree(source, dest, sourceNS, sourceRoot, destNS, destRoot, options);
}
Expand Down
2 changes: 1 addition & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ version: 2.0.{build}
branches:
only:
- master
image: Visual Studio 2017
image: Visual Studio 2019 Preview
configuration: Release
before_build:
appveyor-retry nuget restore
Expand Down

0 comments on commit e468149

Please sign in to comment.