Esempio n. 1
0
        public bool ReplaceFirst(string attributeName, string value, XmlData data)
        {
            if (_xml.DocumentElement == null)
            {
                return(false);
            }

            foreach (XmlNode node in _xml.DocumentElement.ChildNodes)
            {
                if (node.Attributes == null)
                {
                    continue;
                }

                if (node.Attributes[attributeName].Value == value)
                {
                    XmlNode importNode = data.FirstOrDefault(attributeName, value);
                    if (importNode != null)
                    {
                        _xml.DocumentElement.ReplaceChild(_xml.ImportNode(importNode, true), node);
                        SyncKeysWithXml();
                        return(true);
                    }
                }
            }
            return(false);
        }
Esempio n. 2
0
        /// <summary>
        /// Gets current fee list.
        /// </summary>
        /// <param name="args">TODO: Not used.</param>
        /// <returns></returns>
        private XmlData GetFees(Dictionary <string, string> args)
        {
            XmlData fees = new XmlData();

            foreach (string fileName in Directory.GetFiles(BIRTHDAYS_PATH, "*.xml"))
            {
                int sum = 0, expected = 0;
                var fee = new XmlData();
                fee.Load(fileName);
                foreach (Dictionary <string, string> attributes in fee.Keys.Values)
                {
                    if (attributes[XmlData.ACTIVE] == "1")
                    {
                        expected += BIRTHDAY_DEFAULT_FEE;
                    }

                    if (int.TryParse(attributes[XmlData.FEE], out var i))
                    {
                        sum += i;
                    }
                }

                string id;
                if (fee.DocumentElement == null || (id = fee.DocumentElement.Attributes[XmlData.ID]?.Value) == null)
                {
                    continue;
                }

                XmlNode member = fee.FirstOrDefault(XmlData.ID, id);
                if (member?.Attributes == null)
                {
                    continue;
                }

                var feeAttributes = new Dictionary <string, string>();
                feeAttributes.Add(XmlData.ID, id); // Member id.
                feeAttributes.Add(XmlData.NAME, member.Attributes[XmlData.NAME].Value);
                feeAttributes.Add(XmlData.BIRTHDAY, member.Attributes[XmlData.BIRTHDAY].Value);
                feeAttributes.Add(XmlData.FILE, Path.GetFileName(fileName));                       // File with fee data.
                feeAttributes.Add(XmlData.FEE, $"{sum}");                                          // Overall fee.
                feeAttributes.Add(XmlData.EXPECTED, $"{expected}");                                // Expected fee.
                feeAttributes.Add(XmlData.VAL, fee.DocumentElement.Attributes[XmlData.VAL].Value); // Comment.
                fees.Keys.Add(fileName, feeAttributes);
            }
            fees.SyncXmlWithKeys();
            return(fees);
        }
Esempio n. 3
0
        private XmlData GetMember(int id)
        {
            XmlNode memberData = _members.FirstOrDefault(XmlData.ID, $"{id}");

            return(memberData == null ? null : new XmlData(memberData));
        }