Skip to content

Commit f42bbf0

Browse files
authored
Merge pull request #23 from I-RzR-I/feature/SmallCodeAdjustments
Adjust some methods location and new exec function
2 parents b3d58a7 + 6e15575 commit f42bbf0

File tree

18 files changed

+771
-37
lines changed

18 files changed

+771
-37
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,4 +267,6 @@ wwwroot/lib/
267267

268268
# Coverlet
269269
Report/
270-
coverage.*
270+
coverage.*
271+
272+
*.ncrunchsolution

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2022-2023 RzR
3+
Copyright (c) 2022-2024 RzR
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ As a result, you can have control over the messages and types of messages that w
1111
By currently following, 6 general types of messages (`Info`, `Warning`, `Error`, `NotFound`, `AccessDenied`, `Exception`) are implemented that can be returned to the caller.
1212
As you can see in the `MessageType` enum, there are 9 types of messages, for all 3 (`Info`, `Warning`, `Error`) types previously specified exists with new ends `Confirm`. The idea of all of them is to inform UI (or caller) that returned message will be parsed/used as a dialog box/popup/modal.
1313

14-
For more flexible and intuitive use, in solution persist extension method like fluent access to set message, error, etc (`WithMessage`, `WithKeyCode`, `WithCodeMessage`, `WithError`, `WithErrors`).
14+
For more flexible and intuitive use, in solution persist extension method like fluent access to set message, error, etc (`WithMessage`, `WithKeyCode`, `WithCodeMessage`, `WithError`, `WithErrors`). In some cases when you may have the necessity to add in the result additional information like the link between the code execution method and data store name: stored procedure, function or table, etc; in code/result is defined object `RelatedObject` where this information can be stored and returned to the caller.
1515

16-
For more efficiently using, when in some cases when you may need to execute some custom actions after a successful or failed execution request. In that case was added extension methods (`ActionOnSuccess`, `ActionOnFailure`, `ActionOn`, `ExecuteAction`) which allow you to execute this action like insert log when execution has a status equal to failure.
16+
For more efficiently using, when in some cases when you may need to execute some custom actions/functions after a successful or failed execution request. In that case was added extension methods (`ActionOnSuccess`, `ActionOnFailure`, `ActionOn`, `ExecuteAction`, `FunctionOnSuccess`, `FunctionOnFailure`, `FunctionOn`, `ExecuteFunction`) which allow you to execute this action/function like insert log when execution has a status equal to failure.
1717

1818
No additional components or packs are required for use. So, it only needs to be added/installed in the project and can be used instantly.
1919

docs/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,8 @@
5858
-> Add `RelatedObject` in code (means related object in code execution, usually used in case of some errors to show method name, stored procedure, table, etc).<br />
5959
-> Adjust code to solution code style.<br />
6060
-> Adjust exposed methods and add a few new.
61+
62+
63+
### **v1.3.3.6068**
64+
-> Adjust the location for methods: `GetFirstMessage`, `GetFirstMessageWithDetails`.<br />
65+
-> Add a new extension for result execution `FunctionExtensions` (`FunctionOnSuccess`, `FunctionOnFailure`, `FunctionOn`, `ExecuteFunction`), which allows to execute of one or more functions.<br />

docs/usage.md

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,4 +195,28 @@ public IResult<Foo> GetFoo(int recordId)
195195
return result;
196196
}
197197
```
198-
The same situation and implementation can be used for `ActionOn`, `ExecuteAction` with specifying necessary action/s.
198+
The same situation and implementation can be used for `ActionOn`, `ExecuteAction` with specifying necessary action/s.
199+
200+
An example how to user `RelatedObject` in result:
201+
```csharp
202+
public async Task<Result> AddFooAsync(Foo request, CancellationToken cancellationToken
203+
= default)
204+
{
205+
try
206+
{
207+
await _ctx.Foos.AddAsync(request, cancellationToken);
208+
await _ctx.SaveChangesAsync(cancellationToken);
209+
210+
//return success message with data
211+
return true;
212+
}
213+
catch (Exception e)
214+
{
215+
_logger.LogError(e, "Internal error on add foo");
216+
217+
return Result.
218+
.Failure("Internal error on add new foo", relatedObjects: new RelatedObjectModel(nameof(AddFooAsync), "Foos"))
219+
.AddError(e);
220+
}
221+
}
222+
```

src/AggregatedGenericResultMessage/Abstractions/IResult.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
using System.Collections.Generic;
2020
using System.Xml.Serialization;
2121
using AggregatedGenericResultMessage.Abstractions.Models;
22+
using AggregatedGenericResultMessage.Models;
2223

2324
#endregion
2425

@@ -56,5 +57,19 @@ public interface IResult
5657
/// <returns></returns>
5758
/// <remarks></remarks>
5859
SoapResult ToSoapResult();
60+
61+
/// <summary>
62+
/// Get first message from response
63+
/// </summary>
64+
/// <returns></returns>
65+
/// <remarks></remarks>
66+
string GetFirstMessage();
67+
68+
/// <summary>
69+
/// Get first message from response
70+
/// </summary>
71+
/// <returns></returns>
72+
/// <remarks></remarks>
73+
MessageDataModel GetFirstMessageWithDetails();
5974
}
6075
}

src/AggregatedGenericResultMessage/Abstractions/IResultOfT.cs

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
#region U S A G E S
1818

1919
using System.Xml.Serialization;
20-
using AggregatedGenericResultMessage.Models;
2120

2221
#endregion
2322

@@ -31,19 +30,5 @@ public interface IResult<T> : IResult
3130
/// The result of the response, if there is no errors.
3231
/// </summary>
3332
T Response { get; set; }
34-
35-
/// <summary>
36-
/// Get first message from response
37-
/// </summary>
38-
/// <returns></returns>
39-
/// <remarks></remarks>
40-
string GetFirstMessage();
41-
42-
/// <summary>
43-
/// Get first message from response
44-
/// </summary>
45-
/// <returns></returns>
46-
/// <remarks></remarks>
47-
MessageDataModel GetFirstMessageWithDetails();
4833
}
4934
}

src/AggregatedGenericResultMessage/AggregatedGenericResultMessage.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,10 @@
5858
</None>
5959
<None Include="..\.editorconfig" />
6060
</ItemGroup>
61+
62+
<ItemGroup>
63+
<Folder Include="Extensions\Result\Functions\" />
64+
</ItemGroup>
6165
<ProjectExtensions>
6266
<VisualStudio>
6367
<UserProperties BuildVersion_StartDate="2022/7/1" />
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
// ***********************************************************************
2+
// Assembly : RzR.Shared.ResultMessage.AggregatedGenericResultMessage
3+
// Author : RzR
4+
// Created On : 2024-01-31 22:55
5+
//
6+
// Last Modified By : RzR
7+
// Last Modified On : 2024-01-31 22:58
8+
// ***********************************************************************
9+
// <copyright file="BoolExtensions.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 CodeSource;
20+
21+
#endregion
22+
23+
namespace AggregatedGenericResultMessage.Extensions.Common
24+
{
25+
/// -------------------------------------------------------------------------------------------------
26+
/// <summary>An extensions.</summary>
27+
/// <remarks>31-Jan-24.</remarks>
28+
/// =================================================================================================
29+
internal static class BoolExtensions
30+
{
31+
/// -------------------------------------------------------------------------------------------------
32+
/// <summary>Check if source value is equals with true.</summary>
33+
/// <remarks></remarks>
34+
/// <param name="source">Source object to be checked.</param>
35+
/// <returns>True if true, false if not.</returns>
36+
/// =================================================================================================
37+
[CodeSource("https://github.com/I-RzR-I/DomainCommonExtensions", "RzR", 1D)]
38+
internal static bool IsTrue(this bool source)
39+
=> source.IsNotNull() && source.Equals(true);
40+
41+
/// -------------------------------------------------------------------------------------------------
42+
/// <summary>Check if source value is equals with false.</summary>
43+
/// <remarks></remarks>
44+
/// <param name="source">Source object to be checked.</param>
45+
/// <returns>True if false, false if not.</returns>
46+
/// =================================================================================================
47+
[CodeSource("https://github.com/I-RzR-I/DomainCommonExtensions", "RzR", 1D)]
48+
internal static bool IsFalse(this bool source)
49+
=> source.IsNull() || source.Equals(false);
50+
}
51+
}

src/AggregatedGenericResultMessage/Extensions/Result/Actions/ActionExtensions.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,8 @@ public static TResult ActionOnFailure<TResult>(this TResult result, params Actio
7575
/// <param name="onFailure">Action on failure</param>
7676
/// <typeparam name="TResult">Type of result</typeparam>
7777
/// <remarks></remarks>
78-
public static TResult ActionOn<TResult>(this TResult result, Action<TResult> onSuccess, Action<TResult> onFailure)
79-
where TResult : IResult
78+
public static TResult ActionOn<TResult>(this TResult result, Action<TResult> onSuccess,
79+
Action<TResult> onFailure) where TResult : IResult
8080
{
8181
if (!result.IsSuccess)
8282
{
@@ -102,8 +102,8 @@ public static TResult ActionOn<TResult>(this TResult result, Action<TResult> onS
102102
/// <param name="onFailure">Action on failure</param>
103103
/// <typeparam name="TResult">Type of result</typeparam>
104104
/// <remarks></remarks>
105-
public static TResult ActionOn<TResult>(this TResult result, Action<TResult> onSuccess, IEnumerable<Action<TResult>> onFailure)
106-
where TResult : IResult
105+
public static TResult ActionOn<TResult>(this TResult result, Action<TResult> onSuccess,
106+
IEnumerable<Action<TResult>> onFailure) where TResult : IResult
107107
{
108108
if (!result.IsSuccess)
109109
{
@@ -130,8 +130,8 @@ public static TResult ActionOn<TResult>(this TResult result, Action<TResult> onS
130130
/// <param name="onFailure">Action on failure</param>
131131
/// <typeparam name="TResult">Type of result</typeparam>
132132
/// <remarks></remarks>
133-
public static TResult ActionOn<TResult>(this TResult result, IEnumerable<Action<TResult>> onSuccess, Action<TResult> onFailure)
134-
where TResult : IResult
133+
public static TResult ActionOn<TResult>(this TResult result, IEnumerable<Action<TResult>> onSuccess,
134+
Action<TResult> onFailure) where TResult : IResult
135135
{
136136
if (!result.IsSuccess)
137137
{
@@ -158,8 +158,8 @@ public static TResult ActionOn<TResult>(this TResult result, IEnumerable<Action<
158158
/// <param name="onFailure">Action on failure</param>
159159
/// <typeparam name="TResult">Type of result</typeparam>
160160
/// <remarks></remarks>
161-
public static TResult ActionOn<TResult>(this TResult result, IEnumerable<Action<TResult>> onSuccess, IEnumerable<Action<TResult>> onFailure)
162-
where TResult : IResult
161+
public static TResult ActionOn<TResult>(this TResult result, IEnumerable<Action<TResult>> onSuccess,
162+
IEnumerable<Action<TResult>> onFailure) where TResult : IResult
163163
{
164164
if (!result.IsSuccess)
165165
{

0 commit comments

Comments
 (0)