EnvironmentLoader.cs 866 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. using fun.IO.Data;
  2. using fun.IO.Parsers;
  3. using System.IO;
  4. using System.Xml;
  5. using System.Linq;
  6. using Environment = fun.Core.Environment;
  7. namespace fun.IO
  8. {
  9. public sealed class EnvironmentLoader
  10. {
  11. private DataStore data;
  12. private Parser[] parsers;
  13. public EnvironmentLoader()
  14. {
  15. data = new DataStore();
  16. parsers = new Parser[]
  17. {
  18. new EnvironmentParser(data)
  19. };
  20. }
  21. public Environment[] Load(Stream input)
  22. {
  23. var doc = new XmlDocument();
  24. doc.Load(input);
  25. foreach (var node in doc.ChildNodes.OfType<XmlNode>())
  26. foreach (var parser in parsers)
  27. if (parser.TryParse(node))
  28. parser.Parse(node);
  29. return data.Envionments;
  30. }
  31. }
  32. }