// // Copyright (c) Microsoft. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. // using System; using System.Drawing; using System.Threading; using System.Runtime.InteropServices; namespace Microsoft.SqlTools.ServiceLayer.Management { /// /// Enumeration for status of individual actions /// public enum ProgressStatus { Invalid = -1, NotStarted, // Not started InProgress, // In progress Success, // Completed SuccessWithInfo, // Completed, display additional info Warning, // Completed with warning, display exceptions Error, // Not completed because of error, display exceptions Aborted, // Aborted RolledBack, // Rolled back because of a subsequent error StatusCount // = Number of status values - For validation only } /// /// Enumeration for status of the overall operation /// public enum OperationStatus { Invalid = -1, InProgress, // In progress Success, // Completed successfully CompletedWithErrors, // Completed with non-fatal errors Error, // Not completed because of error Aborted, // Abort complete StatusCount // = Number of status values - For validation only } /// /// Interface defining core functionality of a progress control container /// /// NOTE: Refer to the comments for each method/property individually to determine /// whether it is thread-safe and may be used from the worker thread. Also note /// that some members are asynchronous. /// public interface IProgress { //----------- // Properties //----------- /// /// The property that determines if the user should be allowed to abort the /// operation. The default value is true. /// /// NOTE: This property is not thread safe. Set from UI thread. /// bool AllowAbort { get; set; } /// /// The confirmation prompt to display if the user hits the Abort button. /// The abort prompt should be worded such that the abort is confirmed /// if the user hits "Yes". /// /// NOTE: This property is not thread safe. Set from UI thread. /// string AbortPrompt { get; set; } /// /// The ThreadStart delegate. The method referenced by this delegate is run by /// the worker thread to perform the operation. /// /// NOTE: This property is not thread safe. Set from UI thread. /// ThreadStart WorkerThreadStart { get; set; } /// /// Aborted status of the operation. /// /// NOTE: This property is thread safe and may be called from the worker /// thread. Accessing this property may cause caller to block if UI /// is waiting for user confirmation of abort. /// bool IsAborted { get; } /// /// This property determines whether updates should be allowed for /// actions. If this is set to false, any calls that are made /// to add or update an action are ignored. The default value is true. /// /// NOTE: This property is thread safe and may be called from the worker /// thread. /// bool ActionUpdateEnabled { get; set; } //-------- // Methods //-------- /// /// Add an action to the displayed list of actions. Actions are /// displayed in the order they are added. An action can be referenced /// in future calls using the zero-based index that is returned. /// /// The description must be a non-empty string. /// /// NOTE: This method is not thread safe. Call from the UI thread. /// /// Description of the action /// The index of the newly added action. int AddAction(string description); /// /// Add an action to the displayed list of actions. This is meant /// to be called from the worker thread to add an action after /// the operation is already in progress. /// /// Actions are displayed in the order they are added. Use the /// zero-based index of the action based on past actions added /// to reference it in future calls. The description must be a /// non-empty string. /// /// NOTE: This method is thread safe and asynchronous. It may be /// called from the worker thread. /// /// Description of the action void AddActionDynamic(string description); /// /// Update the description of an action /// /// The description must be a non-empty string. /// /// NOTE: This method is thread safe and asynchronous. It may be /// called from the worker thread. /// /// Index of the action /// New description of the action void UpdateActionDescription(int actionIndex, string description); /// /// Update the status of an action /// /// NOTE: This method is thread safe and asynchronous. It may be /// called from the worker thread. /// /// Index of the action /// New status of the action void UpdateActionStatus(int actionIndex, ProgressStatus status); /// /// Update the progress of an action in terms of percentage complete /// /// NOTE: This method is thread safe and asynchronous. It may be /// called from the worker thread. /// /// Index of the action /// Percentage of the action that is complete (0-100) void UpdateActionProgress(int actionIndex, int percentComplete); /// /// Update the progress of an action with a text description of /// the progress /// /// The description must be a non-empty string. /// /// NOTE: This method is thread safe and asynchronous. It may be /// called from the worker thread. /// /// Index of the action /// Description of progress void UpdateActionProgress(int actionIndex, string description); /// /// Add an exception to an action /// /// Exceptions are displayed in the action grid only for actions /// with "Error" or "Warning" status. /// /// NOTE: This method is thread safe and asynchronous. It may be /// called from the worker thread. /// /// Index of the action /// Exception to be added void AddActionException(int actionIndex, Exception e); /// /// Add an info string to an action in the progress report control /// /// Information strings are displayed in the action grid only for /// actions with "SuccessWithInfo" status. The info string must /// be a non-empty string. It should not be formatted or contain /// newline characters. /// /// NOTE: This method is thread safe and asynchronous. It may be /// called from the worker thread. /// /// Index of the action /// Information string to be added void AddActionInfoString(int actionIndex, string infoString); /// /// Call this method when the worker thread performing the operation /// is about to exit. The final result of the operation is supplied in /// the form of a OperationStatus value. /// /// NOTE: This method is thread safe and asynchronous. It may be /// called from the worker thread. /// /// Result of the operation void WorkerThreadExiting(OperationStatus result); } /// /// Enumeration for status of the progress report control w.r.t the operation /// [System.Runtime.InteropServices.ComVisible(false)] public enum ProgressCtrlStatus { Invalid = -1, InProgress, // In progress Success, // Completed successfully CompletedWithErrors, // Completed with non-fatal errors Error, // Not completed because of error Aborting, // User clicked "Abort", aborting operation Aborted, // Abort complete Closed, // User clicked "Close" StatusCount // = Number of status values - For validation only } /// /// Delegate used with ProgressCtrlStatusChanged event. /// public delegate void ProgressCtrlStatusChangedEventHandler(object source, ProgressCtrlStatusChangedEventArgs e); /// /// EventArgs class for use with ProgressCtrlStatusChanged event /// sealed public class ProgressCtrlStatusChangedEventArgs : EventArgs { //------------------ // Public Properties //------------------ public ProgressCtrlStatus Status { get { return m_status; } set { m_status = value; } } //------------- // Private Data //------------- private ProgressCtrlStatus m_status = ProgressCtrlStatus.Invalid; } // Enumeration for progress action grid columns internal enum ProgressActionColumn { Invalid = -1, ActionStatusBitmap, ActionDescription, ActionStatusText, ActionMessage, ActionColumnCount // = Number of columns - For validation only } // Enumeration for progress action display filter internal enum ProgressActionDisplayMode { Invalid = -1, DisplayAllActions, DisplayErrors, DisplaySuccess, DisplayWarnings, ActionDisplayModeCount // = Number of display modes - For validation only } }