Beispiel #1
0
        public bool RunScript(string dsPath)
        {
            if (string.IsNullOrEmpty(GeometryFactoryName))
                throw new Exception("GeometryFactory not set!");

            if (string.IsNullOrEmpty(PersistenceManagerName))
                throw new Exception("PersistenceManager not set!");

            if (!File.Exists(dsPath))
                throw new FileNotFoundException(dsPath + " Does not exist");

            bool success = false;
            System.IO.StringWriter stringStream = new StringWriter();
            executionLog = new StringBuilder();
            ProtoCore.Core core = null;
            ProtoCore.RuntimeCore runtimeCore = null;
            try
            {
                var options = new ProtoCore.Options();
                string assemblyLocation = System.Reflection.Assembly.GetExecutingAssembly().Location;
                string incDir = Path.GetDirectoryName(assemblyLocation);
                options.IncludeDirectories.Add(incDir);

                core = new ProtoCore.Core(options);
                core.BuildStatus.SetStream(stringStream);
                core.Options.RootModulePathName = ProtoCore.Utils.FileUtils.GetFullPathName(dsPath);
                core.Compilers.Add(ProtoCore.Language.kAssociative, new ProtoAssociative.Compiler(core));
                core.Compilers.Add(ProtoCore.Language.kImperative, new ProtoImperative.Compiler(core));

                core.Configurations.Add(Autodesk.DesignScript.Interfaces.ConfigurationKeys.GeometryFactory, GeometryFactoryName);
                core.Configurations.Add(Autodesk.DesignScript.Interfaces.ConfigurationKeys.PersistentManager, PersistenceManagerName);
                ProtoScript.Runners.ProtoScriptRunner fsr = new ProtoScript.Runners.ProtoScriptRunner();

                ExecutionMirror mirror = fsr.LoadAndExecute(dsPath, core, out runtimeCore);
                executionLog.AppendLine("Script executed successfully.");

                executionLog.AppendLine();
                executionLog.AppendLine("=================================CoreDump=================================");
                string coreDump = null;
                try
                {
                    coreDump = mirror.GetCoreDump();
                    executionLog.AppendLine();
                    executionLog.AppendLine(coreDump);
                    success = true;
                }
                catch (System.Exception ex)
                {
                    executionLog.AppendLine(ex.Message);
                    executionLog.AppendLine(ex.StackTrace);

                    success = false;
                }
                finally
                {
                    executionLog.AppendLine("=================================CoreDump=================================");
                }
                
            }
            catch (System.Exception ex)
            {
                success = false;
                executionLog.AppendLine("Fail to execute script.");
                executionLog.AppendLine("Exceptions:");
                executionLog.AppendLine(ex.Message);
                executionLog.AppendLine("StackTrace:");
                executionLog.AppendLine(ex.StackTrace);
            }
            finally
            {
                if (core != null)
                {
                    core.BuildStatus.SetStream(null);
                    runtimeCore.Cleanup();
                }
            }

            return success;
        }
Beispiel #2
0
        public bool RunScript(string dsPath)
        {
            if (string.IsNullOrEmpty(GeometryFactoryName))
            {
                throw new Exception("GeometryFactory not set!");
            }

            if (string.IsNullOrEmpty(PersistenceManagerName))
            {
                throw new Exception("PersistenceManager not set!");
            }

            if (!File.Exists(dsPath))
            {
                throw new FileNotFoundException(dsPath + " Does not exist");
            }

            bool success = false;

            System.IO.StringWriter stringStream = new StringWriter();
            executionLog = new StringBuilder();
            ProtoCore.Core        core        = null;
            ProtoCore.RuntimeCore runtimeCore = null;
            try
            {
                var    options          = new ProtoCore.Options();
                string assemblyLocation = System.Reflection.Assembly.GetExecutingAssembly().Location;
                string incDir           = Path.GetDirectoryName(assemblyLocation);
                options.IncludeDirectories.Add(incDir);

                core = new ProtoCore.Core(options);
                core.BuildStatus.SetStream(stringStream);
                core.Options.RootModulePathName = ProtoCore.Utils.FileUtils.GetFullPathName(dsPath);
                core.Compilers.Add(ProtoCore.Language.kAssociative, new ProtoAssociative.Compiler(core));
                core.Compilers.Add(ProtoCore.Language.kImperative, new ProtoImperative.Compiler(core));

                core.Configurations.Add(Autodesk.DesignScript.Interfaces.ConfigurationKeys.GeometryFactory, GeometryFactoryName);
                core.Configurations.Add(Autodesk.DesignScript.Interfaces.ConfigurationKeys.PersistentManager, PersistenceManagerName);
                ProtoScript.Runners.ProtoScriptRunner fsr = new ProtoScript.Runners.ProtoScriptRunner();

                ExecutionMirror mirror = fsr.LoadAndExecute(dsPath, core, out runtimeCore);
                executionLog.AppendLine("Script executed successfully.");

                executionLog.AppendLine();
                executionLog.AppendLine("=================================CoreDump=================================");
                string coreDump = null;
                try
                {
                    coreDump = mirror.GetCoreDump();
                    executionLog.AppendLine();
                    executionLog.AppendLine(coreDump);
                    success = true;
                }
                catch (System.Exception ex)
                {
                    executionLog.AppendLine(ex.Message);
                    executionLog.AppendLine(ex.StackTrace);

                    success = false;
                }
                finally
                {
                    executionLog.AppendLine("=================================CoreDump=================================");
                }
            }
            catch (System.Exception ex)
            {
                success = false;
                executionLog.AppendLine("Fail to execute script.");
                executionLog.AppendLine("Exceptions:");
                executionLog.AppendLine(ex.Message);
                executionLog.AppendLine("StackTrace:");
                executionLog.AppendLine(ex.StackTrace);
            }
            finally
            {
                if (core != null)
                {
                    core.BuildStatus.SetStream(null);
                    runtimeCore.Cleanup();
                }
            }

            return(success);
        }