public static TydFile FromContent(string content, string filePath) { try { var tydNodeList = TydFromText.Parse(content); var tydDoc = new TydDocument(tydNodeList); return(FromDocument(tydDoc, filePath)); } catch (Exception e) { throw new Exception("Exception loading " + filePath + ": " + e); } }
///<summary> /// Create a new TydFile by loading data from a file at the given path. ///</summary> public static TydFile FromFile(string filePath, bool treatXmlAsOneObject = false) { try { if (Path.GetExtension(filePath).ToLowerInvariant() == ".xml") { //File is xml format //Load it and convert the tyd _nodes from it var contents = File.ReadAllText(filePath); var xmlDoc = new XmlDocument(); xmlDoc.LoadXml(contents); var nodes = new List <TydNode>(); if (treatXmlAsOneObject) { nodes.Add(TydXml.TydNodeFromXmlDocument(xmlDoc)); } else { nodes.AddRange(TydXml.TydNodesFromXmlDocument(xmlDoc)); } return(FromDocument(new TydDocument(nodes), filePath)); } else { //If it's any extension besides xml, we assume the file is Tyd format string readContents; using (var streamReader = new StreamReader(filePath)) { readContents = streamReader.ReadToEnd(); } var tydNodeList = TydFromText.Parse(readContents); var tydDoc = new TydDocument(tydNodeList); return(FromDocument(tydDoc, filePath)); } } catch (Exception e) { throw new Exception("Exception loading " + filePath + ": " + e); } }