1 #region Copyright (c) Microsoft Corporation
2 /// <copyright company='Microsoft Corporation'>
3 /// Copyright (c) Microsoft Corporation. All Rights Reserved.
4 /// Information Contained Herein is Proprietary and Confidential.
8 using System.Diagnostics;
9 using System.Diagnostics.CodeAnalysis;
11 using System.Xml.Schema;
12 using System.Xml.Serialization;
14 #if WEB_EXTENSIONS_CODE
15 namespace System.Web.Compilation.WCFModel
17 namespace Microsoft.VSDesigner.WCFModel
20 #if WEB_EXTENSIONS_CODE
21 internal class SvcMapFileLoader : MapFileLoader
23 public class SvcMapFileLoader : MapFileLoader
26 private string _mapFilePath;
27 private XmlSchemaSet _mapFileSchemaSet;
28 private XmlSerializer _mapFileSerializer;
30 public SvcMapFileLoader(string mapFilePath)
32 Debug.Assert(!string.IsNullOrEmpty(mapFilePath), "mapFilePath is null!");
34 _mapFilePath = mapFilePath;
37 #region protected overrides methods
39 protected override string MapFileName
41 get { return _mapFilePath; }
44 protected override MapFile Wrap(object mapFileImpl)
46 return mapFileImpl is SvcMapFileImpl ? new SvcMapFile((SvcMapFileImpl)mapFileImpl) : null;
49 protected override object Unwrap(MapFile mapFile)
51 return mapFile is SvcMapFile ? ((SvcMapFile)mapFile).Impl : null;
54 [SuppressMessage("Microsoft.Security.Xml", "CA3060:UseXmlReaderForSchemaRead", Justification = "asp.net controls this .xsd file")]
55 protected override XmlSchemaSet GetMapFileSchemaSet()
57 if (_mapFileSchemaSet == null)
59 _mapFileSchemaSet = new XmlSchemaSet();
61 using (var stream = typeof(SvcMapFileImpl).Assembly.GetManifestResourceStream(typeof(SvcMapFileImpl), @"Schema.ServiceMapSchema.xsd"))
63 _mapFileSchemaSet.Add(XmlSchema.Read(stream, null));
67 return _mapFileSchemaSet;
70 protected override XmlSerializer GetMapFileSerializer()
72 if (_mapFileSerializer == null)
74 #if WEB_EXTENSIONS_CODE
75 _mapFileSerializer = new System.Web.Compilation.WCFModel.SvcMapFileXmlSerializer.SvcMapFileImplSerializer();
77 _mapFileSerializer = new XmlSerializer(typeof(SvcMapFileImpl), SvcMapFileImpl.NamespaceUri);
81 return _mapFileSerializer;
84 protected override TextReader GetMapFileReader()
86 return File.OpenText(_mapFilePath);
89 protected override byte[] ReadMetadataFile(string name)
91 return File.ReadAllBytes(Path.Combine(Path.GetDirectoryName(_mapFilePath), name));
94 protected override byte[] ReadExtensionFile(string name)
96 return File.ReadAllBytes(Path.Combine(Path.GetDirectoryName(_mapFilePath), name));
99 #endregion protected overrides methods