// Copyright (C) 2026, The Duplicati Team // https://duplicati.com, hello@duplicati.com // // Permission is hereby granted, free of charge, to any person obtaining a // copy of this software and associated documentation files (the "Software"), // to deal in the Software without restriction, including without limitation // the rights to use, copy, modify, merge, publish, distribute, sublicense, // and/or sell copies of the Software, and to permit persons to whom the // Software is furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in // all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. using System; using System.Threading; using System.Threading.Tasks; namespace Duplicati.Library.Interface { /// /// A snapshot of a single backend event, passed to . /// This mirrors the data flowing through Duplicati.Library.Main.IMessageSink.BackendEvent /// but is declared here so the interface does not depend on Duplicati.Library.Main. /// /// The backend action name (e.g. Put, Get, Delete). /// The event type name (e.g. Started, Completed, Failed). /// The target path of the backend action. /// The size of the element being transferred, or 0 when not applicable. public record ReportBackendEvent(string Action, string Type, string Path, long Size); /// /// A snapshot of a single log entry, passed to . /// This mirrors the data in Duplicati.Library.Logging.LogEntry but is declared here so /// the interface does not depend on Duplicati.Library.Logging. /// /// The formatted log message. /// The log level name (e.g. Information, Warning, Error). /// The log tag associated with the entry. /// The log message id, if any. /// The time the entry was created, in UTC. /// A string representation of an associated exception, or null. public record ReportLogEntry(string Message, string Level, string Tag, string Id, DateTime Timestamp, string Exception); /// /// A snapshot of the operation progress, passed to /// at a regular cadence while an operation is running. The cadence is controlled by the engine, /// not by the module; modules decide how often to act on these snapshots. /// /// The current operation phase name. /// The overall progress, in the range [0, 1]. /// The number of files processed so far. /// The number of bytes processed so far. /// The total number of files, or 0 if still counting. /// The total number of bytes, or 0 if still counting. /// true if the file count and size are not yet final. /// The file currently being processed, or null. /// The size of the file currently being processed. /// The byte offset reached in the file currently being processed. /// The active backend transfers, or an empty array when none. public record ReportProgressSnapshot( string Phase, float Progress, long FilesProcessed, long FileSizeProcessed, long FileCount, long FileSize, bool CountingFiles, string CurrentFilename, long CurrentFileSize, long CurrentFileOffset, ReportBackendEvent[] ActiveTransfers); /// /// Interface for implementing reporting modules that observe an operation's /// lifecycle and progress. /// /// Modules implementing this interface are notified when an operation starts and /// completes ( / ), /// receive every backend event and log entry that flows through the operation's /// message sink ( / ), /// and are polled with periodic progress snapshots while the operation is running /// (). /// /// All callbacks are asynchronous and isolated from one another: an exception /// thrown by one callback is logged and does not abort subsequent callbacks or /// the operation itself. /// public interface IReportModule : IGenericModule { /// /// Gets a value indicating whether the module is configured to do work for the /// current operation. /// /// This is checked once after has been /// called. When is false, the engine skips the /// module entirely: no adapter is appended to the message sink, no progress /// ticker is started, and none of the event callbacks are invoked. This keeps /// the hot path free of per-event interception overhead for modules that have /// nothing to report. /// bool IsActive { get; } /// /// Called when an operation has started, before any work is performed. /// /// The name of the operation (e.g. Backup, Restore). /// The result object that will be populated as the operation runs. /// A token to monitor for cancellation requests. /// A task that represents the asynchronous operation. Task OnOperationStartedAsync(string operationName, IBasicResults result, CancellationToken cancellationToken); /// /// Called when an operation has completed, whether successfully or not. /// /// The populated result object. /// The exception that stopped the operation, or null on success. /// A token to monitor for cancellation requests. /// A task that represents the asynchronous operation. Task OnOperationCompletedAsync(IBasicResults result, Exception exception, CancellationToken cancellationToken); /// /// Called for each backend event reported by the operation's message sink. /// /// A snapshot of the backend event. /// A token to monitor for cancellation requests. /// A task that represents the asynchronous operation. Task OnBackendEventAsync(ReportBackendEvent evt, CancellationToken cancellationToken); /// /// Called for each log entry written during the operation. /// /// A snapshot of the log entry. /// A token to monitor for cancellation requests. /// A task that represents the asynchronous operation. Task OnLogEntryAsync(ReportLogEntry entry, CancellationToken cancellationToken); /// /// Called at a regular cadence while the operation is running, with a snapshot /// of the current operation and backend progress. The cadence is controlled by /// the engine; modules decide how often to act on these snapshots (for example, /// posting an update every 30 seconds). /// /// A snapshot of the current progress. /// A token to monitor for cancellation requests. /// A task that represents the asynchronous operation. Task OnProgressTickAsync(ReportProgressSnapshot snapshot, CancellationToken cancellationToken); } }