Select to view content in your preferred language

Reading aptx file

2031
0
07-09-2020 01:17 AM
by Anonymous User
Not applicable
1 0 2,031

After sometime back I got difficulty on reading aptx file information with ArcPro SDK, refer to this post.

Retrieval of Project/project template metadata 

Thank to Wolfgang Kaiser‌, I found out that aptx is actually a 7zip file, and no wonder I can't use build in Microsoft provided zipfile libraries.

And the there are a lot of 7zip extractor out there in nugget space but some are not working properly to extract that aptx file.

Among them, SevenZipExtractor, 7z.NET nugget libraries can extract that aptx file.

Below is the code snippet how we can achieve and extract aptx info.

Model class generated and modified from xml file

using System.ComponentModel;
using System.Linq;
using System.Runtime.CompilerServices;

 // NOTE: Generated code may require at least .NET Framework 4.5 or .NET Core/Standard 2.0.
    /// <remarks/>
    [System.SerializableAttribute()]
    [System.ComponentModel.DesignerCategoryAttribute("code")]
    [System.Xml.Serialization.XmlTypeAttribute(AnonymousType = true)]
    [System.Xml.Serialization.XmlRootAttribute(Namespace = "", IsNullable = false)]
    public partial class ESRI_ItemInformation: INotifyPropertyChanged
    {

        private string nameField;

        private string guidField;

        private decimal versionField;

        private object createdField;

        private object modifiedField;

        private object catalogpathField;

        private string snippetField;

        private object descriptionField;

        private string summaryField;

        private string titleField;

        private string tagsField;

        private string typeField;

        private string[] typekeywordsField;

        private string thumbnailField;

        private object documentationField;

        private object urlField;

        private object spatialreferenceField;

        private decimal minScaleField;

        private decimal maxScaleField;

        private object datalastModifiedTimeField;

        private object accessinformationField;

        private object licenseinfoField;

        private string cultureField;

        /// <remarks/>
        public string name
        {
            get
            {
                return this.nameField;
            }
            set
            {
                this.nameField = value;
                this.NotifyPropertyChanged();
            }
        }

        /// <remarks/>
        public string guid
        {
            get
            {
                return this.guidField;
            }
            set
            {
                this.guidField = value;
                this.NotifyPropertyChanged();
            }
        }

        /// <remarks/>
        public decimal version
        {
            get
            {
                return this.versionField;
            }
            set
            {
                this.versionField = value;
                this.NotifyPropertyChanged();
            }
        }

        /// <remarks/>
        public object created
        {
            get
            {
                return this.createdField;
            }
            set
            {
                this.createdField = value;
                this.NotifyPropertyChanged();
            }
        }

        /// <remarks/>
        public object modified
        {
            get
            {
                return this.modifiedField;
            }
            set
            {
                this.modifiedField = value;
                this.NotifyPropertyChanged();
            }
        }

        /// <remarks/>
        public object catalogpath
        {
            get
            {
                return this.catalogpathField;
            }
            set
            {
                this.catalogpathField = value;
                this.NotifyPropertyChanged();
            }
        }

        /// <remarks/>
        public string snippet
        {
            get
            {
                return this.snippetField;
            }
            set
            {
                this.snippetField = value;
                this.NotifyPropertyChanged();
            }
        }

        /// <remarks/>
        public object description
        {
            get
            {
                return this.descriptionField;
            }
            set
            {
                this.descriptionField = value;
                this.NotifyPropertyChanged();
            }
        }

        /// <remarks/>
        public string summary
        {
            get
            {
                return this.summaryField;
            }
            set
            {
                this.summaryField = value;
                this.NotifyPropertyChanged();
            }
        }

        /// <remarks/>
        public string title
        {
            get
            {
                return this.titleField;
            }
            set
            {
                this.titleField = value;
                this.NotifyPropertyChanged();
            }
        }

        /// <remarks/>
        public string tags
        {
            get
            {
                return this.tagsField;
            }
            set
            {
                this.tagsField = value;
                this.NotifyPropertyChanged();
            }
        }

        /// <remarks/>
        public string type
        {
            get
            {
                return this.typeField;
            }
            set
            {
                this.typeField = value;
                this.NotifyPropertyChanged();
            }
        }

        /// <remarks/>
        [System.Xml.Serialization.XmlArrayItemAttribute("typekeyword", IsNullable = false)]
        public string[] typekeywords
        {
            get
            {
                return this.typekeywordsField;
            }
            set
            {
                this.typekeywordsField = value;
                this.NotifyPropertyChanged();
            }
        }

        /// <remarks/>
        public string thumbnail
        {
            get
            {
                return this.thumbnailField;
            }
            set
            {
                this.thumbnailField = value;
                this.NotifyPropertyChanged();
            }
        }

        /// <remarks/>
        public object documentation
        {
            get
            {
                return this.documentationField;
            }
            set
            {
                this.documentationField = value;
                this.NotifyPropertyChanged();
            }
        }

        /// <remarks/>
        public object url
        {
            get
            {
                return this.urlField;
            }
            set
            {
                this.urlField = value;
                this.NotifyPropertyChanged();
            }
        }

        /// <remarks/>
        public object spatialreference
        {
            get
            {
                return this.spatialreferenceField;
            }
            set
            {
                this.spatialreferenceField = value;
                this.NotifyPropertyChanged();
            }
        }

        /// <remarks/>
        public decimal minScale
        {
            get
            {
                return this.minScaleField;
            }
            set
            {
                this.minScaleField = value;
                this.NotifyPropertyChanged();
            }
        }

        /// <remarks/>
        public decimal maxScale
        {
            get
            {
                return this.maxScaleField;
            }
            set
            {
                this.maxScaleField = value;
                this.NotifyPropertyChanged();
            }
        }

        /// <remarks/>
        public object datalastModifiedTime
        {
            get
            {
                return this.datalastModifiedTimeField;
            }
            set
            {
                this.datalastModifiedTimeField = value;
                this.NotifyPropertyChanged();
            }
        }

        /// <remarks/>
        public object accessinformation
        {
            get
            {
                return this.accessinformationField;
            }
            set
            {
                this.accessinformationField = value;
                this.NotifyPropertyChanged();
            }
        }

        /// <remarks/>
        public object licenseinfo
        {
            get
            {
                return this.licenseinfoField;
            }
            set
            {
                this.licenseinfoField = value;
                this.NotifyPropertyChanged();
            }
        }

        /// <remarks/>
        [System.Xml.Serialization.XmlAttributeAttribute()]
        public string Culture
        {
            get
            {
                return this.cultureField;
            }
            set
            {
                this.cultureField = value;
                this.NotifyPropertyChanged();
            }
        }

        public event PropertyChangedEventHandler PropertyChanged = delegate { };

        private void NotifyPropertyChanged([CallerMemberName] string propName = "")
        {
            PropertyChanged(this, new PropertyChangedEventArgs(propName));
        }
    }

Real fun part extract and load into object, later part you can freely play with object

For below sample, I am using NuGet Gallery | SevenZipExtractor 1.0.15 

ESRI_ItemInformation TemplateInfo ;

using (ArchiveFile archiveFile = new ArchiveFile(templatePath))
            {
                Entry itemInfoEntry = archiveFile.Entries.FirstOrDefault(x => x.FileName.Equals(@"esriinfo\iteminfo.xml", StringComparison.OrdinalIgnoreCase));
                if (itemInfoEntry != null)
                {
                    MemoryStream memoryStream = new MemoryStream();
                    itemInfoEntry.Extract(memoryStream);
                    memoryStream.Position = 0;

                    XmlSerializer serializer = new XmlSerializer(typeof(ESRI_ItemInformation));
                    TemplateInfo = (ESRI_ItemInformation)serializer.Deserialize(memoryStream);
                }
            }
Tags (1)