Esempio n. 1
0
        /// <summary>
        /// Creates file with birthday.
        /// </summary>
        /// <param name="args"></param>
        /// <returns></returns>
        private XmlData CreateBirthday(Dictionary <string, string> args)
        {
            if (args.ContainsKey(XmlData.ID) && int.TryParse(args[XmlData.ID], out int id) &&
                args.ContainsKey(XmlData.COMMENT))
            {
                // Find member for birthday record:
                XmlNode member = GetMember(id).FirstOrDefault(XmlData.ID, args[XmlData.ID]);
                if (member?.Attributes == null)
                {
                    return(null);
                }

                // Fill members:
                XmlData birthday = new XmlData();
                foreach (Dictionary <string, string> attributes in _members.Keys.Values.OrderBy(n => n[XmlData.NAME]))
                {
                    var newAttributes = new Dictionary <string, string>(attributes);
                    newAttributes.Add(XmlData.FEE, "0"); // Add additional field.
                    birthday.Keys.Add(attributes[XmlData.ID], newAttributes);
                }
                birthday.SyncXmlWithKeys();
                // Fill specific attributes:
                birthday.DocumentElement.SetAttribute(XmlData.ID, member.Attributes[XmlData.ID].Value);
                birthday.DocumentElement.SetAttribute(XmlData.FEE, "0");                                           // Spent funds.
                birthday.DocumentElement.SetAttribute(XmlData.VAL, Uri.UnescapeDataString(args[XmlData.COMMENT])); // Comment.
                return(birthday);
            }
            return(null);
        }
Esempio n. 2
0
        /// <summary>
        /// Returns all birthdays.
        /// </summary>
        /// <param name="args">TODO: Not used.</param>
        /// <returns></returns>
        private XmlData GetBirthdays(Dictionary <string, string> args)
        {
            XmlData  birthdays = new XmlData();
            DateTime today     = DateTime.Now.Date; // Start of day.
            List <Dictionary <string, string> > orderedBirthdays = _members.Keys.Values
                                                                   .Select(e => new { Attribute = e, Birthday = DateTime.Parse(e[XmlData.BIRTHDAY]) })
                                                                   .Select(e => new { e.Attribute, Date = new DateTime(e.Birthday.Month >= today.Month ? today.Year : today.Year + 1, e.Birthday.Month, e.Birthday.Day) })
                                                                   .OrderBy(d => d.Date.Year)
                                                                   .ThenBy(d => d.Date.Month)
                                                                   .ThenBy(d => d.Date.Day)
                                                                   .Select(s => s.Attribute)
                                                                   .ToList();

            // Active and inactive members can participate in fees:
            foreach (Dictionary <string, string> attributes in orderedBirthdays)
            {
                var nodeAttributes = new Dictionary <string, string>();
                nodeAttributes.Add(XmlData.ID, attributes[XmlData.ID]);
                nodeAttributes.Add(XmlData.NAME, attributes[XmlData.NAME]);
                nodeAttributes.Add(XmlData.BIRTHDAY, attributes[XmlData.BIRTHDAY]);
                birthdays.Keys.Add(attributes[XmlData.ID], nodeAttributes);
            }
            birthdays.SyncXmlWithKeys();
            return(birthdays);
        }
Esempio n. 3
0
        /// <summary>
        /// Gets one of the properties.
        /// </summary>
        /// <param name="args"></param>
        /// <returns></returns>
        private XmlData GetProperty(Dictionary <string, string> args)
        {
            XmlData property = new XmlData();

            if (args.ContainsKey(XmlData.ID) && !string.IsNullOrWhiteSpace(args[XmlData.ID]))
            {
                property.Keys[args[XmlData.ID]] = _properties.Keys[args[XmlData.ID]];
            }
            property.SyncXmlWithKeys();
            return(property);
        }
Esempio n. 4
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. 5
0
        /// <summary>
        /// Gets sorted members.
        /// </summary>
        /// <param name="args"></param>
        /// <returns></returns>
        private XmlData GetMembers(Dictionary <string, string> args)
        {
            XmlData members = new XmlData();
            List <Dictionary <string, string> > orderedBirthdays = _members.Keys.Values
                                                                   .Select(e => new { Attribute = e, Birthday = DateTime.Parse(e[XmlData.BIRTHDAY]) })
                                                                   .OrderBy(d => d.Birthday.Month)
                                                                   .ThenBy(d => d.Birthday.Day)
                                                                   .Select(s => s.Attribute)
                                                                   .ToList();

            foreach (Dictionary <string, string> attributes in orderedBirthdays)
            {
                members.Keys.Add(attributes[XmlData.ID], attributes);
            }
            members.SyncXmlWithKeys();
            return(members);
        }
Esempio n. 6
0
        public void Start()
        {
            LoadSettings();

            // Start new root session only if its value is empty:
            string session = _settings.Keys[SESSION_COOKIE][XmlData.VAL];

            if (string.IsNullOrWhiteSpace(session))
            {
                _settings.Keys[SESSION_COOKIE][XmlData.VAL] = GenerateRandomString(16);
                _settings.SyncXmlWithKeys();
                _settings.Save(SETTINGS_FILE);
            }

            // Start listener:
            _server.Start();
        }
Esempio n. 7
0
 /// <summary>
 /// Sets one of the properties.
 /// </summary>
 /// <param name="args"></param>
 /// <param name="inputStream"></param>
 /// <returns></returns>
 private void SetProperty(Dictionary <string, string> args, Stream inputStream)
 {
     if (inputStream != null)
     {
         XmlData properties = new XmlData();
         properties.Load(inputStream);
         foreach (var node in properties.Keys)
         {
             _properties.Keys[node.Key][XmlData.VAL] = node.Value[XmlData.VAL];
         }
     }
     else if (args.ContainsKey(XmlData.ID) && !string.IsNullOrWhiteSpace(args[XmlData.ID]) &&
              args.ContainsKey(XmlData.VAL) && !string.IsNullOrWhiteSpace(args[XmlData.VAL]))
     {
         _properties.Keys[args[XmlData.ID]][XmlData.VAL] = Uri.UnescapeDataString(args[XmlData.VAL]);
     }
     _properties.SyncXmlWithKeys();
     _properties.Save(PROPERTIES_FILE);
 }