/// <summary> /// Function to view metadata /// </summary> private void ViewMetadata_Clicked() { try { Cursor.Current = Cursors.WaitCursor; XmlDocument xmlDoc = RetrieveSelectedMetadataFromCatalog(true); if (xmlDoc == null && styledRecordResponse == null) return; // prepare metadata for service info /* xmlDoc = PrepareMetadata(xmlDoc); if (xmlDoc == null) return; // transform metadata using style sheet //load the Xsl if necessary if (_xsltFull == null) { _xsltFull = new XslCompiledTransform(); try { _xsltFull.Load(_xsltMetadataToHtmlFullFilePath); //MessageBox.Show(_xsltFull.ToString() + _xsltMetadataToHtmlFullFilePath); } catch { throw new Exception(resourceManager.GetString("loadMetadataException")); } }*/ /* string tmpFilePath = GenerateTempFilename("Meta", "html"); XmlWriter xmlWriter = new XmlTextWriter(tmpFilePath, Encoding.UTF8); _xsltFull.Transform(new XmlNodeReader(xmlDoc), xmlWriter); xmlWriter.Close(); */ string tmpFilePath = ""; if (xmlDoc != null && styledRecordResponse == null) { // display metadata in XML format tmpFilePath = GenerateTempFilename("Meta", "xml"); XmlWriter xmlWriter = new XmlTextWriter(tmpFilePath, Encoding.UTF8); XmlNode binaryNode = xmlDoc.GetElementsByTagName("Binary")[0]; if (binaryNode != null) { XmlNode enclosureNode = xmlDoc.GetElementsByTagName("Enclosure")[0]; if (enclosureNode != null) binaryNode.RemoveChild(enclosureNode); } String outputStr = xmlDoc.InnerXml.Replace("utf-16", "utf-8"); xmlWriter.WriteRaw(outputStr); xmlWriter.Close(); } else if (xmlDoc == null && styledRecordResponse != null && styledRecordResponse.Trim().Length > 0) { // display metadata in XML format tmpFilePath = GenerateTempFilename("Meta", "html"); FileInfo fileInfo = new FileInfo(tmpFilePath); System.IO.FileStream fileStream = fileInfo.Create(); StreamWriter sr = new StreamWriter(fileStream); sr.Write(styledRecordResponse); sr.Close(); fileStream.Close(); styledRecordResponse = null; } // pop up a window displaying the summary HTML FormViewMetadata frmViewMetadata = new FormViewMetadata(); //tmp CswRecord record = (CswRecord)(lstSearchResults.SelectedItem); frmViewMetadata.MetadataTitle = record.Title; //tmp frmViewMetadata.Navigate(tmpFilePath); frmViewMetadata.Show(); frmViewMetadata.Activate(); return; } catch (Exception ex) { MessageBox.Show(resourceManager.GetString("viewMetadataFailed"), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } finally { styledRecordResponse = null; Cursor.Current = Cursors.Default; } }
/// <summary> /// Retrieve metadata for the selected record from server, then display it in metadata viwer. /// If failed to retrieve metadata froms erver, display a detailed message including HTTP response from server. /// </summary> private void ViewMetadata_Clicked() { try { Cursor.Current = Cursors.WaitCursor; CswRecord record = (CswRecord)(resultsListBox.SelectedItem); // retrieve metadata XmlDocument xmlDoc = RetrieveSelectedMetadataFromCatalog(true); if (xmlDoc == null && styledRecordResponse == null) return; string tmpFilePath = ""; if (xmlDoc != null && styledRecordResponse == null) { // display metadata in XML format tmpFilePath = GenerateTempFilename("Meta", "xml"); XmlWriter xmlWriter = new XmlTextWriter(tmpFilePath, Encoding.UTF8); XmlNode binaryNode = xmlDoc.GetElementsByTagName("Binary")[0]; if (binaryNode != null) { XmlNode enclosureNode = xmlDoc.GetElementsByTagName("Enclosure")[0]; if (enclosureNode != null) binaryNode.RemoveChild(enclosureNode); } String outputStr = xmlDoc.InnerXml.Replace("utf-16", "utf-8"); xmlWriter.WriteRaw(outputStr); xmlWriter.Close(); } else if(xmlDoc == null && styledRecordResponse != null && styledRecordResponse.Trim().Length > 0) { // display metadata in XML format tmpFilePath = GenerateTempFilename("Meta", "html"); FileInfo fileInfo = new FileInfo(tmpFilePath); System.IO.FileStream fileStream = fileInfo.Create(); StreamWriter sr = new StreamWriter(fileStream); sr.Write(styledRecordResponse); sr.Close(); fileStream.Close(); styledRecordResponse = null; } // pop up a metadata viwer displaying the metadata as HTML FormViewMetadata frmViewMetadata = new FormViewMetadata(); frmViewMetadata.FormClosed += new FormClosedEventHandler(RemoveTempFileAfterMetadataViewerClosed); frmViewMetadata.MetadataTitle = record.Title; // frmViewMetadata.WindowState = FormWindowState.Maximized; frmViewMetadata.Navigate(tmpFilePath); frmViewMetadata.Show(); frmViewMetadata.Activate(); // note: temp file will be deleted when metadata viwer closes. // see "RemoveTempFileAfterMetadataViewerClosed()" } catch (Exception ex) { ShowErrorMessageBox(ex.Message); } finally { styledRecordResponse = null; Cursor.Current = Cursors.Default; } }