示例#1
0
        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;
            }
        }
示例#2
0
 private void OnStartupCompleted(SwApplication app)
 {
     try
     {
         StartupCompleted?.Invoke(this);
     }
     catch (Exception ex)
     {
         Logger.Log(ex);
     }
 }
示例#3
0
        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);
            }
        }
示例#4
0
        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();
        }
示例#5
0
 public static bool IsVersionNewerOrEqual(this SwApplication app, SwVersion_e version,
                                          int?servicePack = null, int?servicePackRev = null)
 {
     return(app.Application.IsVersionNewerOrEqual(version, servicePack, servicePackRev));
 }
示例#6
0
 private void OnStartupCompleted(SwApplication app)
 {
     m_Application.FirstStartupCompleted -= OnStartupCompleted;
     StartupCompleted?.Invoke(this);
 }