Skip to content

Commit

Permalink
Changes to SuccessOrErrors in GenericLibsBase. Made ForceNeedDecompil…
Browse files Browse the repository at this point in the history
…e pttected and NeedsDecompile internal to stop them appearing in json output. Also updated NuGet to use latest EF and Auto
  • Loading branch information
JonPSmith committed Apr 14, 2015
1 parent e55dfe8 commit 7233253
Show file tree
Hide file tree
Showing 18 changed files with 603 additions and 87 deletions.
8 changes: 7 additions & 1 deletion GenericLibsBase/Core/SuccessOrErrors.Generic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,13 @@ public ISuccessOrErrors<T> SetSuccessWithResult(T result, string successformat,
return this;
}

/// <summary>
public new ISuccessOrErrors<T> Combine(object status)
{
base.Combine(status);
return this;
}

/// <summary>
/// This allows the current success message to be updated
/// </summary>
/// <param name="successformat"></param>
Expand Down
51 changes: 51 additions & 0 deletions GenericLibsBase/Core/SuccessOrErrors.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,13 @@ public IReadOnlyList<ValidationResult> Errors
/// </summary>
public bool IsValid { get { return (_localErrors != null && Errors.Count == 0); }}

/// <summary>
/// Returns true if any errors. Note: different to IsValid in that it just checks for errors,
/// i.e. different to IsValid in that no errors but unset Validity will return false.
/// Useful for checking inside a method where the status is being manipulated.
/// </summary>
public bool HasErrors { get { return (_localErrors != null && Errors.Count > 0); } }

/// <summary>
/// Returns true if not errors or not validated yet, else false.
/// </summary>
Expand Down Expand Up @@ -154,6 +161,40 @@ public ISuccessOrErrors AddNamedParameterError(string parameterName, string erro
return this;
}

/// <summary>
/// This combines any errors or warnings into the current status.
/// Note: it does NOT copy any success message into the current status
/// as it is the job of the outer status to set its own success message
/// </summary>
/// <param name="status"></param>
/// <returns></returns>
public ISuccessOrErrors Combine(object status)
{
var castISuccessOrErrors = status as ISuccessOrErrors;
if (castISuccessOrErrors == null)
throw new ArgumentNullException("status", "The status parameter was not derived from a type that supported ISuccessOrErrors.");

if (castISuccessOrErrors.HasErrors)
{
if (castISuccessOrErrors.HasErrors)
{
if (_localErrors == null)
_localErrors = castISuccessOrErrors.Errors.ToList();
else
{
_localErrors.AddRange(castISuccessOrErrors.Errors);
}
}
_localSuccessMessage = string.Empty;
}

if (castISuccessOrErrors.HasWarnings)
_localWarnings.AddRange(castISuccessOrErrors.Warnings);
//Note: we do NOT copy over any success message from the status being combined in.

return this;
}

/// <summary>
/// This sets a success message and sets the IsValid flag to true
/// </summary>
Expand Down Expand Up @@ -191,6 +232,16 @@ public override string ToString()
: string.Format("Failed with {0} error{1}", _localErrors.Count, _localErrors.Count > 1 ? "s" : string.Empty);
}

/// <summary>
/// This returns all the error messages, with parameter name prefix if appropriate, joined together into one long string
/// </summary>
/// <param name="joinWith">By default joined using \n, i.e. newline. Can provide different join string </param>
/// <returns></returns>
public string GetAllErrors(string joinWith = "\n")
{
return string.Join(joinWith, Errors.Select(x => FormatParamNames(x) + x.ErrorMessage));
}

/// <summary>
/// This returns the errors as:
/// If only one error then as a html p
Expand Down
23 changes: 23 additions & 0 deletions GenericLibsBase/ISuccessOrErrors.Generic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,13 @@ public interface ISuccessOrErrors<T>
/// </summary>
bool IsValid { get; }

/// <summary>
/// Returns true if any errors. Note: different to IsValid in that it just checks for errors,
/// i.e. different to IsValid in that no errors but unset Validity will return false.
/// Useful for checking inside a method where the status is being manipulated.
/// </summary>
bool HasErrors { get; }

/// <summary>
/// Returns true if not errors or not validated yet, else false.
/// </summary>
Expand Down Expand Up @@ -113,6 +120,22 @@ public interface ISuccessOrErrors<T>
/// <returns></returns>
ISuccessOrErrors<T> AddNamedParameterError(string parameterName, string errorformat, params object[] args);

/// <summary>
/// This combines any errors or warnings into the current status.
/// Note: it does NOT copy any success message into the current status
/// as it is the job of the outer status to set its own success message
/// </summary>
/// <param name="status"></param>
/// <returns></returns>
ISuccessOrErrors<T> Combine(object status);

/// <summary>
/// This returns all the error messages, with parameter name prefix if appropriate, joined together into one long string
/// </summary>
/// <param name="joinWith">By default joined using \n, i.e. newline. Can provide different join string </param>
/// <returns></returns>
string GetAllErrors(string joinWith = "\n");

/// <summary>
/// This returns the errors as:
/// If only one error then as a html p
Expand Down
24 changes: 23 additions & 1 deletion GenericLibsBase/ISuccessOrErrors.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,13 @@ public interface ISuccessOrErrors
/// </summary>
bool IsValid { get; }

/// <summary>
/// Returns true if any errors. Note: different to IsValid in that it just checks for errors,
/// i.e. different to IsValid in that no errors but unset Validity will return false.
/// Useful for checking inside a method where the status is being manipulated.
/// </summary>
bool HasErrors { get; }

/// <summary>
/// Returns true if not errors or not validated yet, else false.
/// </summary>
Expand All @@ -60,7 +67,6 @@ public interface ISuccessOrErrors
/// </summary>
string SuccessMessage { get; }


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

/// <summary>
/// This combines any errors or warnings into the current status.
/// Note: it does NOT copy any success message into the current status
/// as it is the job of the outer status to set its own success message
/// </summary>
/// <param name="status"></param>
/// <returns></returns>
ISuccessOrErrors Combine(object status);

/// <summary>
/// This sets a success message and sets the IsValid flag to true
/// </summary>
/// <param name="successformat"></param>
/// <param name="args"></param>
ISuccessOrErrors SetSuccessMessage(string successformat, params object[] args);

/// <summary>
/// This returns all the error messages, with parameter name prefix if appropriate, joined together into one long string
/// </summary>
/// <param name="joinWith">By default joined using \n, i.e. newline. Can provide different join string </param>
/// <returns></returns>
string GetAllErrors(string joinWith = "\n");

/// <summary>
/// This returns the errors as:
/// If only one error then as a html p
Expand Down
12 changes: 9 additions & 3 deletions GenericLibsBase/NuGet/GenericLibsBase.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@
<package >
<!-- Steps to making a Nuget package.
Setup
=====
1. Download NuGet.exe from and place it in the directory C:\User\Jon\
2. Make sure path points to it by running the line below
set PATH=%PATH%;C:\Users\Jon\
To create nuget package
=======================
1. Update version numbers
Expand Down Expand Up @@ -37,18 +43,18 @@
-->
<metadata>
<id>GenericLibsBase</id>
<version>1.0.0</version>
<version>1.0.1</version>
<title>GenericLibsBase</title>
<authors>Jon Smith</authors>
<owners>Jon Smith</owners>
<licenseUrl>https://github.com/JonPSmith/GenericServices/blob/master/licence.txt</licenseUrl>
<projectUrl>https://github.com/JonPSmith/GenericServices</projectUrl>
<iconUrl>https://raw.githubusercontent.com/JonPSmith/GenericServices/master/GenericServices/NuGet/GenericServicesNuGetIcon128.png</iconUrl>
<iconUrl>https://raw.githubusercontent.com/JonPSmith/GenericServices/master/GenericLibsBase/NuGet/GenericLibsBaseNuGetIcon128-png8.png</iconUrl>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>
GenericLibsBase is a very small .NET class library holds common items used by GenericServices and other GenericXXX libraries.
</description>
<releaseNotes>First release.</releaseNotes>
<releaseNotes>Added HasErrors, Combine() and GetAllErrors() to SuccessOrErrors/SuccessOrErrors.Generic to make working with nested methods returning a status easier to work with.</releaseNotes>
<copyright>Copyright 2015</copyright>
<frameworkAssemblies>
<frameworkAssembly assemblyName="System.Core" targetFramework="net451" />
Expand Down
4 changes: 2 additions & 2 deletions GenericServices/Core/EfGenericDtoBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public abstract class EfGenericDtoBase
/// and class's TEntity class, or any of the associatedDTO TEntity classes ,
/// has properties with the [Computed] attribute on them.
/// </summary>
public bool NeedsDecompile
internal bool NeedsDecompile
{
get { return _needsDecompile || ForceNeedDecompile; }
set { _needsDecompile = value; }
Expand All @@ -74,7 +74,7 @@ public bool NeedsDecompile
/// Override and set to true if you wish to force NeedDecompile as always on in this DTO.
/// Needed if accessing a calculated field in a related class
/// </summary>
public virtual bool ForceNeedDecompile { get { return false;} }
protected virtual bool ForceNeedDecompile { get { return false;} }

/// <summary>
/// This must be overridden to say what functions the DTO supports.
Expand Down
24 changes: 12 additions & 12 deletions GenericServices/GenericServices.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@
<DocumentationFile>bin\Release\GenericServices.xml</DocumentationFile>
</PropertyGroup>
<ItemGroup>
<Reference Include="AutoMapper, Version=3.3.0.0, Culture=neutral, PublicKeyToken=be96cd2c38ef1005, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\AutoMapper.3.3.0\lib\net40\AutoMapper.dll</HintPath>
<Reference Include="AutoMapper, Version=3.3.1.0, Culture=neutral, PublicKeyToken=be96cd2c38ef1005, processorArchitecture=MSIL">
<HintPath>..\packages\AutoMapper.3.3.1\lib\net40\AutoMapper.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="AutoMapper.Net4, Version=3.3.0.0, Culture=neutral, PublicKeyToken=be96cd2c38ef1005, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\AutoMapper.3.3.0\lib\net40\AutoMapper.Net4.dll</HintPath>
<Reference Include="AutoMapper.Net4, Version=3.3.1.0, Culture=neutral, PublicKeyToken=be96cd2c38ef1005, processorArchitecture=MSIL">
<HintPath>..\packages\AutoMapper.3.3.1\lib\net40\AutoMapper.Net4.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="DelegateDecompiler, Version=1.0.0.0, Culture=neutral, PublicKeyToken=93b26a10a04705bd, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
Expand All @@ -48,16 +48,16 @@
<HintPath>..\packages\DelegateDecompiler.EntityFramework.0.15.0\lib\net45\DelegateDecompiler.EntityFramework.dll</HintPath>
</Reference>
<Reference Include="EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\EntityFramework.6.1.2\lib\net45\EntityFramework.dll</HintPath>
<HintPath>..\packages\EntityFramework.6.1.3\lib\net45\EntityFramework.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="EntityFramework.SqlServer, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\EntityFramework.6.1.2\lib\net45\EntityFramework.SqlServer.dll</HintPath>
<HintPath>..\packages\EntityFramework.6.1.3\lib\net45\EntityFramework.SqlServer.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="GenericLibsBase, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\GenericLibsBase.1.0.0\lib\GenericLibsBase.dll</HintPath>
<HintPath>..\packages\GenericLibsBase.1.0.1\lib\GenericLibsBase.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Mono.Reflection">
<HintPath>..\packages\Mono.Reflection.1.0.0.0\lib\Mono.Reflection.dll</HintPath>
Expand Down
6 changes: 3 additions & 3 deletions GenericServices/NuGet/AssemblyVersionPart.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,6 @@
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]

[assembly: AssemblyVersion("1.0.3.0")]
[assembly: AssemblyFileVersion("1.0.3.0")]
[assembly: AssemblyInformationalVersion("1.0.3")]
[assembly: AssemblyVersion("1.0.6.0")]
[assembly: AssemblyFileVersion("1.0.6.0")]
[assembly: AssemblyInformationalVersion("1.0.6")]
16 changes: 11 additions & 5 deletions GenericServices/NuGet/GenericServices.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
-->
<metadata>
<id>GenericServices</id>
<version>1.0.3</version>
<version>1.0.6</version>
<title>GenericServices</title>
<authors>Jon Smith</authors>
<owners>Jon Smith</owners>
Expand All @@ -54,13 +54,19 @@
<description>
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.
</description>
<releaseNotes>Added .ConfigureAwait(false) to all library async calls. Minor changes to internal interfaces.</releaseNotes>
<releaseNotes>
Correction:
1. Breaking change in making ForceNeedDecompile protected. This stops the property appearing in json output when used in WebApi etc.
2. Also changed NeedsDecompile to internal for same reason as 1.
3. Uses newer GenericLibsBase with improved status methods.
4. Also updated to latest Entity Framework and AutoMapper
</releaseNotes>
<copyright>Copyright 2015</copyright>
<tags>EntityFramework EF ASP.NET MVC DTO Validation Library</tags>
<dependencies>
<dependency id="GenericLibsBase" version="1.0.0" />
<dependency id="EntityFramework" version="6.1" />
<dependency id="AutoMapper" version="3.3" />
<dependency id="GenericLibsBase" version="1.0.1" />
<dependency id="EntityFramework" version="6.1.3" />
<dependency id="AutoMapper" version="3.3.1" />
<dependency id="DelegateDecompiler.EntityFramework" version="0.15" />
</dependencies>
<frameworkAssemblies>
Expand Down
6 changes: 3 additions & 3 deletions GenericServices/packages.config
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="AutoMapper" version="3.3.0" targetFramework="net451" />
<package id="AutoMapper" version="3.3.1" targetFramework="net451" />
<package id="DelegateDecompiler" version="0.15.0" targetFramework="net451" />
<package id="DelegateDecompiler.EntityFramework" version="0.15.0" targetFramework="net451" />
<package id="EntityFramework" version="6.1.2" targetFramework="net451" />
<package id="GenericLibsBase" version="1.0.0" targetFramework="net451" />
<package id="EntityFramework" version="6.1.3" targetFramework="net451" />
<package id="GenericLibsBase" version="1.0.1" targetFramework="net451" />
<package id="Mono.Reflection" version="1.0.0.0" targetFramework="net451" />
</packages>
4 changes: 2 additions & 2 deletions ProfileApp/App.config
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->

<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections>
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 --></configSections>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.1" />
</startup>
Expand Down
20 changes: 12 additions & 8 deletions ProfileApp/ProfileApp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -33,20 +33,24 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="AutoMapper">
<HintPath>..\packages\AutoMapper.3.3.0\lib\net40\AutoMapper.dll</HintPath>
<Reference Include="AutoMapper, Version=3.3.1.0, Culture=neutral, PublicKeyToken=be96cd2c38ef1005, processorArchitecture=MSIL">
<HintPath>..\packages\AutoMapper.3.3.1\lib\net40\AutoMapper.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="AutoMapper.Net4">
<HintPath>..\packages\AutoMapper.3.3.0\lib\net40\AutoMapper.Net4.dll</HintPath>
<Reference Include="AutoMapper.Net4, Version=3.3.1.0, Culture=neutral, PublicKeyToken=be96cd2c38ef1005, processorArchitecture=MSIL">
<HintPath>..\packages\AutoMapper.3.3.1\lib\net40\AutoMapper.Net4.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="DelegateDecompiler">
<HintPath>..\packages\DelegateDecompiler.0.15.0\lib\net40-Client\DelegateDecompiler.dll</HintPath>
</Reference>
<Reference Include="EntityFramework">
<HintPath>..\packages\EntityFramework.6.1.2\lib\net45\EntityFramework.dll</HintPath>
<Reference Include="EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL">
<HintPath>..\packages\EntityFramework.6.1.3\lib\net45\EntityFramework.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="EntityFramework.SqlServer">
<HintPath>..\packages\EntityFramework.6.1.2\lib\net45\EntityFramework.SqlServer.dll</HintPath>
<Reference Include="EntityFramework.SqlServer, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL">
<HintPath>..\packages\EntityFramework.6.1.3\lib\net45\EntityFramework.SqlServer.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Mono.Reflection">
<HintPath>..\packages\Mono.Reflection.1.0.0.0\lib\Mono.Reflection.dll</HintPath>
Expand Down
4 changes: 2 additions & 2 deletions ProfileApp/packages.config
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="AutoMapper" version="3.3.0" targetFramework="net451" />
<package id="AutoMapper" version="3.3.1" targetFramework="net451" />
<package id="DelegateDecompiler" version="0.15.0" targetFramework="net451" />
<package id="EntityFramework" version="6.1.2" targetFramework="net451" />
<package id="EntityFramework" version="6.1.3" targetFramework="net451" />
<package id="Mono.Reflection" version="1.0.0.0" targetFramework="net451" />
</packages>
2 changes: 1 addition & 1 deletion Tests/DTOs/Concrete/DelegateDecompileForced.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ protected internal override CrudFunctions SupportedFunctions
get { return CrudFunctions.List ; }
}

public override bool ForceNeedDecompile
protected override bool ForceNeedDecompile
{
get { return true; }
}
Expand Down
Loading

0 comments on commit 7233253

Please sign in to comment.