Ejemplo n.º 1
0
        public void Load(System.IO.Stream stream)
        {
            LoadContext lc = new LoadContext();

            try
            {
                string fileName = "file.xml";
                if (stream is System.IO.FileStream)
                    fileName = (stream as System.IO.FileStream).Name;
                lc.FileName = fileName;

                var reader = new XmlTextReader(stream);
                var root = XElement.Load(reader, LoadOptions.SetLineInfo);

                ns = XNamespace.Get(ComponentNamespace);
                lc.NS = ns;

                lc.NamespaceManager = new XmlNamespaceManager(reader.NameTable);
                lc.NamespaceManager.AddNamespace("cd", ComponentNamespace);

                // Read format version
                lc.FormatVersion = new Version(1, 2);
                if (root.Attribute("version") != null)
                    lc.FormatVersion = new Version(root.Attribute("version").Value);

                // Decide which condition parser to use
                if (lc.FormatVersion >= new Version(1, 1))
                {
                    ConditionFormat conditionParseFormat = new ConditionFormat();
                    if (lc.FormatVersion == new Version(1, 1))
                        conditionParseFormat.StatesUnderscored = true;
                    else
                        conditionParseFormat.StatesUnderscored = false;

                    lc.ConditionParser = new ConditionParser(conditionParseFormat);

                }
                else
                    lc.ConditionParser = new LegacyConditionParser();

                ComponentDescription description = new ComponentDescription();

                var declaration = root.XPathSelectElement("/cd:declaration", lc.NamespaceManager);
                ReadDeclarationSection(declaration, ns, lc, description);

                ReadConnectionsSection(declaration, lc, description);

                ReadRenderSection(declaration, lc, description);

                m_descriptions = new ComponentDescription[] { description };
            }
            catch (Exception ex)
            {
                lc.Errors.Add(new LoadError(lc.FileName, 0, 0, LoadErrorCategory.Error, "A fatal error occurred - '" + ex.Message + "'"));
                m_descriptions = new ComponentDescription[0];
            }
            finally
            {
                LoadErrors = lc.Errors;
            }
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Creates a new ConditionParser using the specified parse format.
 /// </summary>
 public ConditionParser(ConditionFormat parseFormat)
 {
     ParseFormat = parseFormat;
 }
Ejemplo n.º 3
0
 /// <summary>
 /// Creates a new ConditionParser using the specified parse format.
 /// </summary>
 public ConditionParser(ConditionFormat parseFormat)
 {
     ParseFormat = parseFormat;
 }
Ejemplo n.º 4
0
 /// <summary>
 /// Creates a new ConditionParser using the default parse format.
 /// </summary>
 public ConditionParser()
 {
     ParseFormat = new ConditionFormat();
 }
Ejemplo n.º 5
0
 /// <summary>
 /// Creates a new ConditionParser using the default parse format.
 /// </summary>
 public ConditionParser()
 {
     ParseFormat = new ConditionFormat();
 }