// Copyright (c) Microsoft Corporation. // Licensed under the MIT License. using System; using System.Collections; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Diagnostics; using System.Diagnostics.CodeAnalysis; using System.Text; using System.Windows; using System.Windows.Controls; using System.Windows.Media; namespace Microsoft.Management.UI.Internal { #region UserActionState enum /// /// Represents the availability of an action to a user. /// [SuppressMessage("Microsoft.MSInternal", "CA903:InternalNamespaceShouldNotContainPublicTypes")] public enum UserActionState { /// /// Indicates that the action is enabled and allowed. /// Enabled = 0, /// /// Indicates that the action is disabled. /// Disabled = 1, /// /// Indicates that the action is not visible. /// Hidden = 2, } #endregion #region ControlState enum /// /// Represents the ready-state of a control. /// [SuppressMessage("Microsoft.MSInternal", "CA903:InternalNamespaceShouldNotContainPublicTypes")] public enum ControlState { /// /// Indicates that the control is ready. /// Ready = 0, /// /// Indicates that the control has an error. /// Error = 1, /// /// Indicates that the control is refreshing its data. /// Refreshing = 2, } #endregion #region Utilities class /// /// Provides common methods for use in the library. /// [SuppressMessage("Microsoft.MSInternal", "CA903:InternalNamespaceShouldNotContainPublicTypes")] public static class Utilities { /// /// Gets whether all of the items in are of type T. /// /// The type to verify. /// The items to check. /// Whether all of the items in are of type T. /// The specified value is a null reference. public static bool AreAllItemsOfType(IEnumerable items) { ArgumentNullException.ThrowIfNull(items); foreach (object item in items) { if (item is not T) { return false; } } return true; } /// /// Searches for an element that matches the specified type, and returns the first occurrence in the entire . /// /// The type of the item to find. /// The to search. /// The first element that matches the specified type, if found; otherwise, the default value for type . /// The specified value is a null reference. public static T Find(this IEnumerable items) { ArgumentNullException.ThrowIfNull(items); foreach (object item in items) { if (item is T) { return (T)item; } } return default(T); } /// /// Method to trim the non null strings. /// /// String to Trim. /// Trimmed string. public static string NullCheckTrim(string value) { if (!string.IsNullOrEmpty(value)) { return value.Trim(); } return value; } // A separate copy of ResortObservableCollection is in ADMUX Utility.cs /// /// Restore the original order as far as possible. /// Columns not in the original set will appear at the end. /// /// /// Type of . /// /// /// ObservableCollection to resort to order of /// . /// /// /// Order to which should be resorted. /// All enumerated objects must be of type T. /// /// /// Parameter is not generic to type T /// since it may be a collection of a subclass of type T, /// and IEnumerable'subclass is not compatible with /// IEnumerable'baseclass. /// public static void ResortObservableCollection( ObservableCollection modify, IEnumerable sorted) { int orderedPosition = 0; foreach (T obj in sorted) { T sortedObject = (T)obj; int foundIndex = modify.IndexOf(sortedObject); if (foundIndex >= 0) { modify.Move(foundIndex, orderedPosition); orderedPosition++; if (modify.Count <= orderedPosition) { // All objects present are in the original order break; } } } } } #endregion }