예제 #1
0
        /// <summary>
        /// Must be called to setup the PlugInIntegration
        /// </summary>
        /// <param name="addinPath">The path to the add-in that is calling this setup (typically acquired using GetType().Assembly.Location)</param>
        /// <param name="cookie">The cookie Id of the SolidWorks instance</param>
        /// <param name="version">The version of the currently connected SolidWorks instance</param>
        public static void Setup(string addinPath, string version, int cookie)
        {
            if (UseDetachedAppDomain)
            {
                // Log it
                Logger.LogDebugSource($"Detached AppDomain PlugIn Setup...");

                // Make sure we resolve assemblies in this domain, as it seems to use this domain to resolve
                // assemblies not the appDomain when crossing boundaries
                AppDomain.CurrentDomain.AssemblyResolve += PlugInIntegrationMarshal.AppDomain_AssemblyResolve;

                PlugInAppDomain = AppDomain.CreateDomain("SolidDnaPlugInDomain", null, new AppDomainSetup
                {
                    // Use plug-in folder for resolving plug-ins
                    ApplicationBase = addinPath,
                });

                // Make sure we load our own marshal
                AssembliesToResolve.Add(typeof(PlugInIntegrationMarshal).Assembly.FullName);

                // Run code on new app-domain to configure
                CrossDomain = (PlugInIntegrationMarshal)PlugInAppDomain.CreateInstanceAndUnwrap(typeof(PlugInIntegrationMarshal).Assembly.FullName, typeof(PlugInIntegrationMarshal).FullName);

                // Setup
                CrossDomain.SetupAppDomain(addinPath, version, cookie);
            }
            else
            {
                // Log it
                Logger.LogDebugSource($"PlugIn Setup...");

                // Get the version number (such as 25 for 2016)
                var postFix = "";
                if (version != null && version.Contains("."))
                {
                    postFix = "." + version.Substring(0, version.IndexOf('.'));
                }

                // Store a reference to the current SolidWorks instance
                // Initialize SolidWorks (SolidDNA class)
                AddInIntegration.SolidWorks = new SolidWorksApplication((SldWorks)Activator.CreateInstance(Type.GetTypeFromProgID("SldWorks.Application" + postFix)), cookie);

                // Log it
                Logger.LogDebugSource($"SolidWorks Instance Created? {AddInIntegration.SolidWorks != null}");
            }
        }
예제 #2
0
        /// <summary>
        /// Must be called to setup the PlugInIntegration application domain
        /// </summary>
        public static void Setup(string revisionNumber, int cookie)
        {
            // Make sure we resolve assemblies in this domain, as it seems to use this domain to resolve
            // assemblies not the appDomain when crossing boundaries
            AppDomain.CurrentDomain.AssemblyResolve += PlugInIntegrationMarshal.AppDomain_AssemblyResolve;

            PlugInAppDomain = AppDomain.CreateDomain("SolidDnaPlugInDomain", null, new AppDomainSetup
            {
                // Use plug-in folder for resolving plug-ins
                ApplicationBase = PlugInFolder,
            });

            // Make sure we load our own marshal
            AssembliesToResolve.Add(typeof(PlugInIntegrationMarshal).Assembly.FullName);

            // Run code on new app-domain to configure
            mCrossDomain = (PlugInIntegrationMarshal)PlugInAppDomain.CreateInstanceAndUnwrap(typeof(PlugInIntegrationMarshal).Assembly.FullName, typeof(PlugInIntegrationMarshal).FullName);
            mCrossDomain.SetupAppDomain(revisionNumber, cookie);
        }