diff options
| author | jpbruyere <jp.bruyere@hotmail.com> | 2015-09-09 12:33:45 +0200 |
|---|---|---|
| committer | jpbruyere <jp.bruyere@hotmail.com> | 2015-09-09 12:33:45 +0200 |
| commit | 83a4710020bc9e254241bdce880d20bcbcec0bee (patch) | |
| tree | 6c3d80154d1e791996de2de11f3fa8398662a7f9 /src/Interface.cs | |
| parent | 0c200d4ae4f0f4a7a7c58c3affc7670eb6b2dcff (diff) | |
use Interface.GetStreamFromPath to handle either file or resource in
every loading places
Diffstat (limited to 'src/Interface.cs')
| -rw-r--r-- | src/Interface.cs | 40 |
1 files changed, 20 insertions, 20 deletions
diff --git a/src/Interface.cs b/src/Interface.cs index 2fea548a..1812217b 100644 --- a/src/Interface.cs +++ b/src/Interface.cs @@ -79,11 +79,11 @@ namespace go if (stream == null)//try to find ressource in golib assembly stream = System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream(resId); if (stream == null) - return null; + throw new Exception ("Resource not found: " + path); } else { if (!File.Exists (path)) - return null; - stream = new FileStream (path, FileMode.Open); + throw new FileNotFoundException ("File not found: ", path); + stream = new FileStream (path, FileMode.Open, FileAccess.Read); } return stream; } @@ -92,26 +92,26 @@ namespace go { string root = "Object"; - Stream stream = GetStreamFromPath (path); - if (stream == null) - throw new FileNotFoundException ("GOML file not found", path); - - using (XmlReader reader = XmlReader.Create (stream)) { - while (reader.Read()) { - // first element is the root element - if (reader.NodeType == XmlNodeType.Element) { - root = reader.Name; - break; + using (Stream stream = GetStreamFromPath (path)) { + + #region Pre-read first node to set GraphicObject class for loading + using (XmlReader reader = XmlReader.Create (stream)) { + while (reader.Read()) { + // first element is the root element + if (reader.NodeType == XmlNodeType.Element) { + root = reader.Name; + break; + } } } - } - Type t = Type.GetType("go." + root); - //var go = Activator.CreateInstance(t); - stream.Seek(0,SeekOrigin.Begin); - GraphicObject tmp = Load(stream, t, hostClass); - stream.Dispose (); - return tmp; + Type t = Type.GetType("go." + root); + //var go = Activator.CreateInstance(t); + stream.Seek(0,SeekOrigin.Begin); + #endregion + + return Load(stream, t, hostClass); + } } static GraphicObject Load(Stream stream, Type type, object hostClass = null) { |