Skip to content

Commit 63ca016

Browse files
authored
Merge pull request #10 from I-RzR-I/feature/AddOwnImpPropNotify
Add own implementation for 'INotifyPropertyChanged'.
2 parents dda6a36 + 139a509 commit 63ca016

14 files changed

+495
-35
lines changed

build/pack-repo.ps1

+267
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,267 @@
1+
Param
2+
(
3+
[Parameter(Mandatory = $false)]
4+
[string]$ownVersion,
5+
[Parameter(Mandatory = $false)]
6+
[bool]$runTest
7+
);
8+
9+
$assemblyPath = "..\src\shared\GeneralAssemblyInfo.cs";
10+
$defaultVersion = "1.0.0.0";
11+
$nugetPath = "../nuget";
12+
$data = ("..\src\EntityMaxLengthTrim\EntityMaxLengthTrim.csproj");
13+
$testExec = $false;
14+
15+
<#
16+
.SYNOPSIS
17+
A brief description of the Get-CurrentAssemblyVersion function.
18+
19+
.DESCRIPTION
20+
Get current assembly version
21+
22+
.EXAMPLE
23+
PS C:\> Get-CurrentAssemblyVersion
24+
25+
.NOTES
26+
Additional information about the function.
27+
#>
28+
function Get-CurrentAssemblyVersion
29+
{
30+
[OutputType([string])]
31+
param ()
32+
33+
$assemblyInfo = (Get-Content $assemblyPath);
34+
$asVersion = ($assemblyInfo -match 'AssemblyVersion\(".*"\)');
35+
$asVersion = $asVersion -split ('"');
36+
$asVersion = $asVersion[1];
37+
38+
return $asVersion;
39+
}
40+
41+
<#
42+
.SYNOPSIS
43+
A brief description of the Build-And-Pack-BuildPack function.
44+
45+
.DESCRIPTION
46+
Build project and pack as package (u pkg)
47+
48+
.PARAMETER packVersion
49+
Package/Build version
50+
51+
.PARAMETER currentVersion
52+
A description of the currentVersion parameter.
53+
54+
.EXAMPLE
55+
PS C:\> Build-And-Pack-BuildPack -packVersion 'Value1'
56+
57+
.NOTES
58+
Additional information about the function.
59+
#>
60+
function Set-BuildAndPack
61+
{
62+
[CmdletBinding()]
63+
[OutputType([bool])]
64+
param
65+
(
66+
[Parameter(Mandatory = $true)]
67+
[string]$packVersion,
68+
[string]$currentVersion
69+
)
70+
71+
try
72+
{
73+
Write-Host "Project restore '$($_)'!" -ForegroundColor Green;
74+
dotnet restore $($_);
75+
76+
Write-Host "Build in Release '$($_)'!" -ForegroundColor Green;
77+
$buildResult = dotnet build $($_) --source https://api.nuget.org/v3/index.json -c Release /p:AssemblyVersion=$packVersion /p:AssemblyFileVersion=$packVersion /p:AssemblyInformationalVersion=$packVersion;
78+
if ($LASTEXITCODE -ne 0)
79+
{
80+
Set-VersionAssembly -packVersion $currentVersion;
81+
Write-Host $buildResult;
82+
83+
return $false;
84+
}
85+
86+
Write-Host "Pack in Release '$($_)'!" -ForegroundColor Green;
87+
$packResult = dotnet pack $($_) -p:PackageVersion=$packVersion --no-build -c Release --output $nugetPath;
88+
if ($LASTEXITCODE -ne 0)
89+
{
90+
Set-VersionAssembly -packVersion $currentVersion;
91+
Write-Host $buildResult;
92+
93+
return $false;
94+
}
95+
96+
return $true;
97+
}
98+
catch
99+
{
100+
Write-Host -foregroundcolor Red "An error occurred: $_"
101+
102+
return $false;
103+
}
104+
}
105+
106+
<#
107+
.SYNOPSIS
108+
A brief description of the Get-TimeStamp function.
109+
110+
.DESCRIPTION
111+
Get time stamp version
112+
113+
.EXAMPLE
114+
PS C:\> Get-TimeStamp
115+
116+
.NOTES
117+
Additional information about the function.
118+
#>
119+
function Get-TimeStamp
120+
{
121+
[CmdletBinding()]
122+
[OutputType([int])]
123+
param ()
124+
125+
$current = [System.DateTime]::Now;
126+
$end = [System.DateTime]::Now.Date;
127+
$diff = (New-TimeSpan -Start $current -End $end).TotalSeconds / 10;
128+
$timeSec = If ($diff -le 0) { $diff * -1 }
129+
Else { $diff };
130+
131+
return [int]$timeSec;
132+
}
133+
134+
<#
135+
.SYNOPSIS
136+
A brief description of the Set-VersionAssembly function.
137+
138+
.DESCRIPTION
139+
Set current version in assembly file
140+
141+
.PARAMETER packVersion
142+
A description of the packVersion parameter.
143+
144+
.EXAMPLE
145+
PS C:\> Set-VersionAssembly -packVersion 'Value1'
146+
147+
.NOTES
148+
Additional information about the function.
149+
#>
150+
function Set-VersionAssembly
151+
{
152+
[CmdletBinding()]
153+
[OutputType([void])]
154+
param
155+
(
156+
[Parameter(Mandatory = $true)]
157+
[string]$packVersion
158+
)
159+
$NewVersion = 'AssemblyVersion("' + $packVersion + '")';
160+
$NewFileVersion = 'AssemblyFileVersion("' + $packVersion + '")';
161+
$NewAssemblyInformationalVersion = 'AssemblyInformationalVersion("' + $packVersion + '")';
162+
163+
(Get-Content $assemblyPath -encoding utf8) |
164+
%{ $_ -replace 'AssemblyVersion\("[0-9]+(\.([0-9]+|\*)){1,3}"\)', $NewVersion } |
165+
%{ $_ -replace 'AssemblyFileVersion\("[0-9]+(\.([0-9]+|\*)){1,3}"\)', $NewFileVersion } |
166+
%{ $_ -replace 'AssemblyInformationalVersion\("[0-9x]+(\.([0-9x]+|\*)){1,3}"\)', $NewAssemblyInformationalVersion } |
167+
Set-Content $assemblyPath -encoding utf8
168+
}
169+
170+
<#
171+
.SYNOPSIS
172+
A brief description of the Exec-TestSolution function.
173+
174+
.DESCRIPTION
175+
Execute solution test
176+
177+
.EXAMPLE
178+
PS C:\> Exec-TestSolution
179+
180+
.NOTES
181+
Additional information about the function.
182+
#>
183+
function Exec-TestSolution
184+
{
185+
[CmdletBinding()]
186+
[OutputType([bool])]
187+
param ()
188+
189+
# Merge all streams into stdout
190+
$result = dotnet test "..\src\tests\EntityModelStringTruncateTest\EntityModelStringTruncateTest.csproj" *>&1
191+
192+
# Evaluate success/failure
193+
if ($LASTEXITCODE -eq 0)
194+
{
195+
return $true;
196+
}
197+
else
198+
{
199+
$errorString = $result -join [System.Environment]::NewLine;
200+
Write-Host -foregroundcolor Red "An error occurred: $errorString";
201+
202+
return $false;
203+
}
204+
}
205+
206+
If ($runTest -eq $true)
207+
{
208+
Write-Host "Init test solution...`n" -ForegroundColor Green;
209+
$testExec = Exec-TestSolution;
210+
}
211+
Else { $testExec = $true; }
212+
213+
If ($testExec -eq $true)
214+
{
215+
Write-Host "Path to pack: '$nugetPath'`n" -ForegroundColor Green;
216+
217+
$currentVersion = "";
218+
If ($ownVersion -eq $null -or $ownVersion -eq "") { $currentVersion = Get-CurrentAssemblyVersion; }
219+
Else { $currentVersion = $ownVersion; }
220+
221+
$directoryInfo = Get-ChildItem $nugetPath | Where-Object { $_.Name -match '[a-z]*.1.0.0.nupkg$' } | Measure-Object;
222+
If ($defaultVersion -eq $currentVersion -and $directoryInfo.count -eq 0)
223+
{
224+
Set-VersionAssembly -packVersion $currentVersion;
225+
226+
$data | ForEach-Object {
227+
$buildResult = Set-BuildAndPack -packVersion $currentVersion;
228+
If ($buildResult -eq $false -or $buildResult -contains $false)
229+
{
230+
Write-Host "`nBuild/pack failed!!!" -ForegroundColor Red;
231+
232+
exit;
233+
}
234+
}
235+
236+
Write-Host "`nPack executed with success with version: $currentVersion!" -ForegroundColor Green;
237+
238+
exit;
239+
}
240+
Else
241+
{
242+
$finalVersion = "";
243+
If ($ownVersion -eq $null -or $ownVersion -eq "")
244+
{
245+
$versArray = $currentVersion.Split('.');
246+
$finalVersion = $versArray[0].ToString() + "." + $versArray[1].ToString() + "." + (([int]$versArray[2]) + 1).ToString() + "." + (Get-TimeStamp).ToString();
247+
}
248+
Else { $finalVersion = $ownVersion; }
249+
250+
Set-VersionAssembly -packVersion $finalVersion;
251+
252+
$data | ForEach-Object {
253+
$buildResult = Set-BuildAndPack -packVersion $finalVersion -currentVersion $currentVersion;
254+
If ($buildResult -eq $false -or $buildResult -contains $false)
255+
{
256+
Write-Host "`nBuild/pack failed!!!" -ForegroundColor Red;
257+
258+
exit;
259+
}
260+
}
261+
262+
Write-Host "`nPack executed with success with version: $finalVersion!" -ForegroundColor Green;
263+
264+
exit;
265+
}
266+
}
267+
Else { exit; }

docs/CHANGELOG.md

+5-1
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,8 @@
2424
-> Add option to sign the new version of the files.<br/>
2525

2626
### **1.0.8.2220**
27-
-> Fix wrong modification.<br />
27+
-> Fix wrong modification.<br />
28+
29+
### **1.0.9.5667**
30+
-> Add internal extension.<br />
31+
-> Add own implementation `EntityPropChangeEventBase` for `INotifyPropertyChanged` .<br />

src/EntityMaxLengthTrim/EntityMaxLengthTrim.csproj

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>netstandard2.0</TargetFramework>
54
<TargetFrameworks>net45;netstandard1.5;netstandard2.0;netstandard2.1</TargetFrameworks>
65
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
76
<Authors>RzR</Authors>
@@ -97,7 +96,7 @@
9796
</VisualStudio>
9897
</ProjectExtensions>
9998

100-
<Target Name="PostBuild" AfterTargets="PostBuildEvent">
99+
<!--<Target Name="PostBuild" AfterTargets="PostBuildEvent">
101100
<Exec Command="PowerShell -NoProfile -ExecutionPolicy unrestricted -file $(SolutionDir)../build/pack.ps1 $(ConfigurationName)" />
102-
</Target>
101+
</Target>-->
103102
</Project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
// ***********************************************************************
2+
// Assembly : RzR.Shared.Entity.EntityMaxLengthTrim
3+
// Author : RzR
4+
// Created On : 2023-12-15 14:32
5+
//
6+
// Last Modified By : RzR
7+
// Last Modified On : 2023-12-16 15:12
8+
// ***********************************************************************
9+
// <copyright file="EntityPropChangeEventBase.cs" company="">
10+
// Copyright (c) RzR. All rights reserved.
11+
// </copyright>
12+
//
13+
// <summary>
14+
// </summary>
15+
// ***********************************************************************
16+
17+
#region U S A G E S
18+
19+
using System.ComponentModel;
20+
using EntityMaxLengthTrim.Interceptors;
21+
22+
#endregion
23+
24+
namespace EntityMaxLengthTrim
25+
{
26+
/// -------------------------------------------------------------------------------------------------
27+
/// <summary>An entity property change event base.</summary>
28+
/// <remarks></remarks>
29+
/// <seealso cref="System.ComponentModel.INotifyPropertyChanged" />
30+
/// =================================================================================================
31+
public class EntityPropChangeEventBase : INotifyPropertyChanged
32+
{
33+
/// <summary>
34+
/// Property changed event handler
35+
/// </summary>
36+
public event PropertyChangedEventHandler PropertyChanged;
37+
38+
/// <summary>
39+
/// Property changed event
40+
/// </summary>
41+
/// <param name="callingEntity">Calling entity</param>
42+
/// <param name="propertyName">Changed property name</param>
43+
protected virtual void OnPropertyChanged<T>(T callingEntity, string propertyName)
44+
{
45+
StringInterceptor.ApplyStringMaxAllowedLength(callingEntity, propertyName, false);
46+
PropertyChanged?.Invoke(callingEntity, new PropertyChangedEventArgs(propertyName));
47+
}
48+
49+
/// <summary>
50+
/// Set content to property
51+
/// </summary>
52+
/// <param name="callingEntity">Calling entity</param>
53+
/// <param name="propertyName">Changed property name</param>
54+
/// <param name="getValue">Get property value</param>
55+
/// <param name="setValue">Set property value</param>
56+
/// <typeparam name="T">Calling entity type</typeparam>
57+
/// <returns></returns>
58+
protected virtual void SetContent<T>(T callingEntity, string propertyName, ref string getValue,
59+
ref string setValue)
60+
{
61+
if (getValue == setValue) return;
62+
63+
getValue = setValue;
64+
StringInterceptor.ApplyStringMaxAllowedLength(callingEntity, propertyName, false);
65+
PropertyChanged?.Invoke(callingEntity, new PropertyChangedEventArgs(propertyName));
66+
}
67+
}
68+
}

src/EntityMaxLengthTrim/Extensions/FluentExtensions.cs

+1-2
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,7 @@ public static TEntity ToSafeStoreStrings<TEntity>(this TEntity initSourceObject,
4545
{
4646
return StringInterceptor.ApplyStringMaxAllowedLength(initSourceObject, useDotOnEnd);
4747
}
48-
49-
48+
5049
/// <summary>
5150
/// Prepare initialized object to save store string properties.
5251
/// </summary>

src/EntityMaxLengthTrim/Extensions/IntExtensions.cs

+11
Original file line numberDiff line numberDiff line change
@@ -37,5 +37,16 @@ internal static bool IsNullOrZero(this int source)
3737
{
3838
return source.IsNull() || source == 0;
3939
}
40+
41+
/// <summary>
42+
/// Check if source object is less or equals with 0
43+
/// </summary>
44+
/// <param name="source">Source object to be checked</param>
45+
/// <returns>Return bool value (validation result).</returns>
46+
[CodeSource("https://github.com/I-RzR-I/DomainCommonExtensions", "RzR", 1.0)]
47+
internal static bool IsLessOrEqualWithZero(this int source)
48+
{
49+
return source <= 0;
50+
}
4051
}
4152
}

0 commit comments

Comments
 (0)