/// <summary> /// Update all referances found in the Resource narrative /// </summary> /// <param name="Narrative"></param> /// <param name="ReferanceMap"> Key: Old Referance, Value: New Referance</param> /// <returns>True if an referance was updated, False if none updated</returns> public static bool UpdateAllReferances(this Narrative Narrative, IDictionary <string, string> ReferanceMap) { bool HasUpdated = false; if (Narrative != null) { var xDoc = XElement.Parse(Narrative.Div); //Find and update all <a href=""/> referances List <XElement> LinkList = xDoc.Descendants().Where(x => x.Name.LocalName == "a").ToList(); foreach (var Link in LinkList) { var href = Link.Attributes().FirstOrDefault(x => x.Name.LocalName == "href"); if (href != null) { if (ReferanceMap.ContainsKey(href.Value)) { href.Value = ReferanceMap[href.Value]; HasUpdated = true; } } } //Find and update all <img src=""/> referances List <XElement> LinkListImg = xDoc.Descendants().Where(x => x.Name.LocalName == "img").ToList(); foreach (var Link in LinkListImg) { var src = Link.Attributes().FirstOrDefault(x => x.Name.LocalName == "src"); if (src != null) { if (ReferanceMap.ContainsKey(src.Value)) { src.Value = ReferanceMap[src.Value]; HasUpdated = true; } } } Narrative.Div = xDoc.ToString(); } return(HasUpdated); }