Beispiel #1
0
        public static ISwApplication FromProcess(Process process, IXServiceCollection services)
        {
            var app = RotHelper.TryGetComObjectByMonikerName <ISldWorks>(GetMonikerName(process));

            if (app != null)
            {
                return(FromPointer(app, services));
            }
            else
            {
                throw new Exception($"Cannot access SOLIDWORKS application at process {process.Id}");
            }
        }
Beispiel #2
0
        private void GetMacroParametersManager(bool createIfNotExist, out RotRegister newRegister, out IMacroParameterManager macroParamsMgr)
        {
            macroParamsMgr = RotHelper.TryGetComObjectByMonikerName <IMacroParameterManager>(MACRO_RUNNER_MONIKER_NAME);

            if (macroParamsMgr == null)
            {
                if (createIfNotExist)
                {
                    macroParamsMgr = new MacroParameterManager();
                    newRegister    = new RotRegister(macroParamsMgr, MACRO_RUNNER_MONIKER_NAME);
                }
                else
                {
                    throw new COMException("Macro parameters manager is not registered");
                }
            }
            else
            {
                newRegister = null;
            }
        }
Beispiel #3
0
 public void Dispose()
 {
     m_Logger.Log($"Unregistering object from ROT: {m_Id}", XCad.Base.Enums.LoggerMessageSeverity_e.Debug);
     RotHelper.UnregisterComObject(m_Id);
 }
Beispiel #4
0
 internal RotRegister(object obj, string name, IXLogger logger)
 {
     m_Logger = logger;
     m_Id     = RotHelper.RegisterComObject(obj, name, true, false, m_Logger);
 }
Beispiel #5
0
        internal ISldWorks Start(Action <Process> startHandler, CancellationToken cancellationToken)
        {
            SwVersion_e?vers = null;

            if (m_Version != null)
            {
                vers = m_Version.Major;
            }

            var args = new List <string>();

            if (m_State.HasFlag(ApplicationState_e.Safe))
            {
                args.Add(SwApplicationFactory.CommandLineArguments.SafeMode);
            }

            if (m_State.HasFlag(ApplicationState_e.Silent))
            {
                args.Add(SwApplicationFactory.CommandLineArguments.SilentMode);
            }

            if (m_State.HasFlag(ApplicationState_e.Background))
            {
                args.Add(SwApplicationFactory.CommandLineArguments.BackgroundMode);
            }

            var swPath = FindSwAppPath(vers);

            var prcInfo = new ProcessStartInfo(swPath, string.Join(" ", args));

            if (m_State.HasFlag(ApplicationState_e.Hidden))
            {
                prcInfo.UseShellExecute = false;
                prcInfo.CreateNoWindow  = true;
                prcInfo.WindowStyle     = ProcessWindowStyle.Hidden;
            }

            var prc = Process.Start(prcInfo);

            startHandler.Invoke(prc);

            try
            {
                ISldWorks app;
                do
                {
                    if (cancellationToken.IsCancellationRequested)
                    {
                        throw new AppStartCancelledByUserException();
                    }

                    app = RotHelper.TryGetComObjectByMonikerName <ISldWorks>(SwApplicationFactory.GetMonikerName(prc));
                    Thread.Sleep(100);
                }while (app == null);

                if (m_State.HasFlag(ApplicationState_e.Hidden))
                {
                    app.Visible = false;
                }

                return(app);
            }
            catch
            {
                if (prc != null)
                {
                    try
                    {
                        prc.Kill();
                    }
                    catch
                    {
                    }
                }

                throw;
            }
        }
Beispiel #6
0
 public void Dispose()
 {
     RotHelper.UnregisterComObject(m_Id);
 }
Beispiel #7
0
 internal RotRegister(object obj, string name) 
 {
     m_Id = RotHelper.RegisterComObject(obj, name);
 }