コード例 #1
0
ファイル: Default.cs プロジェクト: jdruin/F5Eagle
        ///////////////////////////////////////////////////////////////////////

        /// <summary>
        ///   Initialize the plugin and add any contained commands.
        ///
        ///   WARNING: PLEASE DO NOT CHANGE THIS METHOD BECAUSE DERIVED PLUGINS
        ///            DEPEND ON ITS EXACT SEMANTICS.
        /// </summary>
        ///
        /// <param name="interpreter">
        ///   The interpreter context we are executing in.
        /// </param>
        ///
        /// <param name="clientData">
        ///   The extra data supplied when this plugin was initially created,
        ///   if any.
        /// </param>
        ///
        /// <param name="result">
        ///   Upon success, this may contain an informational message.
        ///   Upon failure, this must contain an appropriate error message.
        /// </param>
        ///
        /// <returns>
        ///   ReturnCode.Ok on success, ReturnCode.Error on failure.
        /// </returns>
        public virtual ReturnCode Initialize(
            Interpreter interpreter,
            IClientData clientData,
            ref Result result
            )
        {
            ReturnCode code;

            if (FlagOps.HasFlags(
                    this.Flags, PluginFlags.NoInitialize, true))
            {
                if (!FlagOps.HasFlags(
                        this.Flags, PluginFlags.NoInitializeFlag,
                        true))
                {
                    initialized = true;
                }

                if (!FlagOps.HasFlags(
                        this.Flags, PluginFlags.NoResult, true))
                {
                    result = String.Empty;
                }

                code = ReturnCode.Ok;
            }
            else
            {
                //
                // NOTE: We require a valid interpreter context.
                //
                if (interpreter != null)
                {
                    code = ReturnCode.Ok;

                    if ((code == ReturnCode.Ok) && !FlagOps.HasFlags(
                            this.Flags, PluginFlags.NoCommands, true))
                    {
                        //
                        // NOTE: Call the interpreter helper method that
                        //       takes care of loading all valid commands
                        //       (i.e. classes that implement ICommand,
                        //       directly or indirectly) in this plugin.
                        //
                        code = interpreter.AddCommands(
                            this, clientData, CommandFlags.None,
                            ref result);

                        if (code == ReturnCode.Ok)
                        {
                            code = interpreter.MoveExposedAndHiddenCommands(
                                this.Flags, ref result);
                        }
                    }

                    if ((code == ReturnCode.Ok) && !FlagOps.HasFlags(
                            this.Flags, PluginFlags.NoPolicies, true))
                    {
                        //
                        // NOTE: Call the interpreter helper method that
                        //       takes care of loading all valid policies
                        //       (i.e. methods that are flagged as a "policy"
                        //       and are of the appropriate delegate type(s))
                        //       in this plugin.
                        //
                        code = interpreter.AddPolicies(
                            this, clientData, ref result);
                    }

                    Version version = null;

                    if ((code == ReturnCode.Ok) && !FlagOps.HasFlags(
                            this.Flags, PluginFlags.NoProvide, true))
                    {
                        //
                        // NOTE: Grab the plugin version now, if
                        //       necessary, since we know that we
                        //       need it.
                        //
                        if (version == null)
                        {
                            version = this.Version;
                        }

                        //
                        // NOTE: Formally "provide" (i.e. announce) this
                        //       package to the interpreter so that scripts
                        //       can easily detect it.
                        //
                        code = interpreter.PkgProvide(
                            this.GetType().FullName, version,
                            GetPackageFlags(), ref result);
                    }

                    //
                    // NOTE: If the above steps succeeded, mark the
                    //       plugin as initialized and return an
                    //       appropriate result.
                    //
                    if (code == ReturnCode.Ok)
                    {
                        if (!FlagOps.HasFlags(
                                this.Flags, PluginFlags.NoInitializeFlag,
                                true))
                        {
                            initialized = true;
                        }

                        //
                        // NOTE: Returning the loaded plugin name
                        //       and version is HIGHLY RECOMMENDED
                        //       here.
                        //
                        if (!FlagOps.HasFlags(
                                this.Flags, PluginFlags.NoResult, true))
                        {
                            //
                            // NOTE: Grab the plugin version now, if
                            //       necessary, since we know that
                            //       we need it.
                            //
                            if (version == null)
                            {
                                version = this.Version;
                            }

                            result = StringList.MakeList(
                                this.Name, version);
                        }
                    }
                }
                else
                {
                    result = "invalid interpreter";
                    code   = ReturnCode.Error;
                }
            }

            return(code);
        }