Пример #1
0
 public void init(TextReader inputStream)
 {
     reader = inputStream;
     parser.ReInit(reader);
     _worker = new Thread(Run);
     _worker.Start();
 }
Пример #2
0
        public virtual void executeCommand(String commandString, bool blocked)
        {
            List <Object> commandMessages = blocked ? new List <Object>() : null;

            parser.ReInit(new MemoryStream(ASCIIEncoding.ASCII.GetBytes(commandString)));
            Object command = null;

            try
            {
                alreadyReceived.Clear();
                while ((command = parser.basicExpr()) != null)
                {
                    OnCommand(new CommandEventArgs(command, ChannelId));
                    if (blocked)
                    {
                        try
                        {
                            while (blocked)
                            {
                                //router.fillMessageList(ChannelId, commandMessages);
                                int count = commandMessages.Count;
                                if (count > 0)
                                {
                                    MessageEventArgs last = (MessageEventArgs)commandMessages[count - 1];
                                    if (last.Type == EventType.RESULT || last.Type == EventType.ERROR)
                                    {
                                        foreach (object message in commandMessages)
                                        {
                                            ((IList)alreadyReceived).Add(message);
                                        }
                                        commandMessages.Clear();
                                        blocked = false;
                                    }
                                }
                                if (blocked)
                                {
                                    Thread.Sleep(new TimeSpan(10000 * 10));
                                }
                            }
                        }
                        catch (ThreadInterruptedException e)
                        {
                            /* TODO for now we just ignore this case */
                        }
                        blocked = true;
                    }
                }
            }
            catch (ParseException e)
            {
                OnMessage(new MessageEventArgs(EventType.PARSE_ERROR, e, ChannelId));
            }
            catch (TokenMgrError e)
            {
                OnMessage(new MessageEventArgs(EventType.PARSE_ERROR, e, ChannelId));
                parser.ReInit(new MemoryStream(ASCIIEncoding.ASCII.GetBytes(commandString)));
            }
        }
Пример #3
0
        protected void parse(Rete engine, CLIPSParser parser, IList factlist)
        {
            Object itm = null;

            try
            {
                while ((itm = parser.basicExpr()) != null)
                {
                    // System.Console.WriteLine("obj is " + itm.getClass().Name);
                    if (itm is Defrule)
                    {
                        Defrule rule = (Defrule)itm;
                        engine.RuleCompiler.addRule(rule);
                    }
                    else if (itm is Deftemplate)
                    {
                        Deftemplate dt = (Deftemplate)itm;
                        Console.WriteLine("template=" + dt.Name);
                        engine.declareTemplate(dt);
                    }
                    else if (itm is FunctionAction)
                    {
                        FunctionAction fa = (FunctionAction)itm;
                    }
                    else if (itm is IFunction)
                    {
                        IReturnVector rv  = ((IFunction)itm).executeFunction(engine, null);
                        IEnumerator   itr = rv.Iterator;
                        while (itr.MoveNext())
                        {
                            IReturnValue rval = (IReturnValue)itr.Current;
                            Console.WriteLine(rval.StringValue);
                        }
                    }
                }
            }
            catch
            {
                // Console.WriteLine(e.Message);
                parser.ReInit(Console.OpenStandardInput());
            }
        }