Exemplo n.º 1
0
        public static NeuralNetwork FromXML(string xml)
        {
            XMLElement root = XMLReader.Parse(xml);

            int layerCount = int.Parse(root.GetAttribute("Layers").Value);

            XMLElement[] layerXEs = new XMLElement[layerCount];

            Layer[] layers = new Layer[layerCount];
            foreach (XMLElement layerXE in root.Children)
            {
                int layerIndex = int.Parse(layerXE.GetAttribute("Index").Value);

                layerXEs[layerIndex] = layerXE;
            }

            for (int i = 0; i < layerXEs.Length; i++)
            {
                Layer previousLayer = i == 0 ? null : layers[i - 1];

                Layer layer = Layer.FromXML(layerXEs[i], previousLayer);
                layers[i] = layer;
            }

            return(new NeuralNetwork(layers));
        }
Exemplo n.º 2
0
        public TMXTile(XMLElement element)
        {
            name = element.GetAttribute("name", "");
            type = element.GetAttribute("type", "");
            x    = element.GetIntAttribute("x", 0);
            y    = element.GetIntAttribute("y", 0);
            string w = element.GetAttribute("width", null);
            string h = element.GetAttribute("height", null);

            width  = System.Int32.Parse((w == null || "".Equals(w)) ? "0" : w);
            height = System.Int32.Parse((h == null || "".Equals(h)) ? "0" : h);
            XMLElement imageElement = element
                                      .GetChildrenByName("image");

            if (imageElement != null)
            {
                image = imageElement.GetAttribute("source", null);
            }
            XMLElement propsElement = element
                                      .GetChildrenByName("properties");

            if (propsElement != null)
            {
                props = new TMXProperty();
                List <XMLElement> property = propsElement.List("property");
                for (int i = 0; i < property.Count; i++)
                {
                    XMLElement propElement = property[i];
                    string     name_0      = propElement.GetAttribute("name", null);
                    string     value_ren   = propElement.GetAttribute("value", null);
                    props.SetProperty(name_0, value_ren);
                }
            }
        }
Exemplo n.º 3
0
    private void SetUpData()
    {
        string strName = GetName();

        UnityEngine.Object[] files = Resources.LoadAll("StringTables/" + strName, typeof(TextAsset));
        foreach (TextAsset file in files)
        {
            string xmlString = file.text;

            // error message
            string strErrorFile = "Error in file " + file.name;

            //Create XMLParser instance
            XMLParser xmlParser = new XMLParser(xmlString);

            //Call the parser to build the IXMLNode objects
            XMLElement xmlElement = xmlParser.Parse();

            // this will load files that have replaced the file stored in data locally
                        #if UNITY_STANDALONE_WIN
            string strFile = Application.dataPath + "/Resources/" + file.name + ".xml";
            if (System.IO.File.Exists(strFile))
            {
                Debug.Log("An override string table file was found: " + strFile);
                xmlString = System.IO.File.ReadAllText(strFile);
            }
                        #endif

            AddData(strErrorFile, xmlElement);
        }
    }
Exemplo n.º 4
0
        public TMXTileGroup(XMLElement element)
        {
            name    = element.GetAttribute("name", null);
            width   = element.GetIntAttribute("width", 0);
            height  = element.GetIntAttribute("height", 0);
            objects = new List <TMXTile>();

            XMLElement propsElement = element.GetChildrenByName("properties");

            if (propsElement != null)
            {
                List <XMLElement> properties = propsElement.List("property");
                if (properties != null)
                {
                    props = new TMXProperty();
                    for (int p = 0; p < properties.Count; p++)
                    {
                        XMLElement propElement = properties[p];
                        string     name_0      = propElement.GetAttribute("name", null);
                        string     value_ren   = propElement.GetAttribute("value", null);
                        props.SetProperty(name_0, value_ren);
                    }
                }
            }
            List <XMLElement> objectNodes = element.List("object");

            for (int i = 0; i < objectNodes.Count; i++)
            {
                XMLElement objElement = objectNodes[i];
                TMXTile    obj0       = new TMXTile(objElement);
                obj0.index = i;
                CollectionUtils.Add(objects, obj0);
            }
        }
Exemplo n.º 5
0
    public static void SetupData()
    {
        dictSounds = new Dictionary <string, DataSound>();

        //Load all item xml files
        UnityEngine.Object[] files = Resources.LoadAll("Sounds", typeof(TextAsset));
        foreach (TextAsset file in files)
        {
            string xmlString = file.text;

            //Create XMLParser instance
            XMLParser xmlParser = new XMLParser(xmlString);

            //Call the parser to build the IXMLNode objects
            XMLElement xmlElement = xmlParser.Parse();

            //Go through all child node of xmlElement (the parent of the file)
            for (int i = 0; i < xmlElement.Children.Count; i++)
            {
                IXMLNode childNode = xmlElement.Children[i];

                //Get id
                Hashtable hashAttr = XMLUtils.GetAttributes(childNode);
                string    id       = (string)hashAttr["ID"];

                DataSound sound = new DataSound(id, hashAttr);

                // store the sound
                dictSounds.Add(id, sound);
            }
        }
    }
Exemplo n.º 6
0
        private void Set(Stream ins)
        {
            XMLDocument doc  = XMLParser.Parse(ins);
            XMLElement  Pack = doc.GetRoot();

            Set(Pack);
        }
Exemplo n.º 7
0
        public Element CreateElementNS(String namespaceURI, String tagName)
        {
            Element element = null;

            if (namespaceURI == Namespaces.Html)
            {
                element = HTMLElement.Factory(tagName);
            }
            else if (namespaceURI == Namespaces.Svg)
            {
                element = SVGElement.Create(tagName);
            }
            else if (namespaceURI == Namespaces.MathML)
            {
                element = MathMLElement.Create(tagName);
            }
            else if (namespaceURI == Namespaces.Xml)
            {
                element = XMLElement.Create(tagName);
            }
            else
            {
                element = new Element {
                    NamespaceURI = namespaceURI, NodeName = tagName
                }
            };

            element.OwnerDocument = this;
            return(element);
        }
Exemplo n.º 8
0
        private void buttonClear_Click(object sender, EventArgs e)
        {
            textBoxInput.Clear();
            treeViewDoc.Nodes.Clear();

            xmlRoot = null;
        }
Exemplo n.º 9
0
    /// <summary>
    /// Handles opening tags.
    /// </summary>
    /// <param name='tagName'>
    /// Tag name.
    /// </param>
    protected virtual void StartElementHandler(string tagName)
    {
        // placeholder for new element.
        XMLElement newElement;   // no assignment is bad form but necessary

        if (!rootflag)           // need to setup root element...
        {
            newElement  = new XMLElement(tagName.Trim(), null);
            rootElement = newElement;
            rootflag    = true;
        }
        else             // standard new element creations...
        {
            newElement = new XMLElement(tagName.Trim(), currentElement);
        }

        // Add attributes we've encounted thus far
        int i = 0;
        int attributeCount = attributeList.Count;

        while (i < attributeCount)
        {
            newElement.Attributes.Add(attributeList[i]);
            i++;
        }

        // clear saved attribute list
        attributeList = new List <XMLAttribute> ();

        // advance current element
        currentElement = newElement;
    }
Exemplo n.º 10
0
    /// <summary>
    /// Creates and returns an <see cref="XMLElement"/> that corresponds to this <see cref="UtilityNode"/>
    /// </summary>
    /// <param name="args"></param>
    /// <returns>The <see cref="XMLElement"/> corresponding to this <see cref="BehaviourNode"/></returns>
    public override XMLElement ToXMLElement(params object[] args)
    {
        XMLElement result;

        if (this.subElem)
        {
            result = this.subElem.ToXMLElement();
        }
        else
        {
            result = new XMLElement
            {
                name        = CleanName(this.nodeName),
                elemType    = this.GetType().ToString(),
                windowPosX  = this.windowRect.x,
                windowPosY  = this.windowRect.y,
                thirdType   = this.fusionType.ToString(),
                fourthType  = this.curveType.ToString(),
                variableMax = this.variableMax,
                variableMin = this.variableMin,
                slope       = this.slope,
                exp         = this.exp,
                displX      = this.displX,
                displY      = this.displY,
                points      = this.points
            };
        }

        result.Id         = this.identificator;
        result.secondType = this.type.ToString();

        return(result);
    }
Exemplo n.º 11
0
    private static void SetUpData()
    {
        hashConstants = new Hashtable();

        //Load all item xml files
        UnityEngine.Object[] files = Resources.LoadAll("Constants", typeof(TextAsset));
        foreach (TextAsset file in files)
        {
            string xmlString = file.text;

            //Create XMLParser instance
            XMLParser xmlParser = new XMLParser(xmlString);

            //Call the parser to build the IXMLNode objects
            XMLElement xmlElement = xmlParser.Parse();

            string strError = "Error in file " + file.name + ": ";

            //Go through all child node of xmlElement (the parent of the file)
            for (int i = 0; i < xmlElement.Children.Count; i++)
            {
                IXMLNode  childNode = xmlElement.Children[i];
                Hashtable hashAttr  = XMLUtils.GetAttributes(childNode);

                AddData(strError, hashAttr);
            }
        }
    }
Exemplo n.º 12
0
        public void testSimpleXMLElements()
        {
            XMLElement element = new XMLElement();

            element.Add("TestOne", "Test");
            Assert.That(element.Get("TestOne"), Is.EqualTo("Test"));
        }
Exemplo n.º 13
0
        private XMLElement Search(string raw_data, XMLElement element)
        {
            string start_tag       = string.Concat("<", element.Name, ">");
            bool   start_tag_found = raw_data.Contains(start_tag);

            string end_tag       = string.Concat("</", element.Name, ">");
            bool   end_tag_found = raw_data.Contains(end_tag);

            if (!start_tag_found && end_tag_found)
            {
                element.Start_Tag_Not_Found = true;
            }
            if (start_tag_found && !end_tag_found)
            {
                element.End_Tag_Not_Found = true;
            }
            if (!start_tag_found && !end_tag_found)
            {
                element.Exist = false;
            }
            if (start_tag_found && end_tag_found)
            {
                element.Exist = true;
            }

            return(element);
        }
Exemplo n.º 14
0
        public void testXMLTag()
        {
            XMLElement element = new XMLElement();

            element.XMLTag = "Test";
            Assert.That(element.XMLTag, Is.EqualTo("Test"));
        }
Exemplo n.º 15
0
 private void AddNewChannel(XMLElement parent, string jointValueName, string type, string unit)
 {
     parent.append_child("channel")
     .append_child_value("label", jointValueName)
     .append_child_value("type", type)
     .append_child_value("unit", unit);
 }
Exemplo n.º 16
0
        private void SetMoCapStreamDefinition()
        {
            StreamInfo mocapStreamMetaData =
                new StreamInfo("EuroMov-Mocap-Kinect", "MoCap",
                               CHANNELS_PER_SKELETON, DATA_STREAM_NOMINAL_RATE, channel_format_t.cf_double64, currentKinectSensor.UniqueKinectId);

            XMLElement channels = mocapStreamMetaData.desc().append_child("channels");

            //Timestamp channel
            AddNewChannel(channels, "Timestamp", "Time", "Unix time");

            for (int skeletonNumber = 0; skeletonNumber < MAX_SKELETON_TRACKED; skeletonNumber++)
            {
                for (int skeletonJointNumber = 0; skeletonJointNumber < JOINT_COUNT; skeletonJointNumber++)
                {
                    String currentJointName = Enum.GetName(typeof(JointType), skeletonJointNumber);

                    for (int i = 0; i < 3; i++)
                    {
                        AddNewJointChannel(channels, currentJointName + (JointValueNameSuffix)i, (MoCapChannelType)i, "meters");
                    }
                    AddNewJointChannel(channels, currentJointName + JointValueNameSuffix._Conf, MoCapChannelType.Confidence, "normalized");
                }
            }

            // misc meta-data
            mocapStreamMetaData.desc().append_child("acquisition")
            .append_child_value("manufacturer", "Microsoft")
            .append_child_value("model", "Kinect 2.0");

            outletData = new StreamOutlet(mocapStreamMetaData);
        }
Exemplo n.º 17
0
        public void insertElementAt(string strElement, string[,] arrAttributes, string strAttributes, string strText, int iElemIndex, int iElemLevel)
        {
            if (iElemIndex < 0)
            {
                iElemIndex = (Array.IndexOf(this.elements, null) > 0) ? Array.IndexOf(this.elements, null) - 1 : 0;
            }
            if (iElemLevel < 0)
            {
                iElemLevel = this.elements[iElemIndex - 1].level;
            }
            XMLElement Elem      = null;
            int        iAddIndex = iElemIndex;

            if (iElemIndex > 0 && iElemLevel > 0)
            {
                Elem = new XMLElement(strElement, strAttributes, arrAttributes, strText, iElemLevel + 1, this);
            }
            else
            {
                Elem = new XMLElement(strElement, strAttributes, arrAttributes, strText, 1, this);
            }
            this.elements = XMLUtilities.Add(this.elements, iAddIndex, Elem);
            for (int i = iAddIndex; i < Array.IndexOf(this.elements, null); i++)
            {
                this.elements[i].index = i;
            }
        }
Exemplo n.º 18
0
        public String toString()
        {
            Object XMLElement;

            java.lang.StringBuffer outputBuffer;
            String       tagName, objectType, tagLabel;
            SimpleXMLTag sxml;

            tagName      = (String)get("TAG_NAME");
            outputBuffer = new java.lang.StringBuffer("<" + tagName + ">");
            tagLabel     = (String)get("LABEL");
            if (tagLabel != (String)null)
            {
                outputBuffer.append(tagLabel);
            }
            XMLElement = get(tagName);
            objectType = XMLElement.getClass().getName();
            if (debug)
            {
                java.lang.SystemJ.outJ.println("Tag object type is " + objectType);
            }
            if (objectType.endsWith("java.lang.String"))
            {
                outputBuffer.append((String)XMLElement);
            }
            else
            {
                sxml = (SimpleXMLTag)XMLElement;
            }
            outputBuffer.append("\n</" + tagName + ">");
            return(outputBuffer.toString());
        }
Exemplo n.º 19
0
            // adds new element(s)
            // several tags can be concattenated by dots
            //         in that case as many subelements as tags are created
            public XMLElement AddChild(string TagName, string Content)
            {
                string[] parts = TagName.Split('.');

                XMLElement currentParent = this;

                for (int i = 0; i < parts.Length - 1; ++i)
                {
                    XMLElement existingChild = currentParent.FindByType(parts[i]);
                    if (existingChild != null)
                    {
                        currentParent = existingChild;
                    }
                    else
                    {
                        XMLElement newChild = new XMLElement(parts[i]);
                        currentParent.AddChild(newChild);
                        currentParent = newChild;
                    }
                }

                XMLElement newElement = new XMLElement(parts[parts.Length - 1], Content);

                currentParent.AddChild(newElement);
                return(newElement);
            }
Exemplo n.º 20
0
        internal override XMLElement ToXML()
        {
            XMLElement e = XMLElement.Create(GetType().Name);

            e.AddAttribute("FilterSize", $"{FilterSize}");
            e.AddAttribute("Stride", $"{Stride}");
            return(e);
        }
Exemplo n.º 21
0
        private void buttonParse_Click(object sender, EventArgs e)
        {
            XMLParser xmlParser = new XMLParser();

            xmlRoot = xmlParser.parse(this.textBoxInput.Text);

            showXmlRoot();
        }
Exemplo n.º 22
0
        internal static ActivationFunction FromXML(XMLElement root)
        {
            if (root.GetAttribute("Name").Value == "None")
            {
                return(None());
            }

            if (root.GetAttribute("Name").Value == "Sigmoid")
            {
                XMLElement customDataXE = root.ChildWithTag("CustomData");
                float      steepness    = int.Parse(customDataXE.ChildWithTag("steepness").GetAttribute("Value").Value);

                return(Sigmoid(steepness));
            }

            if (root.GetAttribute("Name").Value == "ReLU")
            {
                XMLElement customDataXE   = root.ChildWithTag("CustomData");
                bool       zeroIsPositive = bool.Parse(customDataXE.ChildWithTag("zeroIsPositive").GetAttribute("Value").Value);

                return(ReLU(zeroIsPositive));
            }

            if (root.GetAttribute("Name").Value == "TanH")
            {
                XMLElement customDataXE = root.ChildWithTag("CustomData");
                float      steepness    = int.Parse(customDataXE.ChildWithTag("steepness").GetAttribute("Value").Value);

                return(TanH(steepness));
            }

            if (root.GetAttribute("Name").Value == "LeakyReLU")
            {
                XMLElement customDataXE    = root.ChildWithTag("CustomData");
                float      leakynessFactor = int.Parse(customDataXE.ChildWithTag("leakynessFactor").GetAttribute("Value").Value);
                bool       zeroIsPositive  = bool.Parse(customDataXE.ChildWithTag("zeroIsPositive").GetAttribute("Value").Value);

                return(LeakyReLU(leakynessFactor, zeroIsPositive));
            }

            if (root.GetAttribute("Name").Value == "SoftPlus")
            {
                XMLElement customDataXE = root.ChildWithTag("CustomData");
                float      steepness    = int.Parse(customDataXE.ChildWithTag("steepness").GetAttribute("Value").Value);

                return(SoftPlus(steepness));
            }

            if (root.GetAttribute("Name").Value == "SoftMax")
            {
                XMLElement customDataXE = root.ChildWithTag("CustomData");
                float      steepness    = int.Parse(customDataXE.ChildWithTag("steepness").GetAttribute("Value").Value);

                return(SoftMax(steepness));
            }

            throw new NotImplementedException();    // Never reached
        }
Exemplo n.º 23
0
        internal override XMLElement ToXML()
        {
            XMLElement e = XMLElement.Create(GetType().Name);

            e.AddAttribute("Width", $"{Width}");
            e.AddAttribute("Height", $"{Height}");
            e.AddAttribute("Depth", $"{Depth}");
            return(e);
        }
Exemplo n.º 24
0
    //////////////////////////////////////////
    /// SetUpData()
    //////////////////////////////////////////
    public static void SetUpData()
    {
        m_dictData = new Dictionary <string, ID_Audio>();

        //Load all data xml files
        UnityEngine.Object[] files = Resources.LoadAll("Audio", typeof(TextAsset));
        foreach (TextAsset file in files)
        {
            string xmlString = file.text;

            // error message
            string strErrorFile = "Error in file " + file.name;

            //Create XMLParser instance
            XMLParser xmlParser = new XMLParser(xmlString);

            //Call the parser to build the IXMLNode objects
            XMLElement xmlElement = xmlParser.Parse();

            // this will load files that have replaced the file stored in data locally
                        #if UNITY_STANDALONE_WIN
            string strFile = Application.dataPath + "/Resources/" + file.name + ".xml";
            if (System.IO.File.Exists(strFile))
            {
                Debug.Log("An override audio file was found: " + strFile);
                xmlString = System.IO.File.ReadAllText(strFile);
            }
                        #endif

            //Go through all child node of xmlElement (the parent of the file)
            for (int i = 0; i < xmlElement.Children.Count; i++)
            {
                IXMLNode childNode = xmlElement.Children[i];

                // Get list of children elements
                List <IXMLNode> listChildren = XMLUtils.GetChildrenList(childNode);

                //Get id
                Hashtable hashAttr = XMLUtils.GetAttributes(childNode);
                string    strID    = (string)hashAttr["ID"];
                string    strError = strErrorFile + "(" + strID + "): ";

                ID_Audio data = new ID_Audio(strID, hashAttr, listChildren, strError);

                // store the data
                if (m_dictData.ContainsKey(strID))
                {
                    Debug.LogError(strError + "Duplicate audio data!");
                }
                else
                {
                    // add data to dictionary
                    m_dictData.Add(strID, data);
                }
            }
        }
    }
Exemplo n.º 25
0
 /// <summary>
 /// Handles end tags.
 /// </summary>
 /// <param name='tagName'>
 /// Tag name.
 /// </param>
 protected virtual void EndElementHandler(string tagName)
 {
     if (rootflag)
     {
         if (rootElement != currentElement)
         {
             currentElement = (XMLElement)currentElement.Parent;
         }
     }
 }
Exemplo n.º 26
0
        public void SelectInt_WithPathToNonInt_ThrowsFormatException()
        {
            string xml =
                $@"<testElement>dsasdsa</testElement>";
            string path = "/";

            XMLElement element = new XMLElement(XElement.Parse(xml));

            Assert.Throws <FormatException>(() => element.SelectInt(path));
        }
Exemplo n.º 27
0
        public void SelectString_WithPathToNonExistentItem_ThrowsNullReferenceException()
        {
            string xml =
                $@"<testElement>123</testElement>";
            string path = "nonExistent";

            XMLElement element = new XMLElement(XElement.Parse(xml));

            Assert.Throws <NullReferenceException>(() => element.SelectString(path));
        }
Exemplo n.º 28
0
    // Initializing the data from XML
    private static void SetupData()
    {
        if (bombList != null || triggerList != null)
        {
            Debug.LogError("Ninja object data already initialized!");
        }
        else
        {
            triggerList = new ArrayList();
            bombList    = new ArrayList();
            powUpList   = new ArrayList();

            TextAsset file      = Resources.Load("Ninja/NinjaTriggersAndBombs", typeof(TextAsset)) as TextAsset;
            string    xmlString = file.text;

            //Create XMLParser instance
            XMLParser xmlParser = new XMLParser(xmlString);

            //Call the parser to build the IXMLNode objects
            XMLElement xmlElement = xmlParser.Parse();

            foreach (IXMLNode childNode in xmlElement.Children)
            {
                // Dont need ID for anything...
//				Hashtable hashAttr = XMLUtils.GetAttributes(childNode);
//				string id = (string) hashAttr["ID"];

                //Get trigger properties from xml node
                Hashtable hashTriggerData = XMLUtils.GetChildren(childNode);

                // Add to trigger list if type is trigger
                if (XMLUtils.GetString(hashTriggerData["Type"] as IXMLNode).Equals("Trigger"))
                {
                    triggerList.Add(XMLUtils.GetString(hashTriggerData["PrefabString"] as IXMLNode));
                    numTriggers++;
                }
                // Add to bomb list if type is bomb
                else if (XMLUtils.GetString(hashTriggerData["Type"] as IXMLNode).Equals("Bomb"))
                {
                    bombList.Add(XMLUtils.GetString(hashTriggerData["PrefabString"] as IXMLNode));
                    numBombs++;
                }
                // Add to bomb list if type is powUp
                else if (XMLUtils.GetString(hashTriggerData["Type"] as IXMLNode).Equals("PowerUp"))
                {
                    powUpList.Add(XMLUtils.GetString(hashTriggerData["PrefabString"] as IXMLNode));
                    numPowUps++;
                }
                else
                {
                    Debug.LogError("Unknown ID inside NinjaTriggersAndBombs");
                }
            }
        }
    }
Exemplo n.º 29
0
    public static void SetupData()
    {
        hashData = new Hashtable();

        //Load all data xml files
        UnityEngine.Object[] files = Resources.LoadAll("Ninja/Modes", typeof(TextAsset));
        foreach (TextAsset file in files)
        {
            string xmlString = file.text;

            // error message
            string strErrorFile = "Error in file " + file.name;

            //Create XMLParser instance
            XMLParser xmlParser = new XMLParser(xmlString);

            //Call the parser to build the IXMLNode objects
            XMLElement xmlElement = xmlParser.Parse();

            // we store the data per mode of the ninja game.  the name of the file is the mode.
            NinjaModes eMode = (NinjaModes)System.Enum.Parse(typeof(NinjaModes), file.name);
            hashData[eMode] = new Hashtable();
            Hashtable hashMode = (Hashtable)hashData[eMode];

            //Go through all child node of xmlElement (the parent of the file)
            for (int i = 0; i < xmlElement.Children.Count; i++)
            {
                IXMLNode childNode = xmlElement.Children[i];

                // Get id
                Hashtable hashAttr = XMLUtils.GetAttributes(childNode);
                string    id       = (string)hashAttr["ID"];
                string    strError = strErrorFile + "(" + id + "): ";

                NinjaData data = new NinjaData(id, hashAttr, childNode, strError);

                // we want to stuff the data in each of its scoring categories
                List <NinjaScoring> listScoring = data.GetScoringCategories();
                for (int j = 0; j < listScoring.Count; ++j)
                {
                    NinjaScoring eScoring = listScoring[j];

                    // if the mode doesn't contain this scoring key yet, add it
                    if (!hashMode.ContainsKey(eScoring))
                    {
                        hashMode[eScoring] = new List <NinjaData>();
                    }

                    // add the data to the list of data for this mode/scoring key
                    List <NinjaData> listData = (List <NinjaData>)hashMode[eScoring];
                    listData.Add(data);
                }
            }
        }
    }
Exemplo n.º 30
0
            public XMLElement GetNextSibling(XMLElement element)
            {
                int index = m_Childs.IndexOf(element);

                if ((index == -1) ||
                    (index + 1 >= m_Childs.Count))
                {
                    return(null);
                }
                return(m_Childs[index + 1]);
            }
Exemplo n.º 31
0
	/// <summary>
	/// Handles opening tags.
	/// </summary>
	/// <param name='tagName'>
	/// Tag name.
	/// </param>
	protected virtual void StartElementHandler (string tagName)
	{
		
		// placeholder for new element.
		XMLElement newElement; // no assignment is bad form but necessary
		
		if (!rootflag) { // need to setup root element...
			newElement = new XMLElement (tagName.Trim(), null);
			rootElement = newElement;
			rootflag = true;
		} else { // standard new element creations...
			newElement = new XMLElement (tagName.Trim(), currentElement);
		}
		
		// Add attributes we've encounted thus far
		int i = 0;
		int attributeCount = attributeList.Count;
		while (i < attributeCount) {
			newElement.Attributes.Add (attributeList[i]);
			i++;
		}
		
		// clear saved attribute list
		attributeList = new List<XMLAttribute> ();
		
		// advance current element
		currentElement = newElement;
		
	}
Exemplo n.º 32
0
 /// Prepend a child element with the specified name.
 public XMLElement prepend_copy(XMLElement e)
 {
     return new XMLElement(dll.lsl_prepend_copy(obj, e.obj));
 }
Exemplo n.º 33
0
		public XMLDocument(string header_0, XMLElement root_1) {
			this.header = header_0;
			this.root = root_1;
		}
Exemplo n.º 34
0
 internal void  addSibling(XMLElement elem)
 {
     if (siblings == null)
     {
         siblings = new Dictionary<string,XMLElement>();
     }
     XMLElement head;
     if (siblings.TryGetValue(elem.name, out head))
     {
         elem.next = null;
         elem.prev = head.prev;
         head.prev.next = elem;
         head.prev = elem;
         head.counter += 1;
     }
     else
     {
         elem.prev = elem;
         siblings[elem.name] = elem;
         elem.counter = 1;
     }
 }
Exemplo n.º 35
0
        internal XMLElement ReadElement(string name)
        {
            XMLElement elem = new XMLElement(name);
            string attribute;
            int tkn;
            while (true)
            {
                switch (scanner.Scan())
                {
                    case XMLScanner.XML_GTS:
                        return elem;

                    case XMLScanner.XML_GT:
                        while ((tkn = scanner.Scan()) == XMLScanner.XML_LT)
                        {
                            if (scanner.Scan() != XMLScanner.XML_IDENT)
                            {
                                ThrowException("Element name expected");
                            }
                            string siblingName = scanner.Identifier;
                            XMLElement sibling = ReadElement(siblingName);
                            elem.AddSibling(sibling);
                        }
                        switch (tkn)
                        {
                            case XMLScanner.XML_SCONST:
                                elem.SetStringValue(scanner.String);
                                tkn = scanner.Scan();
                                break;

                            case XMLScanner.XML_ICONST:
                                elem.SetIntValue(scanner.Int);
                                tkn = scanner.Scan();
                                break;

                            case XMLScanner.XML_FCONST:
                                elem.SetRealValue(scanner.Real);
                                tkn = scanner.Scan();
                                break;

                            case XMLScanner.XML_IDENT:
                                if (scanner.Identifier.Equals("null"))
                                {
                                    elem.SetNullValue();
                                }
                                else
                                {
                                    elem.SetStringValue(scanner.Identifier);
                                }
                                tkn = scanner.Scan();
                                break;
                            }
                        if (tkn != XMLScanner.XML_LTS || scanner.Scan() != XMLScanner.XML_IDENT || !scanner.Identifier.Equals(name) || scanner.Scan() != XMLScanner.XML_GT)
                        {
                            ThrowException("Element is not closed");
                        }
                        return elem;

                    case XMLScanner.XML_IDENT:
                        attribute = scanner.Identifier;
                        if (scanner.Scan() != XMLScanner.XML_EQ || scanner.Scan() != XMLScanner.XML_SCONST)
                        {
                            ThrowException("Attribute value expected");
                        }
                        elem.AddAttribute(attribute, scanner.String);
                        continue;

                    default:
                        ThrowException("Unexpected token");
                        break;
                }
            }
        }
Exemplo n.º 36
0
        internal XMLElement readElement(System.String name)
        {
            XMLElement elem = new XMLElement(name);
            System.String attribute;
            XMLScanner.Token tkn;
            while (true)
            {
                switch (scanner.scan())
                {
                    case XMLScanner.Token.GTS:
                        return elem;

                    case XMLScanner.Token.GT:
                        while ((tkn = scanner.scan()) == XMLScanner.Token.LT)
                        {
                            if (scanner.scan() != XMLScanner.Token.IDENT)
                            {
                                throwException("Element name expected");
                            }
                            System.String siblingName = scanner.Identifier;
                            XMLElement sibling = readElement(siblingName);
                            elem.addSibling(sibling);
                        }
                        switch (tkn)
                        {
                            case XMLScanner.Token.SCONST:
                                elem.StringValue = scanner.String;
                                tkn = scanner.scan();
                                break;

                            case XMLScanner.Token.ICONST:
                                elem.IntValue = scanner.Int;
                                tkn = scanner.scan();
                                break;

                            case XMLScanner.Token.FCONST:
                                elem.RealValue = scanner.Real;
                                tkn = scanner.scan();
                                break;

                            case XMLScanner.Token.IDENT:
                                if (scanner.Identifier.Equals("null"))
                                {
                                    elem.setNullValue();
                                }
                                else
                                {
                                    elem.StringValue = scanner.Identifier;
                                }
                                tkn = scanner.scan();
                                break;

                        }
                        if (tkn != XMLScanner.Token.LTS || scanner.scan() != XMLScanner.Token.IDENT || !scanner.Identifier.Equals(name) || scanner.scan() != XMLScanner.Token.GT)
                        {
                            throwException("Element is not closed");
                        }
                        return elem;

                    case XMLScanner.Token.IDENT:
                        attribute = scanner.Identifier;
                        if (scanner.scan() != XMLScanner.Token.EQ || scanner.scan() != XMLScanner.Token.SCONST)
                        {
                            throwException("Attribute value expected");
                        }
                        elem.addAttribute(attribute, scanner.String);
                        continue;

                    default:
                        throwException("Unexpected token");
                        break;

                }
            }
        }
Exemplo n.º 37
0
        internal void CreateObject(XMLElement elem)
        {
            Type cls = ClassDescriptor.LoadClass(storage, elem.name);
            ClassDescriptor desc = storage.GetClassDescriptor(cls);
            int oid = MapId(GetIntAttribute(elem, "id"));
            ByteBuffer buf = new ByteBuffer();
            int offs = ObjectHeader.Sizeof;
            buf.Extend(offs);

            offs = PackObject(elem, desc, offs, buf);

            ObjectHeader.SetSize(buf.arr, 0, offs);
            ObjectHeader.SetType(buf.arr, 0, desc.Oid);

            long pos = storage.Allocate(offs, 0);
            storage.SetPos(oid, pos | StorageImpl.dbModifiedFlag);
            storage.pool.Put(pos, buf.arr, offs);
        }
Exemplo n.º 38
0
    //セルアウトリベートのItem解析
    private void AnalyzeSelloutRebateItem(XMLElement element, ref KiwiDemandInformation dInfo, ref string targetCategory, ref string targetCode, ref string targetName, ref string targetPrice, ref string Period, ref string BeginningMonth, ref string Adjustment, ref string AdjustmentMethod, ref string StartDay, ref string EndDay, ref string ProcessingCategory, ref string Maker, ref string MakerName, List<string> lstLine)
    {
        XMLAttribute attribute = (XMLAttribute)element.arrayAttributes[0];

        switch (attribute.Value)
        {
            case "所属":
                dInfo.Division = ((XMLAttribute)element.arrayAttributes[1]).Value;
                break;

            case "処理区分":
                ProcessingCategory = ((XMLAttribute)element.arrayAttributes[1]).Value;
                break;

            case "対象区分":
                targetCategory = ((XMLAttribute)element.arrayAttributes[1]).Value;
                targetCategory = targetCategory.Replace("得意先", "T");
                targetCategory = targetCategory.Replace("請求先", "G");
                targetCategory = targetCategory.Replace("入金親", "O");
                targetCategory = targetCategory.Replace("団体", "D");
                break;

            case "対象コード":
                targetCode = ((XMLAttribute)element.arrayAttributes[1]).Value;
                break;

            case "対象名称":
                targetName = ((XMLAttribute)element.arrayAttributes[1]).Value;
                break;

            case "対象金額":
                targetPrice = ((XMLAttribute)element.arrayAttributes[1]).Value;
                targetPrice = targetPrice.Replace("仕入価", "1");
                targetPrice = targetPrice.Replace("サロン価", "2");
                break;

            case "精算方法":
                AdjustmentMethod = ((XMLAttribute)element.arrayAttributes[1]).Value;
                AdjustmentMethod = AdjustmentMethod.Replace("現金", "0");
                AdjustmentMethod = AdjustmentMethod.Replace("商品", "1");
                break;

            case "精算期間":
                Period = ((XMLAttribute)element.arrayAttributes[1]).Value;
                Period = Period.Replace("毎月", "0");
                Period = Period.Replace("四半期", "1");
                Period = Period.Replace("半期", "2");
                Period = Period.Replace("通期", "3");
                break;

            case "計算期初月":
                BeginningMonth = ((XMLAttribute)element.arrayAttributes[1]).Value;
                BeginningMonth = BeginningMonth.Replace(" 月", string.Empty);
                break;

            case "メーカー精算条件番号":
                Adjustment = ((XMLAttribute)element.arrayAttributes[1]).Value;
                break;

            case "開始日付":
                StartDay = ((XMLAttribute)element.arrayAttributes[1]).Value;
                StartDay = StartDay.Replace("年 ", "/");
                StartDay = StartDay.Replace("月 ", "/");
                StartDay = StartDay.Replace("日", string.Empty);
                break;

            case "打切日付":
                EndDay = ((XMLAttribute)element.arrayAttributes[1]).Value;
                EndDay = EndDay.Replace("年 ", "/");
                EndDay = EndDay.Replace("月 ", "/");
                EndDay = EndDay.Replace("日", string.Empty);
                break;

            case "メーカーコード":
                Maker = ((XMLAttribute)element.arrayAttributes[1]).Value;
                break;

            case "メーカー名":
                MakerName = ((XMLAttribute)element.arrayAttributes[1]).Value;
                break;

            case "条件1":
            case "条件2":
            case "条件3":
            case "条件4":
            case "条件5":
            case "条件6":
            case "条件7":
            case "条件8":
            case "条件9":
            case "条件10":
                string strCondition = ((XMLAttribute)element.arrayAttributes[1]).Value;
                strCondition = strCondition.Replace("メーカー", "メーカー,");
                strCondition = strCondition.Replace("ブランド", "ブランド,");
                strCondition = strCondition.Replace("ラインアップ", "ラインアップ,");
                strCondition = strCondition.Replace("商品", "商品,");
                strCondition = strCondition.Replace(" ,", ",");
                strCondition = strCondition.Replace(", ", ",");


                lstLine.Add(dInfo.DemandNumber + "," + dInfo.DemandDate + "," + dInfo.Division + "," + dInfo.Operator + "," + ProcessingCategory + "," + targetCategory + "," + targetCode + "," + targetName + "," + targetPrice + "," + Period + "," + BeginningMonth + "," + AdjustmentMethod + "," + Adjustment + "," + StartDay + "," + EndDay + "," + Maker + "," + MakerName + "," + strCondition);
                break;
        }
    }
Exemplo n.º 39
0
    //担当変更のItem解析
    private void AnalyzeChangeOfPersonItem(XMLElement element, ref KiwiDemandInformation dInfo, ref string ChangeDay, List<string> lstLine)
    {
        XMLAttribute attribute = (XMLAttribute)element.arrayAttributes[0];

        switch (attribute.Value)
        {
            case "所属":
                dInfo.Division = ((XMLAttribute)element.arrayAttributes[1]).Value;
                break;

            case "変更日付":
                ChangeDay = ((XMLAttribute)element.arrayAttributes[1]).Value;
                break;

            case "1":
            case "2":
            case "3":
            case "4":
            case "5":
            case "6":
            case "7":
            case "8":
            case "9":
            case "10":
                lstLine.Add(dInfo.DemandNumber + "," + dInfo.DemandDate + "," + dInfo.Operator + "," + dInfo.Division + "," + ChangeDay + "," + ((XMLAttribute)element.arrayAttributes[1]).Value);
                break;
        }
    }
Exemplo n.º 40
0
    //サロンリベートのItem解析
    private void AnalyzeSalonRebateItem(XMLElement element, ref KiwiDemandInformation dInfo, ref string targetCategory, ref string targetCode, ref string targetName, ref string targetPrice, ref string Period, ref string BeginningMonth, ref string Adjustment, ref string AdjustmentMethod, ref string AdjustmentCode, ref string StartDay, ref string EndDay, ref string ProcessingCategory, ref string NewAdjustment, ref string PaymentMonth, ref string PaymentDay, List<string> lstLine) //追加抽出項目を追加する
    {
        XMLAttribute attribute = (XMLAttribute)element.arrayAttributes[0];

        switch (attribute.Value)
        {
            case "所属":
                dInfo.Division = ((XMLAttribute)element.arrayAttributes[1]).Value;
                break;

            case "処理区分":
                ProcessingCategory = ((XMLAttribute)element.arrayAttributes[1]).Value;
                break;

            case "対象区分":
                targetCategory = ((XMLAttribute)element.arrayAttributes[1]).Value;
                targetCategory = targetCategory.Replace("得意先", "T");
                targetCategory = targetCategory.Replace("請求先", "G");
                targetCategory = targetCategory.Replace("入金親", "O");
                targetCategory = targetCategory.Replace("団体", "D");
                break;

            case "対象コード":
                targetCode = ((XMLAttribute)element.arrayAttributes[1]).Value;
                break;

            case "対象名称":
                targetName = ((XMLAttribute)element.arrayAttributes[1]).Value;
                break;

            case "対象金額":
                targetPrice = ((XMLAttribute)element.arrayAttributes[1]).Value;
                targetPrice = targetPrice.Replace("値引後", "1");
                targetPrice = targetPrice.Replace("値引前", "2");
                break;

            case "精算方法":
                AdjustmentMethod = ((XMLAttribute)element.arrayAttributes[1]).Value;
                AdjustmentMethod = AdjustmentMethod.Replace("現金", "0");
                AdjustmentMethod = AdjustmentMethod.Replace("商品", "1");
                break;

            case "精算区分":
                AdjustmentCode = ((XMLAttribute)element.arrayAttributes[1]).Value;
                AdjustmentCode = AdjustmentCode.Replace("月次締", "0");
                AdjustmentCode = AdjustmentCode.Replace("請求締", "1");
                break;

            case "精算期間":
                Period = ((XMLAttribute)element.arrayAttributes[1]).Value;
                Period = Period.Replace("毎月", "0");
                Period = Period.Replace("四半期", "1");
                Period = Period.Replace("半期", "2");
                Period = Period.Replace("通期", "3");
                break;

            case "計算期初月":
                BeginningMonth = ((XMLAttribute)element.arrayAttributes[1]).Value;
                BeginningMonth = BeginningMonth.Replace(" 月", string.Empty);
                break;

            //2015年2月 追加項目"お支払予定日(月ずれ)"
            case "お支払予定日(月ずれ)":
                PaymentMonth = ((XMLAttribute)element.arrayAttributes[1]).Value;
                PaymentMonth = PaymentMonth.Replace("翌月", "1");
                PaymentMonth = PaymentMonth.Replace("翌々月", "2");
                PaymentMonth = PaymentMonth.Replace("3か月後", "3"); //
                break;

            //2015年2月 追加項目"お支払予定日"
            case "お支払予定日":
                PaymentDay = ((XMLAttribute)element.arrayAttributes[1]).Value;
                PaymentDay = PaymentDay.Replace("10 ", "10");
                PaymentDay = PaymentDay.Replace("20 ", "20");
                PaymentDay = PaymentDay.Replace("末 ", "99");
                PaymentDay = PaymentDay.Replace("日払い", string.Empty);
                break;

            //2015年2月 追加項目"リベート精算条件"
            case "リベート精算条件":
                NewAdjustment = ((XMLAttribute)element.arrayAttributes[1]).Value;
                NewAdjustment = NewAdjustment.Replace("新規登録した精算条件番号を設定する", "0");
                NewAdjustment = NewAdjustment.Replace("既に登録されている精算条件番号を設定する", "1");
                break;

            case "リベート精算条件番号":
                Adjustment = ((XMLAttribute)element.arrayAttributes[1]).Value;
                break;

            case "開始日付":
                StartDay = ((XMLAttribute)element.arrayAttributes[1]).Value;
                StartDay = StartDay.Replace("年 ", "/");
                StartDay = StartDay.Replace("月 ", "/");
                StartDay = StartDay.Replace("日", string.Empty);
                break;

            case "打切日付":
                EndDay = ((XMLAttribute)element.arrayAttributes[1]).Value;
                EndDay = EndDay.Replace("年 ", "/");
                EndDay = EndDay.Replace("月 ", "/");
                EndDay = EndDay.Replace("日", string.Empty);
                break;


            case "条件1":
            case "条件2":
            case "条件3":
            case "条件4":
            case "条件5":
            case "条件6":
            case "条件7":
            case "条件8":
            case "条件9":
            case "条件10":
                string strCondition = ((XMLAttribute)element.arrayAttributes[1]).Value;
                strCondition = strCondition.Replace("売上種別", "0");
                strCondition = strCondition.Replace("メーカー", "1");
                strCondition = strCondition.Replace("ブランド", "2");
                strCondition = strCondition.Replace("ラインアップ", "3");
                strCondition = strCondition.Replace("商品", "4");
                strCondition = strCondition.Replace("総合計", "5");
                strCondition = strCondition.Replace("含む", "1");
                strCondition = strCondition.Replace("含まない", "0");
                strCondition = strCondition.Replace(" ,", ",");
                strCondition = strCondition.Replace(", ", ",");

                lstLine.Add(dInfo.DemandNumber + "," + dInfo.DemandDate + "," + dInfo.Division + "," + dInfo.Operator + "," + ProcessingCategory + "," + targetCategory + "," + targetCode + "," + targetName + "," + targetPrice + "," + Period + "," + BeginningMonth + "," + AdjustmentMethod + "," + AdjustmentCode + "," + Adjustment + "," + StartDay + "," + EndDay + ",1," + NewAdjustment + "," + PaymentMonth + "," + PaymentDay + "," + strCondition); //追加抽出項目を追加する
                break;
        }
    }
Exemplo n.º 41
0
    //値引申請のItem解析
    private void AnalyzeDiscountItem(XMLElement element, ref KiwiDemandInformation dInfo, ref string targetCategory, ref string targetCode, ref string Category, ref string ProcessingCategory, List<string> lstLine)
    {
        XMLAttribute attribute = (XMLAttribute)element.arrayAttributes[0];

        switch (attribute.Value)
        {
            case "所属":
                dInfo.Division = ((XMLAttribute)element.arrayAttributes[1]).Value;
                break;

            case "処理区分":
                ProcessingCategory = ((XMLAttribute)element.arrayAttributes[1]).Value;
                break;

            case "対象区分":
                targetCategory = ((XMLAttribute)element.arrayAttributes[1]).Value;
                targetCategory = targetCategory.Replace("得意先", "1");
                targetCategory = targetCategory.Replace("請求先", "2");
                targetCategory = targetCategory.Replace("入金親", "3");
                break;

            case "対象コード":
                targetCode = ((XMLAttribute)element.arrayAttributes[1]).Value;
                break;

            case "管理種別":
                Category = ((XMLAttribute)element.arrayAttributes[1]).Value;
                Category = Category.Replace("商品", "1");
                Category = Category.Replace("ラインアップ", "2");
                Category = Category.Replace("ブランド", "3");
                Category = Category.Replace("メーカー", "4");
                Category = Category.Replace("売上種別", "5");
                break;

            case "条件1":
            case "条件2":
            case "条件3":
            case "条件4":
            case "条件5":
            case "条件6":
            case "条件7":
            case "条件8":
            case "条件9":
            case "条件10":
                lstLine.Add(dInfo.DemandNumber + "," + dInfo.DemandDate + "," + dInfo.Operator + "," + dInfo.Division + "," + ProcessingCategory + "," + targetCategory + "," + targetCode + "," + Category + "," + ((XMLAttribute)element.arrayAttributes[1]).Value);
                break;
        }
    }
Exemplo n.º 42
0
	/// <summary>
	/// Handles end tags.
	/// </summary>
	/// <param name='tagName'>
	/// Tag name.
	/// </param>
	protected virtual void EndElementHandler (string tagName)
	{
		if (rootflag) {
			if (rootElement != currentElement) {
				currentElement = (XMLElement)currentElement.Parent;
			}
		}
	}
Exemplo n.º 43
0
 internal int GetIntAttribute(XMLElement elem, string name)
 {
     string val = elem.GetAttribute(name);
     if (val == null)
     {
         ThrowException("Attribute " + name + " is not set");
     }
     try
     {
         return Int32.Parse(val);
     }
     catch (FormatException)
     {
         ThrowException("Attribute " + name + " should has integer value");
     }
     return -1;
 }
Exemplo n.º 44
0
 internal void addSibling(XMLElement elem)
 {
     if (siblings == null)
     {
         siblings = new Hashtable();
     }
     XMLElement head = (XMLElement)siblings[elem.name];
     if (head != null)
     {
         elem.next = null;
         elem.prev = head.prev;
         head.prev.next = elem;
         head.prev = elem;
         head.counter += 1;
     }
     else
     {
         elem.prev = elem;
         siblings[elem.name] = elem;
         elem.counter = 1;
     }
 }
Exemplo n.º 45
0
 internal string GetAttribute(XMLElement elem, string name)
 {
     string val = elem.GetAttribute(name);
     if (val == null)
     {
         ThrowException("Attribute " + name + " is not set");
     }
     return val;
 }
Exemplo n.º 46
0
        internal void createObject(XMLElement elem)
        {
            ClassDescriptor desc = db.getClassDescriptor(findClassByName(elem.Name));
            int oid = mapId(getIntAttribute(elem, "id"));
            ByteBuffer buf = new ByteBuffer();
            int offs = ObjectHeader.Sizeof;
            buf.extend(offs);

            offs = packObject(elem, desc, offs, buf);

            ObjectHeader.setSize(buf.arr, 0, offs);
            ObjectHeader.setType(buf.arr, 0, desc.Oid);

            long pos = db.allocate(offs, 0);
            db.setPos(oid, pos | DatabaseImpl.dbModifiedFlag);
            db.pool.put(pos, buf.arr, offs);
        }
Exemplo n.º 47
0
 internal void AddSibling(XMLElement elem)
 {
     if (siblings == null)
     {
         //UPGRADE_TODO: Class 'java.util.HashMap' was converted to 'System.Collections.Hashtable' which has a different behavior.
         siblings = new System.Collections.Hashtable();
     }
     //UPGRADE_TODO: Method 'java.util.HashMap.get' was converted to 'System.Collections.Hashtable.Item' which has a different behavior.
     XMLElement prev = (XMLElement) siblings[elem.name];
     if (prev != null)
     {
         elem.next = null;
         elem.prev = prev.prev;
         elem.prev.next = elem;
         prev.prev = elem;
         prev.counter += 1;
     }
     else
     {
         siblings[elem.name] = elem;
         elem.prev = elem;
         elem.counter = 1;
     }
 }
Exemplo n.º 48
0
 internal System.String getAttribute(XMLElement elem, String name)
 {
     System.String val = elem.getAttribute(name);
     if (val == null)
     {
         throwException("Attribute " + name + " is not set");
     }
     return val;
 }
Exemplo n.º 49
0
        internal int packObject(XMLElement objElem, ClassDescriptor desc, int offs, ByteBuffer buf)
        {
            ClassDescriptor.FieldDescriptor[] flds = desc.allFields;
            for (int i = 0, n = flds.Length; i < n; i++)
            {
                ClassDescriptor.FieldDescriptor fd = flds[i];
                FieldInfo f = fd.field;
                String fieldName = fd.fieldName;
                XMLElement elem = (objElem != null)?objElem.getSibling(fieldName):null;
                ClassDescriptor.FieldType type = fd.type;				
                switch (fd.type)
                {
#if NET_FRAMEWORK_20
                    case ClassDescriptor.FieldType.tpNullableByte: 
                    case ClassDescriptor.FieldType.tpNullableSByte: 
                        if (elem != null)
                        {
                            if (elem.isIntValue())
                            {
                                buf.extend(offs + 2);
                                buf.arr[offs++] = (byte) 1;
                                buf.arr[offs++] = (byte) elem.IntValue;
                            }
                            else if (elem.isRealValue())
                            {
                                buf.extend(offs + 2);
                                buf.arr[offs++] = (byte) 1;
                                buf.arr[offs++] = (byte) elem.RealValue;
                            }
                            else if (elem.isNullValue())
                            {
                                buf.extend(offs + 1);
                                buf.arr[offs++] = (byte) 0;
                            }
                            else
                            {
                                throwException("Conversion for field " + fieldName + " is not possible");
                            }
                        } 
                        else 
                        {
                            buf.extend(offs + 1);
                            buf.arr[offs++] = (byte) 0;
                        }
                        continue;
					
                    case ClassDescriptor.FieldType.tpNullableBoolean: 
                        if (elem != null)
                        {
                            if (elem.isIntValue())
                            {
                                buf.extend(offs + 2);
                                buf.arr[offs++] = (byte) 1;
                                buf.arr[offs++] = (byte) (elem.IntValue != 0?1:0);
                            }
                            else if (elem.isRealValue())
                            {
                                buf.extend(offs + 2);
                                buf.arr[offs++] = (byte) 1;
                                buf.arr[offs++] = (byte) (elem.RealValue != 0.0?1:0);
                            }
                            else if (elem.isNullValue())
                            {
                                buf.extend(offs + 1);
                                buf.arr[offs++] = (byte) 0;
                            }
                            else
                            {
                                throwException("Conversion for field " + fieldName + " is not possible");
                            }
                        } 
                        else 
                        {
                            buf.extend(offs + 1);
                            buf.arr[offs++] = (byte) 0;
                        }
                        continue;
					
                    case ClassDescriptor.FieldType.tpNullableShort: 
                    case ClassDescriptor.FieldType.tpNullableUShort: 
                    case ClassDescriptor.FieldType.tpNullableChar: 
                        if (elem != null)
                        {
                            if (elem.isIntValue())
                            {
                                buf.extend(offs + 3);
                                buf.arr[offs++] = (byte) 1;
                                Bytes.pack2(buf.arr, offs, (short) elem.IntValue);
                                offs += 2;
                            }
                            else if (elem.isRealValue())
                            {
                                buf.extend(offs + 3);
                                buf.arr[offs++] = (byte) 1;
                                Bytes.pack2(buf.arr, offs, (short) elem.RealValue);
                                offs += 2;
                            }
                            else if (elem.isNullValue())
                            {
                                buf.extend(offs + 1);
                                buf.arr[offs++] = (byte) 0;
                            }
                            else
                            {
                                throwException("Conversion for field " + fieldName + " is not possible");
                            }
                        } 
                        else 
                        {
                            buf.extend(offs + 1);
                            buf.arr[offs++] = (byte) 0;
                        }
                        continue;
					
                    case ClassDescriptor.FieldType.tpNullableEnum: 
                        if (elem != null)
                        {
                            if (elem.isIntValue())
                            {
                                buf.extend(offs + 5);
                                buf.arr[offs++] = (byte) 1;
                                Bytes.pack4(buf.arr, offs, (int) elem.IntValue);        
                                offs += 4;
                            }
                            else if (elem.isRealValue())
                            {
                                buf.extend(offs + 5);
                                buf.arr[offs++] = (byte) 1;
                                Bytes.pack4(buf.arr, offs, (int) elem.RealValue);
                                offs += 4;
                            }
                            else if (elem.isStringValue()) 
                            {
                                try 
                                {
                                    buf.extend(offs + 5);
                                    buf.arr[offs++] = (byte) 1;
                                    Bytes.pack4(buf.arr, offs, (int)ClassDescriptor.parseEnum(f.FieldType, elem.StringValue));
                                } 
                                catch (ArgumentException)
                                {
                                    throwException("Invalid enum value");
                                }
                            }
                            else if (elem.isNullValue())
                            {
                                buf.extend(offs + 1);
                                buf.arr[offs++] = (byte) 0;
                            }
                            else
                            {
                                throwException("Conversion for field " + fieldName + " is not possible");
                            }
                        }
                        else 
                        {
                            buf.extend(offs + 1);
                            buf.arr[offs++] = (byte) 0;
                        }
                        continue;
					

                    case ClassDescriptor.FieldType.tpNullableInt: 
                    case ClassDescriptor.FieldType.tpNullableUInt: 
                        if (elem != null)
                        {
                            if (elem.isIntValue())
                            {
                                buf.extend(offs + 5);
                                buf.arr[offs++] = (byte) 1;
                                Bytes.pack4(buf.arr, offs, (int) elem.IntValue);
                                offs += 4;
                            }
                            else if (elem.isRealValue())
                            {
                                buf.extend(offs + 5);
                                buf.arr[offs++] = (byte) 1;
                                Bytes.pack4(buf.arr, offs, (int) elem.RealValue);
                                offs += 4;
                            }
                            else if (elem.isNullValue())
                            {
                                buf.extend(offs + 1);
                                buf.arr[offs++] = (byte) 0;
                            }
                            else
                            {
                                throwException("Conversion for field " + fieldName + " is not possible");
                            }
                        }
                        else 
                        {
                            buf.extend(offs + 1);
                            buf.arr[offs++] = (byte) 0;
                        }
                        continue;
					
                    case ClassDescriptor.FieldType.tpNullableLong: 
                    case ClassDescriptor.FieldType.tpNullableULong: 
                        if (elem != null)
                        {
                            if (elem.isIntValue())
                            {
                                buf.extend(offs + 9);
                                buf.arr[offs++] = (byte) 1;
                                Bytes.pack8(buf.arr, offs, elem.IntValue);
                                offs += 9;
                            }
                            else if (elem.isRealValue())
                            {
                                buf.extend(offs + 9);
                                buf.arr[offs++] = (byte) 1;
                                Bytes.pack8(buf.arr, offs, (long) elem.RealValue);
                                offs += 9;
                            }
                            else if (elem.isNullValue())
                            {
                                buf.extend(offs + 1);
                                buf.arr[offs++] = (byte) 0;
                            }
                            else
                            {
                                throwException("Conversion for field " + fieldName + " is not possible");
                            }
                        }
                        else 
                        {
                            buf.extend(offs + 1);
                            buf.arr[offs++] = (byte) 0;
                        }
                        continue;
					
                    case ClassDescriptor.FieldType.tpNullableFloat: 
                        if (elem != null)
                        {
                            if (elem.isIntValue())
                            {
                                buf.extend(offs + 5);
                                buf.arr[offs++] = (byte) 1;
                                Bytes.packF4(buf.arr, offs, (float)elem.IntValue);
                                offs += 4;
                            }
                            else if (elem.isRealValue())
                            {
                                buf.extend(offs + 5);
                                buf.arr[offs++] = (byte) 1;
                                Bytes.packF4(buf.arr, offs, (float) elem.RealValue);
                                offs += 4;
                            }
                            else if (elem.isNullValue())
                            {
                                buf.extend(offs + 1);
                                buf.arr[offs++] = (byte) 0;
                            }
                            else
                            {
                                throwException("Conversion for field " + fieldName + " is not possible");
                            }
                        }
                        else 
                        {
                            buf.extend(offs + 1);
                            buf.arr[offs++] = (byte) 0;
                        }
                        continue;
					
                    case ClassDescriptor.FieldType.tpNullableDouble: 
                        if (elem != null)
                        {
                            if (elem.isIntValue())
                            {
                                buf.extend(offs + 9);
                                buf.arr[offs++] = (byte) 1;
                                Bytes.packF8(buf.arr, offs, (double) elem.IntValue);
                                offs += 8;
                            }
                            else if (elem.isRealValue())
                            {
                                buf.extend(offs + 9);
                                buf.arr[offs++] = (byte) 1;
                                Bytes.packF8(buf.arr, offs, elem.RealValue);
                                offs += 8;
                            }
                            else if (elem.isNullValue())
                            {
                                buf.extend(offs + 1);
                                buf.arr[offs++] = (byte) 0;
                            }
                            else
                            {
                                throwException("Conversion for field " + fieldName + " is not possible");
                            }
                        }
                        else 
                        {
                            buf.extend(offs + 1);
                            buf.arr[offs++] = (byte) 0;
                        }
                        continue;
					
                    case ClassDescriptor.FieldType.tpNullableDecimal: 
                        if (elem != null)
                        {
                            decimal d = 0;
                            if (elem.isIntValue())
                            {
                                d = elem.IntValue;
                            }
                            else if (elem.isRealValue())
                            {
                                d = (decimal)elem.RealValue;
                            }
                            else if (elem.isStringValue())
                            {
                                try 
                                { 
                                    d = Decimal.Parse(elem.StringValue);
                                } 
                                catch (FormatException) 
                                {
                                    throwException("Invalid date");
                                }
                            }
                            else if (elem.isNullValue())
                            {
                                buf.extend(offs + 1);
                                buf.arr[offs++] = (byte) 0;
                                continue;
                            }
                            else
                            {
                                throwException("Conversion for field " + fieldName + " is not possible");
                            }
                            buf.extend(offs + 17);
                            buf.arr[offs++] = (byte) 1;
                            Bytes.packDecimal(buf.arr, offs, d);
                            offs += 16;
                        }
                        else 
                        {
                            buf.extend(offs + 1);
                            buf.arr[offs++] = (byte) 0;
                        }
                        continue;
  
                    case ClassDescriptor.FieldType.tpNullableGuid: 
                        if (elem != null)
                        {
                            if (elem.isStringValue())
                            {
                                buf.extend(offs + 17);
                                buf.arr[offs++] = (byte) 1;
                                Guid guid = new Guid(elem.StringValue);
                                byte[] bits = guid.ToByteArray();
                                Array.Copy(bits, 0, buf.arr, offs, 16);
                                offs += 16;
                            }
                            else if (elem.isNullValue())
                            {
                                 buf.extend(offs + 1);
                                 buf.arr[offs++] = (byte) 0;
                            }
                            else
                            {
                                throwException("Conversion for field " + fieldName + " is not possible");
                            }
                        }
                        else 
                        {
                            buf.extend(offs + 1);
                            buf.arr[offs++] = (byte) 0;
                        }
                        continue;
                    
                    case ClassDescriptor.FieldType.tpNullableDate: 
                        if (elem != null)
                        {
                            if (elem.isIntValue())
                            {
                                buf.extend(offs + 9);
                                buf.arr[offs++] = (byte) 1;
                                Bytes.pack8(buf.arr, offs, elem.IntValue);
                                offs += 8;
                            }
                            else if (elem.isStringValue())
                            {
                                try 
                                { 
                                    buf.extend(offs + 9);
                                    buf.arr[offs++] = (byte) 1;
                                    Bytes.packDate(buf.arr, offs, DateTime.Parse(elem.StringValue));
                                    offs += 8;
                                } 
                                catch (FormatException) 
                                {
                                    throwException("Invalid date");
                                }
                            }
                            else if (elem.isNullValue())
                            {
                                buf.extend(offs + 1);
                                buf.arr[offs++] = (byte) 0;
                            }
                            else
                            {
                                throwException("Conversion for field " + fieldName + " is not possible");
                            }
                        }
                        else 
                        {
                            buf.extend(offs + 1);
                            buf.arr[offs++] = (byte) 0;
                        }
                        continue;

                    case ClassDescriptor.FieldType.tpNullableValue: 
                        if (elem != null || elem.isNullValue())
                        {
                            buf.extend(offs + 1);
                            buf.arr[offs++] = (byte) 0;
                        } 
                        else                         
                        { 
                            offs = packObject(elem, fd.valueDesc, offs, buf);
                        }
                        continue;
#endif

                    case ClassDescriptor.FieldType.tpByte: 
                    case ClassDescriptor.FieldType.tpSByte: 
                        buf.extend(offs + 1);
                        if (elem != null)
                        {
                            if (elem.isIntValue())
                            {
                                buf.arr[offs] = (byte) elem.IntValue;
                            }
                            else if (elem.isRealValue())
                            {
                                buf.arr[offs] = (byte) elem.RealValue;
                            }
                            else
                            {
                                throwException("Conversion for field " + fieldName + " is not possible");
                            }
                        }
                        offs += 1;
                        continue;
					
                    case ClassDescriptor.FieldType.tpBoolean: 
                        buf.extend(offs + 1);
                        if (elem != null)
                        {
                            if (elem.isIntValue())
                            {
                                buf.arr[offs] = (byte) (elem.IntValue != 0?1:0);
                            }
                            else if (elem.isRealValue())
                            {
                                buf.arr[offs] = (byte) (elem.RealValue != 0.0?1:0);
                            }
                            else
                            {
                                throwException("Conversion for field " + fieldName + " is not possible");
                            }
                        }
                        offs += 1;
                        continue;
					
                    case ClassDescriptor.FieldType.tpShort: 
                    case ClassDescriptor.FieldType.tpUShort: 
                    case ClassDescriptor.FieldType.tpChar: 
                        buf.extend(offs + 2);
                        if (elem != null)
                        {
                            if (elem.isIntValue())
                            {
                                Bytes.pack2(buf.arr, offs, (short) elem.IntValue);
                            }
                            else if (elem.isRealValue())
                            {
                                Bytes.pack2(buf.arr, offs, (short) elem.RealValue);
                            }
                            else
                            {
                                throwException("Conversion for field " + fieldName + " is not possible");
                            }
                        }
                        offs += 2;
                        continue;
					
                    case ClassDescriptor.FieldType.tpEnum: 
                        buf.extend(offs + 4);
                        if (elem != null)
                        {
                            if (elem.isIntValue())
                            {
                                Bytes.pack4(buf.arr, offs, (int) elem.IntValue);
                            }
                            else if (elem.isRealValue())
                            {
                                Bytes.pack4(buf.arr, offs, (int) elem.RealValue);
                            }
                            else if (elem.isStringValue()) 
                            {
                                try
                                {
                                    Bytes.pack4(buf.arr, offs, (int)ClassDescriptor.parseEnum(f.FieldType, elem.StringValue));
                                } 
                                catch (ArgumentException)
                                {
                                    throwException("Invalid enum value");
                                }
                            }
                            else
                            {
                                throwException("Conversion for field " + fieldName + " is not possible");
                            }
                        }
                        offs += 4;
                        continue;
					

                    case ClassDescriptor.FieldType.tpInt: 
                    case ClassDescriptor.FieldType.tpUInt: 
                        buf.extend(offs + 4);
                        if (elem != null)
                        {
                            if (elem.isIntValue())
                            {
                                Bytes.pack4(buf.arr, offs, (int) elem.IntValue);
                            }
                            else if (elem.isRealValue())
                            {
                                Bytes.pack4(buf.arr, offs, (int) elem.RealValue);
                            }
                            else
                            {
                                throwException("Conversion for field " + fieldName + " is not possible");
                            }
                        }
                        offs += 4;
                        continue;
					
                    case ClassDescriptor.FieldType.tpLong: 
                    case ClassDescriptor.FieldType.tpULong: 
                        buf.extend(offs + 8);
                        if (elem != null)
                        {
                            if (elem.isIntValue())
                            {
                                Bytes.pack8(buf.arr, offs, elem.IntValue);
                            }
                            else if (elem.isRealValue())
                            {
                                Bytes.pack8(buf.arr, offs, (long) elem.RealValue);
                            }
                            else
                            {
                                throwException("Conversion for field " + fieldName + " is not possible");
                            }
                        }
                        offs += 8;
                        continue;
					
                    case ClassDescriptor.FieldType.tpFloat: 
                        buf.extend(offs + 4);
                        if (elem != null)
                        {
                            if (elem.isIntValue())
                            {
                                Bytes.packF4(buf.arr, offs, (float)elem.IntValue);
                            }
                            else if (elem.isRealValue())
                            {
                                Bytes.packF4(buf.arr, offs, (float) elem.RealValue);
                            }
                            else
                            {
                                throwException("Conversion for field " + fieldName + " is not possible");
                            }
                        }
                        offs += 4;
                        continue;
					
                    case ClassDescriptor.FieldType.tpDouble: 
                        buf.extend(offs + 8);
                        if (elem != null)
                        {
                            if (elem.isIntValue())
                            {
                                Bytes.packF8(buf.arr, offs, (double) elem.IntValue);
                            }
                            else if (elem.isRealValue())
                            {
                                Bytes.packF8(buf.arr, offs, elem.RealValue);
                            }
                            else
                            {
                                throwException("Conversion for field " + fieldName + " is not possible");
                            }
                        }
                        offs += 8;
                        continue;
					
                    case ClassDescriptor.FieldType.tpDecimal: 
                        buf.extend(offs + 16);
                        if (elem != null)
                        {
                            decimal d = 0;
                            if (elem.isIntValue())
                            {
                                d = elem.IntValue;
                            }
                            else if (elem.isRealValue())
                            {
                                d = (decimal)elem.RealValue;
                            }
                            else if (elem.isStringValue())
                            {
                                try 
                                { 
                                    d = Decimal.Parse(elem.StringValue);
                                } 
                                catch (FormatException) 
                                {
                                    throwException("Invalid date");
                                }
                            }
                            else
                            {
                                throwException("Conversion for field " + fieldName + " is not possible");
                            }
                            Bytes.packDecimal(buf.arr, offs, d);

                        }
                        offs += 16;
                        continue;
  
                    case ClassDescriptor.FieldType.tpGuid: 
                        buf.extend(offs + 16);
                        if (elem != null)
                        {
                            if (elem.isStringValue())
                            {
                                Guid guid = new Guid(elem.StringValue);
                                byte[] bits = guid.ToByteArray();
                                Array.Copy(bits, 0, buf.arr, offs, 16);
                            }
                            else
                            {
                                throwException("Conversion for field " + fieldName + " is not possible");
                            }
                        }
                        offs += 16;
                        continue;
                    
                    case ClassDescriptor.FieldType.tpDate: 
                        buf.extend(offs + 8);
                        if (elem != null)
                        {
                            if (elem.isIntValue())
                            {
                                Bytes.pack8(buf.arr, offs, elem.IntValue);
                            }
                            else if (elem.isStringValue())
                            {
                                try 
                                { 
                                    Bytes.packDate(buf.arr, offs, DateTime.Parse(elem.StringValue));
                                } 
                                catch (FormatException) 
                                {
                                    throwException("Invalid date");
                                }
                            }
                            else
                            {
                                throwException("Conversion for field " + fieldName + " is not possible");
                            }
                        }
                        offs += 8;
                        continue;
					
                    case ClassDescriptor.FieldType.tpString: 
                    case ClassDescriptor.FieldType.tpType: 
                        if (elem != null)
                        {
                            string val = null;
                            if (elem.isIntValue())
                            {
                                val = System.Convert.ToString(elem.IntValue);
                            }
                            else if (elem.isRealValue())
                            {
                                val = elem.RealValue.ToString();
                            }
                            else if (elem.isStringValue())
                            {
                                val = elem.StringValue;
                            }
                            else if (elem.isNullValue())
                            {
                                val = null;
                            }
                            else
                            {
                                throwException("Conversion for field " + fieldName + " is not possible");
                            }
                            offs = buf.packString(offs, val);
                            continue;
                        }
                        offs = buf.packI4(offs, -1);
                        continue;
					
                    case ClassDescriptor.FieldType.tpOid: 
                    case ClassDescriptor.FieldType.tpObject: 
                        offs = importRef(elem, offs, buf);
                        continue;
					
                    case ClassDescriptor.FieldType.tpValue: 
                        offs = packObject(elem, fd.valueDesc, offs, buf);
                        continue;
					
                    case ClassDescriptor.FieldType.tpArrayOfByte: 
                    case ClassDescriptor.FieldType.tpArrayOfSByte: 
                        offs = importBinary(elem, offs, buf, fieldName);
                        continue;
					
                    case ClassDescriptor.FieldType.tpCustom:
                    {
                        if (!elem.isStringValue()) 
                        {
                            throwException("text element expected");
                        }
                        String str = elem.StringValue;                    
                        object obj = storage.serializer.Parse(str);                        
                        storage.serializer.Pack(obj, buf.GetWriter());                    
                        offs = buf.used;
                        break;
                    }

                    case ClassDescriptor.FieldType.tpArrayOfBoolean: 
                        if (elem == null || elem.isNullValue())
                        {
                            offs = buf.packI4(offs, -1);
                        }
                        else
                        {
                            XMLElement item = elem.getSibling("element");
                            int len = (item == null)?0:item.Counter;
                            buf.extend(offs + 4 + len);
                            Bytes.pack4(buf.arr, offs, len);
                            offs += 4;
                            while (--len >= 0)
                            {
                                if (item.isIntValue())
                                {
                                    buf.arr[offs] = (byte) (item.IntValue != 0?1:0);
                                }
                                else if (item.isRealValue())
                                {
                                    buf.arr[offs] = (byte) (item.RealValue != 0.0?1:0);
                                }
                                else
                                {
                                    throwException("Conversion for field " + fieldName + " is not possible");
                                }
                                item = item.NextSibling;
                                offs += 1;
                            }
                        }
                        continue;
					
                    case ClassDescriptor.FieldType.tpArrayOfChar: 
                    case ClassDescriptor.FieldType.tpArrayOfShort: 
                    case ClassDescriptor.FieldType.tpArrayOfUShort: 
                        if (elem == null || elem.isNullValue())
                        {
                            offs = buf.packI4(offs, -1);
                        }
                        else
                        {
                            XMLElement item = elem.getSibling("element");
                            int len = (item == null)?0:item.Counter;
                            buf.extend(offs + 4 + len * 2);
                            Bytes.pack4(buf.arr, offs, len);
                            offs += 4;
                            while (--len >= 0)
                            {
                                if (item.isIntValue())
                                {
                                    Bytes.pack2(buf.arr, offs, (short) item.IntValue);
                                }
                                else if (item.isRealValue())
                                {
                                    Bytes.pack2(buf.arr, offs, (short) item.RealValue);
                                }
                                else
                                {
                                    throwException("Conversion for field " + fieldName + " is not possible");
                                }
                                item = item.NextSibling;
                                offs += 2;
                            }
                        }
                        continue;
					
                    case ClassDescriptor.FieldType.tpArrayOfEnum: 
                        if (elem == null || elem.isNullValue())
                        {
                            offs = buf.packI4(offs, -1);
                        }
                        else
                        {
                            XMLElement item = elem.getSibling("element");
                            int len = (item == null)?0:item.Counter;
                            Type elemType = f.FieldType.GetElementType();
                            buf.extend(offs + 4 + len * 4);
                            Bytes.pack4(buf.arr, offs, len);
                            offs += 4;
                            while (--len >= 0)
                            {
                                if (item.isIntValue())
                                {
                                    Bytes.pack4(buf.arr, offs, (int) item.IntValue);
                                }
                                else if (item.isRealValue())
                                {
                                    Bytes.pack4(buf.arr, offs, (int) item.RealValue);
                                }
                                else if (item.isStringValue()) 
                                {
                                    try
                                    {
                                        Bytes.pack4(buf.arr, offs, (int)ClassDescriptor.parseEnum(elemType, item.StringValue));
                                    } 
                                    catch (ArgumentException)
                                    {
                                        throwException("Invalid enum value");
                                    }
                                }
                                else
                                {
                                    throwException("Conversion for field " + fieldName + " is not possible");
                                }
                                item = item.NextSibling;
                                offs += 4;
                            }
                        }
                        continue;
                        

                    case ClassDescriptor.FieldType.tpArrayOfInt: 
                    case ClassDescriptor.FieldType.tpArrayOfUInt: 
                        if (elem == null || elem.isNullValue())
                        {
                            offs = buf.packI4(offs, -1);
                        }
                        else
                        {
                            XMLElement item = elem.getSibling("element");
                            int len = (item == null)?0:item.Counter;
                            buf.extend(offs + 4 + len * 4);
                            Bytes.pack4(buf.arr, offs, len);
                            offs += 4;
                            while (--len >= 0)
                            {
                                if (item.isIntValue())
                                {
                                    Bytes.pack4(buf.arr, offs, (int) item.IntValue);
                                }
                                else if (item.isRealValue())
                                {
                                    Bytes.pack4(buf.arr, offs, (int) item.RealValue);
                                }
                                else
                                {
                                    throwException("Conversion for field " + fieldName + " is not possible");
                                }
                                item = item.NextSibling;
                                offs += 4;
                            }
                        }
                        continue;
					
                    case ClassDescriptor.FieldType.tpArrayOfLong: 
                    case ClassDescriptor.FieldType.tpArrayOfULong: 
                        if (elem == null || elem.isNullValue())
                        {
                            offs = buf.packI4(offs, -1);
                        }
                        else
                        {
                            XMLElement item = elem.getSibling("element");
                            int len = (item == null)?0:item.Counter;
                            buf.extend(offs + 4 + len * 8);
                            Bytes.pack4(buf.arr, offs, len);
                            offs += 4;
                            while (--len >= 0)
                            {
                                if (item.isIntValue())
                                {
                                    Bytes.pack8(buf.arr, offs, item.IntValue);
                                }
                                else if (item.isRealValue())
                                {
                                    Bytes.pack8(buf.arr, offs, (long) item.RealValue);
                                }
                                else
                                {
                                    throwException("Conversion for field " + fieldName + " is not possible");
                                }
                                item = item.NextSibling;
                                offs += 8;
                            }
                        }
                        continue;
					
                    case ClassDescriptor.FieldType.tpArrayOfFloat: 
                        if (elem == null || elem.isNullValue())
                        {
                            offs = buf.packI4(offs, -1);
                        }
                        else
                        {
                            XMLElement item = elem.getSibling("element");
                            int len = (item == null)?0:item.Counter;
                            buf.extend(offs + 4 + len * 4);
                            Bytes.pack4(buf.arr, offs, len);
                            offs += 4;
                            while (--len >= 0)
                            {
                                if (item.isIntValue())
                                {
                                   Bytes.packF4(buf.arr, offs, (float)item.IntValue);
                                }
                                else if (item.isRealValue())
                                {
                                    Bytes.packF4(buf.arr, offs, (float)item.RealValue);
                                }
                                else
                                {
                                    throwException("Conversion for field " + fieldName + " is not possible");
                                }
                                item = item.NextSibling;
                                offs += 4;
                            }
                        }
                        continue;
					
                    case ClassDescriptor.FieldType.tpArrayOfDouble: 
                        if (elem == null || elem.isNullValue())
                        {
                            offs = buf.packI4(offs, -1);
                        }
                        else
                        {
                            XMLElement item = elem.getSibling("element");
                            int len = (item == null)?0:item.Counter;
                            buf.extend(offs + 4 + len * 8);
                            Bytes.pack4(buf.arr, offs, len);
                            offs += 4;
                            while (--len >= 0)
                            {
                                if (item.isIntValue())
                                {
                                    Bytes.packF8(buf.arr, offs, (double)item.IntValue);
                                }
                                else if (item.isRealValue())
                                {
                                    Bytes.packF8(buf.arr, offs, item.RealValue);
                                }
                                else
                                {
                                    throwException("Conversion for field " + fieldName + " is not possible");
                                }
                                item = item.NextSibling;
                                offs += 8;
                            }
                        }
                        continue;
					
                    case ClassDescriptor.FieldType.tpArrayOfDate: 
                        if (elem == null || elem.isNullValue())
                        {
                            offs = buf.packI4(offs, -1);
                        }
                        else
                        {
                            XMLElement item = elem.getSibling("element");
                            int len = (item == null)?0:item.Counter;
                            buf.extend(offs + 4 + len * 8);
                            Bytes.pack4(buf.arr, offs, len);
                            offs += 4;
                            while (--len >= 0)
                            {
                                if (item.isNullValue())
                                {
                                    Bytes.pack8(buf.arr, offs, -1);
                                }
                                else if (item.isStringValue())
                                {
                                    try 
                                    { 
                                        Bytes.packDate(buf.arr, offs, DateTime.Parse(item.StringValue));
                                    }
                                    catch (FormatException)
                                    {
                                        throwException("Conversion for field " + fieldName + " is not possible");
                                    }
                                }
                                item = item.NextSibling;
                                offs += 8;
                            }
                        }
                        continue;
					
                    case ClassDescriptor.FieldType.tpArrayOfDecimal: 
                        if (elem == null || elem.isNullValue())
                        {
                            offs = buf.packI4(offs, -1);
                        }
                        else
                        {
                            XMLElement item = elem.getSibling("element");
                            int len = (item == null)?0:item.Counter;
                            buf.extend(offs + 4 + len * 16);
                            Bytes.pack4(buf.arr, offs, len);
                            offs += 4;
                            while (--len >= 0)
                            {
                                if (item.isStringValue())
                                {
                                    try 
                                    { 
                                        Bytes.packDecimal(buf.arr, offs, Decimal.Parse(item.StringValue));
                                    }
                                    catch (FormatException)
                                    {
                                        throwException("Conversion for field " + fieldName + " is not possible");
                                    }
                                }
                                item = item.NextSibling;
                                offs += 16;
                            }
                        }
                        continue;
					
                    case ClassDescriptor.FieldType.tpArrayOfGuid: 
                        if (elem == null || elem.isNullValue())
                        {
                            offs = buf.packI4(offs, -1);
                        }
                        else
                        {
                            XMLElement item = elem.getSibling("element");
                            int len = (item == null)?0:item.Counter;
                            buf.extend(offs + 4 + len * 16);
                            Bytes.pack4(buf.arr, offs, len);
                            offs += 4;
                            while (--len >= 0)
                            {
                                if (item.isStringValue())
                                {
                                    try 
                                    { 
                                        Bytes.packGuid(buf.arr, offs, new Guid(item.StringValue));
                                    }
                                    catch (FormatException)
                                    {
                                        throwException("Conversion for field " + fieldName + " is not possible");
                                    }
                                }
                                item = item.NextSibling;
                                offs += 16;
                            }
                        }
                        continue;
					
                    case ClassDescriptor.FieldType.tpArrayOfString: 
                        if (elem == null || elem.isNullValue())
                        {
                            offs = buf.packI4(offs, -1);
                        }
                        else
                        {
                            XMLElement item = elem.getSibling("element");
                            int len = (item == null)?0:item.Counter;
                            buf.extend(offs + 4);
                            Bytes.pack4(buf.arr, offs, len);
                            offs += 4;
                            while (--len >= 0)
                            {
                                string val = null;
                                if (item.isIntValue())
                                {
                                    val = System.Convert.ToString(item.IntValue);
                                }
                                else if (item.isRealValue())
                                {
                                    val = item.RealValue.ToString();
                                }
                                else if (item.isStringValue())
                                {
                                    val = item.StringValue;
                                }
                                else if (item.isNullValue())
                                {
                                    val = null;
                                }
                                else
                                {
                                    throwException("Conversion for field " + fieldName + " is not possible");
                                }
                                offs = buf.packString(offs, val);  
                                item = item.NextSibling;
                            }
                        }
                        continue;
					
                    case ClassDescriptor.FieldType.tpArrayOfObject: 
                    case ClassDescriptor.FieldType.tpArrayOfOid: 
                    case ClassDescriptor.FieldType.tpLink: 
                        if (elem == null || elem.isNullValue())
                        {
                            offs = buf.packI4(offs, -1);
                        }
                        else
                        {
                            XMLElement item = elem.getSibling("element");
                            int len = (item == null)?0:item.Counter;
                            offs = buf.packI4(offs, len);
                            while (--len >= 0)
                            {
                                offs = importRef(item, offs, buf);
                                item = item.NextSibling;
                            }
                        }
                        continue;
					
                    case ClassDescriptor.FieldType.tpArrayOfValue: 
                        if (elem == null || elem.isNullValue())
                        {
                            offs = buf.packI4(offs, -1);
                        }
                        else
                        {
                            XMLElement item = elem.getSibling("element");
                            int len = (item == null)?0:item.Counter;
                            offs = buf.packI4(offs, len);
                            ClassDescriptor elemDesc = fd.valueDesc;
                            while (--len >= 0)
                            {
                                offs = packObject(item, elemDesc, offs, buf);
                                item = item.NextSibling;
                            }
                        }
                        continue;					
                }
            }
            return offs;
        }
Exemplo n.º 50
0
 internal int getIntAttribute(XMLElement elem, String name)
 {
     System.String val = elem.getAttribute(name);
     if (val == null)
     {
         throwException("Attribute " + name + " is not set");
     }
     try
     {
         return System.Int32.Parse(val);
     }
     catch (System.FormatException)
     {
         throwException("Attribute " + name + " should has integer value");
     }
     return -1;
 }
Exemplo n.º 51
0
 internal int importRef(XMLElement elem, int offs, ByteBuffer buf) 
 {
     int oid = 0;
     if (elem != null) {
         if (elem.isStringValue()) {
             String str = elem.StringValue;
             offs = buf.packI4(offs, -1-(int)ClassDescriptor.FieldType.tpString);
             return buf.packString(offs, str);
         } else {
             XMLElement value = elem.FirstSibling;
             if (value == null) { 
                 throwException("object reference expected");
             }
             string name = value.Name;
             if (name == "scalar") { 
                 int tid = getIntAttribute(value, "type");
                 string hexStr = getAttribute(value, "value");
                 int len = hexStr.Length;
                 buf.extend(offs + 4 + len/2);
                 Bytes.pack4(buf.arr, offs, -1-tid);
                 offs += 4;
                 if (tid == (int)ClassDescriptor.FieldType.tpCustom) 
                 { 
                     object obj = storage.serializer.Parse(hexStr);  
                     storage.serializer.Pack(obj, buf.GetWriter());                    
                     offs = buf.used;
                 } 
                 else 
                 { 
                     for (int j = 0; j < len; j += 2) 
                     { 
                          buf.arr[offs++] = (byte)((getHexValue(hexStr[j]) << 4) | getHexValue(hexStr[j+1]));
                      }
                 }
                 return offs;
             } else if (name == "type") { 
                 string typeName = getAttribute(value, "name");
                 offs = buf.packI4(offs, -1-(int)ClassDescriptor.FieldType.tpType);
                 return buf.packString(offs, typeName);                        
             } else if (name == "ref") { 
                 oid = mapId(getIntAttribute(value, "id"));
             } else { 
                 ClassDescriptor desc = storage.getClassDescriptor(findClassByName(name));
                 offs = buf.packI4(offs, -(int)ClassDescriptor.FieldType.tpValueTypeBias - desc.Oid);
                 if (desc.isCollection) { 
                     XMLElement item = value.getSibling("element");
                     int len = (item == null) ? 0 : item.Counter; 
                     offs = buf.packI4(offs, len);
                     while (--len >= 0) { 
                         offs = importRef(item, offs, buf);
                         item = item.NextSibling;
                     }
                 } else if (desc.isDictionary) { 
                     XMLElement item = value.getSibling("element");
                     int len = (item == null) ? 0 : item.Counter; 
                     offs = buf.packI4(offs, len);
                     while (--len >= 0) { 
                         XMLElement key = item.getSibling("key");
                         offs = importRef(key, offs, buf);
                         XMLElement val = item.getSibling("value");
                         offs = importRef(val, offs, buf);
                         item = item.NextSibling;
                     }
                 } else { 
                     offs = packObject(value, desc, offs, buf);
                 }
                 return offs;
             }
         }
     }
     return buf.packI4(offs, oid);
 }
Exemplo n.º 52
0
 internal int importBinary(XMLElement elem, int offs, ByteBuffer buf, String fieldName)
 {
     if (elem == null || elem.isNullValue())
     {
         buf.extend(offs + 4);
         Bytes.pack4(buf.arr, offs, -1);
         offs += 4;
     }
     else if (elem.isStringValue())
     {
         String hexStr = elem.StringValue;
         int len = hexStr.Length;
         if (hexStr.StartsWith("#"))
         {
             buf.extend(offs + 4 + len / 2 - 1);
             Bytes.pack4(buf.arr, offs, -2 - getHexValue(hexStr[1]));
             offs += 4;
             for (int j = 2; j < len; j += 2)
             {
                 buf.arr[offs++] = (byte)((getHexValue(hexStr[j]) << 4) | getHexValue(hexStr[j + 1]));
             }
         }
         else
         {
             buf.extend(offs + 4 + len / 2);
             Bytes.pack4(buf.arr, offs, len / 2);
             offs += 4;
             for (int j = 0; j < len; j += 2)
             {
                 buf.arr[offs++] = (byte)((getHexValue(hexStr[j]) << 4) | getHexValue(hexStr[j + 1]));
             }
         }
     }
     else
     {
         XMLElement refElem = elem.getSibling("ref");
         if (refElem != null)
         {
             buf.extend(offs + 4);
             Bytes.pack4(buf.arr, offs, mapId(getIntAttribute(refElem, "id")));
             offs += 4;
         }
         else
         {
             XMLElement item = elem.getSibling("element");
             int len = (item == null) ? 0 : item.Counter;
             buf.extend(offs + 4 + len);
             Bytes.pack4(buf.arr, offs, len);
             offs += 4;
             while (--len >= 0)
             {
                 if (item.isIntValue())
                 {
                     buf.arr[offs] = (byte)item.IntValue;
                 }
                 else if (item.isRealValue())
                 {
                     buf.arr[offs] = (byte)item.RealValue;
                 }
                 else
                 {
                     throwException("Conversion for field " + fieldName + " is not possible");
                 }
                 item = item.NextSibling;
                 offs += 1;
             }
         }
     }
     return offs;
 }
Exemplo n.º 53
0
		public XMLDocument(XMLElement e):this("<?xml version=\"1.0\" standalone=\"yes\" ?>\n", e) {
			
		}
Exemplo n.º 54
0
        internal int packObject(XMLElement objElem, ClassDescriptor desc, int offs, ByteBuffer buf)
        {
            ClassDescriptor.FieldDescriptor[] flds = desc.allFields;
            for (int i = 0, n = flds.Length; i < n; i++)
            {
                ClassDescriptor.FieldDescriptor fd = flds[i];
                FieldInfo f = fd.field;
                String fieldName = fd.fieldName;
                XMLElement elem = (objElem != null) ? objElem.getSibling(fieldName) : null;

                switch (fd.type)
                {
                    case ClassDescriptor.FieldType.tpByte:
                    case ClassDescriptor.FieldType.tpSByte:
                        buf.extend(offs + 1);
                        if (elem != null)
                        {
                            if (elem.isIntValue())
                            {
                                buf.arr[offs] = (byte)elem.IntValue;
                            }
                            else if (elem.isRealValue())
                            {
                                buf.arr[offs] = (byte)elem.RealValue;
                            }
                            else
                            {
                                throwException("Conversion for field " + fieldName + " is not possible");
                            }
                        }
                        offs += 1;
                        continue;

                    case ClassDescriptor.FieldType.tpBoolean:
                        buf.extend(offs + 1);
                        if (elem != null)
                        {
                            if (elem.isIntValue())
                            {
                                buf.arr[offs] = (byte)(elem.IntValue != 0 ? 1 : 0);
                            }
                            else if (elem.isRealValue())
                            {
                                buf.arr[offs] = (byte)(elem.RealValue != 0.0 ? 1 : 0);
                            }
                            else
                            {
                                throwException("Conversion for field " + fieldName + " is not possible");
                            }
                        }
                        offs += 1;
                        continue;

                    case ClassDescriptor.FieldType.tpShort:
                    case ClassDescriptor.FieldType.tpUShort:
                    case ClassDescriptor.FieldType.tpChar:
                        buf.extend(offs + 2);
                        if (elem != null)
                        {
                            if (elem.isIntValue())
                            {
                                Bytes.pack2(buf.arr, offs, (short)elem.IntValue);
                            }
                            else if (elem.isRealValue())
                            {
                                Bytes.pack2(buf.arr, offs, (short)elem.RealValue);
                            }
                            else
                            {
                                throwException("Conversion for field " + fieldName + " is not possible");
                            }
                        }
                        offs += 2;
                        continue;

                    case ClassDescriptor.FieldType.tpEnum:
                        buf.extend(offs + 4);
                        if (elem != null)
                        {
                            if (elem.isIntValue())
                            {
                                Bytes.pack4(buf.arr, offs, (int)elem.IntValue);
                            }
                            else if (elem.isRealValue())
                            {
                                Bytes.pack4(buf.arr, offs, (int)elem.RealValue);
                            }
                            else if (elem.isStringValue())
                            {
                                try
                                {
            #if CF
                                    Bytes.pack4(buf.arr, offs, (int)ClassDescriptor.parseEnum(f.FieldType, elem.StringValue));
            #else
                                    Bytes.pack4(buf.arr, offs, (int)Enum.Parse(f.FieldType, elem.StringValue));
            #endif
                                }
                                catch (ArgumentException)
                                {
                                    throwException("Invalid enum value");
                                }
                            }
                            else
                            {
                                throwException("Conversion for field " + fieldName + " is not possible");
                            }
                        }
                        offs += 4;
                        continue;

                    case ClassDescriptor.FieldType.tpInt:
                    case ClassDescriptor.FieldType.tpUInt:
                        buf.extend(offs + 4);
                        if (elem != null)
                        {
                            if (elem.isIntValue())
                            {
                                Bytes.pack4(buf.arr, offs, (int)elem.IntValue);
                            }
                            else if (elem.isRealValue())
                            {
                                Bytes.pack4(buf.arr, offs, (int)elem.RealValue);
                            }
                            else
                            {
                                throwException("Conversion for field " + fieldName + " is not possible");
                            }
                        }
                        offs += 4;
                        continue;

                    case ClassDescriptor.FieldType.tpLong:
                    case ClassDescriptor.FieldType.tpULong:
                        buf.extend(offs + 8);
                        if (elem != null)
                        {
                            if (elem.isIntValue())
                            {
                                Bytes.pack8(buf.arr, offs, elem.IntValue);
                            }
                            else if (elem.isRealValue())
                            {
                                Bytes.pack8(buf.arr, offs, (long)elem.RealValue);
                            }
                            else
                            {
                                throwException("Conversion for field " + fieldName + " is not possible");
                            }
                        }
                        offs += 8;
                        continue;

                    case ClassDescriptor.FieldType.tpFloat:
                        buf.extend(offs + 4);
                        if (elem != null)
                        {
                            if (elem.isIntValue())
                            {
                                Bytes.packF4(buf.arr, offs, (float)elem.IntValue);
                            }
                            else if (elem.isRealValue())
                            {
                                Bytes.packF4(buf.arr, offs, (float)elem.RealValue);
                            }
                            else
                            {
                                throwException("Conversion for field " + fieldName + " is not possible");
                            }
                        }
                        offs += 4;
                        continue;

                    case ClassDescriptor.FieldType.tpDouble:
                        buf.extend(offs + 8);
                        if (elem != null)
                        {
                            if (elem.isIntValue())
                            {
                                Bytes.packF8(buf.arr, offs, (double)elem.IntValue);
                            }
                            else if (elem.isRealValue())
                            {
                                Bytes.packF8(buf.arr, offs, elem.RealValue);
                            }
                            else
                            {
                                throwException("Conversion for field " + fieldName + " is not possible");
                            }
                        }
                        offs += 8;
                        continue;

                    case ClassDescriptor.FieldType.tpDecimal:
                        buf.extend(offs + 16);
                        if (elem != null)
                        {
                            decimal d = 0;
                            if (elem.isIntValue())
                            {
                                d = elem.IntValue;
                            }
                            else if (elem.isRealValue())
                            {
                                d = (decimal)elem.RealValue;
                            }
                            else if (elem.isStringValue())
                            {
                                try
                                {
                                    d = Decimal.Parse(elem.StringValue);
                                }
                                catch (FormatException)
                                {
                                    throwException("Invalid date");
                                }
                            }
                            else
                            {
                                throwException("Conversion for field " + fieldName + " is not possible");
                            }
                            Bytes.packDecimal(buf.arr, offs, d);

                        }
                        offs += 16;
                        continue;

                    case ClassDescriptor.FieldType.tpGuid:
                        buf.extend(offs + 16);
                        if (elem != null)
                        {
                            if (elem.isStringValue())
                            {
                                Guid guid = new Guid(elem.StringValue);
                                byte[] bits = guid.ToByteArray();
                                Array.Copy(bits, 0, buf.arr, offs, 16);
                            }
                            else
                            {
                                throwException("Conversion for field " + fieldName + " is not possible");
                            }
                        }
                        offs += 16;
                        continue;

                    case ClassDescriptor.FieldType.tpDate:
                        buf.extend(offs + 8);
                        if (elem != null)
                        {
                            if (elem.isIntValue())
                            {
                                Bytes.pack8(buf.arr, offs, elem.IntValue);
                            }
                            else if (elem.isNullValue())
                            {
                                Bytes.pack8(buf.arr, offs, -1);
                            }
                            else if (elem.isStringValue())
                            {
                                try
                                {
                                    Bytes.packDate(buf.arr, offs, DateTime.Parse(elem.StringValue));
                                }
                                catch (FormatException)
                                {
                                    throwException("Invalid date");
                                }
                            }
                            else
                            {
                                throwException("Conversion for field " + fieldName + " is not possible");
                            }
                        }
                        offs += 8;
                        continue;

                    case ClassDescriptor.FieldType.tpString:
                        if (elem != null)
                        {
                            System.String val = null;
                            if (elem.isIntValue())
                            {
                                val = System.Convert.ToString(elem.IntValue);
                            }
                            else if (elem.isRealValue())
                            {
                                val = elem.RealValue.ToString();
                            }
                            else if (elem.isStringValue())
                            {
                                val = elem.StringValue;
                            }
                            else if (elem.isNullValue())
                            {
                                val = null;
                            }
                            else
                            {
                                throwException("Conversion for field " + fieldName + " is not possible");
                            }
                            offs = buf.packString(offs, val);
                            continue;
                        }
                        buf.extend(offs + 4);
                        Bytes.pack4(buf.arr, offs, -1);
                        offs += 4;
                        continue;

                    case ClassDescriptor.FieldType.tpOid:
                    case ClassDescriptor.FieldType.tpObject:
                        {
                            int oid = 0;
                            if (elem != null)
                            {
                                XMLElement refElem = elem.getSibling("ref");
                                if (refElem == null)
                                {
                                    throwException("<ref> element expected");
                                }
                                oid = mapId(getIntAttribute(refElem, "id"));
                            }
                            buf.extend(offs + 4);
                            Bytes.pack4(buf.arr, offs, oid);
                            offs += 4;
                            continue;
                        }

                    case ClassDescriptor.FieldType.tpValue:
                        offs = packObject(elem, fd.valueDesc, offs, buf);
                        continue;

                    case ClassDescriptor.FieldType.tpRaw:
                    case ClassDescriptor.FieldType.tpArrayOfByte:
                    case ClassDescriptor.FieldType.tpArrayOfSByte:
                        offs = importBinary(elem, offs, buf, fieldName);
                        continue;

                    case ClassDescriptor.FieldType.tpArrayOfBoolean:
                        if (elem == null || elem.isNullValue())
                        {
                            buf.extend(offs + 4);
                            Bytes.pack4(buf.arr, offs, -1);
                            offs += 4;
                        }
                        else
                        {
                            XMLElement item = elem.getSibling("element");
                            int len = (item == null) ? 0 : item.Counter;
                            buf.extend(offs + 4 + len);
                            Bytes.pack4(buf.arr, offs, len);
                            offs += 4;
                            while (--len >= 0)
                            {
                                if (item.isIntValue())
                                {
                                    buf.arr[offs] = (byte)(item.IntValue != 0 ? 1 : 0);
                                }
                                else if (item.isRealValue())
                                {
                                    buf.arr[offs] = (byte)(item.RealValue != 0.0 ? 1 : 0);
                                }
                                else
                                {
                                    throwException("Conversion for field " + fieldName + " is not possible");
                                }
                                item = item.NextSibling;
                                offs += 1;
                            }
                        }
                        continue;

                    case ClassDescriptor.FieldType.tpArrayOfChar:
                    case ClassDescriptor.FieldType.tpArrayOfShort:
                    case ClassDescriptor.FieldType.tpArrayOfUShort:
                        if (elem == null || elem.isNullValue())
                        {
                            buf.extend(offs + 4);
                            Bytes.pack4(buf.arr, offs, -1);
                            offs += 4;
                        }
                        else
                        {
                            XMLElement item = elem.getSibling("element");
                            int len = (item == null) ? 0 : item.Counter;
                            buf.extend(offs + 4 + len * 2);
                            Bytes.pack4(buf.arr, offs, len);
                            offs += 4;
                            while (--len >= 0)
                            {
                                if (item.isIntValue())
                                {
                                    Bytes.pack2(buf.arr, offs, (short)item.IntValue);
                                }
                                else if (item.isRealValue())
                                {
                                    Bytes.pack2(buf.arr, offs, (short)item.RealValue);
                                }
                                else
                                {
                                    throwException("Conversion for field " + fieldName + " is not possible");
                                }
                                item = item.NextSibling;
                                offs += 2;
                            }
                        }
                        continue;

                    case ClassDescriptor.FieldType.tpArrayOfEnum:
                        if (elem == null || elem.isNullValue())
                        {
                            buf.extend(offs + 4);
                            Bytes.pack4(buf.arr, offs, -1);
                            offs += 4;
                        }
                        else
                        {
                            XMLElement item = elem.getSibling("element");
                            int len = (item == null) ? 0 : item.Counter;
                            Type elemType = f.FieldType.GetElementType();
                            buf.extend(offs + 4 + len * 4);
                            Bytes.pack4(buf.arr, offs, len);
                            offs += 4;
                            while (--len >= 0)
                            {
                                if (item.isIntValue())
                                {
                                    Bytes.pack4(buf.arr, offs, (int)item.IntValue);
                                }
                                else if (item.isRealValue())
                                {
                                    Bytes.pack4(buf.arr, offs, (int)item.RealValue);
                                }
                                else if (item.isStringValue())
                                {
                                    try
                                    {
            #if CF
                                        Bytes.pack4(buf.arr, offs, (int)ClassDescriptor.parseEnum(elemType, item.StringValue));
            #else
                                        Bytes.pack4(buf.arr, offs, (int)Enum.Parse(elemType, item.StringValue));
            #endif
                                    }
                                    catch (ArgumentException)
                                    {
                                        throwException("Invalid enum value");
                                    }
                                }
                                else
                                {
                                    throwException("Conversion for field " + fieldName + " is not possible");
                                }
                                item = item.NextSibling;
                                offs += 4;
                            }
                        }
                        continue;

                    case ClassDescriptor.FieldType.tpArrayOfInt:
                    case ClassDescriptor.FieldType.tpArrayOfUInt:
                        if (elem == null || elem.isNullValue())
                        {
                            buf.extend(offs + 4);
                            Bytes.pack4(buf.arr, offs, -1);
                            offs += 4;
                        }
                        else
                        {
                            XMLElement item = elem.getSibling("element");
                            int len = (item == null) ? 0 : item.Counter;
                            buf.extend(offs + 4 + len * 4);
                            Bytes.pack4(buf.arr, offs, len);
                            offs += 4;
                            while (--len >= 0)
                            {
                                if (item.isIntValue())
                                {
                                    Bytes.pack4(buf.arr, offs, (int)item.IntValue);
                                }
                                else if (item.isRealValue())
                                {
                                    Bytes.pack4(buf.arr, offs, (int)item.RealValue);
                                }
                                else
                                {
                                    throwException("Conversion for field " + fieldName + " is not possible");
                                }
                                item = item.NextSibling;
                                offs += 4;
                            }
                        }
                        continue;

                    case ClassDescriptor.FieldType.tpArrayOfLong:
                    case ClassDescriptor.FieldType.tpArrayOfULong:
                        if (elem == null || elem.isNullValue())
                        {
                            buf.extend(offs + 4);
                            Bytes.pack4(buf.arr, offs, -1);
                            offs += 4;
                        }
                        else
                        {
                            XMLElement item = elem.getSibling("element");
                            int len = (item == null) ? 0 : item.Counter;
                            buf.extend(offs + 4 + len * 8);
                            Bytes.pack4(buf.arr, offs, len);
                            offs += 4;
                            while (--len >= 0)
                            {
                                if (item.isIntValue())
                                {
                                    Bytes.pack8(buf.arr, offs, item.IntValue);
                                }
                                else if (item.isRealValue())
                                {
                                    Bytes.pack8(buf.arr, offs, (long)item.RealValue);
                                }
                                else
                                {
                                    throwException("Conversion for field " + fieldName + " is not possible");
                                }
                                item = item.NextSibling;
                                offs += 8;
                            }
                        }
                        continue;

                    case ClassDescriptor.FieldType.tpArrayOfFloat:
                        if (elem == null || elem.isNullValue())
                        {
                            buf.extend(offs + 4);
                            Bytes.pack4(buf.arr, offs, -1);
                            offs += 4;
                        }
                        else
                        {
                            XMLElement item = elem.getSibling("element");
                            int len = (item == null) ? 0 : item.Counter;
                            buf.extend(offs + 4 + len * 4);
                            Bytes.pack4(buf.arr, offs, len);
                            offs += 4;
                            while (--len >= 0)
                            {
                                if (item.isIntValue())
                                {
                                    Bytes.packF4(buf.arr, offs, (float)item.IntValue);
                                }
                                else if (item.isRealValue())
                                {
                                    Bytes.packF4(buf.arr, offs, (float)item.RealValue);
                                }
                                else
                                {
                                    throwException("Conversion for field " + fieldName + " is not possible");
                                }
                                item = item.NextSibling;
                                offs += 4;
                            }
                        }
                        continue;

                    case ClassDescriptor.FieldType.tpArrayOfDouble:
                        if (elem == null || elem.isNullValue())
                        {
                            buf.extend(offs + 4);
                            Bytes.pack4(buf.arr, offs, -1);
                            offs += 4;
                        }
                        else
                        {
                            XMLElement item = elem.getSibling("element");
                            int len = (item == null) ? 0 : item.Counter;
                            buf.extend(offs + 4 + len * 8);
                            Bytes.pack4(buf.arr, offs, len);
                            offs += 4;
                            while (--len >= 0)
                            {
                                if (item.isIntValue())
                                {
                                    Bytes.packF8(buf.arr, offs, (double)item.IntValue);
                                }
                                else if (item.isRealValue())
                                {
                                    Bytes.packF8(buf.arr, offs, item.RealValue);
                                }
                                else
                                {
                                    throwException("Conversion for field " + fieldName + " is not possible");
                                }
                                item = item.NextSibling;
                                offs += 8;
                            }
                        }
                        continue;

                    case ClassDescriptor.FieldType.tpArrayOfDate:
                        if (elem == null || elem.isNullValue())
                        {
                            buf.extend(offs + 4);
                            Bytes.pack4(buf.arr, offs, -1);
                            offs += 4;
                        }
                        else
                        {
                            XMLElement item = elem.getSibling("element");
                            int len = (item == null) ? 0 : item.Counter;
                            buf.extend(offs + 4 + len * 8);
                            Bytes.pack4(buf.arr, offs, len);
                            offs += 4;
                            while (--len >= 0)
                            {
                                if (item.isNullValue())
                                {
                                    Bytes.pack8(buf.arr, offs, -1);
                                }
                                else if (item.isStringValue())
                                {
                                    try
                                    {
                                        Bytes.packDate(buf.arr, offs, DateTime.Parse(item.StringValue));
                                    }
                                    catch (FormatException)
                                    {
                                        throwException("Conversion for field " + fieldName + " is not possible");
                                    }
                                }
                                item = item.NextSibling;
                                offs += 8;
                            }
                        }
                        continue;

                    case ClassDescriptor.FieldType.tpArrayOfDecimal:
                        if (elem == null || elem.isNullValue())
                        {
                            buf.extend(offs + 4);
                            Bytes.pack4(buf.arr, offs, -1);
                            offs += 4;
                        }
                        else
                        {
                            XMLElement item = elem.getSibling("element");
                            int len = (item == null) ? 0 : item.Counter;
                            buf.extend(offs + 4 + len * 16);
                            Bytes.pack4(buf.arr, offs, len);
                            offs += 4;
                            while (--len >= 0)
                            {
                                if (item.isStringValue())
                                {
                                    try
                                    {
                                        Bytes.packDecimal(buf.arr, offs, Decimal.Parse(item.StringValue));
                                    }
                                    catch (FormatException)
                                    {
                                        throwException("Conversion for field " + fieldName + " is not possible");
                                    }
                                }
                                item = item.NextSibling;
                                offs += 16;
                            }
                        }
                        continue;

                    case ClassDescriptor.FieldType.tpArrayOfGuid:
                        if (elem == null || elem.isNullValue())
                        {
                            buf.extend(offs + 4);
                            Bytes.pack4(buf.arr, offs, -1);
                            offs += 4;
                        }
                        else
                        {
                            XMLElement item = elem.getSibling("element");
                            int len = (item == null) ? 0 : item.Counter;
                            buf.extend(offs + 4 + len * 16);
                            Bytes.pack4(buf.arr, offs, len);
                            offs += 4;
                            while (--len >= 0)
                            {
                                if (item.isStringValue())
                                {
                                    try
                                    {
                                        Bytes.packGuid(buf.arr, offs, new Guid(item.StringValue));
                                    }
                                    catch (FormatException)
                                    {
                                        throwException("Conversion for field " + fieldName + " is not possible");
                                    }
                                }
                                item = item.NextSibling;
                                offs += 16;
                            }
                        }
                        continue;

                    case ClassDescriptor.FieldType.tpArrayOfString:
                        if (elem == null || elem.isNullValue())
                        {
                            buf.extend(offs + 4);
                            Bytes.pack4(buf.arr, offs, -1);
                            offs += 4;
                        }
                        else
                        {
                            XMLElement item = elem.getSibling("element");
                            int len = (item == null) ? 0 : item.Counter;
                            buf.extend(offs + 4);
                            Bytes.pack4(buf.arr, offs, len);
                            offs += 4;
                            while (--len >= 0)
                            {
                                System.String val = null;
                                if (item.isIntValue())
                                {
                                    val = System.Convert.ToString(item.IntValue);
                                }
                                else if (item.isRealValue())
                                {
                                    val = item.RealValue.ToString();
                                }
                                else if (item.isStringValue())
                                {
                                    val = item.StringValue;
                                }
                                else if (item.isNullValue())
                                {
                                    val = null;
                                }
                                else
                                {
                                    throwException("Conversion for field " + fieldName + " is not possible");
                                }
                                offs = buf.packString(offs, val);
                                item = item.NextSibling;
                            }
                        }
                        continue;

                    case ClassDescriptor.FieldType.tpArrayOfObject:
                    case ClassDescriptor.FieldType.tpArrayOfOid:
                    case ClassDescriptor.FieldType.tpLink:
                        if (elem == null || elem.isNullValue())
                        {
                            buf.extend(offs + 4);
                            Bytes.pack4(buf.arr, offs, -1);
                            offs += 4;
                        }
                        else
                        {
                            XMLElement item = elem.getSibling("element");
                            int len = (item == null) ? 0 : item.Counter;
                            buf.extend(offs + 4 + len * 4);
                            Bytes.pack4(buf.arr, offs, len);
                            offs += 4;
                            while (--len >= 0)
                            {
                                XMLElement href = item.getSibling("ref");
                                if (href == null)
                                {
                                    throwException("<ref> element expected");
                                }
                                int oid = mapId(getIntAttribute(href, "id"));
                                Bytes.pack4(buf.arr, offs, oid);
                                item = item.NextSibling;
                                offs += 4;
                            }
                        }
                        continue;

                    case ClassDescriptor.FieldType.tpArrayOfValue:
                        if (elem == null || elem.isNullValue())
                        {
                            buf.extend(offs + 4);
                            Bytes.pack4(buf.arr, offs, -1);
                            offs += 4;
                        }
                        else
                        {
                            XMLElement item = elem.getSibling("element");
                            int len = (item == null) ? 0 : item.Counter;
                            Bytes.pack4(buf.arr, offs, len);
                            offs += 4;
                            ClassDescriptor elemDesc = fd.valueDesc;
                            while (--len >= 0)
                            {
                                offs = packObject(item, elemDesc, offs, buf);
                                item = item.NextSibling;
                            }
                        }
                        continue;

                    case ClassDescriptor.FieldType.tpArrayOfRaw:
                        if (elem == null || elem.isNullValue())
                        {
                            buf.extend(offs + 4);
                            Bytes.pack4(buf.arr, offs, -1);
                            offs += 4;
                        }
                        else
                        {
                            XMLElement item = elem.getSibling("element");
                            int len = (item == null) ? 0 : item.Counter;
                            Bytes.pack4(buf.arr, offs, len);
                            offs += 4;
                            while (--len >= 0)
                            {
                                offs = importBinary(item, offs, buf, fieldName);
                                item = item.NextSibling;
                            }
                        }
                        continue;
                }
            }
            return offs;
        }
Exemplo n.º 55
0
 public XMLDocument(string h, XMLElement r)
 {
     this.header = h;
     this.root = r;
 }
Exemplo n.º 56
0
 internal int ImportBinary(XMLElement elem, int offs, ByteBuffer buf, string fieldName)
 {
     if (elem == null || elem.IsNullValue())
     {
         buf.Extend(offs + 4);
         Bytes.Pack4(buf.arr, offs, -1);
         offs += 4;
     }
     else if (elem.IsStringValue())
     {
         string hexStr = elem.GetStringValue();
         int len = hexStr.Length;
         if (hexStr.StartsWith("#"))
         {
             buf.Extend(offs + 4 + len / 2 - 1);
             Bytes.Pack4(buf.arr, offs, -2 - GetHexValue(hexStr[1]));
             offs += 4;
             for (int j = 2; j < len; j += 2)
             {
                 buf.arr[offs++] = (byte) ((GetHexValue(hexStr[j]) << 4) | GetHexValue(hexStr[j + 1]));
             }
         }
         else
         {
             buf.Extend(offs + 4 + len / 2);
             Bytes.Pack4(buf.arr, offs, len / 2);
             offs += 4;
             for (int j = 0; j < len; j += 2)
             {
                 buf.arr[offs++] = (byte) ((GetHexValue(hexStr[j]) << 4) | GetHexValue(hexStr[j + 1]));
             }
         }
     }
     else
     {
         XMLElement ref_Renamed = elem.GetSibling("ref");
         if (ref_Renamed != null)
         {
             buf.Extend(offs + 4);
             Bytes.Pack4(buf.arr, offs, MapId(GetIntAttribute(ref_Renamed, "id")));
             offs += 4;
         }
         else
         {
             XMLElement item = elem.GetSibling("element");
             int len = (item == null) ? 0 : item.Counter;
             buf.Extend(offs + 4 + len);
             Bytes.Pack4(buf.arr, offs, len);
             offs += 4;
             while (--len >= 0)
             {
                 if (item.IsIntValue())
                 {
                     buf.arr[offs] = (byte) item.GetIntValue();
                 }
                 else if (item.IsRealValue())
                 {
                     //UPGRADE_WARNING: Data types in Visual C# might be different. Verify the accuracy of narrowing conversions.
                     buf.arr[offs] = (byte) item.GetRealValue();
                 }
                 else
                 {
                     ThrowException("Conversion for field " + fieldName + " is not possible");
                 }
                 item = item.NextSibling;
                 offs += 1;
             }
         }
     }
     return offs;
 }
Exemplo n.º 57
0
 /// Remove a specified child element.
 public void remove_child(XMLElement e)
 {
     dll.lsl_remove_child(obj, e.obj);
 }
Exemplo n.º 58
0
        internal int PackObject(XMLElement objElem, ClassDescriptor desc, int offs, ByteBuffer buf)
        {
            ClassDescriptor.FieldDescriptor[] flds = desc.allFields;
            for (int i = 0, n = flds.Length; i < n; i++)
            {
                ClassDescriptor.FieldDescriptor fd = flds[i];
                string fieldName = fd.fieldName;
                XMLElement elem = (objElem != null) ? objElem.GetSibling(fieldName) : null;

                switch (fd.type)
                {
                    case ClassDescriptor.tpByte:
                        buf.Extend(offs + 1);
                        if (elem != null)
                        {
                            if (elem.IsIntValue())
                            {
                                buf.arr[offs] = (byte) elem.GetIntValue();
                            }
                            else if (elem.IsRealValue())
                            {
                                //UPGRADE_WARNING: Data types in Visual C# might be different. Verify the accuracy of narrowing conversions.
                                buf.arr[offs] = (byte) elem.GetRealValue();
                            }
                            else
                            {
                                ThrowException("Conversion for field " + fieldName + " is not possible");
                            }
                        }
                        offs += 1;
                        continue;

                    case ClassDescriptor.tpBoolean:
                        buf.Extend(offs + 1);
                        if (elem != null)
                        {
                            if (elem.IsIntValue())
                            {
                                buf.arr[offs] = (byte) (elem.GetIntValue() != 0 ? 1 : 0);
                            }
                            else if (elem.IsRealValue())
                            {
                                buf.arr[offs] = (byte) (elem.GetRealValue() != 0.0 ? 1 : 0);
                            }
                            else
                            {
                                ThrowException("Conversion for field " + fieldName + " is not possible");
                            }
                        }
                        offs += 1;
                        continue;

                    case ClassDescriptor.tpShort:
                    case ClassDescriptor.tpChar:
                        buf.Extend(offs + 2);
                        if (elem != null)
                        {
                            if (elem.IsIntValue())
                            {
                                Bytes.Pack2(buf.arr, offs, (short) elem.GetIntValue());
                            }
                            else if (elem.IsRealValue())
                            {
                                //UPGRADE_WARNING: Data types in Visual C# might be different. Verify the accuracy of narrowing conversions.
                                Bytes.Pack2(buf.arr, offs, (short) elem.GetRealValue());
                            }
                            else
                            {
                                ThrowException("Conversion for field " + fieldName + " is not possible");
                            }
                        }
                        offs += 2;
                        continue;

                    case ClassDescriptor.tpInt:
                        buf.Extend(offs + 4);
                        if (elem != null)
                        {
                            if (elem.IsIntValue())
                            {
                                Bytes.Pack4(buf.arr, offs, (int) elem.GetIntValue());
                            }
                            else if (elem.IsRealValue())
                            {
                                //UPGRADE_WARNING: Data types in Visual C# might be different. Verify the accuracy of narrowing conversions.
                                Bytes.Pack4(buf.arr, offs, (int) elem.GetRealValue());
                            }
                            else
                            {
                                ThrowException("Conversion for field " + fieldName + " is not possible");
                            }
                        }
                        offs += 4;
                        continue;

                    case ClassDescriptor.tpLong:
                        buf.Extend(offs + 8);
                        if (elem != null)
                        {
                            if (elem.IsIntValue())
                            {
                                Bytes.Pack8(buf.arr, offs, elem.GetIntValue());
                            }
                            else if (elem.IsRealValue())
                            {
                                //UPGRADE_WARNING: Data types in Visual C# might be different. Verify the accuracy of narrowing conversions.
                                Bytes.Pack8(buf.arr, offs, (long) elem.GetRealValue());
                            }
                            else
                            {
                                ThrowException("Conversion for field " + fieldName + " is not possible");
                            }
                        }
                        offs += 8;
                        continue;

                    case ClassDescriptor.tpFloat:
                        buf.Extend(offs + 4);
                        if (elem != null)
                        {
                            if (elem.IsIntValue())
                            {
                                Bytes.PackF4(buf.arr, offs, (float) elem.GetIntValue());
                            }
                            else if (elem.IsRealValue())
                            {
                                Bytes.PackF4(buf.arr, offs, (float) elem.GetRealValue());
                            }
                            else
                            {
                                ThrowException("Conversion for field " + fieldName + " is not possible");
                            }
                        }
                        offs += 4;
                        continue;

                    case ClassDescriptor.tpDouble:
                        buf.Extend(offs + 8);
                        if (elem != null)
                        {
                            if (elem.IsIntValue())
                            {
                                //UPGRADE_WARNING: Data types in Visual C# might be different. Verify the accuracy of narrowing conversions.
                                Bytes.PackF8(buf.arr, offs, (double) elem.GetIntValue());
                            }
                            else if (elem.IsRealValue())
                            {
                                Bytes.PackF8(buf.arr, offs, (double) elem.GetRealValue());
                            }
                            else
                            {
                                ThrowException("Conversion for field " + fieldName + " is not possible");
                            }
                        }
                        offs += 8;
                        continue;

                    case ClassDescriptor.tpDate:
                        buf.Extend(offs + 8);
                        if (elem != null)
                        {
                            if (elem.IsIntValue())
                            {
                                Bytes.Pack8(buf.arr, offs, elem.GetIntValue());
                            }
                            else if (elem.IsNullValue())
                            {
                                Bytes.Pack8(buf.arr, offs, -1);
                            }
                            else if (elem.IsStringValue())
                            {
                                /* TODOPORT:
                                //UPGRADE_ISSUE: Method 'java.text.DateFormat.parse' was not converted.
                                DateTime date = httpFormatter.parse(elem.GetStringValue(), 0);
                                //UPGRADE_TODO: The 'System.DateTime' structure does not have an equivalent to NULL.
                                if (date == null)
                                {
                                    ThrowException("Invalid date");
                                }
                                //UPGRADE_TODO: Method 'java.util.Date.getTime' was converted to 'DateTime.Ticks' which has a different behavior.
                                Bytes.Pack8(buf.arr, offs, date.Ticks);
                                */
                                ThrowException("Not implemented");
                            }
                            else
                            {
                                ThrowException("Conversion for field " + fieldName + " is not possible");
                            }
                        }
                        offs += 8;
                        continue;

                    case ClassDescriptor.tpString:
                        if (elem != null)
                        {
                            string val = null;
                            if (elem.IsIntValue())
                            {
                                val = Convert.ToString(elem.GetIntValue());
                            }
                            else if (elem.IsRealValue())
                            {
                                val = elem.GetRealValue().ToString();
                            }
                            else if (elem.IsStringValue())
                            {
                                val = elem.GetStringValue();
                            }
                            else if (elem.IsNullValue())
                            {
                                val = null;
                            }
                            else
                            {
                                ThrowException("Conversion for field " + fieldName + " is not possible");
                            }
                            offs = buf.PackString(offs, val, storage.encoding);
                            continue;
                        }

                        buf.Extend(offs + 4);
                        Bytes.Pack4(buf.arr, offs, -1);
                        offs += 4;
                        continue;

                    case ClassDescriptor.tpObject:
                    {
                        int oid = 0;
                        if (elem != null)
                        {
                            XMLElement ref_Renamed = elem.GetSibling("ref");
                            if (ref_Renamed == null)
                            {
                                ThrowException("<ref> element expected");
                            }
                            oid = MapId(GetIntAttribute(ref_Renamed, "id"));
                        }
                        buf.Extend(offs + 4);
                        Bytes.Pack4(buf.arr, offs, oid);
                        offs += 4;
                        continue;
                    }

                    case ClassDescriptor.tpValue:
                        offs = PackObject(elem, fd.valueDesc, offs, buf);
                        continue;

                    case ClassDescriptor.tpRaw:
                    case ClassDescriptor.tpArrayOfByte:
                        offs = ImportBinary(elem, offs, buf, fieldName);
                        continue;

                    case ClassDescriptor.tpArrayOfBoolean:
                        if (elem == null || elem.IsNullValue())
                        {
                            buf.Extend(offs + 4);
                            Bytes.Pack4(buf.arr, offs, -1);
                            offs += 4;
                        }
                        else
                        {
                            XMLElement item = elem.GetSibling("element");
                            int len = (item == null) ? 0 : item.Counter;
                            buf.Extend(offs + 4 + len);
                            Bytes.Pack4(buf.arr, offs, len);
                            offs += 4;
                            while (--len >= 0)
                            {
                                if (item.IsIntValue())
                                {
                                    buf.arr[offs] = (byte) (item.GetIntValue() != 0 ? 1 : 0);
                                }
                                else if (item.IsRealValue())
                                {
                                    buf.arr[offs] = (byte) (item.GetRealValue() != 0.0 ? 1 : 0);
                                }
                                else
                                {
                                    ThrowException("Conversion for field " + fieldName + " is not possible");
                                }
                                item = item.NextSibling;
                                offs += 1;
                            }
                        }
                        continue;

                    case ClassDescriptor.tpArrayOfChar:
                    case ClassDescriptor.tpArrayOfShort:
                        if (elem == null || elem.IsNullValue())
                        {
                            buf.Extend(offs + 4);
                            Bytes.Pack4(buf.arr, offs, -1);
                            offs += 4;
                        }
                        else
                        {
                            XMLElement item = elem.GetSibling("element");
                            int len = (item == null) ? 0 : item.Counter;
                            buf.Extend(offs + 4 + len * 2);
                            Bytes.Pack4(buf.arr, offs, len);
                            offs += 4;
                            while (--len >= 0)
                            {
                                if (item.IsIntValue())
                                {
                                    Bytes.Pack2(buf.arr, offs, (short) item.GetIntValue());
                                }
                                else if (item.IsRealValue())
                                {
                                    //UPGRADE_WARNING: Data types in Visual C# might be different. Verify the accuracy of narrowing conversions.
                                    Bytes.Pack2(buf.arr, offs, (short) item.GetRealValue());
                                }
                                else
                                {
                                    ThrowException("Conversion for field " + fieldName + " is not possible");
                                }
                                item = item.NextSibling;
                                offs += 2;
                            }
                        }
                        continue;

                    case ClassDescriptor.tpArrayOfInt:
                        if (elem == null || elem.IsNullValue())
                        {
                            buf.Extend(offs + 4);
                            Bytes.Pack4(buf.arr, offs, -1);
                            offs += 4;
                        }
                        else
                        {
                            XMLElement item = elem.GetSibling("element");
                            int len = (item == null) ? 0 : item.Counter;
                            buf.Extend(offs + 4 + len * 4);
                            Bytes.Pack4(buf.arr, offs, len);
                            offs += 4;
                            while (--len >= 0)
                            {
                                if (item.IsIntValue())
                                {
                                    Bytes.Pack4(buf.arr, offs, (int) item.GetIntValue());
                                }
                                else if (item.IsRealValue())
                                {
                                    //UPGRADE_WARNING: Data types in Visual C# might be different. Verify the accuracy of narrowing conversions.
                                    Bytes.Pack4(buf.arr, offs, (int) item.GetRealValue());
                                }
                                else
                                {
                                    ThrowException("Conversion for field " + fieldName + " is not possible");
                                }
                                item = item.NextSibling;
                                offs += 4;
                            }
                        }
                        continue;

                    case ClassDescriptor.tpArrayOfLong:
                        if (elem == null || elem.IsNullValue())
                        {
                            buf.Extend(offs + 4);
                            Bytes.Pack4(buf.arr, offs, -1);
                            offs += 4;
                        }
                        else
                        {
                            XMLElement item = elem.GetSibling("element");
                            int len = (item == null) ? 0 : item.Counter;
                            buf.Extend(offs + 4 + len * 8);
                            Bytes.Pack4(buf.arr, offs, len);
                            offs += 4;
                            while (--len >= 0)
                            {
                                if (item.IsIntValue())
                                {
                                    Bytes.Pack8(buf.arr, offs, item.GetIntValue());
                                }
                                else if (item.IsRealValue())
                                {
                                    //UPGRADE_WARNING: Data types in Visual C# might be different. Verify the accuracy of narrowing conversions.
                                    Bytes.Pack8(buf.arr, offs, (long) item.GetRealValue());
                                }
                                else
                                {
                                    ThrowException("Conversion for field " + fieldName + " is not possible");
                                }
                                item = item.NextSibling;
                                offs += 8;
                            }
                        }
                        continue;

                    case ClassDescriptor.tpArrayOfFloat:
                        if (elem == null || elem.IsNullValue())
                        {
                            buf.Extend(offs + 4);
                            Bytes.Pack4(buf.arr, offs, -1);
                            offs += 4;
                        }
                        else
                        {
                            XMLElement item = elem.GetSibling("element");
                            int len = (item == null) ? 0 : item.Counter;
                            buf.Extend(offs + 4 + len * 4);
                            Bytes.Pack4(buf.arr, offs, len);
                            offs += 4;
                            while (--len >= 0)
                            {
                                if (item.IsIntValue())
                                {
                                    Bytes.PackF4(buf.arr, offs, (float) item.GetIntValue());
                                }
                                else if (item.IsRealValue())
                                {
                                    Bytes.PackF4(buf.arr, offs, (float) item.GetRealValue());
                                }
                                else
                                {
                                    ThrowException("Conversion for field " + fieldName + " is not possible");
                                }
                                item = item.NextSibling;
                                offs += 4;
                            }
                        }
                        continue;

                    case ClassDescriptor.tpArrayOfDouble:
                        if (elem == null || elem.IsNullValue())
                        {
                            buf.Extend(offs + 4);
                            Bytes.Pack4(buf.arr, offs, -1);
                            offs += 4;
                        }
                        else
                        {
                            XMLElement item = elem.GetSibling("element");
                            int len = (item == null) ? 0 : item.Counter;
                            buf.Extend(offs + 4 + len * 8);
                            Bytes.Pack4(buf.arr, offs, len);
                            offs += 4;
                            while (--len >= 0)
                            {
                                if (item.IsIntValue())
                                {
                                    //UPGRADE_WARNING: Data types in Visual C# might be different. Verify the accuracy of narrowing conversions.
                                    Bytes.PackF8(buf.arr, offs, (double) item.GetIntValue());
                                }
                                else if (item.IsRealValue())
                                {
                                    Bytes.PackF8(buf.arr, offs, (double) item.GetRealValue());
                                }
                                else
                                {
                                    ThrowException("Conversion for field " + fieldName + " is not possible");
                                }
                                item = item.NextSibling;
                                offs += 8;
                            }
                        }
                        continue;

                    case ClassDescriptor.tpArrayOfDate:
                        if (elem == null || elem.IsNullValue())
                        {
                            buf.Extend(offs + 4);
                            Bytes.Pack4(buf.arr, offs, -1);
                            offs += 4;
                        }
                        else
                        {
                            XMLElement item = elem.GetSibling("element");
                            int len = (item == null) ? 0 : item.Counter;
                            buf.Extend(offs + 4 + len * 8);
                            Bytes.Pack4(buf.arr, offs, len);
                            offs += 4;
                            while (--len >= 0)
                            {
                                if (item.IsNullValue())
                                {
                                    Bytes.Pack8(buf.arr, offs, -1);
                                }
                                else if (item.IsStringValue())
                                {
                                    /* TODOPORT:
                                    //UPGRADE_ISSUE: Method 'java.text.DateFormat.parse' was not converted.
                                    DateTime date = httpFormatter.parse(item.GetStringValue(), 0);
                                    //UPGRADE_TODO: The 'System.DateTime' structure does not have an equivalent to NULL.
                                    if (date == null)
                                    {
                                        ThrowException("Invalid date");
                                    }
                                    //UPGRADE_TODO: Method 'java.util.Date.getTime' was converted to 'DateTime.Ticks' which has a different behavior.
                                    Bytes.Pack8(buf.arr, offs, date.Ticks);
                                    */
                                    ThrowException("Not implemented");
                                }
                                else
                                {
                                    ThrowException("Conversion for field " + fieldName + " is not possible");
                                }
                                item = item.NextSibling;
                                offs += 8;
                            }
                        }
                        continue;

                    case ClassDescriptor.tpArrayOfString:
                        if (elem == null || elem.IsNullValue())
                        {
                            buf.Extend(offs + 4);
                            Bytes.Pack4(buf.arr, offs, -1);
                            offs += 4;
                        }
                        else
                        {
                            XMLElement item = elem.GetSibling("element");
                            int len = (item == null) ? 0 : item.Counter;
                            buf.Extend(offs + 4);
                            Bytes.Pack4(buf.arr, offs, len);
                            offs += 4;
                            while (--len >= 0)
                            {
                                string val = null;
                                if (item.IsIntValue())
                                {
                                    val = Convert.ToString(item.GetIntValue());
                                }
                                else if (item.IsRealValue())
                                {
                                    val = item.GetRealValue().ToString();
                                }
                                else if (item.IsStringValue())
                                {
                                    val = item.GetStringValue();
                                }
                                else if (elem.IsNullValue())
                                {
                                    val = null;
                                }
                                else
                                {
                                    ThrowException("Conversion for field " + fieldName + " is not possible");
                                }

                                offs = buf.PackString(offs, val, storage.encoding);
                                item = item.NextSibling;
                            }
                        }
                        continue;

                    case ClassDescriptor.tpArrayOfObject:
                    case ClassDescriptor.tpLink:
                        if (elem == null || elem.IsNullValue())
                        {
                            buf.Extend(offs + 4);
                            Bytes.Pack4(buf.arr, offs, -1);
                            offs += 4;
                        }
                        else
                        {
                            XMLElement item = elem.GetSibling("element");
                            int len = (item == null) ? 0 : item.Counter;
                            buf.Extend(offs + 4 + len * 4);
                            Bytes.Pack4(buf.arr, offs, len);
                            offs += 4;
                            while (--len >= 0)
                            {
                                XMLElement ref_Renamed = item.GetSibling("ref");
                                if (ref_Renamed == null)
                                {
                                    ThrowException("<ref> element expected");
                                }
                                int oid = MapId(GetIntAttribute(ref_Renamed, "id"));
                                Bytes.Pack4(buf.arr, offs, oid);
                                item = item.NextSibling;
                                offs += 4;
                            }
                        }
                        continue;

                    case ClassDescriptor.tpArrayOfValue:
                        if (elem == null || elem.IsNullValue())
                        {
                            buf.Extend(offs + 4);
                            Bytes.Pack4(buf.arr, offs, -1);
                            offs += 4;
                        }
                        else
                        {
                            XMLElement item = elem.GetSibling("element");
                            int len = (item == null) ? 0 : item.Counter;
                            Bytes.Pack4(buf.arr, offs, len);
                            offs += 4;
                            ClassDescriptor elemDesc = fd.valueDesc;
                            while (--len >= 0)
                            {
                                offs = PackObject(item, elemDesc, offs, buf);
                                item = item.NextSibling;
                            }
                        }
                        continue;

                    case ClassDescriptor.tpArrayOfRaw:
                        if (elem == null || elem.IsNullValue())
                        {
                            buf.Extend(offs + 4);
                            Bytes.Pack4(buf.arr, offs, -1);
                            offs += 4;
                        }
                        else
                        {
                            XMLElement item = elem.GetSibling("element");
                            int len = (item == null) ? 0 : item.Counter;
                            Bytes.Pack4(buf.arr, offs, len);
                            offs += 4;
                            while (--len >= 0)
                            {
                                offs = ImportBinary(item, offs, buf, fieldName);
                                item = item.NextSibling;
                            }
                        }
                        continue;
                    }
            }
            return offs;
        }