CCNet.Build.Reconfigure.ProjectPage.ParseProperties C# (CSharp) Method

ParseProperties() private method

private ParseProperties ( XElement page ) : string>.Dictionary
page XElement
return string>.Dictionary
		private Dictionary<string, string> ParseProperties(XElement page)
		{
			var table = page.XElement("table");
			if (table == null)
				throw new InvalidOperationException("Cannot locate properties table.");

			var map = new Dictionary<string, string>();
			foreach (var tr in table.XElements("tbody/tr"))
			{
				var columns = tr.Elements().ToList();
				if (columns.Count < 2)
					throw new InvalidOperationException("Properties table should contain at least 2 columns.");

				var th = columns[0];
				var td = columns[1];

				var key = th.XValue();
				var value = td.XValue();

				var code = td.XElement("code");
				if (code != null)
					value = code.XValue();

				var status = td.XElement("ac:structured-macro[@ac:name='status']/ac:parameter[@ac:name='title']");
				if (status != null)
					value = status.XValue();

				var user = td.XElements("ac:link/ri:user").Select(e => e.XAttribute("ri:userkey").Value).FirstOrDefault();
				if (user != null)
					value = user;

				var link = td.XElements("ac:link/ri:page").Select(e => e.XAttribute("ri:content-title").Value).FirstOrDefault();
				if (link != null)
					value = link;

				map[key] = value.Trim();
			}

			if (map.Count == 0)
				throw new InvalidOperationException("Cannot locate any rows in properties.");

			return map;
		}