Exemplo n.º 1
0
    public static void InsertAll <T>(string path, Dictionary <int, T> dict, EDataKeyType keyType)
    {
        if (Write == false)
        {
            return;
        }
        XmlDocument xmlDoc = LoadDocument(path);
        FileStream  fs     = File.OpenRead(path);

        if (fs == null)
        {
            return;
        }
        if (dict == null)
        {
            return;
        }
        XmlNode xmlNode = xmlDoc.SelectSingleNode(ROOTNAME);

        Dictionary <int, T> .Enumerator em = dict.GetEnumerator();
        while (em.MoveNext())
        {
            XmlElement xe = xmlDoc.CreateElement(ELEMNAME);
            xmlNode.AppendChild(xe);
            int key = em.Current.Key;
            T   obj = em.Current.Value;
            xe.SetAttribute(keyType.ToString(), key.ToString());
            Save <T>(xe, obj);
        }
        em.Dispose();
        fs.Close();
        fs.Dispose();
        xmlDoc.Save(path);
    }
Exemplo n.º 2
0
    public static void Delete(string path, string key, EDataKeyType keyType)
    {
        if (Write == false)
        {
            return;
        }
        XmlDocument xmlDoc = LoadDocument(path);
        FileStream  fs     = File.OpenRead(path);

        if (fs == null)
        {
            return;
        }
        XmlNodeList xmlNodeList = xmlDoc.SelectSingleNode(ROOTNAME).ChildNodes;
        XmlElement  xe          = null;

        for (int i = 0; i < xmlNodeList.Count; i++)
        {
            xe = xmlNodeList.Item(i) as XmlElement;
            if (xe == null)
            {
                continue;
            }
            string id = xe.GetAttribute(keyType.ToString());
            if (id == key)
            {
                XmlNode node = xmlDoc.SelectSingleNode(ROOTNAME);
                node.RemoveChild(xe);
                break;
            }
        }
        fs.Close();
        fs.Dispose();
        xmlDoc.Save(path);
    }
Exemplo n.º 3
0
    public static void Read(string path, EDataKeyType keyType)
    {
        XmlPath = path;
        KeyType = keyType;
        XmlNodeList nodeList = GTXmlHelper.GetXmlNodeList(XmlPath);

        for (int i = 0; i < nodeList.Count; i++)
        {
            XmlElement xe = nodeList.Item(i) as XmlElement;
            if (xe == null)
            {
                continue;
            }
            int key = xe.GetAttribute(KeyType.ToString()).ToInt32();
            for (int j = 0; j < xe.Attributes.Count; j++)
            {
                string name  = xe.Attributes[j].Name;
                string value = xe.Attributes[j].Value;
                AppendAttribute(key, name, value);
            }
        }
    }
Exemplo n.º 4
0
    public static void Append(string path, string key, object obj, EDataKeyType keyType)
    {
        if (Write == false)
        {
            return;
        }

        XmlDocument xmlDoc = LoadDocument(path);
        FileStream  fs     = File.OpenRead(path);

        if (fs == null)
        {
            return;
        }
        XmlNode    xmlNode = xmlDoc.SelectSingleNode(ROOTNAME);
        XmlElement em      = xmlDoc.CreateElement(ELEMNAME);

        xmlNode.AppendChild(em);
        em.SetAttribute(keyType.ToString(), key);
        Save(em, obj);
        fs.Close();
        fs.Dispose();
        xmlDoc.Save(path);
    }