56 lines
1.5 KiB
C#
56 lines
1.5 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
|
|
namespace HanvonF710XAttendanceService
|
|
{
|
|
internal sealed class MachineUserDeleteItem
|
|
{
|
|
public MachineUserDeleteItem(string serialNumber, string deviceEnrollId)
|
|
{
|
|
SerialNumber = serialNumber ?? "";
|
|
DeviceEnrollId = deviceEnrollId ?? "";
|
|
}
|
|
|
|
public string SerialNumber { get; }
|
|
public string DeviceEnrollId { get; }
|
|
}
|
|
|
|
internal static class MachineUserDeleteBatcher
|
|
{
|
|
public static int CountBatches(int itemCount, int batchSize)
|
|
{
|
|
if (itemCount <= 0)
|
|
{
|
|
return 0;
|
|
}
|
|
|
|
int size = batchSize > 0 ? batchSize : MachineUserDeleteSettings.DefaultBatchSize;
|
|
return (itemCount + size - 1) / size;
|
|
}
|
|
|
|
public static List<List<T>> SplitIntoBatches<T>(IReadOnlyList<T> items, int batchSize)
|
|
{
|
|
var batches = new List<List<T>>();
|
|
if (items == null || items.Count == 0)
|
|
{
|
|
return batches;
|
|
}
|
|
|
|
int size = batchSize > 0 ? batchSize : MachineUserDeleteSettings.DefaultBatchSize;
|
|
for (int i = 0; i < items.Count; i += size)
|
|
{
|
|
int take = Math.Min(size, items.Count - i);
|
|
var batch = new List<T>(take);
|
|
for (int j = 0; j < take; j++)
|
|
{
|
|
batch.Add(items[i + j]);
|
|
}
|
|
|
|
batches.Add(batch);
|
|
}
|
|
|
|
return batches;
|
|
}
|
|
}
|
|
}
|