/// <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); }
/// <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> /// Called when the add-in has connected to SolidWorks /// </summary> public void ConnectedToSolidWorks() { PlugInIntegration.ConnectedToSolidWorks(); }
/// <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> /// 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); } }