-
Notifications
You must be signed in to change notification settings - Fork 490
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8097d9f
commit edbd635
Showing
12 changed files
with
1,169 additions
and
1,109 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
60 changes: 41 additions & 19 deletions
60
RuriLib.Parallelization/Exceptions/RequiredStatusException.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,53 @@ | ||
using System; | ||
using System.Linq; | ||
|
||
namespace RuriLib.Parallelization.Exceptions | ||
namespace RuriLib.Parallelization.Exceptions; | ||
|
||
/// <summary> | ||
/// Exception that is thrown when a method of a <see cref="Parallelizer{TInput, TOutput}"/> can only | ||
/// be executed when its status has one of the specified <see cref="ParallelizerStatus"/> values. | ||
/// </summary> | ||
public class RequiredStatusException : Exception | ||
{ | ||
/// <summary> | ||
/// Exception that is thrown when a method of a <see cref="Parallelizer{TInput, TOutput}"/> can only | ||
/// be executed when its status has one of the specified <see cref="ParallelizerStatus"/> values. | ||
/// When the <see cref="Parallelizer{TInput, TOutput}"/> requires a status of <paramref name="requiredStatus"/> | ||
/// but the status was <paramref name="actualStatus"/>. | ||
/// </summary> | ||
public class RequiredStatusException : Exception | ||
private RequiredStatusException(ParallelizerStatus actualStatus, ParallelizerStatus requiredStatus) | ||
: base($"The operation can only be performed when the Task Manager is in a {requiredStatus} status, but the status was {actualStatus}.") | ||
{ | ||
/// <summary> | ||
/// When the <see cref="Parallelizer{TInput, TOutput}"/> requires a status of <paramref name="requiredStatus"/> | ||
/// but the status was <paramref name="actualStatus"/>. | ||
/// </summary> | ||
public RequiredStatusException(ParallelizerStatus requiredStatus, ParallelizerStatus actualStatus) | ||
: base($"The operation can only be performed when the Task Manager is in a {requiredStatus} status, but the status was {actualStatus}.") | ||
{ | ||
|
||
} | ||
} | ||
|
||
/// <summary> | ||
/// When the <see cref="Parallelizer{TInput, TOutput}"/> requires a status in the <paramref name="requiredStatuses"/> array | ||
/// but the status was <paramref name="actualStatus"/>. | ||
/// </summary> | ||
public RequiredStatusException(ParallelizerStatus[] requiredStatuses, ParallelizerStatus actualStatus) | ||
: base($"The operation can only be performed when the Task Manager is in one of these statuses: {string.Join(", ", requiredStatuses)}, but the status was {actualStatus}.") | ||
{ | ||
/// <summary> | ||
/// When the <see cref="Parallelizer{TInput, TOutput}"/> requires a status in the <paramref name="requiredStatuses"/> array | ||
/// but the status was <paramref name="actualStatus"/>. | ||
/// </summary> | ||
private RequiredStatusException(ParallelizerStatus actualStatus, ParallelizerStatus[] requiredStatuses) | ||
: base($"The operation can only be performed when the Task Manager is in one of these statuses: {string.Join(", ", requiredStatuses)}, but the status was {actualStatus}.") | ||
{ | ||
|
||
} | ||
|
||
/// <summary> | ||
/// Throws a <see cref="RequiredStatusException"/> if the <paramref name="actualStatus"/> is not equal to the <paramref name="requiredStatus"/>. | ||
/// </summary> | ||
public static void ThrowIfNot(ParallelizerStatus actualStatus, ParallelizerStatus requiredStatus) | ||
{ | ||
if (actualStatus != requiredStatus) | ||
{ | ||
throw new RequiredStatusException(actualStatus, requiredStatus); | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Throws a <see cref="RequiredStatusException"/> if the <paramref name="actualStatus"/> is not one of the <paramref name="requiredStatuses"/>. | ||
/// </summary> | ||
public static void ThrowIfNot(ParallelizerStatus actualStatus, ParallelizerStatus[] requiredStatuses) | ||
{ | ||
if (!requiredStatuses.Contains(actualStatus)) | ||
{ | ||
throw new RequiredStatusException(actualStatus, requiredStatuses); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,26 @@ | ||
using System; | ||
|
||
namespace RuriLib.Parallelization.Models | ||
namespace RuriLib.Parallelization.Models; | ||
|
||
/// <summary> | ||
/// Details of an error that happened while processing a work item. | ||
/// </summary> | ||
/// <typeparam name="TInput"></typeparam> | ||
public class ErrorDetails<TInput> | ||
{ | ||
/// <summary>The item that was being processed by the operation.</summary> | ||
public TInput Item { get; set; } | ||
|
||
/// <summary>The exception thrown by the operation.</summary> | ||
public Exception Exception { get; set; } | ||
|
||
/// <summary> | ||
/// Details of an error that happened while processing a work item. | ||
/// Creates error details for a given <paramref name="item"/> for which the work | ||
/// function generated a given <paramref name="exception"/> | ||
/// </summary> | ||
/// <typeparam name="TInput"></typeparam> | ||
public class ErrorDetails<TInput> | ||
public ErrorDetails(TInput item, Exception exception) | ||
{ | ||
/// <summary>The item that was being processed by the operation.</summary> | ||
public TInput Item { get; set; } | ||
|
||
/// <summary>The exception thrown by the operation.</summary> | ||
public Exception Exception { get; set; } | ||
|
||
/// <summary> | ||
/// Creates error details for a given <paramref name="item"/> for which the work | ||
/// function generated a given <paramref name="exception"/> | ||
/// </summary> | ||
public ErrorDetails(TInput item, Exception exception) | ||
{ | ||
Item = item; | ||
Exception = exception; | ||
} | ||
Item = item; | ||
Exception = exception; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,25 @@ | ||
namespace RuriLib.Parallelization.Models | ||
namespace RuriLib.Parallelization.Models; | ||
|
||
/// <summary> | ||
/// Details the result of the execution of the work functions on a given input. | ||
/// </summary> | ||
/// <typeparam name="TInput">The type of input</typeparam> | ||
/// <typeparam name="TOutput">The type of output</typeparam> | ||
public class ResultDetails<TInput, TOutput> | ||
{ | ||
/// <summary>The item that was being processed by the operation.</summary> | ||
public TInput Item { get; set; } | ||
|
||
/// <summary>The result returned by the operation.</summary> | ||
public TOutput Result { get; set; } | ||
|
||
/// <summary> | ||
/// Details the result of the execution of the work functions on a given input. | ||
/// Creates result details for a given <paramref name="item"/> for which | ||
/// the work function generated a given <paramref name="result"/>. | ||
/// </summary> | ||
/// <typeparam name="TInput">The type of input</typeparam> | ||
/// <typeparam name="TOutput">The type of output</typeparam> | ||
public class ResultDetails<TInput, TOutput> | ||
public ResultDetails(TInput item, TOutput result) | ||
{ | ||
/// <summary>The item that was being processed by the operation.</summary> | ||
public TInput Item { get; set; } | ||
|
||
/// <summary>The result returned by the operation.</summary> | ||
public TOutput Result { get; set; } | ||
|
||
/// <summary> | ||
/// Creates result details for a given <paramref name="item"/> for which | ||
/// the work function generated a given <paramref name="result"/>. | ||
/// </summary> | ||
public ResultDetails(TInput item, TOutput result) | ||
{ | ||
Item = item; | ||
Result = result; | ||
} | ||
Item = item; | ||
Result = result; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.