This is a sample code to demonstrate how to use the callbacks interface. Its methods are called from hdmengine to report operation progress and to collect user interactions. For more details on the architectural design, please see the Getting Started section.
Before you read the code sample:
- add hdmengine_hdmclientinteroplib.dll library to your project.
Define the Paragon.DiskMgmt namespace to bring ICallbackReport interfaces into global scope, and System – to bring standard interfaces.
using Paragon.DiskMgmt;
using System;
Declare the main class of the application.
public class ProgressOutput : ICallbackReport
{
Sync object.
private readonly object printLock = new object();
Message callback. Introduce the following parameters: task ID, bRewrite (rewrite last line in console output), and message. You can skip the task ID parameter, if there is only one process using the hdmengine.
public void SendMessageCallback(Guid taskId, Boolean bRewrite, String message)
{
lock (printLock)
{
Console.WriteLine(taskId.ToString() + ":" + "Progress_SendMessageCallback called, bRewrite = {0}, pMessage = {1}", bRewrite, message);
}
}
Set the variable for the operation start of the callback. Including the parameters:
param name: taskId – Task ID
param name: index – Operation index
param name: operationName – Operation name
public void StartOperationCallback(Guid taskId, int index, String operationName)
{
lock (printLock)
{
Console.WriteLine(taskId.ToString() + ":" + "Progress_StartOperationCallback called, index = {0}, pOperationName = {1}", index, operationName);
}
}
Set the variable for the percent of the callback. Including the parameters:
param name: taskId – Task ID
param name: bOperation – True for current operation, false – total operations stack percent
param name: percent – Percent value
public void SetPercentCallback(Guid taskId, Boolean bOperation, int percent)
{
lock (printLock)
{
Console.WriteLine(taskId.ToString() + ":" + "Progress_SetPercentCallback called, bOperation = {0}, percent = {1}", bOperation, percent);
}
}
Set the variable for the statistics of the callback. Including the parameters:
param name: taskId – Task ID
param name: bOperation – True for current operation, false for total stack of operations
param name: elapsedSeconds – Elapsed seconds
param name: remainingSeconds – Estimated remaining seconds.
public void SetStatisticsCallback(Guid taskId, Boolean bOperation, UInt64 elapsedSeconds, UInt64 remainingSeconds)
{
lock (printLock)
{
Console.WriteLine(taskId.ToString() + ":" + "Progress_SetStatisticsCallback called, bOperation = {0}, elapsedSeconds = {1}, remainingSeconds = {2}", bOperation, elapsedSeconds, remainingSeconds);
}
}
Check operation break callback. The variable returns True if all operations must stop.
param name: taskId – Task ID
public Boolean CheckBreakOperationCallback(Guid taskId)
{
In case the reply is True, process the stop signal.
lock (printLock)
{
If the Console.WriteLine(taskId.ToString():Progress_CheckBreakOperationCallback called, and the response returned False, all operations may continue.
return false;
}
}
Support method for user input collection. If “Yes” is selected the response is True.
private Boolean ConsoleInputYes()
{
String input = Console.ReadLine();
return input.Equals("yes", StringComparison.CurrentCultureIgnoreCase);
}
Now you can collect user interactions with AllowActionCallback. Including the parameters:
param name: taskId – Task ID
param name: operation – Operation type
returns – True if allowed.
public Boolean AllowActionCallback(Guid taskId, ProgressAllowActionType operation)
{
lock (printLock)
{
Console.WriteLine(taskId.ToString() + ":" + "ProgressAllowActionCallback called, operation = {0}", operation);
if (operation == ProgressAllowActionType.BreakOperation)
{
Console.WriteLine("\nBreak operation? YES/NO \n");
}
else if (operation == ProgressAllowActionType.BreakOperationWithDataloss)
{
Console.WriteLine("\nThe data of the processing partition will be corrupted!\nBreak operation? YES/NO \n");
}
else if (operation == ProgressAllowActionType.Reboot)
{
Console.WriteLine("\nThere are locked partitions found.\nTo complete this operation your computer needs to be restarted. Restart now? YES/NO \n");
}
else if (operation == ProgressAllowActionType.RestartBreakedOperation)
{
Console.WriteLine("\nThere is abnormal terminated operation found.\nYou need to perform operation restart before any other actions.\nIf you reject restart, data on your disk may remain in destroyed state. Perform restart? YES/NO \n");
}
Boolean input = ConsoleInputYes();
Console.WriteLine(taskId.ToString() + ":" + "User selected {0}", input);
return input;
}
}
Show fix filesystem report callback. Including the parameters:
param name: taskId – Task ID
param name: fixFsReport – Report structure
public void ShowReportFixFsReportCallback(Guid taskId, ref FixFsReport fixFsReport)
{
lock (printLock)
{
Console.WriteLine(taskId.ToString() + ":" + "ProgressShowReportFixFsReportCallback called");
Console.WriteLine(taskId.ToString() + ":" + "Total dirs = {0}", fixFsReport.TotalDirs);
}
}
Show wipe disk or partition report. Including the parameters:
param name: taskId – Task ID
param name: wipeReport – Wipe report structure
public void ShowReportWipeReportCallback(Guid taskId, ref WipeReportExtracted wipeReport)
{
lock (printLock)
{
Console.WriteLine(taskId.ToString() + ":" + "ProgressShowReportWipeReportCallback called");
Console.WriteLine(taskId.ToString() + ":" + "BadBlocksSetCount = {0}", wipeReport.badBlocksSets == null ? 0 : wipeReport.badBlocksSets.Length);
if (wipeReport.badBlocksSets != null)
{
foreach (WipeReportBadBlocksSet blockSet in wipeReport.badBlocksSets)
{
Console.WriteLine(taskId.ToString() + ":" + "Bad block, start sector = {0}, end sector = {0}", blockSet.StartSectors, blockSet.EndSectors);
}
}
}
}
}