Beispiel #1
0
        ///////////////////////////////////////////////////////////////////////

        private /* protected virtual */ void Dispose(
            bool disposing
            )
        {
            TraceOps.DebugTrace(String.Format(
                                    "Dispose: disposing = {0}, interpreter = {1}, disposed = {2}",
                                    disposing, FormatOps.InterpreterNoThrow(interpreter), disposed),
                                typeof(VariableContext).Name, TracePriority.CleanupDebug);

            if (!disposed)
            {
                if (disposing)
                {
                    ////////////////////////////////////
                    // dispose managed resources here...
                    ////////////////////////////////////

                    Free(true);
                }

                //////////////////////////////////////
                // release unmanaged resources here...
                //////////////////////////////////////

                disposed = true;
            }
        }
Beispiel #2
0
        ///////////////////////////////////////////////////////////////////////

        private /* protected virtual */ void Dispose(
            bool disposing
            )
        {
            TraceOps.DebugTrace(String.Format(
                                    "Dispose: disposing = {0}, interpreter = {1}, disposed = {2}",
                                    disposing, FormatOps.InterpreterNoThrow(interpreter), disposed),
                                typeof(InteractiveContext).Name, TracePriority.CleanupDebug);

            if (!disposed)
            {
                if (disposing)
                {
                    ////////////////////////////////////
                    // dispose managed resources here...
                    ////////////////////////////////////

                    interpreter = null; /* NOT OWNED: Do not dispose. */
                    threadId    = 0;

                    ///////////////////////////////////////////////////////////

                    interactive              = false;
                    interactiveInput         = null;
                    previousInteractiveInput = null;
                    interactiveMode          = null;
                    activeInteractiveLoops   = 0;
                    totalInteractiveLoops    = 0;

                    interactiveLoopData        = null;
                    interactiveCommandCallback = null;

#if HISTORY
                    historyLoadData = null;
                    historySaveData = null;

                    historyInfoFilter = null;
                    historyLoadFilter = null;
                    historySaveFilter = null;

                    historyFileName = null;
#endif
                }

                //////////////////////////////////////
                // release unmanaged resources here...
                //////////////////////////////////////

                disposed = true;
            }
        }
Beispiel #3
0
        ///////////////////////////////////////////////////////////////////////

        private static void DumpSetup(
            Interpreter interpreter,
            string friendlyName,
            string baseDirectory,
            string packagePath,
            bool useBasePath,
            AppDomainSetup appDomainSetup
            )
        {
            StringPairList list = new StringPairList();

            AddInfo(appDomainSetup, list, DetailFlags.DebugTrace);

            TraceOps.DebugTrace(String.Format(
                                    "DumpSetup: interpreter = {0}, friendlyName = {1}, " +
                                    "baseDirectory = {2}, packagePath = {3}, " +
                                    "useBasePath = {4}, appDomainSetup = {5}",
                                    FormatOps.InterpreterNoThrow(interpreter),
                                    FormatOps.WrapOrNull(friendlyName),
                                    FormatOps.WrapOrNull(baseDirectory),
                                    FormatOps.WrapOrNull(packagePath),
                                    useBasePath, list), typeof(AppDomainOps).Name,
                                TracePriority.SecurityDebug);
        }
Beispiel #4
0
        ///////////////////////////////////////////////////////////////////////

        private /* protected virtual */ void Dispose(
            bool disposing
            )
        {
            TraceOps.DebugTrace(String.Format(
                                    "Dispose: disposing = {0}, interpreter = {1}, disposed = {2}",
                                    disposing, FormatOps.InterpreterNoThrow(interpreter), disposed),
                                typeof(TestContext).Name, TracePriority.CleanupDebug);

            if (!disposed)
            {
                if (disposing)
                {
                    ////////////////////////////////////
                    // dispose managed resources here...
                    ////////////////////////////////////

                    interpreter = null; /* NOT OWNED: Do not dispose. */
                    threadId    = 0;

                    ///////////////////////////////////////////////////////////

                    targetInterpreter = null; /* NOT OWNED: Do not dispose. */

                    ///////////////////////////////////////////////////////////

                    statistics = null;

                    ///////////////////////////////////////////////////////////

                    if (constraints != null)
                    {
                        constraints.Clear();
                        constraints = null;
                    }

                    ///////////////////////////////////////////////////////////

                    if (failures != null)
                    {
                        failures.Clear();
                        failures = null;
                    }

                    ///////////////////////////////////////////////////////////

                    if (counts != null)
                    {
                        counts.Clear();
                        counts = null;
                    }

                    ///////////////////////////////////////////////////////////

                    if (match != null)
                    {
                        match.Clear();
                        match = null;
                    }

                    ///////////////////////////////////////////////////////////

                    if (skip != null)
                    {
                        skip.Clear();
                        skip = null;
                    }

                    ///////////////////////////////////////////////////////////

                    if (returnCodeMessages != null)
                    {
                        returnCodeMessages.Clear();
                        returnCodeMessages = null;
                    }

                    ///////////////////////////////////////////////////////////

#if DEBUGGER
                    if (breakpoints != null)
                    {
                        breakpoints.Clear();
                        breakpoints = null;
                    }
#endif

                    ///////////////////////////////////////////////////////////

                    path        = null;
                    verbose     = TestOutputType.None;
                    repeatCount = 0;
                }

                //////////////////////////////////////
                // release unmanaged resources here...
                //////////////////////////////////////

                disposed = true;
            }
        }
Beispiel #5
0
        ///////////////////////////////////////////////////////////////////////

#if APPDOMAINS || ISOLATED_INTERPRETERS || ISOLATED_PLUGINS
        private static string GetBasePath(
            Interpreter interpreter, /* OPTIONAL */
            string packagePath,
            ref Result error
            )
        {
            //
            // NOTE: Fetch the raw base directory for the currently executing
            //       application binary.  It is now possible to override the
            //       value used here via the environment.
            //
            string path0 = AssemblyOps.GetAnchorPath();

            if (path0 == null)
            {
                path0 = GlobalState.GetRawBinaryBasePath();
            }

            //
            // NOTE: First, try to use the effective path to the core library
            //       assembly.  This is used to verify that this candidate
            //       application domain base path contains the core library
            //       assembly somewhere underneath it.
            //
            string path1 = GetAssemblyPath();

            if (PathOps.IsUnderPath(interpreter, path1, path0))
            {
                if ((packagePath == null) ||
                    PathOps.IsUnderPath(interpreter, packagePath, path0))
                {
                    return(path0);
                }
            }

            //
            // NOTE: Second, try to use the raw base path for the assembly.
            //       This is used to verify that this candidate application
            //       domain base path contains the core library assembly
            //       somewhere underneath it.
            //
            string path2 = GlobalState.GetRawBasePath();

            if (PathOps.IsUnderPath(interpreter, path1, path2))
            {
                if ((packagePath == null) ||
                    PathOps.IsUnderPath(interpreter, packagePath, path2))
                {
                    return(path2);
                }
            }

            //
            // NOTE: At this point, we have failed to figure out a base path
            //       for the application domain to be created that actually
            //       contains the core library assembly.
            //
            error = String.Format(
                "cannot determine usable base path for the new application " +
                "domain for interpreter {0}, with the raw binary base path " +
                "{1}, assembly path {2}, and raw base path {3}",
                FormatOps.InterpreterNoThrow(interpreter),
                FormatOps.DisplayPath(path0), FormatOps.DisplayPath(path1),
                FormatOps.DisplayPath(path2));

            return(null);
        }
Beispiel #6
0
        ///////////////////////////////////////////////////////////////////////

        public void Free(
            bool global
            )
        {
            TraceOps.DebugTrace(String.Format(
                                    "Free: called, global = {0}, interpreter = {1}, disposed = {2}",
                                    global, FormatOps.InterpreterNoThrow(interpreter), disposed),
                                typeof(VariableContext).Name, TracePriority.CleanupDebug);

            ///////////////////////////////////////////////////////////////////

            interpreter = null; /* NOT OWNED: Do not dispose. */
            threadId    = 0;

            ///////////////////////////////////////////////////////////////////

            if (traceInfo != null)
            {
                traceInfo = null;
            }

            ///////////////////////////////////////////////////////////////////

            //
            // HACK: *SPECIAL CASE* We cannot dispose the current call stack
            //       unless we are [also] disposing of the interpreter itself;
            //       therefore, use the special Free method here instead of the
            //       Dispose method.  The Free method is guaranteed to do the
            //       right thing with regard to the global call frame (assuming
            //       the "global" paramter is correct).
            //
            if (callStack != null)
            {
                callStack.Free(global);
                callStack = null;
            }

            ///////////////////////////////////////////////////////////////////

            //
            // HACK: *SPECIAL CASE* We cannot dispose the uplevel call frame
            //       unless we are [also] disposing of the interpreter itself.
            //
            if (uplevelFrame != null)
            {
                uplevelFrame.Free(global);
                uplevelFrame = null;
            }

            ///////////////////////////////////////////////////////////////////

            //
            // HACK: *SPECIAL CASE* We cannot dispose the procedure call frame
            //       unless we are [also] disposing of the interpreter itself.
            //
            if (procedureFrame != null)
            {
                procedureFrame.Free(global);
                procedureFrame = null;
            }

            ///////////////////////////////////////////////////////////////////

            //
            // HACK: *SPECIAL CASE* We cannot dispose the current call frame
            //       unless we are [also] disposing of the interpreter itself.
            //
            if (currentFrame != null)
            {
                currentFrame.Free(global);
                currentFrame = null;
            }

            ///////////////////////////////////////////////////////////////////

            //
            // HACK: *SPECIAL CASE* We cannot dispose the uplevel call frame
            //       unless we are [also] disposing of the interpreter itself.
            //       If this is really a named scope call frame -AND- we are
            //       being disposed, it should have already been cleaned up by
            //       this point; therefore, this should be a no-op.
            //
            if (globalScopeFrame != null)
            {
                globalScopeFrame.Free(global);
                globalScopeFrame = null;
            }

            ///////////////////////////////////////////////////////////////////

            //
            // HACK: *SPECIAL CASE* We cannot dispose the global call frame
            //       unless we are [also] disposing of the interpreter itself.
            //
            if (globalFrame != null)
            {
                globalFrame.Free(global);
                globalFrame = null;
            }
        }
Beispiel #7
0
        ///////////////////////////////////////////////////////////////////////

        private /* protected virtual */ void Dispose(
            bool disposing
            )
        {
            TraceOps.DebugTrace(String.Format(
                                    "Dispose: disposing = {0}, interpreter = {1}, disposed = {2}",
                                    disposing, FormatOps.InterpreterNoThrow(interpreter), disposed),
                                typeof(EngineContext).Name, TracePriority.CleanupDebug);

            if (!disposed)
            {
                if (disposing)
                {
                    ////////////////////////////////////
                    // dispose managed resources here...
                    ////////////////////////////////////

                    interpreter = null; /* NOT OWNED: Do not dispose. */
                    threadId    = 0;

                    ///////////////////////////////////////////////////////////

#if DEBUGGER
                    interactiveLoopCallback = null;
#endif

                    ///////////////////////////////////////////////////////////

#if SHELL
                    argumentCallback            = null;
                    evaluateScriptCallback      = null;
                    evaluateFileCallback        = null;
                    evaluateEncodedFileCallback = null;
#endif

                    ///////////////////////////////////////////////////////////

                    levels        = 0;
                    maximumLevels = 0;

                    scriptLevels        = 0;
                    maximumScriptLevels = 0;

                    parserLevels        = 0;
                    maximumParserLevels = 0;

                    expressionLevels        = 0;
                    maximumExpressionLevels = 0;

                    previousLevels   = 0;
                    catchLevels      = 0;
                    unknownLevels    = 0;
                    traceLevels      = 0;
                    subCommandLevels = 0;

#if ARGUMENT_CACHE
                    cacheArgument = null;
#endif

#if DEBUGGER
                    watchpointLevels = 0;
#endif

#if NOTIFY || NOTIFY_OBJECT
                    notifyLevels = 0;
                    notifyTypes  = NotifyType.None;
                    notifyFlags  = NotifyFlags.None;
#endif

                    policyLevels = 0;
                    testLevels   = 0;

#if DEBUGGER
                    isDebuggerExiting = false;
#endif

                    stackOverflow = false;

#if DEBUGGER
                    if (debugger != null)
                    {
                        IDisposable disposable = debugger as IDisposable;

                        if (disposable != null)
                        {
                            disposable.Dispose();
                            disposable = null;
                        }

                        debugger = null;
                    }
#endif

#if PREVIOUS_RESULT
                    previousResult = null;
#endif

                    engineFlags    = EngineFlags.None;
                    parseState     = null;
                    returnCode     = ReturnCode.Ok;
                    errorLine      = 0;
                    errorCode      = null;
                    errorInfo      = null;
                    errorFrames    = 0;
                    exception      = null;
                    scriptLocation = null;

                    ///////////////////////////////////////////////////////////

                    if (scriptLocations != null)
                    {
                        scriptLocations.Clear();
                        scriptLocations = null;
                    }

                    ///////////////////////////////////////////////////////////

                    previousProcessId = 0;

                    ///////////////////////////////////////////////////////////

                    if (arraySearches != null)
                    {
                        arraySearches.Clear();
                        arraySearches = null;
                    }

                    ///////////////////////////////////////////////////////////

#if HISTORY
                    historyEngineFilter = null;

                    if (history != null)
                    {
                        history.Clear();
                        history = null;
                    }
#endif

                    ///////////////////////////////////////////////////////////

                    complaint = null;
                }

                //////////////////////////////////////
                // release unmanaged resources here...
                //////////////////////////////////////

                disposed = true;
            }
        }
Beispiel #8
0
        ///////////////////////////////////////////////////////////////////////

        public static ReturnCode UploadDataAsync(
            Interpreter interpreter,
            IClientData clientData,
            StringList arguments,
            CallbackFlags callbackFlags,
            Uri uri,
            string method,
            byte[] rawData,
            ref Result error
            )
        {
            TraceOps.DebugTrace(String.Format(
                                    "UploadDataAsync: interpreter = {0}, clientData = {1}, " +
                                    "arguments = {2}, callbackFlags = {3}, uri = {4}, " +
                                    "method = {5}, rawData = {6}",
                                    FormatOps.InterpreterNoThrow(interpreter),
                                    FormatOps.WrapOrNull(clientData),
                                    FormatOps.WrapOrNull(true, true, arguments),
                                    FormatOps.WrapOrNull(callbackFlags),
                                    FormatOps.WrapOrNull(uri),
                                    FormatOps.WrapOrNull(method),
                                    FormatOps.WrapOrNull(rawData)),
                                typeof(WebOps).Name, TracePriority.NetworkDebug);

            ReturnCode code      = ReturnCode.Ok;
            WebClient  webClient = null;

            try
            {
                ICallback callback = CommandCallback.Create(
                    MarshalFlags.Default, callbackFlags,
                    ObjectFlags.Callback, ByRefArgumentFlags.None,
                    interpreter, null, null, arguments, ref error);

                if (callback != null)
                {
                    try
                    {
                        Result localError = null;

                        webClient = CreateClient(
                            interpreter, "UploadDataAsync", clientData,
                            ref localError);

                        if (webClient != null)
                        {
                            callback.ClientData = new ClientData(
                                new AnyTriplet <WebClient, Uri,
                                                IAnyPair <string, byte[]> >(
                                    webClient, uri, new AnyPair <string,
                                                                 byte[]>(method, rawData)));

                            webClient.UploadDataCompleted +=
                                new UploadDataCompletedEventHandler(
                                    UploadDataAsyncCompleted);

                            /* NO RESULT */
                            webClient.UploadDataAsync(
                                uri, method, rawData, callback);
                        }
                        else if (localError != null)
                        {
                            error = localError;
                            code  = ReturnCode.Error;
                        }
                        else
                        {
                            error = "could not create web client";
                            code  = ReturnCode.Error;
                        }
                    }
                    catch (Exception e)
                    {
                        error = e;
                        code  = ReturnCode.Error;
                    }
                }
                else
                {
                    code = ReturnCode.Error;
                }
            }
            finally
            {
                if ((code != ReturnCode.Ok) && (webClient != null))
                {
                    ReturnCode disposeCode;
                    Result     disposeError = null;

                    disposeCode = ObjectOps.TryDispose(
                        webClient, ref disposeError);

                    if (disposeCode != ReturnCode.Ok)
                    {
                        DebugOps.Complain(
                            interpreter, disposeCode, disposeError);
                    }
                }
            }

            return(code);
        }
Beispiel #9
0
        ///////////////////////////////////////////////////////////////////////

        #region Public Web Upload Methods
        #region Upload Data Methods
        public static ReturnCode UploadData(
            Interpreter interpreter,
            IClientData clientData,
            Uri uri,
            string method,
            byte[] rawData,
            bool trusted,
            ref byte[] bytes,
            ref Result error
            )
        {
            bool wasTrusted = UpdateOps.IsTrusted();

            TraceOps.DebugTrace(String.Format(
                                    "UploadData: interpreter = {0}, clientData = {1}, " +
                                    "uri = {2}, method = {3}, rawData = {4}, trusted = {5}, " +
                                    "wasTrusted = {6}",
                                    FormatOps.InterpreterNoThrow(interpreter),
                                    FormatOps.WrapOrNull(clientData),
                                    FormatOps.WrapOrNull(uri),
                                    FormatOps.WrapOrNull(method),
                                    FormatOps.WrapOrNull(rawData),
                                    trusted, wasTrusted),
                                typeof(WebOps).Name, TracePriority.NetworkDebug);

            ReturnCode code = trusted ? wasTrusted ? ReturnCode.Ok :
                              UpdateOps.SetTrusted(trusted, ref error) : ReturnCode.Ok;

            if (code == ReturnCode.Ok)
            {
                try
                {
                    try
                    {
                        Result localError = null;

                        using (WebClient webClient = CreateClient(
                                   interpreter, "UploadData", clientData,
                                   ref localError))
                        {
                            if (webClient != null)
                            {
                                bytes = webClient.UploadData(
                                    uri, method, rawData);

                                return(ReturnCode.Ok);
                            }
                            else if (localError != null)
                            {
                                error = localError;
                            }
                            else
                            {
                                error = "could not create web client";
                            }
                        }
                    }
                    catch (Exception e)
                    {
                        error = e;
                    }
                }
                finally
                {
                    if (trusted && !wasTrusted)
                    {
                        ReturnCode untrustCode;
                        Result     untrustError = null;

                        untrustCode = UpdateOps.SetTrusted(
                            false, ref untrustError);

                        if (untrustCode != ReturnCode.Ok)
                        {
                            DebugOps.Complain(
                                interpreter, untrustCode, untrustError);
                        }
                    }
                }
            }

            return(ReturnCode.Error);
        }