/Logic/ReportModel/ModelParser.cs

# · C# · 69 lines · 56 code · 13 blank · 0 comment · 7 complexity · 8d9fed16a204c715bc10b40e75d2c809 MD5 · raw file

  1. using System.Collections.Generic;
  2. using System.Linq;
  3. using System.Xml;
  4. namespace ReportingServerManager.Logic.ReportModel
  5. {
  6. class ModelParser
  7. {
  8. readonly XmlNamespaceManager myNamespaceMgr = new XmlNamespaceManager(new NameTable());
  9. readonly Dictionary<string, string> guids = new Dictionary<string, string>();
  10. readonly XmlDocument doc = new XmlDocument();
  11. public bool LoadSMDL(string smdl)
  12. {
  13. myNamespaceMgr.AddNamespace("ds", "http://schemas.microsoft.com/sqlserver/2004/10/semanticmodeling");
  14. doc.LoadXml(smdl);
  15. AddEntityIDs();
  16. AddEntityAttributeIDs();
  17. AddEntityRoleIDs();
  18. AddIdentifyingAttributes();
  19. return true;
  20. }
  21. public bool ContainsGUID(string guid)
  22. {
  23. return guids.ContainsKey(guid);
  24. }
  25. private void AddEntityIDs()
  26. {
  27. AddIDValue("//ds:SemanticModel/ds:Entities/ds:Entity");
  28. }
  29. private void AddEntityAttributeIDs()
  30. {
  31. AddIDValue("//ds:SemanticModel/ds:Entities/ds:Entity/ds:Fields/ds:Attribute");
  32. }
  33. private void AddEntityRoleIDs()
  34. {
  35. AddIDValue("//ds:SemanticModel/ds:Entities/ds:Entity/ds:Fields/ds:Role");
  36. }
  37. private void AddIdentifyingAttributes()
  38. {
  39. var nodeList = doc.SelectNodes("//ds:Entity/ds:IdentifyingAttributes/ds:AttributeReference/ds:AttributeID", myNamespaceMgr);
  40. if (nodeList != null)
  41. foreach (var guid in nodeList.Cast<XmlNode>().Select(node => node.InnerText).Where(guid => guids.ContainsKey(guid) == false))
  42. {
  43. guids.Add(guid, "Exists...");
  44. }
  45. }
  46. private void AddIDValue(string xPath)
  47. {
  48. var nodeList = doc.SelectNodes(xPath, myNamespaceMgr);
  49. if (nodeList != null)
  50. foreach (var guid in nodeList.Cast<XmlNode>().Select(node => node.Attributes != null ? node.Attributes["ID"].Value : null).Where(guid => guids.ContainsKey(guid) == false))
  51. {
  52. guids.Add(guid, "Exists...");
  53. }
  54. }
  55. }
  56. }