Skip to content

Commit 7233253

Browse files
committed
Changes to SuccessOrErrors in GenericLibsBase. Made ForceNeedDecompile pttected and NeedsDecompile internal to stop them appearing in json output. Also updated NuGet to use latest EF and Auto
1 parent e55dfe8 commit 7233253

18 files changed

+603
-87
lines changed

GenericLibsBase/Core/SuccessOrErrors.Generic.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,13 @@ public ISuccessOrErrors<T> SetSuccessWithResult(T result, string successformat,
8787
return this;
8888
}
8989

90-
/// <summary>
90+
public new ISuccessOrErrors<T> Combine(object status)
91+
{
92+
base.Combine(status);
93+
return this;
94+
}
95+
96+
/// <summary>
9197
/// This allows the current success message to be updated
9298
/// </summary>
9399
/// <param name="successformat"></param>

GenericLibsBase/Core/SuccessOrErrors.cs

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,13 @@ public IReadOnlyList<ValidationResult> Errors
7575
/// </summary>
7676
public bool IsValid { get { return (_localErrors != null && Errors.Count == 0); }}
7777

78+
/// <summary>
79+
/// Returns true if any errors. Note: different to IsValid in that it just checks for errors,
80+
/// i.e. different to IsValid in that no errors but unset Validity will return false.
81+
/// Useful for checking inside a method where the status is being manipulated.
82+
/// </summary>
83+
public bool HasErrors { get { return (_localErrors != null && Errors.Count > 0); } }
84+
7885
/// <summary>
7986
/// Returns true if not errors or not validated yet, else false.
8087
/// </summary>
@@ -154,6 +161,40 @@ public ISuccessOrErrors AddNamedParameterError(string parameterName, string erro
154161
return this;
155162
}
156163

164+
/// <summary>
165+
/// This combines any errors or warnings into the current status.
166+
/// Note: it does NOT copy any success message into the current status
167+
/// as it is the job of the outer status to set its own success message
168+
/// </summary>
169+
/// <param name="status"></param>
170+
/// <returns></returns>
171+
public ISuccessOrErrors Combine(object status)
172+
{
173+
var castISuccessOrErrors = status as ISuccessOrErrors;
174+
if (castISuccessOrErrors == null)
175+
throw new ArgumentNullException("status", "The status parameter was not derived from a type that supported ISuccessOrErrors.");
176+
177+
if (castISuccessOrErrors.HasErrors)
178+
{
179+
if (castISuccessOrErrors.HasErrors)
180+
{
181+
if (_localErrors == null)
182+
_localErrors = castISuccessOrErrors.Errors.ToList();
183+
else
184+
{
185+
_localErrors.AddRange(castISuccessOrErrors.Errors);
186+
}
187+
}
188+
_localSuccessMessage = string.Empty;
189+
}
190+
191+
if (castISuccessOrErrors.HasWarnings)
192+
_localWarnings.AddRange(castISuccessOrErrors.Warnings);
193+
//Note: we do NOT copy over any success message from the status being combined in.
194+
195+
return this;
196+
}
197+
157198
/// <summary>
158199
/// This sets a success message and sets the IsValid flag to true
159200
/// </summary>
@@ -191,6 +232,16 @@ public override string ToString()
191232
: string.Format("Failed with {0} error{1}", _localErrors.Count, _localErrors.Count > 1 ? "s" : string.Empty);
192233
}
193234

235+
/// <summary>
236+
/// This returns all the error messages, with parameter name prefix if appropriate, joined together into one long string
237+
/// </summary>
238+
/// <param name="joinWith">By default joined using \n, i.e. newline. Can provide different join string </param>
239+
/// <returns></returns>
240+
public string GetAllErrors(string joinWith = "\n")
241+
{
242+
return string.Join(joinWith, Errors.Select(x => FormatParamNames(x) + x.ErrorMessage));
243+
}
244+
194245
/// <summary>
195246
/// This returns the errors as:
196247
/// If only one error then as a html p

GenericLibsBase/ISuccessOrErrors.Generic.cs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,13 @@ public interface ISuccessOrErrors<T>
7272
/// </summary>
7373
bool IsValid { get; }
7474

75+
/// <summary>
76+
/// Returns true if any errors. Note: different to IsValid in that it just checks for errors,
77+
/// i.e. different to IsValid in that no errors but unset Validity will return false.
78+
/// Useful for checking inside a method where the status is being manipulated.
79+
/// </summary>
80+
bool HasErrors { get; }
81+
7582
/// <summary>
7683
/// Returns true if not errors or not validated yet, else false.
7784
/// </summary>
@@ -113,6 +120,22 @@ public interface ISuccessOrErrors<T>
113120
/// <returns></returns>
114121
ISuccessOrErrors<T> AddNamedParameterError(string parameterName, string errorformat, params object[] args);
115122

123+
/// <summary>
124+
/// This combines any errors or warnings into the current status.
125+
/// Note: it does NOT copy any success message into the current status
126+
/// as it is the job of the outer status to set its own success message
127+
/// </summary>
128+
/// <param name="status"></param>
129+
/// <returns></returns>
130+
ISuccessOrErrors<T> Combine(object status);
131+
132+
/// <summary>
133+
/// This returns all the error messages, with parameter name prefix if appropriate, joined together into one long string
134+
/// </summary>
135+
/// <param name="joinWith">By default joined using \n, i.e. newline. Can provide different join string </param>
136+
/// <returns></returns>
137+
string GetAllErrors(string joinWith = "\n");
138+
116139
/// <summary>
117140
/// This returns the errors as:
118141
/// If only one error then as a html p

GenericLibsBase/ISuccessOrErrors.cs

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,13 @@ public interface ISuccessOrErrors
5050
/// </summary>
5151
bool IsValid { get; }
5252

53+
/// <summary>
54+
/// Returns true if any errors. Note: different to IsValid in that it just checks for errors,
55+
/// i.e. different to IsValid in that no errors but unset Validity will return false.
56+
/// Useful for checking inside a method where the status is being manipulated.
57+
/// </summary>
58+
bool HasErrors { get; }
59+
5360
/// <summary>
5461
/// Returns true if not errors or not validated yet, else false.
5562
/// </summary>
@@ -60,7 +67,6 @@ public interface ISuccessOrErrors
6067
/// </summary>
6168
string SuccessMessage { get; }
6269

63-
6470
/// <summary>
6571
/// Adds a warning message. It places the test 'Warning: ' before the message
6672
/// </summary>
@@ -97,13 +103,29 @@ public interface ISuccessOrErrors
97103
/// <returns></returns>
98104
ISuccessOrErrors AddNamedParameterError(string parameterName, string errorformat, params object[] args);
99105

106+
/// <summary>
107+
/// This combines any errors or warnings into the current status.
108+
/// Note: it does NOT copy any success message into the current status
109+
/// as it is the job of the outer status to set its own success message
110+
/// </summary>
111+
/// <param name="status"></param>
112+
/// <returns></returns>
113+
ISuccessOrErrors Combine(object status);
114+
100115
/// <summary>
101116
/// This sets a success message and sets the IsValid flag to true
102117
/// </summary>
103118
/// <param name="successformat"></param>
104119
/// <param name="args"></param>
105120
ISuccessOrErrors SetSuccessMessage(string successformat, params object[] args);
106121

122+
/// <summary>
123+
/// This returns all the error messages, with parameter name prefix if appropriate, joined together into one long string
124+
/// </summary>
125+
/// <param name="joinWith">By default joined using \n, i.e. newline. Can provide different join string </param>
126+
/// <returns></returns>
127+
string GetAllErrors(string joinWith = "\n");
128+
107129
/// <summary>
108130
/// This returns the errors as:
109131
/// If only one error then as a html p

GenericLibsBase/NuGet/GenericLibsBase.nuspec

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22
<package >
33
<!-- Steps to making a Nuget package.
44
5+
Setup
6+
=====
7+
1. Download NuGet.exe from and place it in the directory C:\User\Jon\
8+
2. Make sure path points to it by running the line below
9+
set PATH=%PATH%;C:\Users\Jon\
10+
511
To create nuget package
612
=======================
713
1. Update version numbers
@@ -37,18 +43,18 @@
3743
-->
3844
<metadata>
3945
<id>GenericLibsBase</id>
40-
<version>1.0.0</version>
46+
<version>1.0.1</version>
4147
<title>GenericLibsBase</title>
4248
<authors>Jon Smith</authors>
4349
<owners>Jon Smith</owners>
4450
<licenseUrl>https://github.com/JonPSmith/GenericServices/blob/master/licence.txt</licenseUrl>
4551
<projectUrl>https://github.com/JonPSmith/GenericServices</projectUrl>
46-
<iconUrl>https://raw.githubusercontent.com/JonPSmith/GenericServices/master/GenericServices/NuGet/GenericServicesNuGetIcon128.png</iconUrl>
52+
<iconUrl>https://raw.githubusercontent.com/JonPSmith/GenericServices/master/GenericLibsBase/NuGet/GenericLibsBaseNuGetIcon128-png8.png</iconUrl>
4753
<requireLicenseAcceptance>false</requireLicenseAcceptance>
4854
<description>
4955
GenericLibsBase is a very small .NET class library holds common items used by GenericServices and other GenericXXX libraries.
5056
</description>
51-
<releaseNotes>First release.</releaseNotes>
57+
<releaseNotes>Added HasErrors, Combine() and GetAllErrors() to SuccessOrErrors/SuccessOrErrors.Generic to make working with nested methods returning a status easier to work with.</releaseNotes>
5258
<copyright>Copyright 2015</copyright>
5359
<frameworkAssemblies>
5460
<frameworkAssembly assemblyName="System.Core" targetFramework="net451" />

GenericServices/Core/EfGenericDtoBase.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public abstract class EfGenericDtoBase
6464
/// and class's TEntity class, or any of the associatedDTO TEntity classes ,
6565
/// has properties with the [Computed] attribute on them.
6666
/// </summary>
67-
public bool NeedsDecompile
67+
internal bool NeedsDecompile
6868
{
6969
get { return _needsDecompile || ForceNeedDecompile; }
7070
set { _needsDecompile = value; }
@@ -74,7 +74,7 @@ public bool NeedsDecompile
7474
/// Override and set to true if you wish to force NeedDecompile as always on in this DTO.
7575
/// Needed if accessing a calculated field in a related class
7676
/// </summary>
77-
public virtual bool ForceNeedDecompile { get { return false;} }
77+
protected virtual bool ForceNeedDecompile { get { return false;} }
7878

7979
/// <summary>
8080
/// This must be overridden to say what functions the DTO supports.

GenericServices/GenericServices.csproj

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,13 @@
3131
<DocumentationFile>bin\Release\GenericServices.xml</DocumentationFile>
3232
</PropertyGroup>
3333
<ItemGroup>
34-
<Reference Include="AutoMapper, Version=3.3.0.0, Culture=neutral, PublicKeyToken=be96cd2c38ef1005, processorArchitecture=MSIL">
35-
<SpecificVersion>False</SpecificVersion>
36-
<HintPath>..\packages\AutoMapper.3.3.0\lib\net40\AutoMapper.dll</HintPath>
34+
<Reference Include="AutoMapper, Version=3.3.1.0, Culture=neutral, PublicKeyToken=be96cd2c38ef1005, processorArchitecture=MSIL">
35+
<HintPath>..\packages\AutoMapper.3.3.1\lib\net40\AutoMapper.dll</HintPath>
36+
<Private>True</Private>
3737
</Reference>
38-
<Reference Include="AutoMapper.Net4, Version=3.3.0.0, Culture=neutral, PublicKeyToken=be96cd2c38ef1005, processorArchitecture=MSIL">
39-
<SpecificVersion>False</SpecificVersion>
40-
<HintPath>..\packages\AutoMapper.3.3.0\lib\net40\AutoMapper.Net4.dll</HintPath>
38+
<Reference Include="AutoMapper.Net4, Version=3.3.1.0, Culture=neutral, PublicKeyToken=be96cd2c38ef1005, processorArchitecture=MSIL">
39+
<HintPath>..\packages\AutoMapper.3.3.1\lib\net40\AutoMapper.Net4.dll</HintPath>
40+
<Private>True</Private>
4141
</Reference>
4242
<Reference Include="DelegateDecompiler, Version=1.0.0.0, Culture=neutral, PublicKeyToken=93b26a10a04705bd, processorArchitecture=MSIL">
4343
<SpecificVersion>False</SpecificVersion>
@@ -48,16 +48,16 @@
4848
<HintPath>..\packages\DelegateDecompiler.EntityFramework.0.15.0\lib\net45\DelegateDecompiler.EntityFramework.dll</HintPath>
4949
</Reference>
5050
<Reference Include="EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL">
51-
<SpecificVersion>False</SpecificVersion>
52-
<HintPath>..\packages\EntityFramework.6.1.2\lib\net45\EntityFramework.dll</HintPath>
51+
<HintPath>..\packages\EntityFramework.6.1.3\lib\net45\EntityFramework.dll</HintPath>
52+
<Private>True</Private>
5353
</Reference>
5454
<Reference Include="EntityFramework.SqlServer, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL">
55-
<SpecificVersion>False</SpecificVersion>
56-
<HintPath>..\packages\EntityFramework.6.1.2\lib\net45\EntityFramework.SqlServer.dll</HintPath>
55+
<HintPath>..\packages\EntityFramework.6.1.3\lib\net45\EntityFramework.SqlServer.dll</HintPath>
56+
<Private>True</Private>
5757
</Reference>
5858
<Reference Include="GenericLibsBase, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
59-
<SpecificVersion>False</SpecificVersion>
60-
<HintPath>..\packages\GenericLibsBase.1.0.0\lib\GenericLibsBase.dll</HintPath>
59+
<HintPath>..\packages\GenericLibsBase.1.0.1\lib\GenericLibsBase.dll</HintPath>
60+
<Private>True</Private>
6161
</Reference>
6262
<Reference Include="Mono.Reflection">
6363
<HintPath>..\packages\Mono.Reflection.1.0.0.0\lib\Mono.Reflection.dll</HintPath>

GenericServices/NuGet/AssemblyVersionPart.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,6 @@
4040
// by using the '*' as shown below:
4141
// [assembly: AssemblyVersion("1.0.*")]
4242

43-
[assembly: AssemblyVersion("1.0.3.0")]
44-
[assembly: AssemblyFileVersion("1.0.3.0")]
45-
[assembly: AssemblyInformationalVersion("1.0.3")]
43+
[assembly: AssemblyVersion("1.0.6.0")]
44+
[assembly: AssemblyFileVersion("1.0.6.0")]
45+
[assembly: AssemblyInformationalVersion("1.0.6")]

GenericServices/NuGet/GenericServices.nuspec

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
-->
4444
<metadata>
4545
<id>GenericServices</id>
46-
<version>1.0.3</version>
46+
<version>1.0.6</version>
4747
<title>GenericServices</title>
4848
<authors>Jon Smith</authors>
4949
<owners>Jon Smith</owners>
@@ -54,13 +54,19 @@
5454
<description>
5555
Generic Services is a .NET class library to help build a service layer, i.e. a layer that acts as a facard/adapter between your data layers containing an Entity Framework database and your User Interface or HTTP service.
5656
</description>
57-
<releaseNotes>Added .ConfigureAwait(false) to all library async calls. Minor changes to internal interfaces.</releaseNotes>
57+
<releaseNotes>
58+
Correction:
59+
1. Breaking change in making ForceNeedDecompile protected. This stops the property appearing in json output when used in WebApi etc.
60+
2. Also changed NeedsDecompile to internal for same reason as 1.
61+
3. Uses newer GenericLibsBase with improved status methods.
62+
4. Also updated to latest Entity Framework and AutoMapper
63+
</releaseNotes>
5864
<copyright>Copyright 2015</copyright>
5965
<tags>EntityFramework EF ASP.NET MVC DTO Validation Library</tags>
6066
<dependencies>
61-
<dependency id="GenericLibsBase" version="1.0.0" />
62-
<dependency id="EntityFramework" version="6.1" />
63-
<dependency id="AutoMapper" version="3.3" />
67+
<dependency id="GenericLibsBase" version="1.0.1" />
68+
<dependency id="EntityFramework" version="6.1.3" />
69+
<dependency id="AutoMapper" version="3.3.1" />
6470
<dependency id="DelegateDecompiler.EntityFramework" version="0.15" />
6571
</dependencies>
6672
<frameworkAssemblies>

GenericServices/packages.config

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<packages>
3-
<package id="AutoMapper" version="3.3.0" targetFramework="net451" />
3+
<package id="AutoMapper" version="3.3.1" targetFramework="net451" />
44
<package id="DelegateDecompiler" version="0.15.0" targetFramework="net451" />
55
<package id="DelegateDecompiler.EntityFramework" version="0.15.0" targetFramework="net451" />
6-
<package id="EntityFramework" version="6.1.2" targetFramework="net451" />
7-
<package id="GenericLibsBase" version="1.0.0" targetFramework="net451" />
6+
<package id="EntityFramework" version="6.1.3" targetFramework="net451" />
7+
<package id="GenericLibsBase" version="1.0.1" targetFramework="net451" />
88
<package id="Mono.Reflection" version="1.0.0.0" targetFramework="net451" />
99
</packages>

ProfileApp/App.config

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<configuration>
33
<configSections>
4-
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
4+
55
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
6-
</configSections>
6+
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 --></configSections>
77
<startup>
88
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.1" />
99
</startup>

ProfileApp/ProfileApp.csproj

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,20 +33,24 @@
3333
<WarningLevel>4</WarningLevel>
3434
</PropertyGroup>
3535
<ItemGroup>
36-
<Reference Include="AutoMapper">
37-
<HintPath>..\packages\AutoMapper.3.3.0\lib\net40\AutoMapper.dll</HintPath>
36+
<Reference Include="AutoMapper, Version=3.3.1.0, Culture=neutral, PublicKeyToken=be96cd2c38ef1005, processorArchitecture=MSIL">
37+
<HintPath>..\packages\AutoMapper.3.3.1\lib\net40\AutoMapper.dll</HintPath>
38+
<Private>True</Private>
3839
</Reference>
39-
<Reference Include="AutoMapper.Net4">
40-
<HintPath>..\packages\AutoMapper.3.3.0\lib\net40\AutoMapper.Net4.dll</HintPath>
40+
<Reference Include="AutoMapper.Net4, Version=3.3.1.0, Culture=neutral, PublicKeyToken=be96cd2c38ef1005, processorArchitecture=MSIL">
41+
<HintPath>..\packages\AutoMapper.3.3.1\lib\net40\AutoMapper.Net4.dll</HintPath>
42+
<Private>True</Private>
4143
</Reference>
4244
<Reference Include="DelegateDecompiler">
4345
<HintPath>..\packages\DelegateDecompiler.0.15.0\lib\net40-Client\DelegateDecompiler.dll</HintPath>
4446
</Reference>
45-
<Reference Include="EntityFramework">
46-
<HintPath>..\packages\EntityFramework.6.1.2\lib\net45\EntityFramework.dll</HintPath>
47+
<Reference Include="EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL">
48+
<HintPath>..\packages\EntityFramework.6.1.3\lib\net45\EntityFramework.dll</HintPath>
49+
<Private>True</Private>
4750
</Reference>
48-
<Reference Include="EntityFramework.SqlServer">
49-
<HintPath>..\packages\EntityFramework.6.1.2\lib\net45\EntityFramework.SqlServer.dll</HintPath>
51+
<Reference Include="EntityFramework.SqlServer, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL">
52+
<HintPath>..\packages\EntityFramework.6.1.3\lib\net45\EntityFramework.SqlServer.dll</HintPath>
53+
<Private>True</Private>
5054
</Reference>
5155
<Reference Include="Mono.Reflection">
5256
<HintPath>..\packages\Mono.Reflection.1.0.0.0\lib\Mono.Reflection.dll</HintPath>

ProfileApp/packages.config

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<packages>
3-
<package id="AutoMapper" version="3.3.0" targetFramework="net451" />
3+
<package id="AutoMapper" version="3.3.1" targetFramework="net451" />
44
<package id="DelegateDecompiler" version="0.15.0" targetFramework="net451" />
5-
<package id="EntityFramework" version="6.1.2" targetFramework="net451" />
5+
<package id="EntityFramework" version="6.1.3" targetFramework="net451" />
66
<package id="Mono.Reflection" version="1.0.0.0" targetFramework="net451" />
77
</packages>

Tests/DTOs/Concrete/DelegateDecompileForced.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ protected internal override CrudFunctions SupportedFunctions
2424
get { return CrudFunctions.List ; }
2525
}
2626

27-
public override bool ForceNeedDecompile
27+
protected override bool ForceNeedDecompile
2828
{
2929
get { return true; }
3030
}

0 commit comments

Comments
 (0)