当前位置: 首页>>代码示例>>C#>>正文


C# ScriptEngine.Run方法代码示例

本文整理汇总了C#中ScriptEngine.Run方法的典型用法代码示例。如果您正苦于以下问题:C# ScriptEngine.Run方法的具体用法?C# ScriptEngine.Run怎么用?C# ScriptEngine.Run使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ScriptEngine的用法示例。


在下文中一共展示了ScriptEngine.Run方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: run

        /// <summary>
        /// Runs a command from an external script file
        /// </summary>
        /// <param name="command">The command to search for</param>
        /// <param name="commandSet">The arguments to pass to the script</param>
        /// <param name="destination">The destination, by default should be a channel, unless pm is true</param>
        /// <param name="target">the target of the nick that has called the command</param>
        /// <param name="pipe">Are we setting up a secondary command? This allows us to execute private commands in a public room</param>
        /// <param name="pm">Are we issuing a private message command?</param>
        private void run( string command, object[] commandSet, string destination, string target, bool pipe = false, bool pm = false )
        {
            string args = string.Empty;
            Guid g = Guid.NewGuid ( );
            var sc = new ScriptContext ( );
            var se = new ScriptEngine ( );

            try
            {
                sc.server = this;
                var noMod = new List<object> ( );

                // TODO: Shorten this statement
                if ( commandSet.Length > 0 )
                    for ( int i = 0; i < commandSet.Length; i++ )
                    {
                        args += string.Format ( "[{0}]; ", commandSet[ i ] );
                        noMod.Add ( commandSet[ i ] );
                    }

                if ( destination.StartsWith ( "#" ) && pm == false )
                    sc.channel = GetChannel ( destination );
                else
                    destination = target;

                sc.nick = target;

                sc.Arguments = noMod;
                args = args.TrimEnd ( ' ' );

                string cmdlet = string.Format ( "{0}\\{1}.cs", CmdPath, command );
                var cmdi = se.GetInterface ( cmdlet );

                if ( cmdi == null )
                {
                    SendMessage ( destination, "Unknown Command" );
                    return;
                }
                else
                {
                    //pc ( "[{0:HH:mm:ss} {1}] {2}", ConsoleColor.Green, DateTime.Now, destination, target );
                    Format ( "Name: {0} - Help: {1} - Usage: {2} - More: {3} - Version: {4} - Permission: {5}",
                        ConsoleColor.DarkGreen,
                        cmdi.Name,
                        cmdi.Help,
                        cmdi.Usage,
                        cmdi.More,
                        cmdi.Version,
                        cmdi.Permission );

                    if ( cmdi.IsPublic )
                    {
                        if ( uac.GetPermission ( target, this ) <= cmdi.Permission )
                            se.Run ( cmdlet, ref sc );
                        else
                            SendMessage ( target,
                                       string.Format ( "You do not have permission to execute the command {0}", command ) );
                    }
                    else if ( pipe )
                    {
                        if ( uac.GetPermission ( target, this ) <= cmdi.Permission )
                            se.Run ( cmdlet, ref sc );
                    }
                    else if ( pm )
                    {
                        if ( uac.GetPermission ( target, this ) <= cmdi.Permission )
                            se.Run ( cmdlet, ref sc );
                        else
                            SendMessage ( target,
                                       string.Format ( "You do not have permission to execute the command {0}", command ) );
                    }
                    else if ( pipe && pm )
                        SendMessage ( target, "Pipe command cannot be used privately" );
                    else
                    {
                        SendMessage ( destination,
                                          string.Format ( "The command \"{0}\" can only be used privately!", command ) );
                    }
                }
            }
            catch ( Exception ex )
            {
                IrcReply.FormatMessage ( string.Format ( "{0}", ex.Message ), ConsoleColor.Red );
                SendMessage ( destination, string.Format ( "{0} -> Command \"{1}\" not found!", target, command ) );
                return;
            }
            SendMessage ( _dbgchan,
                string.Format ( "Command: {0}; Arguments: [{1}]; Callee: [{2}]; Destination: \"{3}\"; Fingerprint: [{4}]",
                    command,
                    ( args.Length > 0 ? args : "{{ null }}" ),
                    target,
//.........这里部分代码省略.........
开发者ID:Blizzardo1,项目名称:Blizzeta-Zero-for-Twitch,代码行数:101,代码来源:Irc.cs


注:本文中的ScriptEngine.Run方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。