Exemplo n.º 1
0
 private void CleanupRuntimeCore()
 {
     // If a runtimeCore was used for the test, call its Cleanup
     if (runtimeCore != null)
     {
         runtimeCore.Cleanup();
     }
 }
Exemplo n.º 2
0
 public void CleanUp()
 {
     if (testCore != null)
     {
         testRuntimeCore.Cleanup();
         testCore = null;
     }
 }
Exemplo n.º 3
0
 private void CleanupRuntimeCore()
 {
     // Executing a test can either come from DebugRunner or TestFrameWork
     // We want the generated runtimecore from either of these frameworks to be properly disposed.
     // The DebugRunner should handle setting runtimeCore in its TearDown function
     // As a fallback, if the runtimeCore is null, it is assumed that the test was run from the TestFramework
     if (runtimeCore == null)
     {
         runtimeCore = thisTest.GetTestRuntimeCore();
     }
     runtimeCore.Cleanup();
 }
Exemplo n.º 4
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.ProtoScriptTestRunner fsr = new ProtoScript.Runners.ProtoScriptTestRunner();

                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);
        }