Skip to content

Commit

Permalink
Added xml docs for changed logic for resources
Browse files Browse the repository at this point in the history
  • Loading branch information
strivitech committed Jan 10, 2022
1 parent 3999e81 commit 3c3913f
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,43 +1,85 @@
namespace OutOfSchool.WebApi.Common.Resources.Codes
{
/// <summary>
/// Contains error codes of all operations with images.
/// </summary>
public enum ImagesOperationErrorCode
{
/// <summary>
/// The default error.
/// </summary>
[ResourcesKey(nameof(DefaultError))]
DefaultError = 0,

/// <summary>
/// The error that can be used when something wrong has happened while uploading images.
/// </summary>
[ResourcesKey(nameof(UploadingError))]
UploadingError = 1,

/// <summary>
/// The error that can be used when something wrong has happened while removing images.
/// </summary>
[ResourcesKey(nameof(RemovingError))]
RemovingError = 2,

/// <summary>
/// The error that can be used when unable to make some operation because of an image storage.
/// </summary>
[ResourcesKey(nameof(ImageStorageError))]
ImageStorageError = 3,

/// <summary>
/// The error that can be used when some image has not found.
/// </summary>
[ResourcesKey(nameof(ImageNotFoundError))]
ImageNotFoundError = 4,

/// <summary>
/// The error that can be used when some image hasn't passed the validation process because of unexpected factors.
/// </summary>
[ResourcesKey(nameof(UnexpectedValidationError))]
UnexpectedValidationError = 5,

/// <summary>
/// The error that can be used when some image hasn't passed the validation process because of the invalid image size.
/// </summary>
[ResourcesKey(nameof(InvalidSizeError))]
InvalidSizeError = 6,

/// <summary>
/// The error that can be used when some image hasn't passed the validation process because of the invalid image format.
/// </summary>
[ResourcesKey(nameof(InvalidFormatError))]
InvalidFormatError = 7,

/// <summary>
/// The error that can be used when some image hasn't passed the validation process because of the invalid image resolution.
/// </summary>
[ResourcesKey(nameof(InvalidResolutionError))]
InvalidResolutionError = 8,

/// <summary>
/// The error that can be used when cannot find the entity for operations with images.
/// </summary>
[ResourcesKey(nameof(EntityNotFoundError))]
EntityNotFoundError = 9,

/// <summary>
/// The error that can be used when no images were given for making operations.
/// </summary>
[ResourcesKey(nameof(NoGivenImagesError))]
NoGivenImagesError = 10,

/// <summary>
/// The error that can be used when something wrong has happened while updating the entity with changed images.
/// </summary>
[ResourcesKey(nameof(UpdateEntityError))]
UpdateEntityError = 11,

/// <summary>
/// The error that can be used when count of images is more than allowed for this type of entity.
/// </summary>
[ResourcesKey(nameof(ExceedingCountOfImagesError))]
ExceedingCountOfImagesError = 12,
}
Expand Down
15 changes: 15 additions & 0 deletions OutOfSchool/OutOfSchool.WebApi/Extensions/OperationExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,28 @@

namespace OutOfSchool.WebApi.Extensions
{
/// <summary>
/// Extensions for app service operations.
/// </summary>
public static class OperationExtensions
{
/// <summary>
/// Returns the <see cref="OperationError"/> localized for the specified culture by the <see cref="ImagesOperationErrorCode"/> code.
/// </summary>
/// <param name="code">The <see cref="ImagesOperationErrorCode"/> code.</param>
/// <returns>The <see cref="OperationError"/> localized for the specified culture.</returns>
public static OperationError GetOperationError(this ImagesOperationErrorCode code)
{
return CreateOperationError(code.ToString(), code.GetResourceValue());
}

/// <summary>
/// Creates a new instance of <see cref="OperationError"/>.
/// </summary>
/// <param name="code">Code of the error.</param>
/// <param name="description">Error's description.</param>
/// <returns>The instance of <see cref="OperationError"/>.</returns>
/// <exception cref="ArgumentException">When <c>code</c> is null.</exception>
public static OperationError CreateOperationError(string code, string description)
{
if (string.IsNullOrEmpty(code))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,39 @@

namespace OutOfSchool.WebApi.Extensions
{
/// <summary>
/// Extensions for receiving essential data from app resources.
/// </summary>
public static class RetrievingResourcesExtensions
{
/// <summary>
/// Returns the value of the string resource localized for the specified culture by the <see cref="ImagesOperationErrorCode"/> code.
/// </summary>
/// <param name="code">The <see cref="ImagesOperationErrorCode"/> code.</param>
/// <param name="culture">The culture you wanna try to get resource value.</param>
/// <returns>The value of the resource localized for the specified culture, or <c>null</c> if a resource key cannot be found in a resource set.</returns>
public static string GetResourceValue(this ImagesOperationErrorCode code, CultureInfo culture = null)
{
var resourceKey = TryGetResourceKey(code);

return GetStringFromResources(ResourceManagers.ImageResourceManager, resourceKey, culture);
}

/// <summary>
/// Returns the value of the resource key by the <see cref="ImagesOperationErrorCode"/> code.
/// </summary>
/// <param name="code">The <see cref="ImagesOperationErrorCode"/> code.</param>
/// <returns>The value of the resource key, or <c>null</c> if a resource key cannot be found in an <see cref="ImagesOperationErrorCode"/> set.</returns>
public static string GetResourceKey(this ImagesOperationErrorCode code) => TryGetResourceKey(code);

/// <summary>
/// Returns the value of the string resource localized for the specified culture.
/// </summary>
/// <param name="resourceManager">The resource manager.</param>
/// <param name="resourceKey">The key to find resource value.</param>
/// <param name="culture">The culture you wanna try to get resource value.</param>
/// <returns>The value of the resource localized for the specified culture, or <c>null</c> if a resource key cannot be found in a resource set.</returns>
/// <exception cref="ArgumentNullException">When resourceManager is null.</exception>
internal static string GetStringFromResources(ResourceManager resourceManager, string resourceKey, CultureInfo culture = null)
{
_ = resourceManager ?? throw new ArgumentNullException(nameof(resourceManager));
Expand Down

0 comments on commit 3c3913f

Please sign in to comment.