Example #1
0
        internal FolderDatasetList GetDatasets(Server oServer, CatalogFolder oFolder, BoundingBox oBounds, bool bAOIFilter, bool bTextFilter, string strSearchString)
        {
            FolderDatasetList oRet = null;

            string strKey = oServer.Url + ':' + oFolder.Hierarchy;

            if (bTextFilter)
            {
                strKey += "_" + strSearchString;
            }
            if (bAOIFilter)
            {
                strKey += "_" + oBounds.GetHashCode().ToString(CultureInfo.InvariantCulture);
            }

            string strFile = Path.Combine(oServer.CacheDir, strKey.GetHashCode().ToString(CultureInfo.InvariantCulture) + ".dap_datasetlist.gz");

            if (File.Exists(strFile))
            {
                try
                {
                    // --- Use SOAP formatting and GZip compression to disk  ---
                    // --- This way we have a nice human readable format and ---
                    // --- we may later move caching to database based.      ---
                    SoapFormatter formatter = new SoapFormatter();
                    formatter.Binder = new FolderDatasetListDeserializationBinder();

                    using (Stream stream = new FileStream(strFile, FileMode.Open, FileAccess.Read, FileShare.Read))
                    {
                        using (GZipStream compStream = new GZipStream(stream, CompressionMode.Decompress))
                        {
                            oRet = (FolderDatasetList)formatter.Deserialize(compStream);
                            compStream.Close();
                            stream.Close();
                        }
                    }
                }
                catch
                {
                    oRet = null;

                    try
                    {
                        if (File.Exists(strFile))
                        {
                            File.Delete(strFile);
                        }
                    }
                    catch (IOException) { }                     // Bug report where this delete failed; suppress failed deletions.
                }
            }

            if (oRet != null && oRet.Timestamp == oFolder.Timestamp && strKey == oRet.Key)
            {
                return(oRet);
            }
            return(null);
        }
Example #2
0
        /// <summary>
        /// Get the list of datasets for a particular path
        /// </summary>
        /// <param name="oServer"></param>
        /// <param name="strHierarchy"></param>
        /// <param name="iTimestamp"></param>
        /// <param name="oBounds"></param>
        /// <param name="bAOIFilter"></param>
        /// <param name="bTextFilter"></param>
        /// <param name="strSearchString"></param>
        /// <returns>true if server's cache version changed or some other error occured</returns>
        internal bool bGetDatasetList(Server oServer, string strHierarchy, int iTimestamp, BoundingBox oBounds, bool bAOIFilter, bool bTextFilter, string strSearchString)
        {
            string strEdition;

            System.Xml.XmlDocument oDoc = null;
            string strKey = oServer.Url + ':' + strHierarchy;

            if (!bAOIFilter && !bTextFilter)
            {
                oDoc = oServer.Command.GetCatalog(strHierarchy, 1, 0, 0, null, null, null);
            }
            else if (!bAOIFilter && bTextFilter)
            {
                oDoc = oServer.Command.GetCatalog(strHierarchy, 1, 0, 0, strSearchString, null, null);
            }
            else if (bAOIFilter && !bTextFilter)
            {
                oDoc = oServer.Command.GetCatalog(strHierarchy, 1, 0, 0, null, oBounds, null);
            }
            else if (bAOIFilter && bTextFilter)
            {
                oDoc = oServer.Command.GetCatalog(strHierarchy, 1, 0, 0, strSearchString, oBounds, null);
            }

            if (bTextFilter)
            {
                strKey += "_" + strSearchString;
            }
            if (bAOIFilter)
            {
                strKey += "_" + oBounds.GetHashCode().ToString(CultureInfo.InvariantCulture);
            }

            string strFile = Path.Combine(oServer.CacheDir, strKey.GetHashCode().ToString(CultureInfo.InvariantCulture) + ".dap_datasetlist.gz");

            FolderDatasetList oDataset = FolderDatasetList.Parse(oServer, strKey, iTimestamp, oDoc, out strEdition);

            if (strEdition != oServer.CacheVersion)
            {
                oServer.UpdateConfiguration();
                return(false);
            }

            if (oDataset != null)
            {
                try
                {
                    if (File.Exists(strFile))
                    {
                        File.Delete(strFile);
                    }

                    // --- Use SOAP formatting and GZip compression to disk  ---
                    // --- This way we have a nice human readable format and ---
                    // --- we may later move caching to database based.      ---
                    SoapFormatter formatter = new SoapFormatter();

                    using (Stream stream = new FileStream(strFile, FileMode.Create, FileAccess.Write, FileShare.None))
                    {
                        using (GZipStream compStream = new GZipStream(stream, CompressionMode.Compress, true))
                        {
                            formatter.Serialize(compStream, oDataset);
                            compStream.Close();
                            stream.Close();
                        }
                    }
                }
                catch
                {
                }
            }

            return(true);
        }