using System.Collections.Generic;
namespace HRM.BO
{
///
/// Employee Profile Picture Bulk Upload (second tab of Employee Bulk Upload): the pictures are
/// copied into one folder on the server, each named by its Employee No, then checked and saved
/// the same way an approved profile-picture request is — the original into empFileupload, the
/// 100px thumbnail into EmployeePhotos\EmpthumbnailsImage.
///
public static class EmployeePhotoBulkUploadRules
{
/// The folder the pictures are copied into, at the content root next to EmployeePhotos.
public const string FolderName = "EmployeePhotoBulkUpload";
/// The same picture types the profile-update request takes.
public static readonly string[] Extensions = { ".jpg", ".jpeg", ".png" };
/// Per picture: the original is stored in the database, so it is kept to a sensible size.
public const int MaxFileSizeMB = 5;
/// The thumbnail is 100 x 100; a smaller picture is enlarged and looks blurred.
public const int MinSidePixels = 100;
}
/// What the instructions show before anything is checked.
public class EmployeePhotoBulkUploadInfo
{
/// The application's folder and the picture folder only, e.g. HRM.UI\EmployeePhotoBulkUpload — never the full server path.
public string FolderPath { get; set; }
public List Extensions { get; set; }
public int MaxFileSizeMB { get; set; }
public int MinSidePixels { get; set; }
/// Files in the folder now (subfolders and system files such as Thumbs.db are not counted).
public int FileCount { get; set; }
}
/// One file of the folder and what the checks (or the save) found.
public class EmployeePhotoBulkUploadFile
{
public const string Ready = "ready";
public const string Warning = "warning";
public const string Error = "error";
public string FileName { get; set; }
/// The Employee No as the system spells it once found; the file name without its extension until then.
public string EmployeeNo { get; set; }
public int EmployeeID { get; set; }
public string EmployeeName { get; set; }
public long SizeBytes { get; set; }
public int Width { get; set; }
public int Height { get; set; }
/// The employee already has a profile picture: saving replaces it.
public bool HasPhoto { get; set; }
/// ready | warning | error.
public string Status { get; set; }
public List Errors { get; set; } = new List();
public List Warnings { get; set; } = new List();
}
public class EmployeePhotoBulkUploadReadResult
{
public string FolderPath { get; set; }
public List Files { get; set; } = new List();
/// Subfolders of the folder: their pictures are not read, so the screen says so.
public List Subfolders { get; set; } = new List();
public int ReadyCount { get; set; }
public int WarningCount { get; set; }
public int ErrorCount { get; set; }
public int ReplaceCount { get; set; }
/// At least one picture, and not one file with an error.
public bool CanSave { get; set; }
}
///
/// One save of the whole folder, run on the server away from the request and followed by the
/// screen. All or nothing: either every picture is saved, or none is and everything is as it was.
///
public class EmployeePhotoBulkUploadRun
{
public const string Running = "running";
public const string Saved = "saved";
public const string Failed = "failed";
public string RunID { get; set; }
/// running | saved | failed.
public string Status { get; set; }
/// What it is doing now, e.g. "Reading every picture".
public string Step { get; set; }
public int Total { get; set; }
public int Done { get; set; }
public string Message { get; set; }
public int SavedCount { get; set; }
public int ReplacedCount { get; set; }
/// Failed: the pictures that stopped the save. Saved: any picture with a note (e.g. could not be removed from the folder).
public List Files { get; set; } = new List();
/// EmployeeIDs whose picture changed, so the caller can drop what it has cached for them.
public List SavedEmployeeIDs { get; set; } = new List();
public System.DateTime StartedAt { get; set; }
public System.DateTime? FinishedAt { get; set; }
/// When the current step began.
public System.DateTime StepStartedAt { get; set; }
/// Worked out by the server, so the screen needs no clock of its own (its time zone may differ).
public int ElapsedSeconds { get; set; }
public int StepElapsedSeconds { get; set; }
}
public interface IEmployeePhotoBulkUploadService
{
EmployeePhotoBulkUploadInfo GetInfo();
/// Checks every picture in the folder. Nothing is saved.
EmployeePhotoBulkUploadReadResult ReadFolder(int payrollTypeID);
/// Reserves a save of the folder; only one runs at a time. RunSave then does the work.
EmployeePhotoBulkUploadRun BeginSave(int payrollTypeID);
///
/// Saves every picture of the folder or none: every check is run again, every picture is read
/// in full, then all of them go into the database in ONE transaction and their thumbnails are
/// written; a failure anywhere rolls the database back and puts the old thumbnails back.
/// Long-running: call it away from the request.
///
void RunSave(string runID, int payrollTypeID);
/// A copy of the run as it is now; null when there is no such run.
EmployeePhotoBulkUploadRun GetRun(string runID);
/// The save running now, if any (so a reopened screen can follow it).
EmployeePhotoBulkUploadRun GetActiveRun();
}
}