コード例 #1
0
        ///////////////////////////////////////////////////////////////////////

        public static bool HasFlags(
            ObjectOptionType flags,
            ObjectOptionType hasFlags,
            bool all
            )
        {
            if (all)
            {
                return((flags & hasFlags) == hasFlags);
            }
            else
            {
                return((flags & hasFlags) != ObjectOptionType.None);
            }
        }
コード例 #2
0
        public override ReturnCode Execute(
            Interpreter interpreter,
            IClientData clientData,
            ArgumentList arguments,
            ref Result result
            )
        {
            ReturnCode code;

            if (interpreter != null)
            {
                if (arguments != null)
                {
                    if (arguments.Count >= 2)
                    {
                        string subCommand = arguments[1];
                        bool   tried      = false;

                        code = ScriptOps.TryExecuteSubCommandFromEnsemble(
                            interpreter, this, clientData, arguments, true,
                            false, ref subCommand, ref tried, ref result);

                        if ((code == ReturnCode.Ok) && !tried)
                        {
                            //
                            // NOTE: Programmatically interact with the debugger (breakpoint, watch,
                            //       eval, etc).
                            //
                            switch (subCommand)
                            {
                            case "clear":
                            {
                                if (arguments.Count == 2)
                                {
                                    code = interpreter.ClearCallbackQueue(ref result);

                                    if (code == ReturnCode.Ok)
                                    {
                                        result = String.Empty;
                                    }
                                }
                                else
                                {
                                    result = "wrong # args: should be \"callback clear\"";
                                    code   = ReturnCode.Error;
                                }
                                break;
                            }

                            case "count":
                            {
                                if (arguments.Count == 2)
                                {
                                    int count = 0;

                                    code = interpreter.CountCallbacks(ref count, ref result);

                                    if (code == ReturnCode.Ok)
                                    {
                                        result = count;
                                    }
                                }
                                else
                                {
                                    result = "wrong # args: should be \"callback count\"";
                                    code   = ReturnCode.Error;
                                }
                                break;
                            }

                            case "dequeue":
                            {
                                if (arguments.Count >= 2)
                                {
                                    OptionDictionary options = ObjectOps.GetDequeueOptions();

                                    int argumentIndex = Index.Invalid;

                                    if (arguments.Count > 2)
                                    {
                                        code = interpreter.GetOptions(options, arguments, 0, 2, Index.Invalid, true, ref argumentIndex, ref result);
                                    }
                                    else
                                    {
                                        code = ReturnCode.Ok;
                                    }

                                    if (code == ReturnCode.Ok)
                                    {
                                        if (argumentIndex == Index.Invalid)
                                        {
                                            Type        returnType;
                                            ObjectFlags objectFlags;
                                            string      objectName;
                                            string      interpName;
                                            bool        create;
                                            bool        dispose;
                                            bool        alias;
                                            bool        aliasRaw;
                                            bool        aliasAll;
                                            bool        aliasReference;
                                            bool        toString;

                                            ObjectOps.ProcessFixupReturnValueOptions(
                                                options, null, out returnType, out objectFlags,
                                                out objectName, out interpName, out create,
                                                out dispose, out alias, out aliasRaw, out aliasAll,
                                                out aliasReference, out toString);

                                            //
                                            // NOTE: Which Tcl interpreter do we want a command alias created
                                            //       in, if any?
                                            //
                                            ICallback callback = null;

                                            code = interpreter.DequeueCallback(ref callback, ref result);

                                            if (code == ReturnCode.Ok)
                                            {
                                                ObjectOptionType objectOptionType = ObjectOptionType.Dequeue |
                                                                                    ObjectOps.GetOptionType(aliasRaw, aliasAll);

                                                code = MarshalOps.FixupReturnValue(
                                                    interpreter, interpreter.Binder, interpreter.CultureInfo,
                                                    returnType, objectFlags, ObjectOps.GetInvokeOptions(
                                                        objectOptionType), objectOptionType, objectName, interpName,
                                                    callback, create, dispose, alias, aliasReference, toString,
                                                    ref result);
                                            }
                                        }
                                        else
                                        {
                                            result = "wrong # args: should be \"callback dequeue ?options?\"";
                                            code   = ReturnCode.Error;
                                        }
                                    }
                                }
                                else
                                {
                                    result = "wrong # args: should be \"callback dequeue ?options?\"";
                                    code   = ReturnCode.Error;
                                }
                                break;
                            }

                            case "enqueue":
                            {
                                if (arguments.Count >= 3)
                                {
                                    ICallback callback = CommandCallback.Create(
                                        MarshalFlags.Default, CallbackFlags.Default,
                                        ObjectFlags.Callback, ByRefArgumentFlags.None,
                                        interpreter, clientData, null, new StringList(
                                            arguments, 2), ref result);

                                    if (callback != null)
                                    {
                                        code = interpreter.EnqueueCallback(callback, ref result);

                                        if (code == ReturnCode.Ok)
                                        {
                                            result = String.Empty;
                                        }
                                    }
                                    else
                                    {
                                        code = ReturnCode.Error;
                                    }
                                }
                                else
                                {
                                    result = "wrong # args: should be \"callback enqueue name ?arg ...?\"";
                                    code   = ReturnCode.Error;
                                }
                                break;
                            }

                            case "execute":
                            {
                                if (arguments.Count == 2)
                                {
                                    code = interpreter.ExecuteCallbackQueue(ref result);
                                }
                                else
                                {
                                    result = "wrong # args: should be \"callback execute\"";
                                    code   = ReturnCode.Error;
                                }
                                break;
                            }

                            case "list":
                            {
                                if ((arguments.Count == 2) || (arguments.Count == 3))
                                {
                                    string pattern = null;

                                    if (arguments.Count == 3)
                                    {
                                        pattern = arguments[2];
                                    }

                                    StringList list = null;

                                    code = interpreter.ListCallbacks(
                                        pattern, false, ref list, ref result);

                                    if (code == ReturnCode.Ok)
                                    {
                                        result = list;
                                    }
                                }
                                else
                                {
                                    result = "wrong # args: should be \"callback list ?pattern?\"";
                                    code   = ReturnCode.Error;
                                }
                                break;
                            }

                            default:
                            {
                                result = ScriptOps.BadSubCommand(
                                    interpreter, null, null, subCommand, this, null, null);

                                code = ReturnCode.Error;
                                break;
                            }
                            }
                        }
                    }
                    else
                    {
                        result = "wrong # args: should be \"callback option ?arg ...?\"";
                        code   = ReturnCode.Error;
                    }
                }
                else
                {
                    result = "invalid argument list";
                    code   = ReturnCode.Error;
                }
            }
            else
            {
                result = "invalid interpreter";
                code   = ReturnCode.Error;
            }

            return(code);
        }
コード例 #3
0
        ////////////////////////////////////////////////////////////////////////

        #region IExecute Members
        public override ReturnCode Execute(
            Interpreter interpreter,
            IClientData clientData,
            ArgumentList arguments,
            ref Result result
            )
        {
            if (interpreter == null)
            {
                result = "invalid interpreter";
                return(ReturnCode.Error);
            }

            _Cmdlets.Script script = GetScriptCmdlet(clientData, ref result);

            if (script == null)
            {
                return(ReturnCode.Error);
            }

            if (arguments == null)
            {
                result = "invalid argument list";
                return(ReturnCode.Error);
            }

            if (arguments.Count < 2)
            {
                result = String.Format(
                    "wrong # args: should be \"{0} option ?arg ...?\"",
                    this.Name);

                return(ReturnCode.Error);
            }

            ReturnCode code       = ReturnCode.Ok;
            string     subCommand = arguments[1];
            bool       tried      = false;

            code = Utility.TryExecuteSubCommandFromEnsemble(
                interpreter, this, clientData, arguments, true,
                false, ref subCommand, ref tried, ref result);

            if ((code == ReturnCode.Ok) && !tried)
            {
                switch (subCommand)
                {
                case "about":
                {
                    if (arguments.Count == 2)
                    {
                        IPlugin plugin = this.Plugin;

                        if (plugin != null)
                        {
                            code = plugin.About(
                                interpreter, ref result);
                        }
                        else
                        {
                            result = "invalid command plugin";
                            code   = ReturnCode.Error;
                        }
                    }
                    else
                    {
                        result = String.Format(
                            "wrong # args: should be \"{0} {1}\"",
                            this.Name, subCommand);

                        code = ReturnCode.Error;
                    }
                    break;
                }

                case "debug":
                {
                    if (arguments.Count == 3)
                    {
                        try
                        {
                            script.WriteDebug(arguments[2]);         /* throw */
                            result = String.Empty;
                        }
                        catch (Exception e)
                        {
                            Engine.SetExceptionErrorCode(interpreter, e);

                            result = e;
                            code   = ReturnCode.Error;
                        }
                    }
                    else
                    {
                        result = String.Format(
                            "wrong # args: should be \"{0} {1} text\"",
                            this.Name, subCommand);

                        code = ReturnCode.Error;
                    }
                    break;
                }

                case "error":
                {
                    if (arguments.Count == 4)
                    {
                        object enumValue = Utility.TryParseEnum(
                            typeof(ReturnCode), arguments[2],
                            true, true, ref result);

                        if (enumValue is ReturnCode)
                        {
                            try
                            {
                                script.WriteErrorRecord(
                                    (ReturnCode)enumValue,
                                    arguments[3]);         /* throw */

                                result = String.Empty;
                            }
                            catch (Exception e)
                            {
                                Engine.SetExceptionErrorCode(interpreter, e);

                                result = e;
                                code   = ReturnCode.Error;
                            }
                        }
                        else
                        {
                            code = ReturnCode.Error;
                        }
                    }
                    else
                    {
                        result = String.Format(
                            "wrong # args: should be \"{0} {1} code result\"",
                            this.Name, subCommand);

                        code = ReturnCode.Error;
                    }
                    break;
                }

                case "invoke":
                {
                    if (arguments.Count >= 3)
                    {
                        OptionDictionary options = new OptionDictionary(
                            new IOption[] {
                                new Option(null, OptionFlags.None, Index.Invalid,
                                           Index.Invalid, "-addtohistory", null)
                            }, Utility.GetFixupReturnValueOptions().Values);

                        int argumentIndex = Index.Invalid;

                        code = interpreter.GetOptions(options, arguments, 0, 2,
                                                      Index.Invalid, true, ref argumentIndex, ref result);

                        if (code == ReturnCode.Ok)
                        {
                            if ((argumentIndex != Index.Invalid) &&
                                ((argumentIndex + 1) == arguments.Count))
                            {
                                Type        returnType;
                                ObjectFlags objectFlags;
                                string      objectName;
                                string      interpName;
                                bool        create;
                                bool        dispose;
                                bool        alias;
                                bool        aliasRaw;
                                bool        aliasAll;
                                bool        aliasReference;
                                bool        toString;

                                Utility.ProcessFixupReturnValueOptions(
                                    options, null, out returnType, out objectFlags,
                                    out objectName, out interpName, out create,
                                    out dispose, out alias, out aliasRaw,
                                    out aliasAll, out aliasReference, out toString);

                                bool addToHistory = false;

                                if (options.IsPresent("-addtohistory"))
                                {
                                    addToHistory = true;
                                }

                                Collection <PSObject> returnValue = null;

                                try
                                {
                                    code = InvokePipeline(
                                        arguments[argumentIndex], addToHistory,
                                        ref returnValue, ref result);
                                }
                                catch (Exception e)
                                {
                                    Engine.SetExceptionErrorCode(interpreter, e);

                                    result = e;
                                    code   = ReturnCode.Error;
                                }

                                if (code == ReturnCode.Ok)
                                {
                                    ObjectOptionType objectOptionType =
                                        Utility.GetOptionType(aliasRaw, aliasAll);

                                    code = Utility.FixupReturnValue(interpreter,
                                                                    GetBinder(interpreter, this.Plugin),
                                                                    interpreter.CultureInfo, returnType,
                                                                    objectFlags, Utility.GetInvokeOptions(
                                                                        objectOptionType), objectOptionType,
                                                                    objectName, interpName, returnValue,
                                                                    create, dispose, alias, aliasReference,
                                                                    toString, ref result);
                                }
                            }
                            else
                            {
                                if ((argumentIndex != Index.Invalid) &&
                                    Option.LooksLikeOption(arguments[argumentIndex]))
                                {
                                    result = OptionDictionary.BadOption(
                                        options, arguments[argumentIndex]);
                                }
                                else
                                {
                                    result = String.Format(
                                        "wrong # args: should be \"{0} {1} ?options? script\"",
                                        this.Name, subCommand);
                                }

                                code = ReturnCode.Error;
                            }
                        }
                    }
                    else
                    {
                        result = String.Format(
                            "wrong # args: should be \"{0} {1} ?options? script\"",
                            this.Name, subCommand);

                        code = ReturnCode.Error;
                    }
                    break;
                }

                case "options":
                {
                    if (arguments.Count == 2)
                    {
                        IPlugin plugin = this.Plugin;

                        if (plugin != null)
                        {
                            code = plugin.Options(
                                interpreter, ref result);
                        }
                        else
                        {
                            //
                            // NOTE: There is (normally) no plugin
                            //       context for this library.
                            //
                            code = GetDefineConstants(ref result);
                        }
                    }
                    else
                    {
                        result = String.Format(
                            "wrong # args: should be \"{0} {1}\"",
                            this.Name, subCommand);

                        code = ReturnCode.Error;
                    }
                    break;
                }

                case "progress":
                {
                    if (arguments.Count >= 5)
                    {
                        OptionDictionary options = new OptionDictionary(
                            new IOption[] {
                                new Option(null, OptionFlags.MustHaveValue |
                                           OptionFlags.NoCase, Index.Invalid, Index.Invalid,
                                           "-currentOperation", null),
                                new Option(null, OptionFlags.MustHaveIntegerValue |
                                           OptionFlags.NoCase, Index.Invalid, Index.Invalid,
                                           "-parentActivityId", null),
                                new Option(null, OptionFlags.MustHaveIntegerValue |
                                           OptionFlags.NoCase, Index.Invalid, Index.Invalid,
                                           "-percentComplete", null),
                                new Option(typeof(ProgressRecordType),
                                           OptionFlags.MustHaveIntegerValue | OptionFlags.NoCase,
                                           Index.Invalid, Index.Invalid, "-recordType",
                                           new Variant((ProgressRecordType)(-1))),
                                new Option(null, OptionFlags.MustHaveIntegerValue |
                                           OptionFlags.NoCase, Index.Invalid, Index.Invalid,
                                           "-secondsRemaining", null),
                                new Option(null, OptionFlags.None, Index.Invalid,
                                           Index.Invalid, Option.EndOfOptions, null)
                            });

                        int argumentIndex = Index.Invalid;

                        code = interpreter.GetOptions(options, arguments, 0, 2,
                                                      Index.Invalid, true, ref argumentIndex, ref result);

                        if (code == ReturnCode.Ok)
                        {
                            if ((argumentIndex != Index.Invalid) &&
                                ((argumentIndex + 3) == arguments.Count))
                            {
                                Variant value            = null;
                                string  currentOperation = null;

                                if (options.IsPresent("-currentOperation", true, ref value))
                                {
                                    currentOperation = value.ToString();
                                }

                                int parentActivityId = Identifier.Invalid;

                                if (options.IsPresent("-parentActivityId", true, ref value))
                                {
                                    parentActivityId = (int)value.Value;
                                }

                                int percentComplete = Percent.Invalid;

                                if (options.IsPresent("-percentComplete", true, ref value))
                                {
                                    percentComplete = (int)value.Value;
                                }

                                ProgressRecordType recordType = (ProgressRecordType)(-1);

                                if (options.IsPresent("-recordType", true, ref value))
                                {
                                    recordType = (ProgressRecordType)value.Value;
                                }

                                int secondsRemaining = Count.Invalid;

                                if (options.IsPresent("-secondsRemaining", true, ref value))
                                {
                                    secondsRemaining = (int)value.Value;
                                }

                                int activityId = Identifier.Invalid;

                                code = Value.GetInteger2(
                                    (IGetValue)arguments[argumentIndex], ValueFlags.AnyInteger,
                                    interpreter.CultureInfo, ref activityId, ref result);

                                if (code == ReturnCode.Ok)
                                {
                                    try
                                    {
                                        ProgressRecord progressRecord = new ProgressRecord(
                                            activityId, arguments[argumentIndex + 1],
                                            arguments[argumentIndex + 2]);         /* throw */

                                        if (currentOperation != null)
                                        {
                                            progressRecord.CurrentOperation = currentOperation;
                                        }

                                        if (parentActivityId != Identifier.Invalid)
                                        {
                                            progressRecord.ParentActivityId = parentActivityId;         /* throw */
                                        }
                                        if (percentComplete != Percent.Invalid)
                                        {
                                            progressRecord.PercentComplete = percentComplete;         /* throw */
                                        }
                                        if (recordType != (ProgressRecordType)(-1))
                                        {
                                            progressRecord.RecordType = recordType;         /* throw */
                                        }
                                        if (secondsRemaining != Count.Invalid)
                                        {
                                            progressRecord.SecondsRemaining = secondsRemaining;
                                        }

                                        script.WriteProgress(progressRecord);         /* throw */

                                        result = String.Empty;
                                    }
                                    catch (Exception e)
                                    {
                                        Engine.SetExceptionErrorCode(interpreter, e);

                                        result = e;
                                        code   = ReturnCode.Error;
                                    }
                                }
                            }
                            else
                            {
                                if ((argumentIndex != Index.Invalid) &&
                                    Option.LooksLikeOption(arguments[argumentIndex]))
                                {
                                    result = OptionDictionary.BadOption(
                                        options, arguments[argumentIndex]);
                                }
                                else
                                {
                                    result = String.Format(
                                        "wrong # args: should be \"{0} {1} ?options? activityId activity statusDescription\"",
                                        this.Name, subCommand);
                                }

                                code = ReturnCode.Error;
                            }
                        }
                    }
                    else
                    {
                        result = String.Format(
                            "wrong # args: should be \"{0} {1} ?options? activityId activity statusDescription\"",
                            this.Name, subCommand);

                        code = ReturnCode.Error;
                    }
                    break;
                }

                case "remove":
                {
                    if (arguments.Count == 2)
                    {
                        code = script.RemoveMetaCommand(interpreter, ref result);

                        if (code == ReturnCode.Ok)
                        {
                            result = String.Empty;
                        }
                    }
                    else
                    {
                        result = String.Format(
                            "wrong # args: should be \"{0} {1}\"",
                            this.Name, subCommand);

                        code = ReturnCode.Error;
                    }
                    break;
                }

                case "status":
                {
                    if (arguments.Count == 2)
                    {
                        result = StringList.MakeList(
                            "Disposed", script.Disposed,         /* PEDANTIC */
                            "FlagsCallback", script.FlagsCallback,
                            "StateCallback", script.StateCallback,
                            "ParameterCallback", script.ParameterCallback,
                            "Listener", script.Listener,
                            "PreInitialize", script.PreInitialize,
                            "CreateFlags", script.CreateFlags,
                            "EngineFlags", script.EngineFlags,
                            "SubstitutionFlags", script.SubstitutionFlags,
                            "EventFlags", script.EventFlags,
                            "ExpressionFlags", script.ExpressionFlags,
                            "Console", script.Console,
                            "Unsafe", script.Unsafe,
                            "Standard", script.Standard,
                            "Force", script.Force,
                            "Exceptions", script.Exceptions,
                            "Policies", script.Policies,
                            "Deny", script.Deny,
                            "MetaCommand", script.MetaCommand,
                            "Text", script.Text,
                            "Interpreter", script.Interpreter,
                            "Tokens", script.Tokens,
                            "CommandRuntime", script.CommandRuntime,
                            "Stopping", script.Stopping);         /* throw */
                    }
                    else
                    {
                        result = String.Format(
                            "wrong # args: should be \"{0} {1}\"",
                            this.Name, subCommand);

                        code = ReturnCode.Error;
                    }
                    break;
                }

                case "verbose":
                {
                    if (arguments.Count == 3)
                    {
                        try
                        {
                            script.WriteVerbose(arguments[2]);         /* throw */
                            result = String.Empty;
                        }
                        catch (Exception e)
                        {
                            Engine.SetExceptionErrorCode(interpreter, e);

                            result = e;
                            code   = ReturnCode.Error;
                        }
                    }
                    else
                    {
                        result = String.Format(
                            "wrong # args: should be \"{0} {1} text\"",
                            this.Name, subCommand);

                        code = ReturnCode.Error;
                    }
                    break;
                }

                default:
                {
                    result = Utility.BadSubCommand(
                        interpreter, null, null, subCommand, this, null, null);

                    code = ReturnCode.Error;
                    break;
                }
                }
            }

            return(code);
        }
コード例 #4
0
        public override ReturnCode Execute(
            Interpreter interpreter,
            IClientData clientData,
            ArgumentList arguments,
            ref Result result
            )
        {
            ReturnCode code = ReturnCode.Ok;

            if (interpreter != null)
            {
                if (arguments != null)
                {
                    if (arguments.Count >= 2)
                    {
                        string subCommand = arguments[1];
                        bool   tried      = false;

                        code = ScriptOps.TryExecuteSubCommandFromEnsemble(
                            interpreter, this, clientData, arguments, true,
                            false, ref subCommand, ref tried, ref result);

                        if ((code == ReturnCode.Ok) && !tried)
                        {
                            switch (subCommand)
                            {
                            case "deserialize":
                            {
                                if (arguments.Count >= 4)
                                {
#if SERIALIZATION
                                    OptionDictionary options = ObjectOps.GetDeserializeOptions();

                                    int argumentIndex = Index.Invalid;

                                    code = interpreter.GetOptions(options, arguments, 0, 2, Index.Invalid, true, ref argumentIndex, ref result);

                                    if (code == ReturnCode.Ok)
                                    {
                                        if ((argumentIndex != Index.Invalid) && ((argumentIndex + 2) == arguments.Count))
                                        {
                                            bool verbose;
                                            bool strictType;
                                            bool noCase;

                                            ObjectOps.ProcessGetTypeOptions(
                                                options, out verbose, out strictType, out noCase);

                                            Type        returnType;
                                            ObjectFlags objectFlags;
                                            string      objectName;
                                            string      interpName;
                                            bool        create;
                                            bool        dispose;
                                            bool        alias;
                                            bool        aliasRaw;
                                            bool        aliasAll;
                                            bool        aliasReference;
                                            bool        toString;

                                            ObjectOps.ProcessFixupReturnValueOptions(
                                                options, null, out returnType, out objectFlags,
                                                out objectName, out interpName, out create,
                                                out dispose, out alias, out aliasRaw, out aliasAll,
                                                out aliasReference, out toString);

                                            if (noCase)
                                            {
                                                objectFlags |= ObjectFlags.NoCase;
                                            }

                                            Variant  value    = null;
                                            Encoding encoding = null;

                                            if (options.IsPresent("-encoding", ref value))
                                            {
                                                encoding = (Encoding)value.Value;
                                            }

                                            if (code == ReturnCode.Ok)
                                            {
                                                Type       objectType = null;
                                                ResultList errors     = null;

                                                code = Value.GetType(interpreter,
                                                                     arguments[argumentIndex], null, interpreter.GetAppDomain(),
                                                                     Value.GetTypeValueFlags(strictType, verbose, noCase),
                                                                     interpreter.CultureInfo, ref objectType, ref errors);

                                                if (code == ReturnCode.Ok)
                                                {
                                                    byte[] bytes = null;

                                                    code = StringOps.GetBytes(
                                                        encoding, arguments[argumentIndex + 1],
                                                        EncodingType.Default, ref bytes, ref result);

                                                    if (code == ReturnCode.Ok)
                                                    {
                                                        object @object = null;

                                                        code = XmlOps.Deserialize(
                                                            objectType, bytes, ref @object, ref result);

                                                        if (code == ReturnCode.Ok)
                                                        {
                                                            ObjectOptionType objectOptionType =
                                                                ObjectOptionType.Deserialize |
                                                                ObjectOps.GetOptionType(aliasRaw, aliasAll);

                                                            code = MarshalOps.FixupReturnValue(
                                                                interpreter, interpreter.Binder, interpreter.CultureInfo,
                                                                returnType, objectFlags, ObjectOps.GetInvokeOptions(
                                                                    objectOptionType), objectOptionType, objectName, interpName,
                                                                @object, create, dispose, alias, aliasReference, toString,
                                                                ref result);
                                                        }
                                                    }
                                                }
                                                else
                                                {
                                                    errors.Insert(0, String.Format(
                                                                      "type \"{0}\" not found",
                                                                      arguments[argumentIndex]));

                                                    result = errors;
                                                }
                                            }
                                        }
                                        else
                                        {
                                            if ((argumentIndex != Index.Invalid) &&
                                                Option.LooksLikeOption(arguments[argumentIndex]))
                                            {
                                                result = OptionDictionary.BadOption(options, arguments[argumentIndex]);
                                            }
                                            else
                                            {
                                                result = "wrong # args: should be \"xml deserialize ?options? type xml\"";
                                            }

                                            code = ReturnCode.Error;
                                        }
                                    }
#else
                                    result = "not implemented";
                                    code   = ReturnCode.Error;
#endif
                                }
                                else
                                {
                                    result = "wrong # args: should be \"xml deserialize ?options? type xml\"";
                                    code   = ReturnCode.Error;
                                }
                                break;
                            }

                            case "serialize":
                            {
                                if (arguments.Count >= 4)
                                {
#if SERIALIZATION
                                    OptionDictionary options = ObjectOps.GetSerializeOptions();

                                    int argumentIndex = Index.Invalid;

                                    code = interpreter.GetOptions(options, arguments, 0, 2, Index.Invalid, true, ref argumentIndex, ref result);

                                    if (code == ReturnCode.Ok)
                                    {
                                        if ((argumentIndex != Index.Invalid) && ((argumentIndex + 2) == arguments.Count))
                                        {
                                            bool noCase = false;

                                            if (options.IsPresent("-nocase"))
                                            {
                                                noCase = true;
                                            }

                                            bool strictType = false;

                                            if (options.IsPresent("-stricttype"))
                                            {
                                                strictType = true;
                                            }

                                            bool verbose = false;

                                            if (options.IsPresent("-verbose"))
                                            {
                                                verbose = true;
                                            }

                                            Variant  value    = null;
                                            Encoding encoding = null;

                                            if (options.IsPresent("-encoding", ref value))
                                            {
                                                encoding = (Encoding)value.Value;
                                            }

                                            if (code == ReturnCode.Ok)
                                            {
                                                Type       objectType = null;
                                                ResultList errors     = null;

                                                code = Value.GetType(interpreter,
                                                                     arguments[argumentIndex], null, interpreter.GetAppDomain(),
                                                                     Value.GetTypeValueFlags(strictType, verbose, noCase),
                                                                     interpreter.CultureInfo, ref objectType, ref errors);

                                                if (code == ReturnCode.Ok)
                                                {
                                                    IObject @object = null;

                                                    code = interpreter.GetObject(
                                                        arguments[argumentIndex + 1], LookupFlags.Default,
                                                        ref @object, ref result);

                                                    if (code == ReturnCode.Ok)
                                                    {
                                                        byte[] bytes = null;

                                                        code = XmlOps.Serialize(
                                                            (@object != null) ? @object.Value : null,
                                                            objectType, null, ref bytes, ref result);

                                                        if (code == ReturnCode.Ok)
                                                        {
                                                            string stringValue = null;

                                                            code = StringOps.GetString(
                                                                encoding, bytes, EncodingType.Default,
                                                                ref stringValue, ref result);

                                                            if (code == ReturnCode.Ok)
                                                            {
                                                                result = stringValue;
                                                            }
                                                        }
                                                    }
                                                }
                                                else
                                                {
                                                    errors.Insert(0, String.Format(
                                                                      "type \"{0}\" not found",
                                                                      arguments[argumentIndex]));

                                                    result = errors;
                                                }
                                            }
                                        }
                                        else
                                        {
                                            if ((argumentIndex != Index.Invalid) &&
                                                Option.LooksLikeOption(arguments[argumentIndex]))
                                            {
                                                result = OptionDictionary.BadOption(options, arguments[argumentIndex]);
                                            }
                                            else
                                            {
                                                result = "wrong # args: should be \"xml serialize ?options? type object\"";
                                            }

                                            code = ReturnCode.Error;
                                        }
                                    }
#else
                                    result = "not implemented";
                                    code   = ReturnCode.Error;
#endif
                                }
                                else
                                {
                                    result = "wrong # args: should be \"xml serialize ?options? type object\"";
                                    code   = ReturnCode.Error;
                                }
                                break;
                            }

                            case "validate":
                            {
                                if (arguments.Count == 4)
                                {
                                    XmlDocument document = null;

                                    code = XmlOps.LoadString(
                                        arguments[3], ref document, ref result);

                                    if (code == ReturnCode.Ok)
                                    {
                                        code = XmlOps.Validate(
                                            arguments[2], document, ref result);

                                        if (code == ReturnCode.Ok)
                                        {
                                            result = String.Empty;
                                        }
                                    }
                                }
                                else
                                {
                                    result = "wrong # args: should be \"xml validate schemaXml documentXml\"";
                                    code   = ReturnCode.Error;
                                }
                                break;
                            }

                            default:
                            {
                                result = ScriptOps.BadSubCommand(
                                    interpreter, null, null, subCommand, this, null, null);

                                code = ReturnCode.Error;
                                break;
                            }
                            }
                        }
                    }
                    else
                    {
                        result = "wrong # args: should be \"xml option ?arg ...?\"";
                        code   = ReturnCode.Error;
                    }
                }
                else
                {
                    result = "invalid argument list";
                    code   = ReturnCode.Error;
                }
            }
            else
            {
                result = "invalid interpreter";
                code   = ReturnCode.Error;
            }

            return(code);
        }