예제 #1
0
        /// <summary>
        /// Find all DLL's in specified directory and load available plugins.
        /// </summary>
        /// <param name="pluginsPath">Path containing plugin DLL's.</param>
        public void LocatePlugins(string path, CommandHost commandHost = null)
        {
            // logger.Info("Loading plugins...");
            this.pluginCollection.Clear();

            foreach (string file in Directory.GetFiles(path))
            {
                FileInfo fileInfo = new FileInfo(file);

                if (fileInfo.Extension.Equals(".dll"))
                {
                    // Add any plugins from file if it contains a valid assembly.
                    try
                    {
                        Assembly pluginAssembly = LoadAssembly(file);
                        if (pluginAssembly != null &&
                            TryAddPlugins(pluginAssembly) &&
                            commandHost != null)
                        {
                            commandHost.LocateCommands(pluginAssembly);
                        }
                    }
                    catch (ReflectionTypeLoadException e)
                    {
                        // logger.Warning("Tried to load {0}, but wasn't a plugin assembly.", fileInfo.Name);
                    }
                }
            }
        }
예제 #2
0
        private static void Main(string[] args)
        {
            Console.Title = "Lyudmila Server App";
            Logger.Init();

            if (!Directory.Exists("Web"))
            {
                Directory.CreateDirectory("Web");
                Logger.Write("No config files found.", LogLevel.Error);
                Console.ReadKey(true);
                Commands.Quit();
            }

            Logger.Write("Starting Web Server...", LogLevel.HTTP);
            new Thread(httpServer.Listen).Start();
            HttpServer.IPList();

            MyIP = LocalIPAddress();
            InitializeSender();
            InitializeReceiver();

            var cmdHost = new CommandHost();

            var running = cmdHost.InvokeCommand(Console.ReadLine());

            while (running)
            {
                Console.ForegroundColor = ConsoleColor.White;
                running = cmdHost.InvokeCommand(Console.ReadLine());
            }

            Commands.Quit();
        }
 public void InvokeGenerate(StackStateMachine machine, Instruction instruction)
 {
     if (InstructionCollection.ContainsKey(instruction.Args[0].Value))
     {
         CommandHost host = InstructionCollection[instruction.Args[0].Value];
         host.Invoke(machine, instruction);
         return;
     }
     throw new ArgumentException("不能生成 " + instruction.Args[0].Value);
 }
 void performInstruction(Instruction instruction)
 {
     if (InstructionCollection.ContainsKey(instruction.InstructionCode))
     {
         CommandHost host = InstructionCollection[instruction.InstructionCode];
         host.Invoke(this, instruction);
         return;
     }
     throw new ArgumentException("没有这样的命令:" + instruction.InstructionCode);
 }
        private void BuildCodeBySPSchema(object item)
        {
            SOCommand sp = item as SOCommand;
            //List<SOCommandParameter> paramList = DbSchemaHelper.Instance.CurrentSchema.GetCommandParameterList(sp);

            //生成代码文件
            CommandHost host = new CommandHost();

            host.SP = sp;
            //host.ParamList = paramList;
            host.TemplateFile = templateFile;

            foreach (object obj in listBox3.Items)
            {
                string[] ss = obj.ToString().Split('|');

                host.SetValue(ss[0], ss[1].Replace("[<->]", "|"));
            }

            Engine engine = new Engine();

            string fileName  = string.Empty;
            string separator = txtFileNamePrefix.Text.Trim();

            if (separator != "")
            {
                fileName = string.Format("{0}{1}", sp.Name.RemovePrefix(separator, 10), host.FileExtention);
            }
            else
            {
                fileName = string.Format("{0}{1}", sp.Name, host.FileExtention);
            }

            string outputContent = engine.ProcessTemplate(File.ReadAllText(templateFile), host);
            string outputFile    = Path.Combine(outputPath, fileName);

            StringBuilder sb = new StringBuilder();

            if (host.ErrorCollection.HasErrors)
            {
                foreach (CompilerError err in host.ErrorCollection)
                {
                    sb.AppendLine(err.ToString());
                }
                outputContent = outputContent + Environment.NewLine + sb.ToString();
                outputFile    = outputFile + ".error";
            }

            if (Directory.Exists(outputPath) == false)
            {
                Directory.CreateDirectory(outputPath);
            }
            File.WriteAllText(outputFile, outputContent, Encoding.UTF8);
        }
예제 #6
0
        static void Main(string[] args)
        {
            var host = new CommandHost();

            host.RegisterDefaultCommands();

            host.RegisterVariable(new Variable <decimal>("1", "A decimal test variable.", 0m));
            host.RegisterVariable(new DelegatedVariable <decimal>("2", () =>
            {
                Console.WriteLine("getting tester");
                return(tester);
            }, (val) =>
            {
                Console.WriteLine("setting tester to {0}", val);
                tester = val;
            }, () =>
            {
                Console.WriteLine("getting tester string");
                return(tester.ToString());
            }, (val) =>
            {
                Console.Write("setting tester string to {0}... ", val);

                decimal d;

                if (decimal.TryParse(val, out d))
                {
                    Console.WriteLine("success!");
                    tester = d;
                    return(true);
                }
                else
                {
                    Console.WriteLine("fail.");
                    return(false);
                }
            }, "A delegated decimal test variable."));

            host.GetCommand("cvar").Invocation += Program_Invocation;

            host.GetVariable("1").Change += Program_Change;

            string cmd = null;

            while (Read(out cmd))
            {
                EvaluationResult res;

                try
                {
                    res = host.Evaluate(cmd);

                    if (!res.TruthValue && !dbg)
                    {
                        Console.Write("{0} [{1}]: ", res.Status, res.CommonStatus);
                    }


                    if (!string.IsNullOrWhiteSpace(res.Output))
                    {
                        Console.WriteLine(res.Output);
                    }

                    if (!res.TruthValue && dbg)
                    {
                        ConsoleColor oBG = Console.BackgroundColor, oFG = Console.ForegroundColor;
                        Console.BackgroundColor = ConsoleColor.White;
                        Console.ForegroundColor = ConsoleColor.Black;

                        var split = new List <string>(res.ToString().Split('\n'));

                        for (int i = 0; i < split.Count; i++)
                        {
                            var line = split[i].Trim('\r');

                            if (line.Length > Console.BufferWidth)
                            {
                                split.Insert(i + 1, line.Substring(Console.BufferWidth));
                                split[i] = line.Substring(0, Console.BufferWidth);
                            }
                            else
                            {
                                split[i] = line + spacez.Substring(0, Console.BufferWidth - line.Length);
                            }

                            Console.Write(split[i]);
                        }

                        Console.BackgroundColor = oBG; Console.ForegroundColor = oFG;
                    }
                }
                catch (FormatException x)
                {
                    Console.WriteLine("Error: {0}", x.Message);
                }
            }

            Console.Write("Press any key to terminate... ");
            Console.ReadKey(true);
        }