133 lines
6.6 KiB
C#
133 lines
6.6 KiB
C#
using System.Collections.Generic;
|
|
|
|
namespace HRM.BO
|
|
{
|
|
/// <summary>
|
|
/// 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.
|
|
/// </summary>
|
|
public static class EmployeePhotoBulkUploadRules
|
|
{
|
|
/// <summary>The folder the pictures are copied into, at the content root next to EmployeePhotos.</summary>
|
|
public const string FolderName = "EmployeePhotoBulkUpload";
|
|
|
|
/// <summary>The same picture types the profile-update request takes.</summary>
|
|
public static readonly string[] Extensions = { ".jpg", ".jpeg", ".png" };
|
|
|
|
/// <summary>Per picture: the original is stored in the database, so it is kept to a sensible size.</summary>
|
|
public const int MaxFileSizeMB = 5;
|
|
|
|
/// <summary>The thumbnail is 100 x 100; a smaller picture is enlarged and looks blurred.</summary>
|
|
public const int MinSidePixels = 100;
|
|
}
|
|
|
|
/// <summary>What the instructions show before anything is checked.</summary>
|
|
public class EmployeePhotoBulkUploadInfo
|
|
{
|
|
/// <summary>The application's folder and the picture folder only, e.g. HRM.UI\EmployeePhotoBulkUpload — never the full server path.</summary>
|
|
public string FolderPath { get; set; }
|
|
public List<string> Extensions { get; set; }
|
|
public int MaxFileSizeMB { get; set; }
|
|
public int MinSidePixels { get; set; }
|
|
/// <summary>Files in the folder now (subfolders and system files such as Thumbs.db are not counted).</summary>
|
|
public int FileCount { get; set; }
|
|
}
|
|
|
|
/// <summary>One file of the folder and what the checks (or the save) found.</summary>
|
|
public class EmployeePhotoBulkUploadFile
|
|
{
|
|
public const string Ready = "ready";
|
|
public const string Warning = "warning";
|
|
public const string Error = "error";
|
|
|
|
public string FileName { get; set; }
|
|
/// <summary>The Employee No as the system spells it once found; the file name without its extension until then.</summary>
|
|
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; }
|
|
/// <summary>The employee already has a profile picture: saving replaces it.</summary>
|
|
public bool HasPhoto { get; set; }
|
|
/// <summary>ready | warning | error.</summary>
|
|
public string Status { get; set; }
|
|
public List<string> Errors { get; set; } = new List<string>();
|
|
public List<string> Warnings { get; set; } = new List<string>();
|
|
}
|
|
|
|
public class EmployeePhotoBulkUploadReadResult
|
|
{
|
|
public string FolderPath { get; set; }
|
|
public List<EmployeePhotoBulkUploadFile> Files { get; set; } = new List<EmployeePhotoBulkUploadFile>();
|
|
/// <summary>Subfolders of the folder: their pictures are not read, so the screen says so.</summary>
|
|
public List<string> Subfolders { get; set; } = new List<string>();
|
|
public int ReadyCount { get; set; }
|
|
public int WarningCount { get; set; }
|
|
public int ErrorCount { get; set; }
|
|
public int ReplaceCount { get; set; }
|
|
/// <summary>At least one picture, and not one file with an error.</summary>
|
|
public bool CanSave { get; set; }
|
|
}
|
|
|
|
/// <summary>
|
|
/// 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.
|
|
/// </summary>
|
|
public class EmployeePhotoBulkUploadRun
|
|
{
|
|
public const string Running = "running";
|
|
public const string Saved = "saved";
|
|
public const string Failed = "failed";
|
|
|
|
public string RunID { get; set; }
|
|
/// <summary>running | saved | failed.</summary>
|
|
public string Status { get; set; }
|
|
/// <summary>What it is doing now, e.g. "Reading every picture".</summary>
|
|
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; }
|
|
/// <summary>Failed: the pictures that stopped the save. Saved: any picture with a note (e.g. could not be removed from the folder).</summary>
|
|
public List<EmployeePhotoBulkUploadFile> Files { get; set; } = new List<EmployeePhotoBulkUploadFile>();
|
|
/// <summary>EmployeeIDs whose picture changed, so the caller can drop what it has cached for them.</summary>
|
|
public List<int> SavedEmployeeIDs { get; set; } = new List<int>();
|
|
public System.DateTime StartedAt { get; set; }
|
|
public System.DateTime? FinishedAt { get; set; }
|
|
/// <summary>When the current step began.</summary>
|
|
public System.DateTime StepStartedAt { get; set; }
|
|
/// <summary>Worked out by the server, so the screen needs no clock of its own (its time zone may differ).</summary>
|
|
public int ElapsedSeconds { get; set; }
|
|
public int StepElapsedSeconds { get; set; }
|
|
}
|
|
|
|
public interface IEmployeePhotoBulkUploadService
|
|
{
|
|
EmployeePhotoBulkUploadInfo GetInfo();
|
|
|
|
/// <summary>Checks every picture in the folder. Nothing is saved.</summary>
|
|
EmployeePhotoBulkUploadReadResult ReadFolder(int payrollTypeID);
|
|
|
|
/// <summary>Reserves a save of the folder; only one runs at a time. RunSave then does the work.</summary>
|
|
EmployeePhotoBulkUploadRun BeginSave(int payrollTypeID);
|
|
|
|
/// <summary>
|
|
/// 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.
|
|
/// </summary>
|
|
void RunSave(string runID, int payrollTypeID);
|
|
|
|
/// <summary>A copy of the run as it is now; null when there is no such run.</summary>
|
|
EmployeePhotoBulkUploadRun GetRun(string runID);
|
|
|
|
/// <summary>The save running now, if any (so a reopened screen can follow it).</summary>
|
|
EmployeePhotoBulkUploadRun GetActiveRun();
|
|
}
|
|
}
|