protected static void ComRegister(Type t) { var keyPath = string.Format(@"SOFTWARE\SolidWorks\AddIns\{0:b}", t.GUID); // Create our registry folder for the add-in using (var rk = Microsoft.Win32.Registry.LocalMachine.CreateSubKey(keyPath)) { // Load add-in when SolidWorks opens rk.SetValue(null, 1); // // IMPORTANT: // // In this special case, COM register won't load the wrong AngelSix.SolidDna.dll file // as it isn't loading multiple instances and keeping them in memory // // So loading the path of the AngelSix.SolidDna.dll file that should be in the same // folder as the add-in dll right now will work fine to get the add-in path // var pluginPath = typeof(PlugInIntegration).CodeBaseNormalized(); // Let plug-ins configure title and descriptions PlugInIntegration.ConfigurePlugIns(pluginPath, log: false); // Set SolidWorks add-in title and description rk.SetValue("Title", SolidWorksAddInTitle); rk.SetValue("Description", SolidWorksAddInDescription); } }
/// <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> /// 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) { // Get the path to this actual add-in dll var myPath = this.AssemblyPath(); PreConnectToSolidWorks(); // // 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(GetType().Assembly.Location, ((SldWorks)ThisSW).RevisionNumber(), Cookie, // Setup IoC (construction) => { // Add SolidDna-specific services // -------------------------------- // Add localization manager construction.Services.AddSingleton <ILocalizationManager>(new LocalizationManager { StringResourceDefinition = new ResourceDefinition { Type = ResourceDefinitionType.EmbeddedResource, Location = "AngelSix.SolidDna.Localization.Strings.Strings-{0}.xml", UseDefaultCultureIfNotFound = true, } }); // Configure any services this class wants to add // ------------------------------------------------ ConfigureServices(construction); }); // Any pre-load steps PreLoadPlugIns(); // Perform any plug-in configuration PlugInIntegration.ConfigurePlugIns(myPath); // 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); }
protected static void ComRegister(Type t) { // Create new instance of ComRegister add-in to setup DI new ComRegisterAddInIntegration(); try { // Get assembly name var assemblyName = t.Assembly.Location; // Log it Logger.LogInformationSource($"Registering {assemblyName}"); // Get registry key path var keyPath = string.Format(@"SOFTWARE\SolidWorks\AddIns\{0:b}", t.GUID); // Create our registry folder for the add-in using (var rk = Microsoft.Win32.Registry.LocalMachine.CreateSubKey(keyPath)) { // Load add-in when SolidWorks opens rk.SetValue(null, 1); // // IMPORTANT: // // In this special case, COM register won't load the wrong AngelSix.SolidDna.dll file // as it isn't loading multiple instances and keeping them in memory // // So loading the path of the AngelSix.SolidDna.dll file that should be in the same // folder as the add-in dll right now will work fine to get the add-in path // var pluginPath = typeof(PlugInIntegration).CodeBaseNormalized(); // Force auto-discovering plug-in during COM registration PlugInIntegration.AutoDiscoverPlugins = true; Logger.LogInformationSource("Configuring plugins..."); // Let plug-ins configure title and descriptions PlugInIntegration.ConfigurePlugIns(pluginPath); // Set SolidWorks add-in title and description rk.SetValue("Title", SolidWorksAddInTitle); rk.SetValue("Description", SolidWorksAddInDescription); Logger.LogInformationSource($"COM Registration successful. '{SolidWorksAddInTitle}' : '{SolidWorksAddInDescription}'"); } } catch (Exception ex) { Logger.LogCriticalSource($"COM Registration error. {ex}"); throw; } }
protected static void ComRegister(Type t) { var keyPath = string.Format(@"SOFTWARE\SolidWorks\AddIns\{0:b}", t.GUID); // Create our registry folder for the add-in using (var rk = Microsoft.Win32.Registry.LocalMachine.CreateSubKey(keyPath)) { // Load add-in when SolidWorks opens rk.SetValue(null, 1); // Let plug-ins configure title and descriptions PlugInIntegration.ConfigurePlugIns(); // Set SolidWorks add-in title and description rk.SetValue("Title", SolidWorksAddInTitle); rk.SetValue("Description", SolidWorksAddInDescription); } }
/// <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); }
public void ConfigurePlugIns() { PlugInIntegration.ConfigurePlugIns(); }
/// <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) { try { // Get the path to this actual add-in dll var assemblyFilePath = this.AssemblyFilePath(); var assemblyPath = this.AssemblyPath(); // Log it Logger.LogDebugSource($"{SolidWorksAddInTitle} Connected to SolidWorks..."); // Log it Logger.LogDebugSource($"Firing PreConnectToSolidWorks..."); // Fire event PreConnectToSolidWorks(); // // 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); // Log it Logger.LogDebugSource($"Setting AddinCallbackInfo..."); // Setup callback info var ok = ((SldWorks)ThisSW).SetAddinCallbackInfo2(0, this, Cookie); // Log it Logger.LogDebugSource($"PlugInIntegration Setup..."); // Setup plug-in application domain PlugInIntegration.Setup(assemblyPath, ((SldWorks)ThisSW).RevisionNumber(), Cookie); // Log it Logger.LogDebugSource($"Firing PreLoadPlugIns..."); // Any pre-load steps PreLoadPlugIns(); // Log it Logger.LogDebugSource($"Configuring PlugIns..."); // Perform any plug-in configuration PlugInIntegration.ConfigurePlugIns(assemblyPath); // Log it Logger.LogDebugSource($"Firing ApplicationStartup..."); // Call the application startup function for an entry point to the application ApplicationStartup(); // Log it Logger.LogDebugSource($"Firing ConnectedToSolidWorks..."); // Inform listeners ConnectedToSolidWorks(); // Log it Logger.LogDebugSource($"PlugInIntegration ConnectedToSolidWorks..."); // And plug-in domain listeners PlugInIntegration.ConnectedToSolidWorks(); // Return ok return(true); } catch (Exception ex) { // Log it Logger.LogCriticalSource($"Unexpected error: {ex}"); return(false); } }
/// <summary> /// Runs any initialization code required on plug-ins /// </summary> /// <param name="addinPath">The path to the add-in that is calling this setup (typically acquired using GetType().Assembly.Location)</param> public void ConfigurePlugIns(string addinPath) { PlugInIntegration.ConfigurePlugIns(addinPath); }
/// <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) { try { // Get the path to this actual add-in dll var assemblyFilePath = this.AssemblyFilePath(); var assemblyPath = this.AssemblyPath(); // Setup IoC IoC.Setup(assemblyFilePath, construction => { // Add SolidDna-specific services // -------------------------------- // Add localization manager construction.Services.AddSingleton <ILocalizationManager>(new LocalizationManager { StringResourceDefinition = new ResourceDefinition { Type = ResourceDefinitionType.EmbeddedResource, Location = "AngelSix.SolidDna.Localization.Strings.Strings-{0}.xml", UseDefaultCultureIfNotFound = true, } }); // Configure any services this class wants to add // ------------------------------------------------ ConfigureServices(construction); }); // Log it (critical, so regardless of log level it will write out) Logger.LogCriticalSource($"DI Setup complete for {AddInIntegration.SolidWorksAddInTitle}"); // Log it Logger.LogDebugSource($"{SolidWorksAddInTitle} Connected to SolidWorks..."); // Log it Logger.LogDebugSource($"Assembly Path {assemblyFilePath}"); // Log it Logger.LogDebugSource($"Firing PreConnectToSolidWorks..."); // Fire event PreConnectToSolidWorks(); // // 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); // Log it Logger.LogDebugSource($"Setting AddinCallbackInfo..."); // Setup callback info var ok = ((SldWorks)ThisSW).SetAddinCallbackInfo2(0, this, Cookie); // Log it Logger.LogDebugSource($"PlugInIntegration Setup..."); // Setup plug-in application domain PlugInIntegration.Setup(assemblyPath, ((SldWorks)ThisSW).RevisionNumber(), Cookie); // Log it Logger.LogDebugSource($"Firing PreLoadPlugIns..."); // Any pre-load steps PreLoadPlugIns(); // Log it Logger.LogDebugSource($"Configuring PlugIns..."); // Perform any plug-in configuration PlugInIntegration.ConfigurePlugIns(assemblyPath); // Log it Logger.LogDebugSource($"Firing ApplicationStartup..."); // Call the application startup function for an entry point to the application ApplicationStartup(); // Log it Logger.LogDebugSource($"Firing ConnectedToSolidWorks..."); // Inform listeners ConnectedToSolidWorks(); // Log it Logger.LogDebugSource($"PlugInIntegration ConnectedToSolidWorks..."); // And plug-in domain listeners PlugInIntegration.ConnectedToSolidWorks(); // Return ok return(true); } catch (Exception ex) { // Try to log it to logger if it made it try { Logger.LogCriticalSource($"Unexpected error: {ex}"); } catch { // Fallback just write a static log directly File.AppendAllText(Path.ChangeExtension(this.AssemblyFilePath(), "fatal.log.txt"), $"\r\nUnexpected error: {ex}"); } return(false); } }