/// <summary>
        /// Attempts to retrieve any stored data from the document cache.
        /// </summary>
        /// <param name="type"></param>
        /// <param name="key"></param>
        /// <param name="nav"></param>
        /// <returns></returns>
        protected virtual bool TryGetCachedData(string type, string key, out XPathDataCacheItem item)
        {
            object   value;
            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)
            {
                if (cacheProv.TryRetrieveFromCache(type, key, out value))
                {
                    if (!(value is XPathDataCacheItem))
                    {
                        throw new InvalidCastException("The data returned from the cache for this XPath datasource '" + this.ID + "' was not an XPathNavigator.");
                    }

                    item = (XPathDataCacheItem)value;
                    return(true);
                }
            }

            item = null;
            return(false);
        }
Example #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);
        }