Ejemplo n.º 1
0
        /// <summary>
        /// Called when SolidWorks has loaded our add-in and wants us to do our connection logic
        /// </summary>
        /// <param name="ThisSW">The current SolidWorks instance</param>
        /// <param name="Cookie">The current SolidWorks cookie Id</param>
        /// <returns></returns>
        public bool ConnectToSW(object ThisSW, int Cookie)
        {
            // Setup IoC
            IoCContainer.Ensure();

            // Store a reference to the current SolidWorks instance
            // Initialize SolidWorks (SolidDNA class)
            SolidWorks = new SolidWorksApplication((SldWorks)ThisSW, Cookie);

            // Setup plug-in app domain
            PlugInIntegration.Setup(SolidWorks);

            // Any pre-load steps
            PreLoadPlugIns();

            // Perform any plug-in configuration
            PlugInIntegration.ConfigurePlugIns();

            // Call the application startup function for an entry point to the application
            ApplicationStartup();

            // Inform listeners
            ConnectedToSolidWorks();

            // And plug-in domain listeners
            PlugInIntegration.ConnectedToSolidWorks();

            // Return ok
            return(true);
        }
        /// <summary>
        /// Configures the app-domain that the plug-ins run inside of
        /// </summary>
        /// <param name="version">The version of the currently connected SolidWorks instance</param>
        /// <param name="cookie">The cookie Id of the SolidWorks instance</param>
        public void SetupAppDomain(string version, int cookie)
        {
            // Setup IoC
            IoCContainer.Ensure();

            // 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);

            // And hook into the resolver
            AppDomain.CurrentDomain.AssemblyResolve += AppDomain_AssemblyResolve;
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Must be called to setup the PlugInIntegration
        /// </summary>
        public static void Setup(string revisionNumber, int cookie)
        {
            if (UseDetachedAppDomain)
            {
                // 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
                CrossDomain = (PlugInIntegrationMarshal)PlugInAppDomain.CreateInstanceAndUnwrap(typeof(PlugInIntegrationMarshal).Assembly.FullName, typeof(PlugInIntegrationMarshal).FullName);

                // Setup
                CrossDomain.SetupAppDomain(revisionNumber, cookie);
            }
            else
            {
                // Setup IoC
                IoCContainer.Ensure();

                // Get the version number (such as 25 for 2016)
                var postFix = "";
                if (revisionNumber != null && revisionNumber.Contains("."))
                {
                    postFix = "." + revisionNumber.Substring(0, revisionNumber.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);
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Called when SolidWorks has loaded our add-in and wants us to do our connection logic
        /// </summary>
        /// <param name="ThisSW">The current SolidWorks instance</param>
        /// <param name="Cookie">The current SolidWorks cookie Id</param>
        /// <returns></returns>
        public bool ConnectToSW(object ThisSW, int Cookie)
        {
            PreConnectToSolidWorks();

            // Setup IoC
            IoCContainer.Ensure();

            //
            //   NOTE: Do not need to create it here, as we now create it inside PlugInIntegration.Setup in it's own AppDomain
            //         If we change back to loading directly (not in an app domain) then uncomment this
            //
            // Store a reference to the current SolidWorks instance
            // Initialize SolidWorks (SolidDNA class)
            //SolidWorks = new SolidWorksApplication((SldWorks)ThisSW, Cookie);

            // Setup callback info
            var ok = ((SldWorks)ThisSW).SetAddinCallbackInfo2(0, this, Cookie);

            // Setup plug-in application domain
            PlugInIntegration.Setup(((SldWorks)ThisSW).RevisionNumber(), Cookie);

            // Any pre-load steps
            PreLoadPlugIns();

            // Perform any plug-in configuration
            PlugInIntegration.ConfigurePlugIns();

            // Call the application startup function for an entry point to the application
            ApplicationStartup();

            // Inform listeners
            ConnectedToSolidWorks();

            // And plug-in domain listeners
            PlugInIntegration.ConnectedToSolidWorks();

            // Return ok
            return(true);
        }