示例#1
0
        public void SaveDotSTATCodelistFile(ICodelistObject codelist)
        {
            CodelistExporter _codeExp = new CodelistExporter(codelist.Id, codelist);
            List<ISTAT.IO.Utility.FileGeneric> files = new List<ISTAT.IO.Utility.FileGeneric>();
            List<ContactRef> contacs = GetConfigContact();
            string ExportFileName;

            ExportFileName = "DotStatExport-" + codelist.Id + "_" + codelist.AgencyId + "_" + codelist.Version;

            _codeExp.CreateData(contacs);

            System.Xml.XmlDocument xDoc_code = _codeExp.XMLDoc;
            MemoryStream xmlStream_code = new MemoryStream();
            xDoc_code.Save(xmlStream_code);
            xmlStream_code.Flush();
            xmlStream_code.Position = 0;
            ISTAT.IO.Utility.FileGeneric file_code = new ISTAT.IO.Utility.FileGeneric();
            file_code.filename = _codeExp.Code.ToString() + ".xml";
            file_code.stream = xmlStream_code;
            files.Add(file_code);

            Stream streamCSV = CSVWriter.CreateStream(_codeExp.DataView);
            ISTAT.IO.Utility.FileGeneric file_csv = new ISTAT.IO.Utility.FileGeneric();
            file_csv.filename = _codeExp.DataFilename;
            file_csv.stream = streamCSV;
            files.Add(file_csv);

            string fileZip = System.Web.HttpContext.Current.Server.MapPath("OutputFiles" + "\\" + ExportFileName + ".zip");

            System.IO.File.Delete(fileZip);
            Ionic.Utils.Zip.ZipFile zip = new Ionic.Utils.Zip.ZipFile(fileZip);
            foreach (ISTAT.IO.Utility.FileGeneric file in files)
                zip.AddFileStream(file.filename, string.Empty, file.stream);
            zip.Save();

            SendAttachment(fileZip, ExportFileName + ".zip");
        }
示例#2
0
        public bool CreateData(List<ContactRef> contacsNode,List<SecurityDef> securitiesNode,bool includeCommon=true,bool includeData=false)
        {
            if (this.sdmxObjects == null) return false;

            Org.Sdmxsource.Sdmx.Api.Model.Objects.DataStructure.IDataStructureObject _dsd =
                this.sdmxObjects.DataStructures.First();

            System.Xml.XmlDocument xDom = new System.Xml.XmlDocument();

            #region Root node
            System.Xml.XmlElement _rootNode = xDom.CreateElement("OECD.STAT");
            _rootNode.SetAttribute("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance");
            _rootNode.SetAttribute("xmlns:xsd", "http://www.w3.org/2001/XMLSchema");
            _rootNode.SetAttribute("Version", "1.0");
            #endregion

            #region Admin node

            System.Xml.XmlElement _adminNode = xDom.CreateElement("Admin");

            System.Xml.XmlElement _separatorNode = xDom.CreateElement("Separator");
            _separatorNode.InnerText = "|";
            _adminNode.AppendChild(_separatorNode);

            #region Contacts Node

            System.Xml.XmlElement _contactsNode = xDom.CreateElement("Contacts");
            foreach (ContactRef _conRef in contacsNode)
            {
                System.Xml.XmlElement _contactNode = xDom.CreateElement("Contact");
                System.Xml.XmlElement _nameNode = xDom.CreateElement("Name");
                _nameNode.InnerText = _conRef.name;
                System.Xml.XmlElement _directionNode = xDom.CreateElement("Direction");
                _directionNode.InnerText = _conRef.direction;
                System.Xml.XmlElement _emailNode = xDom.CreateElement("E-mail");
                _emailNode.InnerText = _conRef.email;
                System.Xml.XmlElement _languageNode = xDom.CreateElement("Language");
                _languageNode.InnerText = ((int)LocalisedKey.en).ToString();
                _contactNode.AppendChild(_nameNode);
                _contactNode.AppendChild(_directionNode);
                _contactNode.AppendChild(_emailNode);
                _contactNode.AppendChild(_languageNode);
                _contactsNode.AppendChild(_contactNode);
            }
            _adminNode.AppendChild(_contactsNode);

            #endregion;

            #region Secutiry node

            System.Xml.XmlElement _securityNode = xDom.CreateElement("Security");

            foreach (SecurityDef _secRef in securitiesNode)
            {

                System.Xml.XmlElement _membershipNode = xDom.CreateElement("Membership");
                System.Xml.XmlElement _userGroupNode = xDom.CreateElement("UserGroup");
                _userGroupNode.InnerText = _secRef.userGroup;
                System.Xml.XmlElement _domainNode = xDom.CreateElement("Domain");
                _domainNode.InnerText = _secRef.domain;
                _membershipNode.AppendChild(_userGroupNode);
                _membershipNode.AppendChild(_domainNode);
                _securityNode.AppendChild(_membershipNode);

            }
            _adminNode.AppendChild(_securityNode);

            #endregion

            #endregion

            #region Dataset node
            System.Xml.XmlElement _datasetNode = xDom.CreateElement("Dataset");

            System.Xml.XmlElement _datasetNameNode_en = xDom.CreateElement("DatasetName");
            System.Xml.XmlElement _datasetNameLanguageNode_en = xDom.CreateElement("Language");
            _datasetNameLanguageNode_en.InnerText = ((int)LocalisedKey.en).ToString();
            System.Xml.XmlElement _datasetNameValueNode_en = xDom.CreateElement("Value");
            _datasetNameValueNode_en.AppendChild(xDom.CreateCDataSection((_dsd.Names.Count > 0 && _dsd.Names[0] != null) ? _dsd.Names[0].Value : string.Empty));
            _datasetNameNode_en.AppendChild(_datasetNameLanguageNode_en);
            _datasetNameNode_en.AppendChild(_datasetNameValueNode_en);

            System.Xml.XmlElement _datasetNameNode_it = xDom.CreateElement("DatasetName");
            System.Xml.XmlElement _datasetNameLanguageNode_it = xDom.CreateElement("Language");
            _datasetNameLanguageNode_it.InnerText = ((int)LocalisedKey.it).ToString();
            System.Xml.XmlElement _datasetNameValueNode_it = xDom.CreateElement("Value");
            _datasetNameValueNode_it.AppendChild(xDom.CreateCDataSection((_dsd.Names.Count > 1 && _dsd.Names[1] != null) ? _dsd.Names[1].Value : _dsd.Names[0].Value));
            _datasetNameNode_it.AppendChild(_datasetNameLanguageNode_it);
            _datasetNameNode_it.AppendChild(_datasetNameValueNode_it);

            _datasetNode.AppendChild(_datasetNameNode_en);
            _datasetNode.AppendChild(_datasetNameNode_it);

            System.Xml.XmlElement _codeNode = xDom.CreateElement("Code");
            _codeNode.InnerText = _dsd.Id;
            _datasetNode.AppendChild(_codeNode);

            System.Xml.XmlElement _actionNode = xDom.CreateElement("Action");
            _actionNode.InnerText = "CREATE";
            _datasetNode.AppendChild(_actionNode);

            System.Xml.XmlElement _updatequeriesNode = xDom.CreateElement("UpdateQueries");
            _updatequeriesNode.InnerText = "true";
            _datasetNode.AppendChild(_updatequeriesNode);

            System.Xml.XmlElement _themeNode = xDom.CreateElement("Theme");
            _themeNode.InnerText = "General Statistics|General Statistics";
            _datasetNode.AppendChild(_themeNode);

            System.Xml.XmlElement _directorateNode = xDom.CreateElement("Directorate");
            _directorateNode.InnerText = "STD";
            _datasetNode.AppendChild(_directorateNode);

            #endregion

            #region Dimensions node

            _codelistExport = new List<CodelistExporter>();

            System.Xml.XmlElement _dimsNode = xDom.CreateElement("Dimensions");

            foreach (Org.Sdmxsource.Sdmx.Api.Model.Objects.DataStructure.IDimension dim in _dsd.DimensionList.Dimensions)
            {
                if (dim.HasCodedRepresentation())
                {
                    ISet<Org.Sdmxsource.Sdmx.Api.Model.Objects.Codelist.ICodelistObject> codelists =
                        sdmxObjects.GetCodelists(
                        new Org.Sdmxsource.Sdmx.Util.Objects.Reference.MaintainableRefObjectImpl()
                        {
                            AgencyId = dim.Representation.Representation.MaintainableReference.AgencyId,
                            MaintainableId = dim.Representation.Representation.MaintainableReference.MaintainableId,
                            Version = dim.Representation.Representation.MaintainableReference.Version
                        }
                        );
                    if (codelists != null &&  codelists.Count>0)
                    {
                        ISTAT.EXPORT.CodelistExporter exporter = new CodelistExporter(dim.Id, codelists.First());
                        exporter.CreateData(contacsNode);
                        _codelistExport.Add(exporter);
                        _dimsNode.AppendChild(exporter.Get_DimensionNode(xDom, codelists.First(), includeCommon, includeData));
                    }
                }
            }

            foreach (Org.Sdmxsource.Sdmx.Api.Model.Objects.DataStructure.IAttributeObject att in _dsd.Attributes)
            {
                if (att.HasCodedRepresentation())
                {
                    ISet<Org.Sdmxsource.Sdmx.Api.Model.Objects.Codelist.ICodelistObject> codelists =
                        sdmxObjects.GetCodelists(
                        new Org.Sdmxsource.Sdmx.Util.Objects.Reference.MaintainableRefObjectImpl()
                        {
                            AgencyId = att.Representation.Representation.MaintainableReference.AgencyId,
                            MaintainableId = att.Representation.Representation.MaintainableReference.MaintainableId,
                            Version = att.Representation.Representation.MaintainableReference.Version
                        }
                        );
                    if (codelists != null && codelists.Count>0)
                    {
                        ISTAT.EXPORT.CodelistExporter exporter = new CodelistExporter(att.Id, codelists.First());
                        exporter.CreateData(contacsNode);
                        _codelistExport.Add(exporter);
                        _dimsNode.AppendChild(exporter.Get_DimensionNode(xDom, codelists.First(), includeCommon, includeData));
                    }
                }
            }

            System.Xml.XmlElement _dimensionCountNode = xDom.CreateElement("DimensionCount");
            _dimensionCountNode.InnerText = _codelistExport.Count.ToString();
            _datasetNode.AppendChild(_dimensionCountNode);

            _datasetNode.AppendChild(_dimsNode);

            #endregion

            _rootNode.AppendChild(_adminNode);
            _rootNode.AppendChild(_datasetNode);

            xDom.AppendChild(_rootNode);
            _xmlDoc = xDom;

            return true;
        }