public void Refresh() { try { lock (_lock) { IsCurrentlyRefresh = true; if (null != RotItems) { RotItems.Dispose(); } RotItems = RunningObjectTable.GetActiveProxyInformations("", ""); AddItems(); RemoveItems(); } } catch (Exception) { throw; } finally { IsCurrentlyRefresh = false; } }
/// <summary> /// Returns the count of accessible com proxies /// </summary> /// <param name="type">target proxy type</param> /// <returns>count of accessible proxies</returns> public static int GetAccessibleProxyCount(ProxyType type) { IEnumerable <AccessibleWindowTarget> targets = ConvertToTargets(type); IDisposableSequence <ProxyInformation> result = GetAccessibleProxiesFromPath(targets); int count = result.Count; result.Dispose(); return(count); }
/// <summary> /// Returns an accessible com proxy through the IAccessible interface /// </summary> /// <param name="type">target proxy type</param> /// <param name="throwExceptionIfNothingFound">throw an exception if no proxy found</param> /// <returns>com proxy instance or null</returns> public static object GetAccessibleProxy(ProxyType type, bool throwExceptionIfNothingFound) { IEnumerable <AccessibleWindowTarget> targets = ConvertToTargets(type); IDisposableSequence <ProxyInformation> result = GetAccessibleProxiesFromPath(targets, 1); if (result.Count == 0 && throwExceptionIfNothingFound) { throw new ArgumentOutOfRangeException("type", "Unable to find accessible proxy"); } return(result); }
/// <summary> /// Returns first running com proxy, wrapped by T /// </summary> /// <typeparam name="T"></typeparam> /// <param name="componentName"></param> /// <param name="className"></param> /// <param name="throwExceptionIfNotFound"></param> /// <returns></returns> public static T GetActiveInstance <T>(string componentName, string className, bool throwExceptionIfNotFound = false) where T : class, ICOMObject { IDisposableSequence <T> result = GetActiveInstances <T>(componentName, className); T item = result.FirstOrDefault(); result.Dispose(item); if (throwExceptionIfNotFound && null == item) { throw new ArgumentOutOfRangeException(componentName + ", " + className); } return(item); }
/// <summary> /// Returns all accessible com proxies through the IAccessible interface /// </summary> /// <param name="type">target proxy type</param> public static IDisposableSequence GetAccessibleProxies(ProxyType type) { IEnumerable <AccessibleWindowTarget> targets = ConvertToTargets(type); IDisposableSequence <ProxyInformation> result = GetAccessibleProxiesFromPath(targets); List <object> newResult = new List <object>(); foreach (ProxyInformation item in result) { newResult.Add(item.Proxy); } return(null); }
/// <summary> /// Returns first running com proxy, wrapped by T /// </summary> /// <typeparam name="T"></typeparam> /// <param name="componentName">component name, for example Excel</param> /// <param name="className">class name, for example Application</param> /// <param name="predicate">filter predicate</param> /// <param name="throwExceptionIfNotFound">throw ArgumentOutOfRangeException if no instance match</param> /// <returns>target instance or null(Nothing in Visual Basic)</returns> /// <exception cref="NetOfficeCOMException">occurs if no instance match and throwExceptionIfNotFound is set</exception> public static T GetActiveInstance <T>(string componentName, string className, Func <T, bool> predicate, bool throwExceptionIfNotFound = false) where T : class, ICOMObject { IDisposableSequence <T> result = GetActiveInstances <T>(componentName, className, predicate); T item = result.FirstOrDefault(); result.Dispose(item); if (throwExceptionIfNotFound && null == item) { throw new NetOfficeCOMException(String.Format("Unable to find active instance {0}.", componentName + " " + className)); } return(item); }
/// <summary> /// Returns all running com proxies, wrapped by T /// </summary> /// <param name="componentName">component name, for example Excel</param> /// <param name="className">class name, for example Application</param> /// <returns>ICOMObject enumerator</returns> public static IDisposableSequence <T> GetActiveInstances <T>(string componentName, string className) where T : class, ICOMObject { Type typeOfT = typeof(T); IDisposableSequence instances = GetActiveInstances(componentName, className); List <T> result = new List <T>(); foreach (object item in instances) { T newItem = Activator.CreateInstance(typeOfT, new object[] { null, item }) as T; result.Add(newItem); } return(new DisposableGenericList <T>(result.ToArray())); }
/// <summary> /// Returns first running com proxy, wrapped by T /// </summary> /// <typeparam name="T"></typeparam> /// <param name="predicate">filter predicate</param> /// <param name="throwExceptionIfNotFound">throw ArgumentOutOfRangeException if no instance match</param> /// <returns>target instance or null(Nothing in Visual Basic)</returns> /// <exception cref="NetOfficeException">given type doesnt have a ComProgIdAttribute annotation</exception> /// <exception cref="NetOfficeCOMException">occurs if no instance match and throwExceptionIfNotFound is set</exception> public static T GetActiveInstance <T>(Func <T, bool> predicate, bool throwExceptionIfNotFound = false) where T : class, ICOMObject { Type type = typeof(T); var attribute = type.GetCustomAttribute <ComProgIdAttribute>(true); if (null == attribute) { throw new NetOfficeException("Missing ComProgIdAttribute."); } string[] array = ConvertProgId(attribute.Value); IDisposableSequence <T> result = GetActiveInstances <T>(array[0], array[1], predicate); T item = result.FirstOrDefault(); result.Dispose(item); if (throwExceptionIfNotFound && null == item) { throw new NetOfficeCOMException(String.Format("Unable to find active instance {0}.", array[0] + " " + array[1])); } return(item); }
/// <summary> /// Returns all running com proxies, wrapped by T /// </summary> /// <returns>ICOMObject enumerator</returns> /// <exception cref="NetOfficeException">given type doesnt have a ComProgIdAttribute annotation</exception> public static IDisposableSequence <T> GetActiveInstances <T>() where T : class, ICOMObject { Type type = typeof(T); var attribute = type.GetCustomAttribute <ComProgIdAttribute>(true); if (null == attribute) { throw new NetOfficeException("Missing ComProgIdAttribute."); } string[] array = ConvertProgId(attribute.Value); IDisposableSequence instances = GetActiveInstances(array[0], array[1]); List <T> result = new List <T>(); foreach (object item in instances) { T newItem = Activator.CreateInstance(type, new object[] { null, item }) as T; result.Add(newItem); } return(new DisposableGenericList <T>(result.ToArray())); }