/// <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; }
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; }
/// <summary> /// Get the root catalog hierarchy for a particular path /// </summary> /// <param name="oServer"></param> /// <param name="oBounds"></param> /// <param name="bAOIFilter"></param> /// <param name="bTextFilter"></param> /// <param name="strSearchString"></param> /// <returns>The hierarchy as a CatalogFolder</returns> internal CatalogFolder GetCatalogHierarchyRoot(Server oServer, BoundingBox oBounds, bool bAOIFilter, bool bTextFilter, string strSearchString, out bool bEntireCatalogMode, out string strEdition) { XmlDocument oDoc = null; strEdition = ""; bEntireCatalogMode = false; string strKey = oServer.Url; if (bTextFilter) strKey += "_" + strSearchString; if (bAOIFilter) strKey += "_" + oBounds.GetHashCode().ToString(CultureInfo.InvariantCulture); string strFile = Path.Combine(oServer.CacheDir, strKey.GetHashCode().ToString(CultureInfo.InvariantCulture) + ".dap_cataloghierarchy.gz"); if (File.Exists(strFile)) { try { // --- Use GZip compression to disk --- using (Stream stream = new FileStream(strFile, FileMode.Open, FileAccess.Read, FileShare.Read)) { using (GZipStream compStream = new GZipStream(stream, CompressionMode.Decompress)) { oDoc = new XmlDocument(); oDoc.Load(compStream); compStream.Close(); stream.Close(); CatalogFolder oCatalogFolder = CatalogFolder.Parse(oDoc, out strEdition); if (oCatalogFolder != null && strEdition == oServer.CacheVersion) return oCatalogFolder; oDoc = null; } } } catch { oDoc = null; if (File.Exists(strFile)) File.Delete(strFile); } } if (oDoc == null) { try { if (!bAOIFilter && !bTextFilter) oDoc = oServer.Command.GetCatalogHierarchy(); else if (!bAOIFilter && bTextFilter) oDoc = oServer.Command.GetCatalogHierarchy(strSearchString); else if (bAOIFilter && !bTextFilter) oDoc = oServer.Command.GetCatalogHierarchy(oBounds); else if (bAOIFilter && bTextFilter) oDoc = oServer.Command.GetCatalogHierarchy(strSearchString, oBounds); } catch (DapException) { // Assume the server is older bEntireCatalogMode = true; return null; } catch { oDoc = null; } if (oDoc == null) { // --- do something to disable server --- #if !DAPPLE m_oServerTree.NoResponseError(); #else if (m_oServerTree != null) m_oServerTree.NoResponseError(oServer); #endif return null; } #if DAPPLE // --- Looks like the server is online now --- if (m_oServerTree != null) m_oServerTree.ReenableServer(oServer); #endif CatalogFolder oCatalogFolder = CatalogFolder.Parse(oDoc, out strEdition); if (oCatalogFolder == null) { // --- check to see if this is an unknown request --- System.Xml.XmlNodeList oNodeList; System.Xml.XmlNode oNode; oNodeList = oDoc.SelectNodes("//" + Geosoft.Dap.Xml.Common.Constant.Tag.ERROR_TAG); if (oNodeList != null && oNodeList.Count > 0) { oNode = oNodeList[0]; if (oNode != null && oNode.InnerText.ToLower() == "unknown request.") bEntireCatalogMode = true; } } else { if (strEdition != oServer.CacheVersion) { oServer.UpdateConfiguration(); return null; } try { if (File.Exists(strFile)) File.Delete(strFile); // --- Use GZip compression to disk --- using (Stream stream = new FileStream(strFile, FileMode.Create, FileAccess.Write, FileShare.None)) { using (GZipStream compStream = new GZipStream(stream, CompressionMode.Compress, true)) { XmlWriter writer = XmlWriter.Create(compStream); oDoc.Save(writer); compStream.Close(); stream.Close(); } } } catch { } return oCatalogFolder; } } return null; }