public bool ConnectToSW(object ThisSW, int cookie) { m_Logger.Log("Loading add-in"); try { var app = ThisSW as ISldWorks; AddInId = cookie; app.SetAddinCallbackInfo(0, this, AddInId); m_Application = new SwApplication(app, m_Logger); SwMacroFeatureDefinition.Application = m_Application; m_CommandManager = new SwCommandManager(m_Application, AddInId, m_Logger); return(OnConnect()); } catch (Exception ex) { m_Logger.Log(ex); throw; } }
private void OnStartupCompleted(SwApplication app) { try { StartupCompleted?.Invoke(this); } catch (Exception ex) { Logger.Log(ex); } }
public bool ConnectToSW(object ThisSW, int cookie) { m_IsDisposed = false; try { var app = ThisSW as ISldWorks; AddInId = cookie; if (app.IsVersionNewerOrEqual(Enums.SwVersion_e.Sw2015)) { app.SetAddinCallbackInfo2(0, this, AddInId); } else { app.SetAddinCallbackInfo(0, this, AddInId); } m_Application = new SwApplication(app); m_Application.FirstStartupCompleted += OnStartupCompleted; var svcCollection = GetServicesCollection(); ConfigureServices?.Invoke(this, svcCollection); OnConfigureServices(svcCollection); m_SvcProvider = svcCollection.CreateProvider(); Logger = m_SvcProvider.GetService <IXLogger>(); m_Application.Init(svcCollection); Logger.Log("Loading add-in"); SwMacroFeatureDefinition.Application = m_Application; m_CommandManager = new SwCommandManager(Application, AddInId, m_SvcProvider, this.GetType().GUID); Connect?.Invoke(this); OnConnect(); return(true); } catch (Exception ex) { Logger.Log(ex); return(false); } }
protected virtual void Dispose(bool disposing) { if (disposing) { m_CommandManager.Dispose(); } if (m_Application != null) { if (Marshal.IsComObject(m_Application)) { Marshal.ReleaseComObject(m_Application); } } m_Application = null; GC.Collect(); GC.WaitForPendingFinalizers(); GC.Collect(); GC.WaitForPendingFinalizers(); }
public static bool IsVersionNewerOrEqual(this SwApplication app, SwVersion_e version, int?servicePack = null, int?servicePackRev = null) { return(app.Application.IsVersionNewerOrEqual(version, servicePack, servicePackRev)); }
private void OnStartupCompleted(SwApplication app) { m_Application.FirstStartupCompleted -= OnStartupCompleted; StartupCompleted?.Invoke(this); }