/// <summary> /// Used to pass a callback message onto our plug-ins /// </summary> /// <param name="arg"></param> public void Callback(string arg) { // Log it Logger.LogDebugSource($"SolidWorks Callback fired {arg}"); PlugInIntegration.OnCallback(arg); }
/// <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); }
/// <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); }
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 is about to unload our add-in and wants us to do our disconnection logic /// </summary> /// <returns></returns> public bool DisconnectFromSW() { // Log it Logger.LogDebugSource($"{SolidWorksAddInTitle} Disconnected from SolidWorks..."); // Log it Logger.LogDebugSource($"Firing DisconnectedFromSolidWorks..."); // Inform listeners DisconnectedFromSolidWorks(); // And plug-in domain listeners PlugInIntegration.DisconnectedFromSolidWorks(); // Log it Logger.LogDebugSource($"Tearing down..."); // Clean up plug-in app domain PlugInIntegration.Teardown(); // Dispose SolidWorks COM //SolidWorks?.Dispose(); //SolidWorks = null; // 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) { PlugInIntegration.Setup(version, 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 += AppDomain_AssemblyResolve; }
/// <summary> /// Configures the app-domain that the plug-ins run inside of /// </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> /// <param name="configureServices">Provides a callback to inject any services into the Dna.Framework DI system</param> public void SetupAppDomain(string addinPath, string version, int cookie, Action <FrameworkConstruction> configureServices = null) { PlugInIntegration.Setup(addinPath, version, cookie, configureServices); // 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 += AppDomain_AssemblyResolve; }
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; } }
/// <summary> /// Loads the assembly, finds all <see cref="SolidPlugIn"/> implementations and /// creates a list of <see cref="PlugInDetails"/> for them /// </summary> /// <param name="fullPath">The assembly full path to load</param> /// <returns></returns> public static List <PlugInDetails> GetPlugInDetails(string fullPath) { var list = new List <PlugInDetails>(); PlugInIntegration.GetPlugIns(fullPath, (plugin) => list.Add(new PlugInDetails { AssemblyFullName = plugin.GetType().AssemblyBaseNormalized(), FullPath = fullPath, TypeFullName = plugin.GetType().FullName })); return(list); }
public void ConfigurePlugIns() { // Try and find the title from the first plug-in found var plugins = PlugInIntegration.SolidDnaPlugIns(); if (plugins.Count > 0) { AddInIntegration.SolidWorksAddInTitle = plugins.First().AddInTitle; AddInIntegration.SolidWorksAddInDescription = plugins.First().AddInDescription; } // Load all plug-in's at this stage for faster lookup mPlugIns = PlugInIntegration.SolidDnaPlugIns(); }
/// <summary> /// Called by the SolidWorks domain (AddInIntegration) when a callback is fired /// </summary> /// <param name="name">The parameter passed into the generic callback</param> public void OnCallback(string name) { try { // Let listeners know PlugInIntegration.OnCallback(name); } catch (Exception ex) { Debugger.Break(); // Log it Logger.Log($"OnCallback failed. {ex.GetErrorMessage()}"); } }
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 is about to unload our add-in and wants us to do our disconnection logic /// </summary> /// <returns></returns> public bool DisconnectFromSW() { // Inform listeners DisconnectedFromSolidWorks(); // And plug-in domain listeners PlugInIntegration.DisconnectedFromSolidWorks(); // Clean up plug-in app domain PlugInIntegration.Teardown(); // Dipose SolidWorks COM SolidWorks?.Dispose(); SolidWorks = null; // Return ok return(true); }
/// <summary> /// Runs any initialization code reqiured on plug-ins /// </summary> public static void ConfigurePlugIns() { if (mCrossDomain != null) { mCrossDomain.ConfigurePlugIns(); } else { // This is usually run for the ComRegister function // Try and find the title from the first plug-in found var plugins = PlugInIntegration.SolidDnaPlugIns(loadAll: true); if (plugins.Count > 0) { AddInIntegration.SolidWorksAddInTitle = plugins.First().AddInTitle; AddInIntegration.SolidWorksAddInDescription = plugins.First().AddInDescription; } } }
/// <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); }
/// <summary> /// Loads the assembly, finds all <see cref="SolidPlugIn"/> implementations and /// creates a list of <see cref="PlugInDetails"/> for them /// </summary> /// <param name="fullPath">The assembly full path to load</param> /// <returns></returns> public List <PlugInDetails> GetPlugInDetails(string fullPath) { return(PlugInIntegration.GetPlugInDetails(fullPath)); }
/// <summary> /// Adds a plug-in based on it's <see cref="SolidPlugIn"/> implementation /// </summary> /// <typeparam name="fullPath">The absolute path to the plug-in dll</typeparam> public void AddPlugIn(string fullPath) { PlugInIntegration.AddPlugIn(fullPath); }
/// <summary> /// Adds a plug-in based on it's <see cref="SolidPlugIn"/> implementation /// </summary> /// <typeparam name="T">The class that implements the <see cref="SolidPlugIn"/></typeparam> /// </param> public void AddPlugIn <T>() { PlugInIntegration.AddPlugIn <T>(); }
/// <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); } }
public void ConfigurePlugIns() { PlugInIntegration.ConfigurePlugIns(); }
/// <summary> /// Called when the add-in has disconnected from SolidWorks /// </summary> public void DisconnectedFromSolidWorks() { PlugInIntegration.DisconnectedFromSolidWorks(); }
/// <summary> /// Called when the add-in has connected to SolidWorks /// </summary> public void ConnectedToSolidWorks() { PlugInIntegration.ConnectedToSolidWorks(); }
/// <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> /// Configures the app-domain that the plug-ins run inside of /// </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 void SetupAppDomain(string addinPath, string version, int cookie) { PlugInIntegration.Setup(addinPath, version, cookie); }
/// <summary> /// Used to pass a callback message onto our plug-ins /// </summary> /// <param name="arg"></param> public void Callback(string arg) { PlugInIntegration.OnCallback(arg); }
/// <summary> /// Tears down the app-domain that the plug-ins run inside of /// </summary> public void Teardown() { PlugInIntegration.Teardown(); }
/// <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); } }