Exemplo n.º 1
0
        public void Parse()
        {
            while (m_reader.Read())
            {
                XmlNodeType nType = m_reader.NodeType;

                if (nType == XmlNodeType.Element)
                {
                    string name           = XmlConvert.DecodeName(m_reader.Name);
                    bool   isEmptyElement = m_reader.IsEmptyElement;

                    VariantBase.EnumType elementType = GetVariantTypeFromSchema();
                    Variant attributes = new Variant(VariantBase.EnumType.Bag);
                    for (int i = 0; i < m_reader.AttributeCount; ++i)
                    {
                        m_reader.MoveToAttribute(i);
                        VariantBase.EnumType attrType = GetVariantTypeFromSchema();
                        if (attrType != VariantBase.EnumType.Buffer)
                        {
                            attributes.Add(XmlConvert.DecodeName(m_reader.Name), new Variant(attrType, m_reader.Value));
                        }
                        else
                        {
                            attributes.Add(XmlConvert.DecodeName(m_reader.Name), new Variant(Convert.FromBase64String(m_reader.Value)));
                        }
                    }

                    StartElement(name, attributes, elementType);

                    if (isEmptyElement)
                    {
                        EndElement();
                    }
                }
                else if (nType == XmlNodeType.Text)
                {
                    Characters(m_reader.Value);
                }
                else if (nType == XmlNodeType.Comment)
                {
                    Comment(m_reader.Value);
                }
                else if (nType == XmlNodeType.ProcessingInstruction)
                {
                    ProcessingInstruction(XmlConvert.DecodeName(m_reader.Name), m_reader.Value);
                }
                else if (nType == XmlNodeType.EndElement)
                {
                    EndElement();
                }
                else if (nType == XmlNodeType.CDATA)
                {
                    Characters(m_reader.Value);
                }
            }
        }
Exemplo n.º 2
0
        private static void SelectImpl(Variant input, string path, Variant result)
        {
            string head = "", tail = "";

            Match myMatch = Regex.Match(path, @"[^/]+");

            if (myMatch.Success)
            {
                head = myMatch.Value;
                tail = path.Substring(myMatch.Index + myMatch.Length);
            }
            else
            {
                result.Add(input);
                return;
            }

            string node = "", pred_key = "", pred_val = "";

            myMatch = Regex.Match(head, @"^(\*|\w+)(\[@?(\w+)=""?(\w+)""?\])?");
            if (myMatch.Success)
            {
                node     = myMatch.Groups[1].Value;
                pred_key = myMatch.Groups[3].Value;
                pred_val = myMatch.Groups[4].Value;
            }
            else
            {
                throw new VariantException("Select path has invalid syntax: " + head);
            }

            Variant nodes = new Variant(EnumType.List);

            if (node.Length == 0 || node == "*")
            {
                foreach (VariantItem item in input)
                {
                    nodes.Add(item.Value);
                }
            }
            else if (input.Is(EnumType.Mapping))
            {
                foreach (VariantItem item in input.Range(node))
                {
                    nodes.Add(item.Value);
                }
            }

            foreach (VariantItem item in nodes)
            {
                if (pred_key.Length == 0 || (item.Value.Is(EnumType.Mapping) && item.Value.ContainsKey(pred_key) && item.Value[pred_key].AnyCast().As <string>() == pred_val))
                {
                    SelectImpl(item.Value, tail, result);
                }
            }
        }
Exemplo n.º 3
0
        public Variant Range(string key)
        {
            Variant result = new Variant(Variant.EnumType.List);

            if (ContainsKey(key))
            {
                result.Add(Value[key]);
            }

            return(result);
        }
Exemplo n.º 4
0
        public Variant Range(string key)
        {
            Variant result = new Variant(Variant.EnumType.List);

            foreach (KeyValuePair <string, Variant> kv in Value)
            {
                if (kv.Key == key)
                {
                    result.Add(kv.Value);
                }
            }

            return(result);
        }
Exemplo n.º 5
0
        protected Variant ReadVariant()
        {
            Variant.EnumType type = ReadType();

            switch (type)
            {
            case Variant.EnumType.None:
                return(new Variant(Variant.EnumType.None));

            case Variant.EnumType.String:
                return(new Variant(ReadString()));

            case Variant.EnumType.Any:
                return(new Variant(Variant.EnumType.Any, ReadString()));

            case Variant.EnumType.Float:
                return(new Variant(ReadFloat()));

            case Variant.EnumType.Double:
                return(new Variant(ReadDouble()));

            case Variant.EnumType.Int32:
                return(new Variant(ReadInt32()));

            case Variant.EnumType.UInt32:
                return(new Variant(ReadUInt32()));

            case Variant.EnumType.Int64:
                return(new Variant(ReadInt64()));

            case Variant.EnumType.UInt64:
                return(new Variant(ReadUInt64()));

            case Variant.EnumType.Boolean:
                return(new Variant(ReadBoolean()));

            case Variant.EnumType.Time:
                if ((m_mode & BinaryMode.DateTimeAsTicks) == 0)
                {
                    throw new VariantException("Binary data has DateTimeAsTicks mode disabled which is not supported in the protean.NET BinaryReader");
                }
                return(new Variant(ReadTime()));

            case Variant.EnumType.DateTime:
                if ((m_mode & BinaryMode.DateTimeAsTicks) == 0)
                {
                    throw new VariantException("Binary data has DateTimeAsTicks mode disabled which is not supported in the protean.NET BinaryReader");
                }
                return(new Variant(ReadDateTime()));

            case Variant.EnumType.Date:
                throw new VariantException("Attempt to read Date variant which is no longer supported");

            case Variant.EnumType.Tuple:
            {
                int length = ReadInt32();

                Variant result = new Variant(Variant.EnumType.Tuple, length);
                for (int i = 0; i < length; ++i)
                {
                    result[i] = ReadVariant();
                }
                return(result);
            }

            case Variant.EnumType.List:
            {
                int length = ReadInt32();

                Variant result = new Variant(type, length);
                for (int i = 0; i < length; ++i)
                {
                    result.Add(ReadVariant());
                }
                return(result);
            }

            case Variant.EnumType.Dictionary:
            case Variant.EnumType.Bag:
            {
                int length = ReadInt32();

                Variant result = new Variant(type);
                for (int i = 0; i < length; ++i)
                {
                    String  key   = ReadString();
                    Variant value = ReadVariant();

                    result.Add(key, value);
                }
                return(result);
            }

            case Variant.EnumType.TimeSeries:
            {
                Variant result = new Variant(type);

                int length = ReadInt32();

                for (int i = 0; i < length; ++i)
                {
                    DateTime time  = ReadDateTime();
                    Variant  value = ReadVariant();

                    result.Add(time, value);
                }

                return(result);
            }

            case Variant.EnumType.Object:
            {
                string  className = ReadString();
                int     version   = ReadInt32();
                Variant param     = ReadVariant();


                IVariantObject obj = null;
                if (m_factory != null)
                {
                    obj = m_factory.Create(className);

                    if (obj == null && (m_mode & BinaryMode.CreateProxy) == 0)
                    {
                        throw new VariantException("Object of class " + className + " is not regsistered in factory");
                    }
                }

                if (obj == null)
                {
                    obj = new VariantObjectProxy(className);
                }

                obj.Inflate(param, version);

                return(new Variant(obj));
            }

            case Variant.EnumType.Exception:
            {
                string xtype    = ReadString();
                string xmessage = ReadString();
                string xsource  = ReadString();
                string xstack   = ReadString();

                return(new Variant(new VariantExceptionInfo(xtype, xmessage, xsource, xstack)));
            }

            case Variant.EnumType.Buffer:
            {
                int length = ReadInt32();
                return(new Variant(ReadBytes(length, true)));
            }

            case Variant.EnumType.DataTable:
            {
                return(new Variant(ReadDataTable()));
            }

            case Variant.EnumType.Array:
            {
                return(new Variant(ReadArray()));
            }

            default:
                throw new VariantException("Case exhaustion: " + type.ToString());
            }
        }