private void ShowMetadata(ILayer layer)
        {
            if (layer is IDataLayer)
            {
                //Check style sheet exists
                if (File.Exists(cboStyleSheets.Text) == false)
                {
                    System.Windows.Forms.MessageBox.Show("The selected style sheet does not exist!", "Missing Style Sheet");
                    return;
                }

                //QI for IDataLayer
                IDataLayer dataLayer = (IDataLayer)layer;
                //Get the metadata
                IMetadata metaData = (IMetadata)dataLayer.DataSourceName;
                //Get the xml property set from the metadata
                IXmlPropertySet2 xml = (IXmlPropertySet2)metaData.Metadata;

                //Save the xml to a temporary file and transforms it using the selected style sheet
                xml.SaveAsFile(cboStyleSheets.Text, "", false, ref m_tempFile);

                //Navigate the web browser to the temporary file
                object obj = null;
                webBrowser1.Navigate(m_tempFile);
            }
            else
            {
                System.Windows.Forms.MessageBox.Show("Metadata shown for IDataLayer objects only", "IDataLayer objects only");
            }
        }
        /// <summary>
        /// Extracts metadata xml of entity and send publication request to server.
        /// </summary>
        /// <param name="entity">Entity to publish</param>
        /// <returns>Publish results</returns>
        public string[] publish(IGxObject entity)
        {
            string[]  results  = new string[1];
            IMetadata metaData = (IMetadata)entity;

            //Get the xml property set from the metadata
            IXmlPropertySet2 xml = (IXmlPropertySet2)metaData.Metadata;

            if (TranslateMetadata(xml, out xmlFilePaths))
            {
                string sXml = "";
                if (translatorPath.Trim().Length == 0)
                {
                    sXml = File.ReadAllText(xmlFilePaths[0], Encoding.UTF8); /// untransformed xml no translator configured.
                }
                else
                {
                    sXml = File.ReadAllText(xmlFilePaths[1], Encoding.UTF8); /// transformed xml.
                }
                return(publish(entity, sXml));
            }
            else
            {
                results[0] = StringMessages.ErrorOnTranslation;
                return(results);
            }
        }
Пример #3
0
        /// <summary>
        /// Translates metadata document
        /// </summary>
        /// <remarks>
        /// used to translate source metadata to another format using xslt.
        /// </remarks>
        /// <param name="propertySet">IXmlPropertySet2 metadata to be converted</param>
        /// <param name="xmlFilePaths">string[] output string array of file paths.</param>
        /// <returns>Returns true if execution was successful.</returns>
        private bool TranslateMetadata(IXmlPropertySet2 propertySet, out string[] xmlFilePaths)
        {
            const string noHeader     = "";
            const bool   ansiRestrict = false;
            string       sourceXml    = Path.GetTempFileName();

            propertySet.SaveAsFile(null, noHeader, ansiRestrict, ref sourceXml);
            ESRITranslator gpTool = GpHelper.xmlTranslator(sourceXml);

            // Request that the GpHelper execute the instantiated tool. A wrapper is
            // used to abstract error handling and allow a simple integer success code
            // equivalency check to determine success/failure.
            return(GpHelper.Execute(gpTool, out xmlFilePaths) == 0);
        }
Пример #4
0
        /// <summary>
        /// Extracts metadata xml of entity and send publication request to server.
        /// </summary>
        /// <param name="entity">Entity to publish</param>
        /// <returns>Publish results</returns>
        public string[] publish(IGxObject entity)
        {
            string[]  results  = new string[1];
            IMetadata metaData = (IMetadata)entity;

            //Get the xml property set from the metadata
            IXmlPropertySet2 xml = (IXmlPropertySet2)metaData.Metadata;

            string[] xmlFilePaths;
            TranslateMetadata(xml, out xmlFilePaths);
            string sXml = File.ReadAllText(xmlFilePaths[0], Encoding.UTF8); /// untransformed xml.

            return(publish(entity, sXml));
        }
Пример #5
0
        /// <summary>
        /// Translates metadata document 
        /// </summary>
        /// <remarks>
        /// used to translate source metadata to another format using xslt.
        /// </remarks>
        /// <param name="propertySet">IXmlPropertySet2 metadata to be converted</param>
        /// <param name="xmlFilePaths">string[] output string array of file paths.</param>
        /// <returns>Returns true if execution was successful.</returns>
        private bool TranslateMetadata(IXmlPropertySet2 propertySet, out string[] xmlFilePaths)
        {
            const string noHeader = "";
            const bool ansiRestrict = false;
            string sourceXml = Path.GetTempFileName();

            propertySet.SaveAsFile(null, noHeader, ansiRestrict, ref sourceXml);
            ESRITranslator gpTool = GpHelper.xmlTranslator(sourceXml);

            // Request that the GpHelper execute the instantiated tool. A wrapper is
            // used to abstract error handling and allow a simple integer success code
            // equivalency check to determine success/failure.
            return (GpHelper.Execute(gpTool, out xmlFilePaths) == 0);
        }
        /// <summary>
        /// Translates metadata document
        /// </summary>
        /// <remarks>
        /// used to translate source metadata to another format using xslt.
        /// </remarks>
        /// <param name="propertySet">IXmlPropertySet2 metadata to be converted</param>
        /// <param name="xmlFilePaths">string[] output string array of file paths.</param>
        /// <returns>Returns true if execution was successful.</returns>
        private bool TranslateMetadata(IXmlPropertySet2 propertySet, out string[] xmlFilePaths)
        {
            const string noHeader     = "";
            const bool   ansiRestrict = false;
            string       sourceXml    = Path.GetTempFileName();

            propertySet.SaveAsFile(null, noHeader, ansiRestrict, ref sourceXml);

            String selectedStyleCfg = Globals.ArcGISInstallationFolderFromCommandLine + "\\Metadata\\Config\\" + Globals.ArcGISDesktopMetadataConfig + ".cfg";

            translatorPath = readTranslatorFromConfig(selectedStyleCfg);
            ESRITranslator gpTool = GpHelper.xmlTranslator(sourceXml, translatorPath);

            // Request that the GpHelper execute the instantiated tool. A wrapper is
            // used to abstract error handling and allow a simple integer success code
            // equivalency check to determine success/failure.
            return(GpHelper.Execute(gpTool, out xmlFilePaths) == 0);
        }
Пример #7
0
        /// <summary>
        /// Translates metadata document 
        /// </summary>
        /// <remarks>
        /// used to translate source metadata to another format using xslt.
        /// </remarks>
        /// <param name="propertySet">IXmlPropertySet2 metadata to be converted</param>
        /// <param name="xmlFilePaths">string[] output string array of file paths.</param>
        /// <returns>Returns true if execution was successful.</returns>
        private bool TranslateMetadata(IXmlPropertySet2 propertySet, out string[] xmlFilePaths)
        {
            const string noHeader = "";
            const bool ansiRestrict = false;
            string sourceXml = Path.GetTempFileName();
          
            propertySet.SaveAsFile(null, noHeader, ansiRestrict, ref sourceXml);

            String selectedStyleCfg = Globals.ArcGISInstallationFolderFromCommandLine + "\\Metadata\\Config\\" + Globals.ArcGISDesktopMetadataConfig + ".cfg";

            translatorPath = readTranslatorFromConfig(selectedStyleCfg);
            ESRITranslator gpTool = GpHelper.xmlTranslator(sourceXml, translatorPath);

            // Request that the GpHelper execute the instantiated tool. A wrapper is
            // used to abstract error handling and allow a simple integer success code
            // equivalency check to determine success/failure.
            return (GpHelper.Execute(gpTool, out xmlFilePaths) == 0);
        }
Пример #8
0
        private string GetMetadataXml(int layerId)
        {
            var    mapServer      = (IMapServer3)_serverObjectHelper.ServerObject;
            string defaultMapName = mapServer.DefaultMapName;



            var      msDataAccess = (IMapServerDataAccess)_serverObjectHelper.ServerObject;
            IDataset layer        = null;

            string xml = null;

            try
            {
                var obj = msDataAccess.GetDataSource(defaultMapName, layerId);
                // Try to cast as a IRasterBandCollection
                var rasterBandCollection = obj as IRasterBandCollection;
                if (rasterBandCollection != null && rasterBandCollection.Count > 0)
                {
                    layer = rasterBandCollection.Item(0).RasterDataset as IDataset;
                }
                else
                {
                    layer = obj as IDataset;
                }
            }
#if DEBUG
            catch (NotImplementedException ex)
            {
                var xmlBuilder = new StringBuilder();
                using (XmlWriter xtw = XmlWriter.Create(xmlBuilder))
                {
                    xtw.WriteStartDocument();
                    xtw.WriteStartElement("error");
                    xtw.WriteString("Metadata could not be retrieved for this layer.");
                    xtw.WriteStartElement("details");
                    xtw.WriteString(ex.ToString());
                    xtw.WriteEndElement();
                    xtw.WriteEndElement();
                    xtw.WriteEndDocument();
                }
                xml = xmlBuilder.ToString();
            }
#else
            catch (NotImplementedException)
            {
                xml = string.Format("<error>Metadata could not be retrieved for this layer.</error>");
            }
#endif

            if (layer != null)
            {
                IMetadata metadata = layer.FullName as IMetadata;
                if (metadata != null)
                {
                    IXmlPropertySet2 propSet = metadata.Metadata as IXmlPropertySet2;
                    if (propSet != null)
                    {
                        xml = propSet.GetXml(string.Empty);
                    }
                }
            }
            if (string.IsNullOrEmpty(xml))
            {
                xml = "<error>No metadata found for this layer.</error>";
            }
            return(xml);
        }