Esempio n. 1
0
 private void Buffer_OnNext(ITracked<MPack> p)
 {
     try
     {
         var map = p.Value as MPackMap;
         if (map != null)
         {
             if (map.ContainsKey(CONST.HDR_CMD))
             {
                 MPack response = null;
                 switch (map[CONST.HDR_CMD].To<string>())
                 {
                     //case CONST.CMD_USER:
                     //    logCmd = "USER";
                     //    response = User(p.Observe());
                     //    break;
                     //case CONST.CMD_AUTH:
                     //    logCmd = "AUTH";
                     //    response = Auth(p.Observe());
                     //    break;
                     case CONST.CMD_OPEN:
                         response = Open(p.Observe());
                         break;
                     case CONST.CMD_CLOSE:
                         response = Close(p.Observe());
                         break;
                     case CONST.CMD_EXECUTE:
                         response = Execute(p.Observe());
                         break;
                         //default:
                         //    throw new ArgumentException($"Command {map[CONST.HDR_CMD].To<string>()} not recognized.");
                 }
                 if (response != null)
                     WritePacket(response);
             }
         }
     }
     catch (Exception e)
     {
         p.Observe();
         MPackMap err = new MPackMap();
         err[CONST.HDR_STATUS] = MPack.From(CONST.STA_ERROR);
         err[CONST.HDR_VALUE] = MPack.From(e.Message);
         if (p.Value is MPackMap && ((MPackMap)p.Value).ContainsKey(CONST.HDR_ID))
             err[CONST.HDR_ID] = p.Value[CONST.HDR_ID];
         WritePacket(err);
     }
 }
Esempio n. 2
0
        internal void Eat(List <IElement> raw, ITracked tracked)
        {
            Unit = tracked.IndentationTracker.Minimum;

            IParent last = this;
            int     parentIndentation = 0;

            // IMPORTANT: block quote processing
            for (int i = 0; i < raw.Count; i++)
            {
                var current = raw[i];
                if (current.TypeCode == ElementType.ListItem)
                {
                    if (current is ListItem item && item.Enumerator != null)
                    {
                        if (i < raw.Count - 1)
                        {
                            if (raw[i + 1] is ListItem next)
                            {
                                item.Analyze(next);
                            }
                        }
                    }

                    last = last.Add(current);
                    continue;
                }

                if (current.TypeCode == ElementType.Comment || current.TypeCode == ElementType.Section)
                {
                    last = last.Add(current);
                    parentIndentation = current.Indentation;
                    continue;
                }

                if (current is Paragraph paragraph)
                {
                    paragraph.Unit = Unit;
                    if (last.TypeCode == ElementType.ListItem || last.Parent?.TypeCode == ElementType.ListItem)
                    {
                        last = last.Add(current);
                        continue;
                    }

                    if (last.TypeCode == ElementType.BlockQuote)
                    {
                        if (paragraph.IsAttribution())
                        {
                            last = last.Add(paragraph);
                            continue;
                        }
                    }

                    var tuple = paragraph.Parse(parentIndentation, Unit, last);
                    if (tuple.Item1)
                    {
                        last = tuple.Item2;
                        continue;
                    }

                    current = tuple.Item2;
                }

                last = last.Add(current);
                parentIndentation = current.Indentation;
            }

            if (Elements.LastOrDefault() is BlockQuote end)
            {
                end.FillAttribution();
            }
        }
Esempio n. 3
0
 public static UIntPtr AddressOf(ITracked tracked)
 {
     return(Magic.addressOf(tracked));
 }
 internal TrackedBaseVisitor <T> Inherit(ITracked item)
 {
     SectionTracker     = item.SectionTracker;
     IndentationTracker = item.IndentationTracker;
     return(this);
 }