Esempio n. 1
0
        /// <summary>Commit changes made to the collection.</summary>
        async Task ICollectionRef <T> .Commit()
        {
            try
            {
                using LiteRepository _liteRepo = new LiteRepository(RefConfig.Location);
                if (ToSave.Any() || ToModify.Any())
                {
                    IList <T> _combinedList = ToSave.Concat(ToModify).ToList();
                    _liteRepo.Upsert <T>(_combinedList, RefConfig.Collection);
                }
                if (ToRemove.Any())
                {
                    BsonValue[] _bsonValues = ToRemove.Select(_id => new BsonValue(_id)).ToArray();
                    _liteRepo.DeleteMany <T>(Query.In("_id", _bsonValues), RefConfig.Collection);
                }

                await Task.Run(() =>
                {
                    ToSave.Clear();
                    ToModify.Clear();
                    ToRemove.Clear();
                });
            }
            catch (Exception ex)
            { throw ex; }
        }
Esempio n. 2
0
        public override XmlNode ToXml(XmlDocument doc)
        {
            XmlElement root = doc.CreateElement("secDNS:update", "urn:ietf:params:xml:ns:secDNS-1.1");

            root.SetAttribute("xmlns:secDNS", "urn:ietf:params:xml:ns:secDNS-1.1");

            XmlAttribute xsd = doc.CreateAttribute("xsi", "schemaLocation", "http://www.w3.org/2001/XMLSchema-instance");

            xsd.Value = "urn:ietf:params:xml:ns:secDNS-1.1 secDNS-1.1.xsd";
            root.Attributes.Append(xsd);

            if (ToRemove.Any())
            {
                XmlElement removeNode = doc.CreateElement("secDNS:rem", "urn:ietf:params:xml:ns:secDNS-1.1");

                foreach (SecDNSData data in ToRemove)
                {
                    removeNode.AppendChild(data.ToXml(doc));
                }

                root.AppendChild(removeNode);
            }

            if (ToAdd.Any())
            {
                XmlElement addNode = doc.CreateElement("secDNS:add", "urn:ietf:params:xml:ns:secDNS-1.1");

                foreach (SecDNSData data in ToAdd)
                {
                    addNode.AppendChild(data.ToXml(doc));
                }

                root.AppendChild(addNode);
            }

            return(root);
        }