/// <summary>
 /// Creates a new ConditionParser using the specified parse format.
 /// </summary>
 public ConditionParser(ConditionFormat parseFormat)
 {
     ParseFormat = parseFormat;
 }
Beispiel #2
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 root = XElement.Load(stream, LoadOptions.SetLineInfo);

                // 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.Elements().First(x => x.Name == ComponentNamespace + "declaration");
                ReadDeclarationSection(declaration, ns, lc, description);

                ReadConnectionsSection(declaration, lc, description);

                ReadRenderSection(declaration, lc, description);

                m_descriptions = new [] { 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;
            }
        }
 /// <summary>
 /// Creates a new ConditionParser using the default parse format.
 /// </summary>
 public ConditionParser()
 {
     ParseFormat = new ConditionFormat();
 }