/// <summary>
        /// Adds the XPath document to the documents cache provider.
        /// </summary>
        /// <param name="type"></param>
        /// <param name="key"></param>
        /// <param name="nav"></param>
        protected virtual void AddToCache(string type, string key, XPathDataCacheItem item)
        {
            Document doc = this.Document;

            if (null == doc)
            {
                throw new NullReferenceException("This data source is not part of the document heirarchy and cannot use the caching capabilities available");
            }

            IPDFCacheProvider cacheProv = doc.CacheProvider;

            if (null != cacheProv)
            {
                DateTime expires = DateTime.Now.AddMinutes(this.CacheDuration);
                cacheProv.AddToCache(type, key, item, expires);
            }
        }
예제 #2
0
        protected virtual System.Xml.Xsl.XslCompiledTransform DoGetTransformer(int cacheduration, IPDFDataSource source, PDFDataContext context)
        {
            if (null == _transformer)
            {
                string path = this.XSLTPath;
                if (string.IsNullOrEmpty(path))
                {
                    throw new NullReferenceException(string.Format(Errors.XSLTPathOrTransformerNotSetOnInstance, source.ID));
                }

                path = source.MapPath(path);
                IPDFCacheProvider cache = ((Scryber.Components.Document)source.Document).CacheProvider;
                System.Xml.Xsl.XslCompiledTransform transformer;

                object found;

                if (cacheduration > 0 && cache.TryRetrieveFromCache(XSLTCacheType, path, out found))
                {
                    transformer = (System.Xml.Xsl.XslCompiledTransform)found;
                }
                else
                {
                    transformer = new System.Xml.Xsl.XslCompiledTransform(XSLTUseDebug);
                    try
                    {
                        transformer.Load(path);
                    }
                    catch (Exception ex)
                    {
                        throw new PDFDataException(string.Format(Errors.XSLTCouldNotBeLoadedFromPath, path), ex);
                    }

                    if (cacheduration > 0)
                    {
                        cache.AddToCache(XSLTCacheType, path, transformer, new TimeSpan(0, cacheduration, 0));
                    }
                }

                _transformer = transformer;
            }

            return(_transformer);
        }