Ejemplo n.º 1
0
        ///<summary>
        /// Create a new TydFile from a TydDocument.
        ///</summary>
        public static TydFile FromDocument(TydDocument doc, string filePath = null)
        {
            TydFile t = new TydFile();

            t.docNode  = doc;
            t.filePath = filePath;
            return(t);
        }
Ejemplo n.º 2
0
        ///<summary>
        /// Create a new TydFile from a TydDocument.
        ///</summary>
        public static TydFile FromDocument(TydDocument doc, string filePath = null)
        {
            doc.Name = Path.GetFileName(filePath);
            var t = new TydFile();

            t._docNode  = doc;
            t._filePath = filePath;
            return(t);
        }
Ejemplo n.º 3
0
 ///<summary>
 /// Registers all _nodes from doc.
 /// When we resolve later, we'll be able to use the _nodes in this document as a sources.
 ///</summary>
 public static void RegisterAllFrom(TydDocument doc)
 {
     for (var i = 0; i < doc.Count; i++)
     {
         var tydCol = doc[i] as TydCollection;
         if (tydCol != null)
         {
             Register(tydCol);
         }
     }
 }
Ejemplo n.º 4
0
 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);
     }
 }
Ejemplo n.º 5
0
        ///<summary>
        /// Registers all root nodes in a doc.
        /// When we resolve later, we'll be able to use the nodes in this document as a sources.
        ///</summary>
        public static void RegisterAllRoots(TydDocument doc)
        {
            if (!initialized)
            {
                throw new Exception("Used Tyd.Inheritance when it was not initialized.");
            }

            for (int i = 0; i < doc.Count; i++)
            {
                var tydCol = doc[i] as TydCollection;
                if (tydCol != null)
                {
                    Register(tydCol);
                }
            }
        }
Ejemplo n.º 6
0
        ///<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);
            }
        }