Changeset 4522
- Timestamp:
- 12/31/07 05:54:24 (1 year ago)
- Files:
-
- trunk/nuxleus/Source/Nuxleus.Command/Nuxleus.Command.csproj (modified) (1 diff)
- trunk/nuxleus/Source/Nuxleus.Extension/Nuxleus.Extension.csproj (modified) (1 diff)
- trunk/nuxleus/Source/Nuxleus.IO/AsyncResult (added)
- trunk/nuxleus/Source/Nuxleus.IO/AsyncResult/NuxleusAsyncResult.cs (added)
- trunk/nuxleus/Source/Nuxleus.IO/Nuxleus.IO.csproj (modified) (1 diff)
- trunk/nuxleus/Source/Nuxleus.Web/HttpApplication/Global.cs (modified) (4 diffs)
- trunk/nuxleus/Source/Nuxleus.Web/HttpHandler/NuxleusHttpAsyncFileNotFoundHandler.cs (modified) (3 diffs)
- trunk/nuxleus/Source/Nuxleus.Web/HttpHandler/NuxleusHttpAsyncHandler.cs (modified) (3 diffs)
- trunk/nuxleus/Source/Nuxleus.Web/HttpHandler/NuxleusHttpAsyncXmlServiceOperationHandler.cs (modified) (12 diffs)
- trunk/nuxleus/Source/Nuxleus.Web/Nuxleus.Web.csproj (modified) (3 diffs)
- trunk/nuxleus/Source/Nuxleus/Agent.cs (modified) (2 diffs)
- trunk/nuxleus/Source/Xameleon/Transform/AsyncProcess.cs (modified) (3 diffs)
- trunk/nuxleus/Source/Xameleon/Transform/XsltTransformationManager.cs (modified) (10 diffs)
- trunk/nuxleus/Web/Development/Web.config (modified) (3 diffs)
- trunk/nuxleus/Web/Development/service/flickr/return-images-by-tag-name/service.op (modified) (1 diff)
- trunk/nuxleus/Web/Development/service/proxy/return-news-by-location/service.op (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/nuxleus/Source/Nuxleus.Command/Nuxleus.Command.csproj
r4359 r4522 43 43 <ItemGroup> 44 44 <Compile Include="Agent.cs" /> 45 <Compile Include="ICommand.cs" /> 45 46 <Compile Include="Program.cs" /> 46 47 <Compile Include="Properties\AssemblyInfo.cs" /> trunk/nuxleus/Source/Nuxleus.Extension/Nuxleus.Extension.csproj
r4359 r4522 45 45 <Compile Include="Agent.cs" /> 46 46 <Compile Include="Properties\AssemblyInfo.cs" /> 47 <Compile Include="StringUtils\Substring.cs" /> 47 48 </ItemGroup> 48 49 <ItemGroup> trunk/nuxleus/Source/Nuxleus.IO/Nuxleus.IO.csproj
r4359 r4522 51 51 <ItemGroup> 52 52 <Compile Include="Agent.cs" /> 53 <Compile Include="AsyncResult\NuxleusAsyncResult.cs" /> 53 54 <Compile Include="Clipboard\Cache.cs" /> 54 55 <Compile Include="Clipboard\Clipboard.cs" /> trunk/nuxleus/Source/Nuxleus.Web/HttpApplication/Global.cs
r4521 r4522 47 47 BaseXsltContext m_baseXsltContext; 48 48 String m_baseUri; 49 UTF8Encoding m_encoding; 49 50 static HashAlgorithm m_hashAlgorithm = HashAlgorithm.MD5; 50 51 … … 70 71 m_geoIPLookup = new Dictionary<String, IPLocation>(); 71 72 m_requestXsltParams = null; 73 m_encoding = new UTF8Encoding(); 72 74 73 75 using(XmlReader configReader = XmlReader.Create(HttpContext.Current.Server.MapPath("~/App_Data/aws.config"))) … … 155 157 Application["as_debug"] = m_DEBUG; 156 158 Application["as_hashkey"] = hashkey; 159 Application["as_encoding"] = m_encoding; 157 160 } 158 161 … … 169 172 Application["debug"] = Application["as_debug"]; 170 173 Application["hashkey"] = Application["as_hashkey"]; 174 Application["encoding"] = Application["as_encoding"]; 171 175 } 172 176 trunk/nuxleus/Source/Nuxleus.Web/HttpHandler/NuxleusHttpAsyncFileNotFoundHandler.cs
r4521 r4522 24 24 using Nuxleus.Cryptography; 25 25 using Nuxleus.Bucker; 26 using Nuxleus.Async; 26 27 27 28 namespace Nuxleus.Web.HttpHandler { … … 38 39 Hashtable m_xsltParams; 39 40 Hashtable m_namedXsltHashtable; 40 TransformServiceAsyncResult m_transformAsyncResult;41 NuxleusAsyncResult m_transformAsyncResult; 41 42 AsyncCallback m_callback; 42 43 String m_httpMethod; … … 69 70 m_namedXsltHashtable = (Hashtable)context.Application["namedXsltHashtable"]; 70 71 m_transformContext = new Transform.Context(context, m_hashAlgorithm, (string)context.Application["hashkey"], fileInfo, (Hashtable)m_xsltParams.Clone(), fileInfo.LastWriteTimeUtc, fileInfo.Length); 71 m_transformAsyncResult = new TransformServiceAsyncResult(cb, extraData);72 m_transformAsyncResult = new NuxleusAsyncResult(cb, extraData); 72 73 m_callback = cb; 73 m_transformAsyncResult. _context = context;74 m_transformAsyncResult.m_context = context; 74 75 m_builder = new StringBuilder(); 75 76 m_CONTENT_IS_MEMCACHED = false; trunk/nuxleus/Source/Nuxleus.Web/HttpHandler/NuxleusHttpAsyncHandler.cs
r4521 r4522 24 24 using Nuxleus.Cryptography; 25 25 using Nuxleus.Bucker; 26 using Nuxleus.Async; 26 27 27 28 namespace Nuxleus.Web.HttpHandler … … 39 40 Hashtable m_xsltParams; 40 41 Hashtable m_namedXsltHashtable; 41 TransformServiceAsyncResult m_transformAsyncResult;42 NuxleusAsyncResult m_transformAsyncResult; 42 43 AsyncCallback m_callback; 43 44 String m_httpMethod; … … 75 76 m_namedXsltHashtable = (Hashtable)context.Application["namedXsltHashtable"]; 76 77 m_transformContext = new Transform.Context(context, m_hashAlgorithm, (string)context.Application["hashkey"], fileInfo, (Hashtable)m_xsltParams.Clone(), fileInfo.LastWriteTimeUtc, fileInfo.Length); 77 m_transformAsyncResult = new TransformServiceAsyncResult(cb, extraData);78 m_transformAsyncResult = new NuxleusAsyncResult(cb, extraData); 78 79 m_callback = cb; 79 m_transformAsyncResult. _context = context;80 m_transformAsyncResult.m_context = context; 80 81 m_builder = new StringBuilder(); 81 82 m_CONTENT_IS_MEMCACHED = false; trunk/nuxleus/Source/Nuxleus.Web/HttpHandler/NuxleusHttpAsyncXmlServiceOperationHandler.cs
r4521 r4522 4 4 5 5 using System; 6 using System.Diagnostics; 6 7 using System.IO; 7 8 using System.Data; … … 18 19 using Saxon.Api; 19 20 using System.Xml; 21 using Mvp.Xml; 20 22 using Nuxleus.Configuration; 21 23 using Nuxleus.Transform; … … 25 27 using Nuxleus.Bucker; 26 28 using Nuxleus.Async; 29 using System.Globalization; 27 30 28 31 namespace Nuxleus.Web.HttpHandler { … … 31 34 32 35 XmlServiceOperationManager m_xmlServiceOperationManager; 36 XsltTransformationManager m_xslTransformationManager; 37 Transform.Context m_transformContext; 38 Transform.Transform m_transform; 39 Hashtable m_xsltParams; 40 Hashtable m_namedXsltHashtable; 41 TransformServiceAsyncResult m_transformAsyncResult; 33 42 MemcachedClient m_memcachedClient; 34 43 QueueClient m_queueClient; … … 52 61 string m_lastModifiedKey; 53 62 string m_lastModifiedDate; 63 UTF8Encoding m_encoding; 64 Stopwatch m_stopwatch; 54 65 55 66 public void ProcessRequest (HttpContext context) { … … 72 83 m_httpMethod = m_httpContext.Request.HttpMethod; 73 84 m_memcachedClient = (Client)context.Application["memcached"]; 85 m_encoding = (UTF8Encoding)context.Application["encoding"]; 74 86 m_queueClient = (QueueClient)context.Application["queueclient"]; 75 87 m_hashkey = (string)context.Application["hashkey"]; 76 88 m_xmlServiceOperationManager = (XmlServiceOperationManager)context.Application["xmlServiceOperationManager"]; 89 m_xslTransformationManager = (XsltTransformationManager)context.Application["xslTransformationManager"]; 90 m_transform = m_xslTransformationManager.Transform; 91 m_xsltParams = (Hashtable)context.Application["globalXsltParams"]; 92 m_transformContext = new Transform.Context(context, m_hashAlgorithm, (string)context.Application["hashkey"], fileInfo, (Hashtable)m_xsltParams.Clone(), fileInfo.LastWriteTimeUtc, fileInfo.Length); 93 m_namedXsltHashtable = (Hashtable)context.Application["namedXsltHashtable"]; 77 94 m_xmlSourceETagDictionary = m_xmlServiceOperationManager.XmlSourceETagDictionary; 78 95 m_xmlReaderDictionary = m_xmlServiceOperationManager.XmlReaderDictionary; … … 89 106 m_lastModifiedKey = String.Format("LastModified:{0}", m_context.RequestUri); 90 107 m_lastModifiedDate = String.Empty; 91 92 108 m_stopwatch = new Stopwatch(); 109 110 m_stopwatch.Start(); 93 111 bool hasXmlSourceChanged = m_xmlServiceOperationManager.HasXmlSourceChanged(m_context.RequestXmlETag, requestUri); 94 112 … … 119 137 if (context.Request.Headers["If-None-Match"] == m_requestHashcode) { 120 138 121 if (m_USE_MEMCACHED && m_memcachedClient.KeyExists(m_lastModifiedKey) && !hasXmlSourceChanged) {139 if (m_USE_MEMCACHED && m_memcachedClient.KeyExists(m_lastModifiedKey) && !hasXmlSourceChanged) { 122 140 m_lastModifiedDate = (string)m_memcachedClient.Get(m_lastModifiedKey); 123 141 if (context.Request.Headers["If-Modified-Since"] == m_lastModifiedDate) { … … 158 176 Process: 159 177 try { 178 string xmlStylesheetHref = String.Empty; 179 bool processWithEmbeddedPIStylsheet = false; 160 180 XmlReader reader = m_xmlServiceOperationManager.GetXmlReader(m_context.RequestXmlETag, requestUri); 161 while (reader.Read()) { 162 if (reader.IsStartElement()) { 163 switch (reader.Name) { 164 case "service:operation": 165 m_writer.WriteLine(reader.ReadOuterXml()); 166 break; 167 default: 168 break; 169 } 181 do { 182 switch (reader.NodeType) { 183 case XmlNodeType.ProcessingInstruction: 184 switch (reader.Name) { 185 case "xml-stylesheet": 186 string piValue = reader.Value; 187 if (piValue.Contains("type=\"text/xsl\"") && piValue.Contains("href=")) { 188 processWithEmbeddedPIStylsheet = true; 189 xmlStylesheetHref = SubstringBefore(SubstringAfter(piValue, "href=\""), "\""); 190 } 191 //Console.WriteLine("Stylesheet Href = {0}", xmlStylesheetHref); 192 break; 193 default: 194 break; 195 } 196 break; 197 case XmlNodeType.Element: 198 if (reader.IsStartElement()) { 199 switch (reader.Name) { 200 case "service:operation": 201 Uri baseXsltUri = new Uri(context.Request.MapPath(xmlStylesheetHref)); 202 string baseXslt = baseXsltUri.GetHashCode().ToString(); 203 204 if (!m_xslTransformationManager.NamedXsltHashtable.ContainsKey(baseXslt)) { 205 m_xslTransformationManager.AddTransformer(baseXslt, baseXsltUri); 206 m_xslTransformationManager.NamedXsltHashtable.Add(baseXslt, baseXsltUri); 207 } 208 if (!m_xslTransformationManager.XmlSourceHashtable.ContainsKey(m_context.RequestXmlETag)) { 209 using (MemoryStream stream = new MemoryStream(m_encoding.GetBytes(reader.ReadOuterXml().ToCharArray()))) { 210 m_xslTransformationManager.AddXmlSource(m_context.RequestXmlETag.ToString(), (Stream)stream); 211 } 212 } 213 //m_writer.WriteLine(reader.ReadOuterXml()); 214 m_transform.BeginProcess(m_transformContext, context, m_xslTransformationManager, m_writer, baseXslt, m_nuxleusAsyncResult); 215 216 break; 217 default: 218 break; 219 } 220 } 221 break; 222 case XmlNodeType.EndElement: 223 224 continue; 225 case XmlNodeType.Text: 226 case XmlNodeType.SignificantWhitespace: 227 case XmlNodeType.Whitespace: 228 229 break; 230 case XmlNodeType.CDATA: 231 232 break; 233 case XmlNodeType.Comment: 234 break; 235 case XmlNodeType.DocumentType: 236 break; 237 case XmlNodeType.EntityReference: 238 reader.ResolveEntity(); 239 continue; 240 241 case XmlNodeType.XmlDeclaration: 242 case XmlNodeType.EndEntity: 243 continue; 244 default: 245 break; 246 //throw new InvalidOperationException(); 247 170 248 } 171 } 249 } while (reader.Read()); 172 250 goto CompleteCall; 173 251 } catch (Exception e) { … … 182 260 m_lastModifiedDate = DateTime.UtcNow.ToString("r"); 183 261 } 184 context.Response.Expires = 15;185 262 context.Response.AppendHeader("Cache-Control", "max-age=3600"); 186 263 context.Response.AddHeader("Last-Modified", m_lastModifiedDate); … … 199 276 } 200 277 if (!m_CONTENT_IS_MEMCACHED && m_USE_MEMCACHED) { 201 m_memcachedClient.Set(m_context.GetRequestHashcode(true).ToString(), output, DateTime.Now.AddHours( 1));278 m_memcachedClient.Set(m_context.GetRequestHashcode(true).ToString(), output, DateTime.Now.AddHours(4)); 202 279 m_memcachedClient.Set(m_lastModifiedKey, m_lastModifiedDate); 203 280 } 204 281 } 282 m_stopwatch.Stop(); 283 Console.WriteLine("Total processing time:\t\t{0} ms", m_stopwatch.ElapsedMilliseconds); 205 284 } 206 285 … … 220 299 m_httpContext.Response.Output.WriteLine("</html>"); 221 300 } 301 302 /// <summary> 303 /// Modified from Oleg Tkachenko's SubstringBefore and SubstringAfter extension functions 304 /// @ http://www.tkachenko.com/blog/archives/000684.html 305 /// This will be moved into an appropriate class once I have the time. 306 /// </summary> 307 /// <param name="source"></param> 308 /// <param name="value"></param> 309 /// <returns></returns> 310 public static string SubstringAfter (string source, string value) { 311 if (string.IsNullOrEmpty(value)) { 312 return source; 313 } 314 CompareInfo compareInfo = CultureInfo.InvariantCulture.CompareInfo; 315 int index = compareInfo.IndexOf(source, value, CompareOptions.Ordinal); 316 if (index < 0) { 317 //No such substring 318 return string.Empty; 319 } 320 return source.Substring(index + value.Length); 321 } 322 323 public static string SubstringBefore (string source, string value) { 324 if (string.IsNullOrEmpty(value)) { 325 return value; 326 } 327 CompareInfo compareInfo = CultureInfo.InvariantCulture.CompareInfo; 328 int index = compareInfo.IndexOf(source, value, CompareOptions.Ordinal); 329 if (index < 0) { 330 //No such substring 331 return string.Empty; 332 } 333 return source.Substring(0, index); 334 } 222 335 #endregion 223 336 } trunk/nuxleus/Source/Nuxleus.Web/Nuxleus.Web.csproj
r4521 r4522 112 112 </Compile> 113 113 <Compile Include="Agent.cs" /> 114 <Compile Include=" AsyncResult\NuxleusAsyncResult.cs" />114 <Compile Include="HttpHandler\temp.cs" /> 115 115 <Compile Include="XmlServiceOperation\Context.cs" /> 116 116 <Compile Include="HttpHandler\NuxleusHttpAsyncQueryEntityHandler.cs" /> … … 131 131 <Compile Include="HttpModule\*.cs" /> 132 132 <Compile Include="XmlServiceOperation\XmlServiceOperationManager.cs" /> 133 <Compile Include="XmlServiceOperation\XmlServiceOperationReader.cs" /> 133 134 </ItemGroup> 134 135 <ItemGroup> … … 182 183 </ItemGroup> 183 184 <ItemGroup> 185 <Folder Include="AsyncResult\" /> 184 186 <Folder Include="Properties\" /> 185 187 </ItemGroup> trunk/nuxleus/Source/Nuxleus/Agent.cs
r4374 r4522 9 9 public struct Agent : IAgent 10 10 { 11 PostOffice _postOffice;12 Hashtable _resultHashtable;13 LoadBalancer _loadBalancer;11 PostOffice m_postOffice; 12 Hashtable m_resultHashtable; 13 LoadBalancer m_loadBalancer; 14 14 15 15 public Agent (LoadBalancer loadBalancer) 16 16 { 17 _loadBalancer = LoadBalancer.GetLoadBalancer();18 _postOffice = null;19 _resultHashtable = new Hashtable();17 m_loadBalancer = LoadBalancer.GetLoadBalancer(); 18 m_postOffice = null; 19 m_resultHashtable = new Hashtable(); 20 20 } 21 21 22 public PostOffice PostOffice { get { return _postOffice; } set {_postOffice = value; } }23 public Hashtable Result { get { return _resultHashtable; } set {_resultHashtable = value; } }22 public PostOffice PostOffice { get { return m_postOffice; } set { m_postOffice = value; } } 23 public Hashtable Result { get { return m_resultHashtable; } set { m_resultHashtable = value; } } 24 24 25 25 public Response MakeRequest (Request request) 26 26 { 27 if ( _postOffice == null)27 if (m_postOffice == null) 28 28 { 29 _postOffice =_loadBalancer.GetPostOffice;29 m_postOffice = m_loadBalancer.GetPostOffice; 30 30 } 31 ///TODO: Create the logic for adding a new request to the _postOffice.Inbox.31 ///TODO: Create the logic for adding a new request to the m_postOffice.Inbox. 32 32 ///For now will just return a new Response() so we can compile; 33 33 return new Response(); … … 36 36 public string GetResponse (Guid id) 37 37 { 38 return (string) _resultHashtable[id];38 return (string)m_resultHashtable[id]; 39 39 } 40 40 public void AuthenticateRequest () { } trunk/nuxleus/Source/Xameleon/Transform/AsyncProcess.cs
r3980 r4522 8 8 using System.Text; 9 9 using System.Web.SessionState; 10 using Nuxleus.Async; 10 11 11 12 namespace Nuxleus.Transform … … 17 18 { 18 19 19 public void BeginProcess(Context context, HttpContext httpContext, XsltTransformationManager manager, TextWriter writer, TransformServiceAsyncResult result)20 public void BeginProcess(Context context, HttpContext httpContext, XsltTransformationManager manager, TextWriter writer, NuxleusAsyncResult result) 20 21 { 21 22 BeginProcess(context, httpContext, manager, writer, manager.BaseXsltName, result); 22 23 } 23 24 24 public void BeginProcess (Context context, HttpContext httpContext, XsltTransformationManager manager, TextWriter writer, String xsltName, TransformServiceAsyncResult result)25 public void BeginProcess (Context context, HttpContext httpContext, XsltTransformationManager manager, TextWriter writer, String xsltName, NuxleusAsyncResult result) 25 26 { 26 27 XsltTransformer transformer = manager.GetTransformer(xsltName); … … 50 51 } 51 52 52 result.CompleteCall();53 //result.CompleteCall(); 53 54 } 54 55 } trunk/nuxleus/Source/Xameleon/Transform/XsltTransformationManager.cs
r4511 r4522 8 8 using Nuxleus.Cryptography; 9 9 10 namespace Nuxleus.Transform 11 { 10 namespace Nuxleus.Transform { 12 11 13 12 //NOTE: TransformEngine enum PLACEHOLDER FOR FUTURE USE 14 13 public enum TransformEngine { SAXON, MVPXML, NET_1_1, NET_2_0, NET_3_0, NET_3_5, SILVERLIGHT } 15 14 16 public struct XsltTransformationManager 17 { 15 public struct XsltTransformationManager { 18 16 19 17 Hashtable m_xsltHashtable; … … 36 34 static TransformEngine m_transformEngine; 37 35 38 public XsltTransformationManager(Processor processor) 39 : this(processor, new Transform(), new XmlUrlResolver(), new Serializer(), new Hashtable(), new Hashtable(), new Hashtable(), new Hashtable(), new Hashtable(), new Hashtable(), null, null, null) 40 { 41 } 42 public XsltTransformationManager(Processor processor, Transform transform) 43 : this(processor, transform, new XmlUrlResolver(), new Serializer(), new Hashtable(), new Hashtable(), new Hashtable(), new Hashtable(), new Hashtable(), new Hashtable(), null, null, null) 44 { 45 } 46 public XsltTransformationManager(Processor processor, Transform transform, XmlUrlResolver resolver) 47 : this(processor, transform, resolver, new Serializer(), new Hashtable(), new Hashtable(), new Hashtable(), new Hashtable(), new Hashtable(), new Hashtable(), null, null, null) 48 { 49 } 50 public XsltTransformationManager(Processor processor, Transform transform, XmlUrlResolver resolver, Serializer serializer) 51 : this(processor, transform, resolver, serializer, new Hashtable(), new Hashtable(), new Hashtable(), new Hashtable(), new Hashtable(), new Hashtable(), null, null, null) 52 { 53 } 54 public XsltTransformationManager(Processor processor, Transform transform, XmlUrlResolver resolver, Serializer serializer, Hashtable xsltHashtable) 55 : this(processor, transform, resolver, serializer, xsltHashtable, new Hashtable(), new Hashtable(), new Hashtable(), new Hashtable(), new Hashtable(), null, null, null) 56 { 57 } 58 public XsltTransformationManager(Processor processor, Transform transform, XmlUrlResolver resolver, Serializer serializer, Hashtable xsltHashtable, Hashtable namedXsltHashtable) 59 : this(processor, transform, resolver, serializer, xsltHashtable, new Hashtable(), new Hashtable(), namedXsltHashtable, new Hashtable(), new Hashtable(), null, null, null) 60 { 61 } 62 public XsltTransformationManager(Processor processor, Transform transform, XmlUrlResolver resolver, Serializer serializer, Hashtable xsltHashtable, Hashtable xmlSourceHashtable, Hashtable namedXsltHashtable) 63 : this(processor, transform, resolver, serializer, xsltHashtable, xmlSourceHashtable, new Hashtable(), namedXsltHashtable, new Hashtable(), new Hashtable(), null, null, null) 64 { 65 } 66 public XsltTransformationManager(Processor processor, Transform transform, XmlUrlResolver resolver, Serializer serializer, Hashtable xsltHashtable, Hashtable xmlSourceHashtable, Hashtable xdmNodeHashtable, Hashtable namedXsltHashtable) 67 : this(processor, transform, resolver, serializer, xsltHashtable, xmlSourceHashtable, xdmNodeHashtable, namedXsltHashtable, new Hashtable(), new Hashtable(), null, null, null) 68 { 69 } 70 public XsltTransformationManager(Processor processor, Transform transform, XmlUrlResolver resolver, Serializer serializer, Hashtable xsltHashtable, Hashtable xmlSourceHashtable, Hashtable xdmNodeHashtable, Hashtable namedXsltHashtable, Hashtable namedXsltETagIndex) 71 : this(processor, transform, resolver, serializer, xsltHashtable, xmlSourceHashtable, xdmNodeHashtable, namedXsltHashtable, namedXsltETagIndex, new Hashtable(), null, null, null) 72 { 73 } 74 public XsltTransformationManager(Processor processor, Transform transform, XmlUrlResolver resolver, Serializer serializer, Hashtable xsltHashtable, Hashtable xmlSourceHashtable, Hashtable xdmNodeHashtable, Hashtable namedXsltHashtable, Hashtable namedXsltETagIndex, Hashtable xdmNodeETagIndex) 75 : this(processor, transform, resolver, serializer, xsltHashtable, xmlSourceHashtable, xdmNodeHashtable, namedXsltHashtable, namedXsltETagIndex, xdmNodeETagIndex, null, null, null) 76 { 36 public XsltTransformationManager (Processor processor) 37 : this(processor, new Transform(), new XmlUrlResolver(), new Serializer(), new Hashtable(), new Hashtable(), new Hashtable(), new Hashtable(), new Hashtable(), new Hashtable(), null, null, null) { 38 } 39 public XsltTransformationManager (Processor processor, Transform transform) 40 : this(processor, transform, new XmlUrlResolver(), new Serializer(), new Hashtable(), new Hashtable(), new Hashtable(), new Hashtable(), new Hashtable(), new Hashtable(), null, null, null) { 41 } 42 public XsltTransformationManager (Processor processor, Transform transform, XmlUrlResolver resolver) 43 : this(processor, transform, resolver, new Serializer(), new Hashtable(), new Hashtable(), new Hashtable(), new Hashtable(), new Hashtable(), new Hashtable(), null, null, null) { 44 } 45 public XsltTransformationManager (Processor processor, Transform transform, XmlUrlResolver resolver, Serializer serializer) 46 : this(processor, transform, resolver, serializer, new Hashtable(), new Hashtable(), new Hashtable(), new Hashtable(), new Hashtable(), new Hashtable(), null, null, null) { 47 } 48 public XsltTransformationManager (Processor processor, Transform transform, XmlUrlResolver resolver, Serializer serializer, Hashtable xsltHashtable) 49 : this(processor, transform, resolver, serializer, xsltHashtable, new Hashtable(), new Hashtable(), new Hashtable(), new Hashtable(), new Hashtable(), null, null, null) { 50 } 51 public XsltTransformationManager (Processor processor, Transform transform, XmlUrlResolver resolver, Serializer serializer, Hashtable xsltHashtable, Hashtable namedXsltHashtable) 52 : this(processor, transform, resolver, serializer, xsltHashtable, new Hashtable(), new Hashtable(), namedXsltHashtable, new Hashtable(), new Hashtable(), null, null, null) { 53 } 54 public XsltTransformationManager (Processor processor, Transform transform, XmlUrlResolver resolver, Serializer serializer, Hashtable xsltHashtable, Hashtable xmlSourceHashtable, Hashtable namedXsltHashtable) 55 : this(processor, transform, resolver, serializer, xsltHashtable, xmlSourceHashtable, new Hashtable(), namedXsltHashtable, new Hashtable(), new Hashtable(), null, null, null) { 56 } 57 public XsltTransformationManager (Processor processor, Transform transform, XmlUrlResolver resolver, Serializer serializer, Hashtable xsltHashtable, Hashtable xmlSourceHashtable, Hashtable xdmNodeHashtable, Hashtable namedXsltHashtable) 58 : this(processor, transform, resolver, serializer, xsltHashtable, xmlSourceHashtable, xdmNodeHashtable, namedXsltHashtable, new Hashtable(), new Hashtable(), null, null, null) { 59 } 60 public XsltTransformationManager (Processor processor, Transform transform, XmlUrlResolver resolver, Serializer serializer, Hashtable xsltHashtable, Hashtable xmlSourceHashtable, Hashtable xdmNodeHashtable, Hashtable namedXsltHashtable, Hashtable namedXsltETagIndex) 61 : this(processor, transform, resolver, serializer, xsltHashtable, xmlSourceHashtable, xdmNodeHashtable, namedXsltHashtable, namedXsltETagIndex, new Hashtable(), null, null, null) { 62 } 63 public XsltTransformationManager (Processor processor, Transform transform, XmlUrlResolver resolver, Serializer serializer, Hashtable xsltHashtable, Hashtable xmlSourceHashtable, Hashtable xdmNodeHashtable, Hashtable namedXsltHashtable, Hashtable namedXsltETagIndex, Hashtable xdmNodeETagIndex) 64 : this(processor, transform, resolver, serializer, xsltHashtable, xmlSourceHashtable, xdmNodeHashtable, namedXsltHashtable, namedXsltETagIndex, xdmNodeETagIndex, null, null, null) { 77 65 } 78 66 public XsltTransformationManager … … 91 79 String baseXsltUriHash, 92 80 String baseXsltName 93 ) 94 { 81 ) { 95 82 m_baseXsltUri = baseXsltUri; 96 83 m_baseXsltUriHash = baseXsltUriHash; … … 114 101 } 115 102 116 public void SetBaseXsltContext(BaseXsltContext baseXsltContext) 117 { 103 public void SetBaseXsltContext (BaseXsltContext baseXsltContext) { 118 104 m_baseXsltUri = baseXsltContext.BaseXsltUri; 119 105 m_baseXsltName = baseXsltContext.Name; … … 123 109 } 124 110 125 public bool HasXmlSourceChanged(string eTag) 126 { 111 public bool HasXmlSourceChanged (string eTag) { 127 112 if (m_xdmNodeETagIndex[eTag] != null) 128 113 return false; … … 131 116 } 132 117 133 public string GetXdmNodeHashtableCount() 134 { 118 public string GetXdmNodeHashtableCount () { 135 119 return m_xdmNodeETagIndex.Count.ToString(); 136 120 } 137 121 138 public bool HasBaseXsltSourceChanged() 139 { 122 public bool HasBaseXsltSourceChanged () { 140 123 string namedETag = (string)m_namedXsltETagIndex[m_baseXsltName]; 141 124 if (namedETag != null && namedETag == GenerateNamedETagKey(m_baseXsltName, m_baseXsltUri)) 142 125 return false; 143 else 144 { 126 else { 145 127 m_namedXsltETagIndex[m_baseXsltName] = (string)m_baseXsltUriHash; 146 128 return true; … … 148 130 } 149 131 150 public void AddTransformer(Uri uri) 151 { 132 public void AddTransformer (Uri uri) { 152 133 addTransformer(GenerateNamedETagKey(uri.LocalPath, uri), uri.LocalPath, uri, m_resolver, null, null, null); 153 134 } 154 public void AddTransformer(string name, Uri uri) 155 { 135 public void AddTransformer (string name, Uri uri) { 156 136 addTransformer(GenerateNamedETagKey(name, uri), name, uri, m_resolver, null, null, null); 157 137 } 158 public void AddTransformer(string name, Uri uri, XmlUrlResolver resolver) 159 { 138 public void AddTransformer (string name, Uri uri, XmlUrlResolver resolver) { 160 139 addTransformer(GenerateNamedETagKey(name, uri), name, uri, resolver, null, null, null); 161 140 } 162 public void AddTransformer(string name, Uri uri, XmlUrlResolver resolver, string initialMode) 163 { 141 public void AddTransformer (string name, Uri uri, XmlUrlResolver resolver, string initialMode) { 164 142 addTransformer(GenerateNamedETagKey(name, uri), name, uri, resolver, initialMode, null, null); 165 143 } 166 public void AddTransformer(string name, Uri uri, XmlUrlResolver resolver, string initialMode, string initialTemplate) 167 { 144 public void AddTransformer (string name, Uri uri, XmlUrlResolver resolver, string initialMode, string initialTemplate) { 168 145 addTransformer(GenerateNamedETagKey(name, uri), name, uri, resolver, initialMode, initialTemplate, null); 169 146 } 170 public void AddTransformer(string name, Uri uri, XmlUrlResolver resolver, string initialMode, string initialTemplate, string baseOutputUri) 171 { 147 public void AddTransformer (string name, Uri uri, XmlUrlResolver resolver, string initialMode, string initialTemplate, string baseOutputUri) { 172 148 addTransformer(GenerateNamedETagKey(name, uri), name, uri, resolver, initialMode, initialTemplate, baseOutputUri); 173 149 } 174 private void addTransformer(string key, string name, Uri uri, XmlUrlResolver resolver, string initialMode, string initialTemplate, string baseOutputUri) 175 { 150 private void addTransformer (string key, string name, Uri uri, XmlUrlResolver resolver, string initialMode, string initialTemplate, string baseOutputUri) { 176 151 XsltTransformer transformer = createNewTransformer(uri); 177 152 transformer.InputXmlResolver = resolver; … … 186 161 } 187 162 188 public void AddXmlSource(string name, Uri uri) 189 { 190 Stream xmlStream = createNewXmlStream(uri); 191 m_sourceHashtable[name] = (Stream)xmlStream; 192 } 193 194 public XdmNode GetXdmNode(string name, string xmlSource) 195 { 163 public void AddXmlSource (string sourceXmlETag, Stream xmlStream) { 164 m_sourceHashtable[sourceXmlETag] = xmlStream; 165 } 166 167 public void AddXmlSource (string name, Uri uri) { 168 m_sourceHashtable[name] = createNewXmlStream(uri); 169 } 170 171 public XdmNode GetXdmNode (string name, string xmlSource) { 196 172 Uri xmlSourceUri = new Uri(xmlSource); 197 173 return GetXdmNode(name, xmlSourceUri); 198 174 } 199 public XdmNode GetXdmNode(string name, Uri xmlSourceUri) 200 { 175 public XdmNode GetXdmNode (string name, Uri xmlSourceUri) { 201 176 202 177 Uri xdmNodeUri = (Uri)m_xdmNodeETagIndex[name]; 203 if (xdmNodeUri != null && xdmNodeUri == xmlSourceUri) 204 { 178 if (xdmNodeUri != null && xdmNodeUri == xmlSourceUri) { 205 179 return getXdmNode(name, xmlSourceUri, false); 206 } 207 else 208 { 180 } else { 209 181 m_xdmNodeETagIndex[name] = xmlSourceUri; 210 182 return getXdmNode(name, xmlSourceUri, true); 211 183 } 212 184 } 213 private XdmNode getXdmNode(string key, Uri xmlSourceUri, bool replaceExistingXdmNode) 214 { 185 private XdmNode getXdmNode (string key, Uri xmlSourceUri, bool replaceExistingXdmNode) { 215 186 216 187 XdmNode node = (XdmNode)m_xdmNodeHashtable[key]; 217 188 218 if (node != null && !replaceExistingXdmNode) 219 { 189 if (node != null && !replaceExistingXdmNode) { 220 190 return node; 221 } 222 else 223 { 224 using (Stream stream = createNewXmlStream(xmlSourceUri)) 225 { 191 } else if (m_sourceHashtable.ContainsKey(key)) { 192 node = createNewXdmNode((Stream)m_sourceHashtable[key]); 193 } else { 194 using (Stream stream = createNewXmlStream(xmlSourceUri)) { 226 195 node = createNewXdmNode(stream); 227 196 } … … 231 200 } 232 201 233 private Stream createNewXmlStream(Uri xmlSourceUri) 234 { 202 private Stream createNewXmlStream (Uri xmlSourceUri) { 235 203 return (Stream)m_resolver.GetEntity(xmlSourceUri, null, typeof(Stream)); 236 204 } 237 205 238 private XdmNode createNewXdmNode(Stream xmlSourceStream) 239 { 206 private XdmNode createNewXdmNode (Stream xmlSourceStream) { 240 207 return (XdmNode)m_builder.Build(xmlSourceStream); 241 208 } 242 209 243 public XsltTransformer GetTransformer(string eTag, Uri xsltUri) 244 { 210 public XsltTransformer GetTransformer (string eTag, Uri xsltUri) { 245 211 return getTransformer(eTag, xsltUri, true); 246 212 } 247 public XsltTransformer GetTransformer(string name, string href, Uri baseUri) 248 { 213 public XsltTransformer GetTransformer (string name, string href, Uri baseUri) { 249 214 Uri xsltUri = new Uri(baseUri, href); 250 215 return getTransformer(GenerateNamedETagKey(name, xsltUri), name, xsltUri); 251 216 } 252 public XsltTransformer GetTransformer(string name) 253 { 217 public XsltTransformer GetTransformer (string name) { 254 218 Uri xsltUri = (Uri)m_namedXsltHashtable[name]; 255 219 return getTransformer(GenerateNamedETagKey(name, xsltUri), name, xsltUri); 256 220 } 257 private XsltTransformer getTransformer(string key, string xsltName, Uri xsltUri) 258 { 221 private XsltTransformer getTransformer (string key, string xsltName, Uri xsltUri) { 259 222 string namedETag = (string)m_namedXsltETagIndex[xsltName]; 260 if (namedETag != null && namedETag == key) 261 { 223 if (namedETag != null && namedETag == key) { 262 224 return getTransformer(namedETag, xsltUri, false); 263 } 264 else 265 { 225 } else { 266 226 m_namedXsltETagIndex[xsltName] = key; 267 227 return getTransformer(key, xsltUri, true); 268 228 } 269 229 } 270 private XsltTransformer getTransformer(string key, Uri xsltUri, bool replaceExistingXsltTransformer) 271 { 230 private XsltTransformer getTransformer (string key, Uri xsltUri, bool replaceExistingXsltTransformer) { 272 231 XsltTransformer transformer; 273 232 transformer = (XsltTransformer)m_namedXsltHashtable[key]; 274 233 275 if (transformer != null && !replaceExistingXsltTransformer) 276 { 234 if (transformer != null && !replaceExistingXsltTransformer) { 277 235 return transformer; 278 } 279 else 236 } else 280 237 transformer = createNewTransformer(xsltUri); 281 238 … … 284 241 } 285 242 286 public static String GenerateNamedETagKey(String name, Uri sourceUri, params object[] objectParams) 287 { 243 public static String GenerateNamedETagKey (String name, Uri sourceUri, params object[] objectParams) { 288 244 FileInfo fileInfo = new FileInfo(sourceUri.LocalPath); 289 245 return name + ":" + Context.GenerateETag((string)HttpContext.Current.Application["hashkey"], _hashAlgorithm, fileInfo.LastWriteTimeUtc, fileInfo.Length, sourceUri, objectParams); 290 246 } 291 247 292 private XsltTransformer createNewTransformer(Uri xsltUri) 293 { 294 using (Stream stream = createNewXmlStream(xsltUri)) 295 { 248 private XsltTransformer createNewTransformer (Uri xsltUri) { 249 using (Stream stream = createNewXmlStream(xsltUri)) { 296 250 return m_compiler.Compile(stream).Load(); 297 251 } 298 252 } 299 253 300 public Hashtable XsltHashtable 301 { 254 public Hashtable XsltHashtable { 302 255 get { return m_xsltHashtable; } 303 256 set { m_xsltHashtable = value; } 304 257 } 305 public Hashtable XmlSourceHashtable 306 { 258 public Hashtable XmlSourceHashtable { 307 259 get { return m_sourceHashtable; } 308 260 set { m_sourceHashtable = value; } 309 261 } 310 public Hashtable NamedXsltHashtable 311 { 262 public Hashtable NamedXsltHashtable { 312 263 get { return m_namedXsltHashtable; } 313 264 set { m_namedXsltHashtable = value; } 314 265 } 315 public HashAlgorithm HashAlgorithm 316 { 266 public HashAlgorithm HashAlgorithm { 317 267 get { return _hashAlgorithm; } 318 268 set { _hashAlgorithm = value; } 319 269 } 320 public Processor Processor 321 { 270 public Processor Processor { 322 271 get { return m_processor; } 323 272 set { m_processor = value; } 324 273 }
