Exemplo n.º 1
0
 /// <summary>
 ///     Loads all of the layout XML files in a directory.
 /// </summary>
 /// <param name="dirPath">The path to the directory to load XML files from.</param>
 /// <returns>The layouts that were loaded.</returns>
 public static StructureLayoutCollection LoadLayoutsFromDirectory(string dirPath)
 {
     var result = new StructureLayoutCollection();
     foreach (string file in Directory.EnumerateFiles(dirPath, "*.xml"))
     {
         StructureLayoutCollection layouts = LoadLayouts(file);
         result.Import(layouts);
     }
     return result;
 }
Exemplo n.º 2
0
        /// <summary>
        ///     Loads all of the layout XML files in a directory.
        /// </summary>
        /// <param name="dirPath">The path to the directory to load XML files from.</param>
        /// <returns>The layouts that were loaded.</returns>
        private StructureLayoutCollection LoadLayoutsFromDirectory(string dirPath)
        {
            var result = new StructureLayoutCollection();

            foreach (string file in Directory.EnumerateFiles(dirPath, "*.xml"))
            {
                StructureLayoutCollection layouts = LoadLayouts(file);
                result.Import(layouts);
            }
            return(result);
        }
Exemplo n.º 3
0
 /// <summary>
 /// Processes the queued structure list, resolving the layout referenced by each structure.
 /// </summary>
 /// <param name="layouts">The layout collection to search for layouts in.</param>
 private void ProcessStructReferences(StructureLayoutCollection layouts)
 {
     // Resolve each struct field's layout reference
     while (_structs.Count > 0)
     {
         var queuedStruct = _structs.Dequeue();
         if (!layouts.HasLayout(queuedStruct.LayoutName))
         {
             throw new InvalidOperationException("Unable to find layout \"" + queuedStruct.LayoutName + "\" referenced by structure \"" + queuedStruct.Name + "\"");
         }
         var layout = layouts.GetLayout(queuedStruct.LayoutName);
         queuedStruct.Owner.AddStructField(queuedStruct.Name, queuedStruct.Offset, layout);
     }
 }
Exemplo n.º 4
0
        /// <summary>
        ///     Loads all of the structure layouts defined in an XML document.
        /// </summary>
        /// <param name="layoutDocument">The XML document to load structure layouts from.</param>
        /// <returns>The layouts that were loaded.</returns>
        public static StructureLayoutCollection LoadLayouts(XDocument layoutDocument)
        {
            // Make sure there is a root <layouts> tag
            XContainer layoutContainer = layoutDocument.Element("layouts");
            if (layoutContainer == null)
                throw new ArgumentException("Invalid layout document");

            // Layout tags have the format:
            // <layout for="(layout's purpose)">(structure fields)</layout>
            var result = new StructureLayoutCollection();
            foreach (XElement layout in layoutContainer.Elements("layout"))
            {
                string name = XMLUtil.GetStringAttribute(layout, "for");
                int size = XMLUtil.GetNumericAttribute(layout, "size", 0);
                result.AddLayout(name, LoadLayout(layout, size));
            }
            return result;
        }
Exemplo n.º 5
0
        /// <summary>
        ///     Loads all of the structure layouts defined in an XML document.
        /// </summary>
        /// <param name="layoutDocument">The XML document to load structure layouts from.</param>
        /// <returns>The layouts that were loaded.</returns>
        private StructureLayoutCollection LoadLayouts(XDocument layoutDocument)
        {
            // Make sure there is a root <layouts> tag
            XContainer layoutContainer = layoutDocument.Element("layouts");

            if (layoutContainer == null)
            {
                throw new ArgumentException("Invalid layout document");
            }

            // Layout tags have the format:
            // <layout for="(layout's purpose)">(structure fields)</layout>
            var result = new StructureLayoutCollection();

            foreach (XElement layout in layoutContainer.Elements("layout"))
            {
                string name = XMLUtil.GetStringAttribute(layout, "for");
                int    size = (int)XMLUtil.GetNumericAttribute(layout, "size", 0);
                result.AddLayout(name, LoadLayout(layout, size));
            }
            return(result);
        }
Exemplo n.º 6
0
 /// <summary>
 /// Processes the queued structure list, resolving the layout referenced by each structure.
 /// </summary>
 /// <param name="layouts">The layout collection to search for layouts in.</param>
 private void ProcessStructReferences(StructureLayoutCollection layouts)
 {
     // Resolve each struct field's layout reference
     while (_structs.Count > 0)
     {
         var queuedStruct = _structs.Dequeue();
         if (!layouts.HasLayout(queuedStruct.LayoutName))
             throw new InvalidOperationException("Unable to find layout \"" + queuedStruct.LayoutName + "\" referenced by structure \"" + queuedStruct.Name + "\"");
         var layout = layouts.GetLayout(queuedStruct.LayoutName);
         queuedStruct.Owner.AddStructField(queuedStruct.Name, queuedStruct.Offset, layout);
     }
 }