< Summary

Information
Class: SolidEdgeCommunity.Extensions.ApplicationExtensions
Assembly: SolidEdgeCommunity
File(s): D:\a\SolidEdge.Community\SolidEdge.Community\src\SolidEdgeCommunity\Extensions\ApplicationExtensions.cs
Line coverage
87%
Covered lines: 51
Uncovered lines: 7
Coverable lines: 58
Total lines: 338
Line coverage: 87.9%
Branch coverage
62%
Covered branches: 5
Total branches: 8
Branch coverage: 62.5%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
CreateCommand(...)100%210%
GetActiveDocument(...)100%11100%
GetActiveDocument(...)100%11100%
GetActiveDocument(...)100%11100%
GetActiveDocument(...)100%11100%
GetActiveEnvironment(...)100%11100%
GetEnvironment(...)100%44100%
GetGlobalParameter(...)100%11100%
GetGlobalParameter(...)100%11100%
GetNativeWindow(...)100%11100%
GetProcess(...)100%11100%
GetVersion(...)100%11100%
GetWindowHandle(...)100%11100%
StartCommand(...)100%11100%
StartCommand(...)100%11100%
StartCommand(...)100%11100%
StartCommand(...)100%11100%
StartCommand(...)100%11100%
StartCommand(...)100%11100%
StartCommand(...)100%11100%
StartCommand(...)100%11100%
StartCommand(...)100%11100%
StartCommand(...)100%11100%
StartCommand(...)100%11100%
StartCommand(...)100%11100%
StartCommand(...)100%11100%
StartCommand(...)100%11100%
StartCommand(...)100%11100%
StartCommand(...)100%210%
StartCommand(...)100%11100%
StartCommand(...)100%11100%
StartCommand(...)100%11100%
StartCommand(...)100%210%
Show(...)100%210%
ShowDialog(...)0%620%
ShowDialog(...)50%22100%

File(s)

D:\a\SolidEdge.Community\SolidEdge.Community\src\SolidEdgeCommunity\Extensions\ApplicationExtensions.cs

#LineLine coverage
 1using System;
 2using System.Diagnostics;
 3using System.Linq;
 4using System.Windows.Forms;
 5
 6namespace SolidEdgeCommunity.Extensions;
 7
 8/// <summary>
 9/// SolidEdgeFramework.Application extension methods.
 10/// </summary>
 11public static class ApplicationExtensions
 12{
 13    /// <summary>
 14    /// Creates a Solid Edge command control.
 15    /// </summary>
 16    /// <param name="application"></param>
 17    /// <param name="CmdFlags"></param>
 18    public static Command CreateCommand(this Application application, seCmdFlag CmdFlags)
 019        => application.CreateCommand((int)CmdFlags);
 20
 21    /// <summary>
 22    /// Returns the currently active document.
 23    /// </summary>
 24    /// <remarks>An exception will be thrown if there is no active document.</remarks>
 125    public static SolidEdgeDocument GetActiveDocument(this Application application) => application.GetActiveDocument(tru
 26
 27    /// <summary>
 28    /// Returns the currently active document.
 29    /// </summary>
 30    public static SolidEdgeDocument GetActiveDocument(this Application application, bool throwOnError)
 31    {
 32        try
 33        {
 34            // ActiveDocument will throw an exception if no document is open.
 335            return (SolidEdgeDocument)application.ActiveDocument;
 36        }
 237        catch when (!throwOnError)
 38        {
 139        }
 40
 141        return null;
 142    }
 43
 44    /// <summary>
 45    /// Returns the currently active document.
 46    /// </summary>
 47    /// <typeparam name="T">The type to return.</typeparam>
 48    /// /// <remarks>An exception will be thrown if there is no active document or if the cast fails.</remarks>
 149    public static T GetActiveDocument<T>(this Application application) where T : class => application.GetActiveDocument<
 50
 51    /// <summary>
 52    /// Returns the currently active document.
 53    /// </summary>
 54    /// <typeparam name="T">The type to return.</typeparam>
 55    public static T GetActiveDocument<T>(this Application application, bool throwOnError) where T : class
 56    {
 57        try
 58        {
 59            // ActiveDocument will throw an exception if no document is open.
 260            return (T)application.ActiveDocument;
 61        }
 162        catch when (!throwOnError)
 63        {
 164        }
 65
 166        return null;
 167    }
 68
 69    /// <summary>
 70    /// Returns the environment that belongs to the current active window of the document.
 71    /// </summary>
 72    public static Environment GetActiveEnvironment(this Application application)
 73    {
 174        Environments environments = application.Environments;
 175        return environments.Item(application.ActiveEnvironment);
 76    }
 77
 78    ///// <summary>
 79    ///// Returns the application events.
 80    ///// </summary>
 81    //public static SolidEdgeFramework.ISEApplicationEvents_Event GetApplicationEvents(this SolidEdgeFramework.Applicati
 82    //{
 83    //    return (SolidEdgeFramework.ISEApplicationEvents_Event)application.ApplicationEvents;
 84    //}
 85
 86    ///// <summary>
 87    ///// Returns the application window events.
 88    ///// </summary>
 89    //public static SolidEdgeFramework.ISEApplicationWindowEvents_Event GetApplicationWindowEvents(this SolidEdgeFramewo
 90    //{
 91    //    return (SolidEdgeFramework.ISEApplicationWindowEvents_Event)application.ApplicationWindowEvents;
 92    //}
 93
 94    /// <summary>
 95    /// Returns an environment specified by CATID.
 96    /// </summary>
 97    public static Environment GetEnvironment(this Application application, string CATID)
 98    {
 299        var guid1 = new Guid(CATID);
 2100        var environments = application.Environments;
 101
 6102        for (int i = 1; i <= environments.Count; i++)
 103        {
 2104            var environment = environments.Item(i);
 2105            var guid2 = new Guid(environment.CATID);
 106
 2107            if (guid1.Equals(guid2))
 108            {
 1109                return environment;
 110            }
 111        }
 112
 1113        return null;
 114    }
 115
 116    ///// <summary>
 117    ///// Returns the feature library events.
 118    ///// </summary>
 119    //public static SolidEdgeFramework.ISEFeatureLibraryEvents_Event GetFeatureLibraryEvents(this SolidEdgeFramework.App
 120    //{
 121    //    return (SolidEdgeFramework.ISEFeatureLibraryEvents_Event)application.FeatureLibraryEvents;
 122    //}
 123
 124    ///// <summary>
 125    ///// Returns the file UI events.
 126    ///// </summary>
 127    //public static SolidEdgeFramework.ISEFileUIEvents_Event GetFileUIEvents(this SolidEdgeFramework.Application applica
 128    //{
 129    //    return (SolidEdgeFramework.ISEFileUIEvents_Event)application.FileUIEvents;
 130    //}
 131
 132    /// <summary>
 133    /// Returns the value of a specified global constant.
 134    /// </summary>
 135    public static object GetGlobalParameter(this Application application, ApplicationGlobalConstants globalConstant)
 136    {
 1137        object value = null;
 1138        application.GetGlobalParameter(globalConstant, ref value);
 1139        return value;
 140    }
 141
 142    /// <summary>
 143    /// Returns the value of a specified global constant.
 144    /// </summary>
 145    /// <typeparam name="T">The type to return.</typeparam>
 146    public static T GetGlobalParameter<T>(this Application application, ApplicationGlobalConstants globalConstant)
 147    {
 1148        object value = null;
 1149        application.GetGlobalParameter(globalConstant, ref value);
 1150        return (T)value;
 151    }
 152
 153    /// <summary>
 154    /// Returns a NativeWindow object that represents the main application window.
 155    /// </summary>
 1156    public static NativeWindow GetNativeWindow(this Application application) => NativeWindow.FromHandle(new IntPtr(appli
 157
 158    ///// <summary>
 159    ///// Returns the new file UI events.
 160    ///// </summary>
 161    //public static SolidEdgeFramework.ISENewFileUIEvents_Event GetNewFileUIEvents(this SolidEdgeFramework.Application a
 162    //{
 163    //    return (SolidEdgeFramework.ISENewFileUIEvents_Event)application.NewFileUIEvents;
 164    //}
 165
 166    ///// <summary>
 167    ///// Returns the SEEC events.
 168    ///// </summary>
 169    //public static SolidEdgeFramework.ISEECEvents_Event GetSEECEvents(this SolidEdgeFramework.Application application)
 170    //{
 171    //    return (SolidEdgeFramework.ISEECEvents_Event)application.SEECEvents;
 172    //}
 173
 174    /// <summary>
 175    /// Returns a Process object that represents the application process.
 176    /// </summary>
 1177    public static Process GetProcess(this Application application) => Process.GetProcessById(application.ProcessID);
 178
 179    ///// <summary>
 180    ///// Returns the shortcut menu events.
 181    ///// </summary>
 182    //public static SolidEdgeFramework.ISEShortCutMenuEvents_Event GetShortcutMenuEvents(this SolidEdgeFramework.Applica
 183    //{
 184    //    return (SolidEdgeFramework.ISEShortCutMenuEvents_Event)application.ShortcutMenuEvents;
 185    //}
 186
 187    /// <summary>
 188    /// Returns a Version object that represents the application version.
 189    /// </summary>
 1190    public static Version GetVersion(this Application application) => new(application.Version);
 191
 192    /// <summary>
 193    /// Returns a point object to the application main window.
 194    /// </summary>
 1195    public static IntPtr GetWindowHandle(this Application application) => new(application.hWnd);
 196
 197    /// <summary>
 198    /// Activates a specified Solid Edge command.
 199    /// </summary>
 200    public static void StartCommand(this Application application, AssemblyCommandConstants CommandID)
 1201        => application.StartCommand((SolidEdgeCommandConstants)CommandID);
 202
 203    /// <summary>
 204    /// Activates a specified Solid Edge command.
 205    /// </summary>
 206    public static void StartCommand(this Application application, CuttingPlaneLineCommandConstants CommandID)
 1207        => application.StartCommand((SolidEdgeCommandConstants)CommandID);
 208
 209    /// <summary>
 210    /// Activates a specified Solid Edge command.
 211    /// </summary>
 212    public static void StartCommand(this Application application, DetailCommandConstants CommandID)
 1213        => application.StartCommand((SolidEdgeCommandConstants)CommandID);
 214
 215    /// <summary>
 216    /// Activates a specified Solid Edge command.
 217    /// </summary>
 218    public static void StartCommand(this Application application, DrawingViewEditCommandConstants CommandID)
 1219        => application.StartCommand((SolidEdgeCommandConstants)CommandID);
 220
 221    /// <summary>
 222    /// Activates a specified Solid Edge command.
 223    /// </summary>
 224    public static void StartCommand(this Application application, ExplodeCommandConstants CommandID)
 1225        => application.StartCommand((SolidEdgeCommandConstants)CommandID);
 226
 227    /// <summary>
 228    /// Activates a specified Solid Edge command.
 229    /// </summary>
 230    public static void StartCommand(this Application application, LayoutCommandConstants CommandID)
 1231        => application.StartCommand((SolidEdgeCommandConstants)CommandID);
 232
 233    /// <summary>
 234    /// Activates a specified Solid Edge command.
 235    /// </summary>
 236    public static void StartCommand(this Application application, LayoutInPartCommandConstants CommandID)
 1237        => application.StartCommand((SolidEdgeCommandConstants)CommandID);
 238
 239    /// <summary>
 240    /// Activates a specified Solid Edge command.
 241    /// </summary>
 242    public static void StartCommand(this Application application, MotionCommandConstants CommandID)
 1243        => application.StartCommand((SolidEdgeCommandConstants)CommandID);
 244
 245    /// <summary>
 246    /// Activates a specified Solid Edge command.
 247    /// </summary>
 248    public static void StartCommand(this Application application, PartCommandConstants CommandID)
 1249        => application.StartCommand((SolidEdgeCommandConstants)CommandID);
 250
 251    /// <summary>
 252    /// Activates a specified Solid Edge command.
 253    /// </summary>
 254    public static void StartCommand(this Application application, ProfileCommandConstants CommandID)
 1255        => application.StartCommand((SolidEdgeCommandConstants)CommandID);
 256
 257    /// <summary>
 258    /// Activates a specified Solid Edge command.
 259    /// </summary>
 260    public static void StartCommand(this Application application, ProfileHoleCommandConstants CommandID)
 1261        => application.StartCommand((SolidEdgeCommandConstants)CommandID);
 262
 263    /// <summary>
 264    /// Activates a specified Solid Edge command.
 265    /// </summary>
 266    public static void StartCommand(this Application application, ProfilePatternCommandConstants CommandID)
 1267        => application.StartCommand((SolidEdgeCommandConstants)CommandID);
 268
 269    /// <summary>
 270    /// Activates a specified Solid Edge command.
 271    /// </summary>
 272    public static void StartCommand(this Application application, ProfileRevolvedCommandConstants CommandID)
 1273        => application.StartCommand((SolidEdgeCommandConstants)CommandID);
 274
 275    /// <summary>
 276    /// Activates a specified Solid Edge command.
 277    /// </summary>
 278    public static void StartCommand(this Application application, SheetMetalCommandConstants CommandID)
 1279        => application.StartCommand((SolidEdgeCommandConstants)CommandID);
 280
 281    /// <summary>
 282    /// Activates a specified Solid Edge command.
 283    /// </summary>
 284    public static void StartCommand(this Application application, SimplifyCommandConstants CommandID)
 1285        => application.StartCommand((SolidEdgeCommandConstants)CommandID);
 286
 287    /// <summary>
 288    /// Activates a specified Solid Edge command.
 289    /// </summary>
 290    public static void StartCommand(this Application application, SolidEdgeConstants.SolidEdgeCommandConstants CommandID
 0291        => application.StartCommand((SolidEdgeCommandConstants)CommandID);
 292
 293    /// <summary>
 294    /// Activates a specified Solid Edge command.
 295    /// </summary>
 296    public static void StartCommand(this Application application, StudioCommandConstants CommandID)
 1297        => application.StartCommand((SolidEdgeCommandConstants)CommandID);
 298
 299    /// <summary>
 300    /// Activates a specified Solid Edge command.
 301    /// </summary>
 302    public static void StartCommand(this Application application, TubingCommandConstants CommandID)
 1303        => application.StartCommand((SolidEdgeCommandConstants)CommandID);
 304
 305    /// <summary>
 306    /// Activates a specified Solid Edge command.
 307    /// </summary>
 308    public static void StartCommand(this Application application, WeldmentCommandConstants CommandID)
 1309        => application.StartCommand((SolidEdgeCommandConstants)CommandID);
 310
 311    /// <summary>
 312    /// Activates a specified Solid Edge command.
 313    /// </summary>
 314    public static void StartCommand(this Application application, SolidEdgeCommandConstants CommandID)
 0315        => application.StartCommand((SolidEdgeCommandConstants)CommandID);
 316
 317    /// <summary>
 318    /// Shows the form with the application main window as the owner.
 319    /// </summary>
 320    public static void Show(this Application application, Form form)
 321    {
 0322        ArgumentNullException.ThrowIfNull(form);
 323
 0324        form.Show(application.GetNativeWindow());
 0325    }
 326
 327    /// <summary>
 328    /// Shows the form as a modal dialog box with the application main window as the owner.
 329    /// </summary>
 330    public static DialogResult ShowDialog(this Application application, Form form)
 0331        => form == null ? throw new ArgumentNullException(nameof(form)) : form.ShowDialog(application.GetNativeWindow())
 332
 333    /// <summary>
 334    /// Shows the form as a modal dialog box with the application main window as the owner.
 335    /// </summary>
 336    public static DialogResult ShowDialog(this Application application, CommonDialog dialog)
 1337        => dialog == null ? throw new ArgumentNullException(nameof(dialog)) : dialog.ShowDialog(application.GetNativeWin
 338}

Methods/Properties

CreateCommand(SolidEdgeFramework.Application,SolidEdgeConstants.seCmdFlag)
GetActiveDocument(SolidEdgeFramework.Application)
GetActiveDocument(SolidEdgeFramework.Application,System.Boolean)
GetActiveDocument(SolidEdgeFramework.Application)
GetActiveDocument(SolidEdgeFramework.Application,System.Boolean)
GetActiveEnvironment(SolidEdgeFramework.Application)
GetEnvironment(SolidEdgeFramework.Application,System.String)
GetGlobalParameter(SolidEdgeFramework.Application,SolidEdgeFramework.ApplicationGlobalConstants)
GetGlobalParameter(SolidEdgeFramework.Application,SolidEdgeFramework.ApplicationGlobalConstants)
GetNativeWindow(SolidEdgeFramework.Application)
GetProcess(SolidEdgeFramework.Application)
GetVersion(SolidEdgeFramework.Application)
GetWindowHandle(SolidEdgeFramework.Application)
StartCommand(SolidEdgeFramework.Application,SolidEdgeConstants.AssemblyCommandConstants)
StartCommand(SolidEdgeFramework.Application,SolidEdgeConstants.CuttingPlaneLineCommandConstants)
StartCommand(SolidEdgeFramework.Application,SolidEdgeConstants.DetailCommandConstants)
StartCommand(SolidEdgeFramework.Application,SolidEdgeConstants.DrawingViewEditCommandConstants)
StartCommand(SolidEdgeFramework.Application,SolidEdgeConstants.ExplodeCommandConstants)
StartCommand(SolidEdgeFramework.Application,SolidEdgeConstants.LayoutCommandConstants)
StartCommand(SolidEdgeFramework.Application,SolidEdgeConstants.LayoutInPartCommandConstants)
StartCommand(SolidEdgeFramework.Application,SolidEdgeConstants.MotionCommandConstants)
StartCommand(SolidEdgeFramework.Application,SolidEdgeConstants.PartCommandConstants)
StartCommand(SolidEdgeFramework.Application,SolidEdgeConstants.ProfileCommandConstants)
StartCommand(SolidEdgeFramework.Application,SolidEdgeConstants.ProfileHoleCommandConstants)
StartCommand(SolidEdgeFramework.Application,SolidEdgeConstants.ProfilePatternCommandConstants)
StartCommand(SolidEdgeFramework.Application,SolidEdgeConstants.ProfileRevolvedCommandConstants)
StartCommand(SolidEdgeFramework.Application,SolidEdgeConstants.SheetMetalCommandConstants)
StartCommand(SolidEdgeFramework.Application,SolidEdgeConstants.SimplifyCommandConstants)
StartCommand(SolidEdgeFramework.Application,SolidEdgeConstants.SolidEdgeCommandConstants)
StartCommand(SolidEdgeFramework.Application,SolidEdgeConstants.StudioCommandConstants)
StartCommand(SolidEdgeFramework.Application,SolidEdgeConstants.TubingCommandConstants)
StartCommand(SolidEdgeFramework.Application,SolidEdgeConstants.WeldmentCommandConstants)
StartCommand(SolidEdgeFramework.Application,SolidEdgeFramework.SolidEdgeCommandConstants)
Show(SolidEdgeFramework.Application,System.Windows.Forms.Form)
ShowDialog(SolidEdgeFramework.Application,System.Windows.Forms.Form)
ShowDialog(SolidEdgeFramework.Application,System.Windows.Forms.CommonDialog)