Ejemplo n.º 1
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Converts the specified chunk of XML into a list of contributions
        /// (i.e. ContributionCollection).
        /// </summary>
        /// ------------------------------------------------------------------------------------
        public override object Deserialize(string xmlBlob)
        {
            // TODO: Deal with approved license objects of contributions.

            var contributionCollection = GetElementFromXml(xmlBlob).Elements("contributor").Select(e =>
            {
                Role role;
                _olacSystem.TryGetRoleByCode(e.Element("role").Value, out role);
                var contrib = new Contribution(e.Element("name").Value, role);
                // We have this permissive business because we released versions of SayMore (prior to 1.1.120) which used the local
                // format, rather than a universal one.
                var when = e.Element("date").Value;
                try
                {
                    contrib.Date = DateTimeExtensions.ParseDateTimePermissivelyWithException(when);
                }
                catch (Exception exception)
                {
                    Logger.WriteEvent("Handled exception in ContributionSerializer.Deserialize:\r\n{0}", exception.ToString());
                    contrib.Date = DateTime.MinValue;
                    // looked like it would take hours to change scores of methods to propogate a progress thing (e.g. ErrorCollector) down this far. Sigh...  progress.WriteError("SayMore had trouble understanding the date '{0}', on a contribution by {1}. For now, it was replaced by {2}", d, contrib.ContributorName, contrib.Date.ToString(CultureInfo.CurrentCulture));
                }
                contrib.Comments = e.Element("notes")?.Value;
                return(contrib);
            });

            return((contributionCollection.Any()) ? new ContributionCollection(contributionCollection) : null);
        }
Ejemplo n.º 2
0
        private static string GetRoleFromOlacList(string savedRole)
        {
            Role role;

            if (OlacSystem.TryGetRoleByCode(savedRole, out role))
            {
                return(role.Name);
            }

            if (OlacSystem.TryGetRoleByName(savedRole, out role))
            {
                return(role.Name);
            }

            return(savedRole);
        }
Ejemplo n.º 3
0
        public void TryGetRoleByCode_TryInvalidCode_ReturnsFalse()
        {
            Role role;

            Assert.IsFalse(_system.TryGetRoleByCode("junk", out role));
        }