示例#1
0
        private void WriterTask(CancellationToken token)
        {
            while (!token.IsCancellationRequested || this.buffer.Count > 0)
            {
                if (this.buffer.TryTake(out DataRecord record))
                {
                    var failed = record.Parsed.Values.FirstOrDefault(x => x.IsFailed);
                    if (failed != null)
                    {
                        lock (this.buffer)
                        {
                            this.exceptionRecordCount++;
                            ErrorOutput.Write($"Line {record.RecordNumber} - Column {failed.Column.Name} - ");
                            ErrorOutput.WriteLine(string.Join(", ", record.Source));
                        }
                    }
                    else
                    {
                        foreach (var writer in this.writers)
                        {
                            writer.WriteLine(record.Parsed);
                        }

                        lock (this.buffer)
                        {
                            this.successfulRecordCount++;
                        }
                    }
                }
                else
                {
                    Thread.Sleep(50);
                }
            }
        }
示例#2
0
        // wrapper for yyparse
        public TranslationUnit Parse(TextReader tr, SourceFile file = null, ParserDebug dgb = null)
        {
            if (dgb != null)
            {
                this.debug = (ParserDebug)dgb;
                DebugLevel = 1;
            }

            if (file != null)
            {
                currentFile = file;
            }
            lexer = new DelphiScanner(tr);
            lexer.yyLexDebugLevel = DebugLevel;

            Object parserRet;

            try
            {
                parserRet = yyparse(lexer);
            }
            catch (MultiDelphiException yye)
            {
                yyerror(yye.Message);
                return(null);
            }
            catch (Exception e)
            {
                ErrorOutput.WriteLine(e.Message + " in line " + lexer.yylineno());
                ErrorOutput.WriteLine(e.StackTrace);
                return(null);
            }
            finally {
                lexer = null;
            }

            if (!(parserRet is TranslationUnit))
            {
                throw new ParserException("Non-final node derived from parsing:" + parserRet.GetType());
            }

            return((TranslationUnit)parserRet);
        }
示例#3
0
 /// <summary>
 /// Add command
 /// </summary>
 /// <param name="command">Command</param>
 /// <param name="commands">Commands</param>
 private void AddCommand(ICommand command, List <ICommand> commands)
 {
     if (command != null)
     {
         foreach (string key in command.Keys)
         {
             string k = key.Trim().ToLower();
             if (commandsDictionary.ContainsKey(k))
             {
                 ErrorOutput.WriteLine("Duplicate key \"" + k + "\" in \"" + command.GetType().FullName + "\". Registered command class: \"" + commandsDictionary[k].GetType().FullName + "\"");
             }
             else
             {
                 commandsDictionary.Add(k, command);
             }
         }
         commands.Add(command);
     }
 }
示例#4
0
 /// <summary>
 /// Parse command
 /// </summary>
 /// <param name="command">Command</param>
 public void ParseCommand(string command)
 {
     string[] args = command.Split(' ');
     if (args != null)
     {
         if (args.Length > 0)
         {
             string   arg = args[0];
             ICommand cmd = GetCommandByKey(arg);
             if (cmd != null)
             {
                 cmd.Execute(new CommandContext(this, command.Substring((command.Length > arg.Length) ? arg.Length + 1 : arg.Length), StandardOutput, ErrorOutput));
             }
             else
             {
                 ErrorOutput.WriteLine("Unknown command \"" + arg.Trim().ToLower() + "\"");
             }
         }
     }
 }
示例#5
0
 /// <summary>
 /// Context recieved callback
 /// </summary>
 /// <param name="asyncResult">Asynchronous result</param>
 private void ContextReceivedCallback(IAsyncResult asyncResult)
 {
     try
     {
         if (IsListening)
         {
             HttpListenerContext context = httpListener.EndGetContext(asyncResult);
             httpListener.BeginGetContext(new AsyncCallback(ContextReceivedCallback), null);
             using (Stream stream = context.Response.OutputStream)
             {
                 foreach (IPlugin plugin in plugins)
                 {
                     ListenerContext listener_context = new ListenerContext(context, StandardOutput, ErrorOutput);
                     plugin.OnRequest(listener_context);
                     stream.Write(listener_context.ResponseBytes, 0, listener_context.ResponseBytes.Length);
                 }
             }
         }
     }
     catch (Exception e)
     {
         ErrorOutput.WriteLine(e);
     }
 }
示例#6
0
        /// <summary>
        /// Reload plugins
        /// </summary>
        public void ReloadPlugins()
        {
            List <IPlugin>  plugins  = new List <IPlugin>();
            List <ICommand> commands = new List <ICommand>();

            commandsDictionary.Clear();
            try
            {
                string plugins_directory = Path.Combine(Environment.CurrentDirectory, "plugins");
                UnloadPlugins();
                if (Directory.Exists(plugins_directory))
                {
                    string[] files = Directory.GetFiles(plugins_directory, "*.dll");
                    if (files != null)
                    {
                        foreach (string file in files)
                        {
                            if (file != null)
                            {
                                try
                                {
                                    Assembly assembly = Assembly.LoadFile(file);
                                    if (assembly != null)
                                    {
                                        Type[] types = assembly.GetExportedTypes();
                                        if (types != null)
                                        {
                                            foreach (Type type in types)
                                            {
                                                if (type != null)
                                                {
                                                    if (type.IsClass && typeof(IPlugin).IsAssignableFrom(type))
                                                    {
                                                        IPlugin plugin = Activator.CreateInstance(type) as IPlugin;
                                                        if (plugin != null)
                                                        {
                                                            ICommand[] plugin_commands = plugin.Commands;
                                                            if (plugin_commands != null)
                                                            {
                                                                foreach (ICommand plugin_command in plugin_commands)
                                                                {
                                                                    AddCommand(plugin_command, commands);
                                                                }
                                                            }
                                                            plugins.Add(plugin);
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                                catch (Exception e)
                                {
                                    ErrorOutput.WriteLine(e);
                                }
                            }
                        }
                    }
                }
                try
                {
                    Assembly assembly = Assembly.GetExecutingAssembly();
                    if (assembly != null)
                    {
                        Type[] types = assembly.GetTypes();
                        if (types != null)
                        {
                            foreach (Type type in types)
                            {
                                if (type != null)
                                {
                                    if (type.IsClass && typeof(ICommand).IsAssignableFrom(type))
                                    {
                                        ICommand command = Activator.CreateInstance(type) as ICommand;
                                        AddCommand(command, commands);
                                    }
                                }
                            }
                        }
                    }
                }
                catch (Exception e)
                {
                    ErrorOutput.WriteLine(e);
                }
            }
            catch (Exception e)
            {
                ErrorOutput.WriteLine(e);
            }
            this.plugins = plugins.ToArray();
            plugins.Clear();
            this.commands = commands.ToArray();
            commands.Clear();
            foreach (IPlugin plugin in this.plugins)
            {
                plugin.OnLoad(this);
            }
        }