πŸ“„ IrbyImaging.Utility – JobStatus.cs Documentation


πŸ“‘ Table of Contents

  1. 🌟 Overview & Purpose
  2. πŸ—‚ File Structure
  3. πŸš€ Dependencies & Technologies
  4. πŸ”‘ Key Functional Areas
  5. πŸ“Š Data Model: JobStatus Enum
  6. πŸ›  Helper Methods & Utilities
  7. πŸ“ Enumeration Members
  8. πŸ’‘ Usage Examples
  9. πŸ“ UML Diagram
  10. πŸ”š Conclusion

🌟 Overview & Purpose

The JobStatus.cs file defines a simple enumeration (enum) representing the state of a job within the IrbyImaging solution.
It provides a strongly-typed way to manage and display job statuses (Active, Closed, Other) throughout business logic, UI layers, and data access codeβ€”ensuring consistency, compile-time safety, and easy localization or display customization via DataAnnotations.


πŸ—‚ File Structure

IrbyImaging.Utility/
└── JobStatus.cs

JobStatus.cs at a glance:

  • Namespace: IrbyImaging.Utility
  • Primary Construct: public enum JobStatus
  • Attributes: [Display(Name = "...")] on each enum member for UI-friendly labels.

πŸš€ Dependencies & Technologies

Category Details
.NET Framework .NET Standard / .NET Core compatible
Language C# (Version β‰₯ 7.0)
Annotations System.ComponentModel.DataAnnotations
Code Analysis XML Documentation Comments

πŸ”‘ Key Functional Areas

  1. Type-Safe Status Management
    Encapsulates job states in a single enum to avoid β€œmagic strings” or β€œmagic numbers.”
  2. Display Customization
    Uses [Display(Name = "...")] to provide human-friendly names for UI/data-binding scenarios.
  3. Localization-Ready
    Display attribute can be extended to use resource files for multilingual support.

πŸ“Š Data Model: JobStatus Enum

using System.ComponentModel.DataAnnotations;

namespace IrbyImaging.Utility
{
    /// <summary>
    /// Enum representing possible states of a Job.
    /// </summary>
    public enum JobStatus
    {
        /// <summary>The job is currently active and in progress.</summary>
        [Display(Name = "Active")]
        Active,

        /// <summary>The job has been completed or closed.</summary>
        [Display(Name = "Closed")]
        Closed,

        /// <summary>Any other/unclassified job state.</summary>
        [Display(Name = "Other")]
        Other
    }
}

πŸ›  Helper Methods & Utilities

While JobStatus itself is an enum, you often need to retrieve the display name at runtime. Below is a common extension method to extract the DisplayAttribute.Name:

using System;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Reflection;

public static class EnumExtensions
{
    /// <summary>
    /// Retrieves the Display(Name) attribute value of an enum member.
    /// </summary>
    public static string GetDisplayName(this Enum enumValue)
    {
        var memberInfo = enumValue
            .GetType()
            .GetMember(enumValue.ToString())
            .FirstOrDefault();

        if (memberInfo != null)
        {
            var displayAttr = memberInfo
                .GetCustomAttribute<DisplayAttribute>();

            if (displayAttr != null)
                return displayAttr.Name;
        }

        // Fallback to the enum name if no DisplayAttribute found
        return enumValue.ToString();
    }
}

πŸ“ Enumeration Members

Enum Member Display Name Description
Active "Active" The job is currently in progress.
Closed "Closed" The job has been completed or terminated.
Other "Other" Any other/unclassified job state.

πŸ’‘ Usage Examples

1. Basic Assignment

JobStatus current = JobStatus.Active;

2. Displaying a User‑Friendly Name

using IrbyImaging.Utility;

JobStatus status = JobStatus.Closed;
// Using the extension method from Helper Utilities
string display = status.GetDisplayName();  
Console.WriteLine($"Job is currently: {display}");
// Output: Job is currently: Closed

3. Binding to UI Controls (e.g., in ASP.NET MVC / Razor)

@using IrbyImaging.Utility
@inject IHtmlHelper Html

@* Generate a dropdown list for JobStatus *@
@Html.DropDownListFor(
    model => model.SelectedStatus,
    Enum.GetValues(typeof(JobStatus)).Cast<JobStatus>().Select(s =>
        new SelectListItem {
            Value = s.ToString(),
            Text = s.GetDisplayName()
        }
    ),
    "Select Status"
)

πŸ“ UML Diagram

%% UML for JobStatus Enum
classDiagram
    direction LR
    class JobStatus {
        <<enumeration>>
        +Active
        +Closed
        +Other
    }

πŸ”š Conclusion

The JobStatus enum is a lightweight yet powerful part of the IrbyImaging.Utility library:

  • 🎯 Purpose: Standardize job states across the application.
  • πŸ›‘ Benefits: Type safety, compile-time validation, and consistent UI presentation.
  • 🀝 Extensible: Easily supports localization and advanced display scenarios.

By leveraging the DisplayAttribute and straightforward extension methods, you can seamlessly integrate JobStatus into your service, data, and presentation layersβ€”ensuring clear, maintainable, and user‑friendly status handling throughout your imaging workflow.