/// <summary>
        /// The main.
        /// </summary>
        /// <param name="args">
        /// The args.
        /// </param>
        public static void Main(string[] args)
        {
            // 1. Create a test mutable codelist with Count codes.
            const int Count = 1000;
            string countStr = Count.ToString(CultureInfo.InvariantCulture);
            ICodelistMutableObject codelist = new CodelistMutableCore();
            codelist.Id = "CL_K" + countStr;
            codelist.AgencyId = "TEST";
            codelist.AddName("en", "Test CL with " + countStr);
            for (int i = 0; i < Count; i++)
            {
                ICodeMutableObject code = new CodeMutableCore();
                code.Id = i.ToString(CultureInfo.InvariantCulture);
                code.AddName("en", "Code " + code.Id);
                codelist.AddItem(code);
            }

            // 2. Select the out filename
            string output = string.Format(CultureInfo.InvariantCulture, "{0}.xml", codelist.Id);

            // 3. Create the immutable instance of the codelist
            ICodelistObject immutableInstance = codelist.ImmutableInstance;

            using (FileStream writer = File.OpenWrite(output))
            using (XmlWriter xmlWriter = XmlWriter.Create(writer, new XmlWriterSettings { Encoding = Encoding.UTF8, Indent = true }))
            {
                // 4. Create the StructureMutableWritingManager, a faster but limited to a subset of SDMX v2.0 writer. 
                IStructureWriterManager writingManager = new StructureMutableWritingManager(xmlWriter);

                // 5. Write the codelist as a SDMX-ML v2.0 Registry Interface document. Other options include SDMX-ML 2.0 Structure document.
                writingManager.WriteStructure(immutableInstance, new HeaderImpl("ZZ9", "ZZ9"), new SdmxStructureFormat(StructureOutputFormat.GetFromEnum(StructureOutputFormatEnumType.SdmxV21StructureDocument)), null);
            }
        }
 /// <summary>
 /// Builds the time codelist.
 /// </summary>
 /// <param name="minPeriod">The minimum period.</param>
 /// <param name="maxPeriod">The maximum period.</param>
 /// <returns>the time codelist.</returns>
 public static ICodelistMutableObject BuildTimeCodelist(ISdmxDate minPeriod, ISdmxDate maxPeriod)
 {
     ICodelistMutableObject timeCodeList = new CodelistMutableCore();
     var startDate = minPeriod.FormatAsDateString(true);
     ICodeMutableObject startCode = new CodeMutableCore { Id = startDate };
     var endDate = maxPeriod.FormatAsDateString(false);
     ICodeMutableObject endCode = !startDate.Equals(endDate) ? new CodeMutableCore { Id = endDate } : null;
     SetupTimeCodelist(startCode, endCode, timeCodeList);
     return timeCodeList;
 }
예제 #3
0
        /// <summary>
        /// Handles the CodeList element child elements
        /// </summary>
        /// <param name="parent">
        /// The parent ICodelistMutableObject object
        /// </param>
        /// <param name="localName">
        /// The name of the current xml element
        /// </param>
        /// <returns>
        /// The <see cref="StructureReaderBaseV20.ElementActions"/>.
        /// </returns>
        private ElementActions HandleChildElements(ICodelistMutableObject parent, object localName)
        {
            ElementActions actions = null;
            if (NameTableCache.IsElement(localName, ElementNameTable.Code))
            {
                var code = new CodeMutableCore();
                code.Id = Helper.TrySetFromAttribute(this.Attributes, AttributeNameTable.value, code.Id);
                code.ParentCode = Helper.TrySetFromAttribute(
                    this.Attributes, AttributeNameTable.parentCode, code.ParentCode);
                code.Urn = Helper.TrySetFromAttribute(this.Attributes, AttributeNameTable.urn, code.Urn);
                parent.AddItem(code);
                actions = this.BuildElementActions(code, this.HandleAnnotableChildElements, this.HandleTextChildElement);
            }

            return actions;
        }
        /// <summary>
        /// Retrieve Codelist
        /// </summary>
        /// <param name="info">
        /// The current StructureRetrieval state 
        /// </param>
        /// <returns>
        /// A <see cref="ICodelistMutableObject"/> 
        /// </returns>
        public ICodelistMutableObject GetCodeList(StructureRetrievalInfo info)
        {
            var codelist = new CodelistMutableCore();
            var name = new TextTypeWrapperMutableCore { Locale = CustomCodelistConstants.Lang, Value = CustomCodelistConstants.CountCodeListName, };
            codelist.Names.Add(name);
            codelist.Id = CustomCodelistConstants.CountCodeList;
            codelist.AgencyId = CustomCodelistConstants.Agency;
            codelist.Version = CustomCodelistConstants.Version;
            int xsMeasureMult = 1;

            if (info.MeasureComponent != null)
            {
                info.Logger.Info("|-- Get XS Measure count");
                xsMeasureMult = GetXsMeasureCount(info);
            }

            object value = ExecuteSql(info);

            // setup count codelist
            var countCode = new CodeMutableCore();
            var text = new TextTypeWrapperMutableCore { Locale = CustomCodelistConstants.Lang, Value = CustomCodelistConstants.CountCodeDescription, };
            countCode.Names.Add(text);

            // normally count(*) should always return a number. Checking just in case I missed something.
            if (value != null && !Convert.IsDBNull(value))
            {
                // in .net, oracle will return 128bit decimal, sql server 32bit int, while mysql & sqlite 64bit long.
                long count = Convert.ToInt64(value, CultureInfo.InvariantCulture);

                // check if there are XS measure mappings. In this case there could be multiple measures/obs per row. 
                // even if they are not, then will be static mappings
                count *= xsMeasureMult;

                countCode.Id = count.ToString(CultureInfo.InvariantCulture);
                codelist.AddItem(countCode);
            }
            else
            {
                countCode.Id = CustomCodelistConstants.CountCodeDefault;
            }

            return codelist;
        }
        public void TestBuildSuccessResponse(SdmxSchemaEnumType version)
        {
            var responseBuilder = new SubmitStructureResponseBuilder();
            ISdmxObjects sdmxObjects = new SdmxObjectsImpl();
            var codelist = new CodelistMutableCore() { Id = "CL_TEST", Version = "1.0", AgencyId = "TEST" };
            codelist.AddName("en", "Test Codelist");
            for (int i = 0; i < 10; i++)
            {
                ICodeMutableObject item = new CodeMutableCore() { Id = "TEST_" + i.ToString(CultureInfo.InvariantCulture) };
                item.AddName("en", "Name for " + item.Id);
                codelist.AddItem(item);
            }

            sdmxObjects.AddCodelist(codelist.ImmutableInstance);
            var output = responseBuilder.BuildSuccessResponse(sdmxObjects, SdmxSchema.GetFromEnum(version));
            var fileName = "TestBuildSuccessResponse" + version + ".xml";
            output.Untyped.Save(fileName);
            using (IReadableDataLocation dataLocation = new FileReadableDataLocation(fileName))
            {
                XMLParser.ValidateXml(dataLocation, version);
            }
        }
        private ICodelistMutableObject InsertCodeInCodelist(ICodelistMutableObject cl)
        {
            if (cl == null) return null;

            ICodeMutableObject code = new CodeMutableCore();

            string code_id = txt_id_new.Text.Trim();

            IList<ITextTypeWrapperMutableObject> code_names = AddTextName_new.TextObjectList;
            IList<ITextTypeWrapperMutableObject> code_descs = AddTextDescription_new.TextObjectList;
            string code_parent_id = txt_parentid_new.Text.Trim();
            string code_order_str = txt_order_new.Text.Trim();

            #region CODE ID
            if ( ValidationUtils.CheckIdFormat( code_id ) )
            {
                code.Id = code_id;
            }
            else
            {
                lblErrorOnNewInsert.Text = Resources.Messages.err_id_format;
                Utils.AppendScript( "openPopUp('df-Dimension', 600);" );
                Utils.AppendScript("location.href= '#codes';");
                return null;
            }

            IEnumerable<ICodeMutableObject> codes = (from c in cl.Items where c.Id == code_id select c).OfType<ICodeMutableObject>();
            if (codes.Count() > 0)
            {
                lblErrorOnNewInsert.Text = Resources.Messages.err_id_exist;
                Utils.AppendScript( "openPopUp('df-Dimension', 600);" );
                Utils.AppendScript("location.href= '#codes';");
                return null;
            }
            #endregion

            #region CODE NAMES
            if (code_names != null)
            {
                foreach (var tmpName in code_names)
                {
                    code.AddName(tmpName.Locale, tmpName.Value);
                }
            }
            else
            {
                lblErrorOnNewInsert.Text = Resources.Messages.err_list_name_format;
                Utils.AppendScript( "openPopUp('df-Dimension', 600);" );
                Utils.AppendScript("location.href= '#codes';");
                return null;
            }
            #endregion

            #region CODE DESCRIPTIONS
            if (code_descs != null)
            {
                foreach (var tmpDescription in code_descs)
                {
                    code.AddDescription(tmpDescription.Locale, tmpDescription.Value);
                }
            }
            #endregion

            #region PARANT ID

            if ( code_id.Equals( code_parent_id ) )
            {
                lblErrorOnNewInsert.Text = Resources.Messages.err_parent_id_same_value;
                Utils.AppendScript( "openPopUp('df-Dimension-update', 600 );" );
                Utils.AppendScript("location.href= '#codes';");
                return null;
            }

            if (!code_parent_id.Equals(string.Empty) && ValidationUtils.CheckIdFormat(code_id))
            {
                IEnumerable<ICodeMutableObject> parentCode = (from c in cl.Items where c.Id == code_parent_id select c).OfType<ICodeMutableObject>();
                if (parentCode.Count() > 0)
                    code.ParentCode = code_parent_id;
                else
                {
                    lblErrorOnNewInsert.Text = Resources.Messages.err_parent_id_not_found;
                    Utils.AppendScript( "openPopUp('df-Dimension', 600);" );
                    Utils.AppendScript("location.href= '#codes';");
                    return null;
                }
            }
            #endregion

            #region CODE ORDER
            int tmpOrder = 0;
            if (!code_order_str.Equals(string.Empty) && !int.TryParse( code_order_str, out tmpOrder ) )
            {
                lblErrorOnNewInsert.Text = Resources.Messages.err_order_format_invalid;
                Utils.AppendScript( "openPopUp('df-Dimension', 600);" );
                Utils.AppendScript("location.href= '#codes';");
                return null;
            }
            else
            {
                if ( tmpOrder < 0 )
                {
                    lblErrorOnNewInsert.Text = Resources.Messages.err_order_less_than_zero;
                    Utils.AppendScript( "openPopUp('df-Dimension', 600);" );
                    Utils.AppendScript("location.href= '#codes';");
                    return null;
                }
            }
            #endregion

            int indexOrder;
            if (!int.TryParse(code_order_str, out indexOrder))
                indexOrder = cl.Items.Count + 1;
            else { indexOrder--; }
            if (indexOrder < 0
                || indexOrder > cl.Items.Count) indexOrder = cl.Items.Count;

            cl.Items.Insert(indexOrder, code);

            try
            {
                // Ultimo controllo se ottengo Immutable istanze validazione completa
                var canRead = cl.ImmutableInstance;
            }
            catch (Exception ex)
            {
                cl.Items.RemoveAt(indexOrder);
                return null;
            }
            return cl;
        }
 /// <summary>
 ///     The create sample codelist.
 /// </summary>
 /// <returns>
 ///     The <see cref="ICodelistObject" />.
 /// </returns>
 private static ICodelistObject CreateSampleCodelist()
 {
     ICodelistMutableObject codelist = new CodelistMutableCore();
     codelist.Id = "CL_3166A2";
     codelist.AgencyId = "ISO";
     codelist.AddName("en", "Test CL");
     ICodeMutableObject code = new CodeMutableCore();
     code.Id = "AR";
     code.AddName("en", "Code " + code.Id);
     codelist.AddItem(code);
     ICodelistObject immutableInstance = codelist.ImmutableInstance;
     return immutableInstance;
 }
예제 #8
0
        private ICodelistObject GetTimeCodeList(ICodelistObject FreqCodelist, IDataflowObject df, IDataStructureObject kf)
        {
            ICodelistObject CL_TIME_MA = GetCodeList(df, kf, kf.TimeDimension);
            if (CL_TIME_MA == null || CL_TIME_MA.Items == null || CL_TIME_MA.Items.Count != 2)
                return CL_TIME_MA;

            //string format_time = (CL_TIME_MA.Items[0].Id.Contains("-")) ? "yyyy-MM-dd" : "yyyy";
            string time_min_normal = CL_TIME_MA.Items[0].Id;
            string time_max_normal = CL_TIME_MA.Items[1].Id;

            /*fabio 04/11/2015 v3.0.0.0*/
            if (time_min_normal.CompareTo(time_max_normal) > 0)
            {
                time_max_normal = CL_TIME_MA.Items[0].Id;
                time_min_normal = CL_TIME_MA.Items[1].Id;
            }
            else
            {
                time_max_normal = CL_TIME_MA.Items[1].Id;
                time_min_normal = CL_TIME_MA.Items[0].Id;
            }
            /*fine fabio 04/11/2015 v3.0.0.0*/

            string FrequencyDominant = null;
            if (CodemapObj.PreviusCostraint != null
                && CodemapObj.PreviusCostraint.ContainsKey(kf.FrequencyDimension.Id))
                FrequencyDominant = CodemapObj.PreviusCostraint[kf.FrequencyDimension.Id].First();
            if (FrequencyDominant == null)
            {
                FrequencyDominant = "A";
                if (FreqCodelist.Items.Count(c => c.Id.ToUpper() == "S") > 0) FrequencyDominant = "S";
                if (FreqCodelist.Items.Count(c => c.Id.ToUpper() == "Q") > 0) FrequencyDominant = "Q";
                if (FreqCodelist.Items.Count(c => c.Id.ToUpper() == "M") > 0) FrequencyDominant = "M";
            }
            if (!CL_TIME_MA.Items[0].Id.Contains("-"))
            {
                time_min_normal = string.Format("{0}-{1}-{2}", CL_TIME_MA.Items[0].Id, "01", "01");
                time_max_normal = string.Format("{0}-{1}-{2}", CL_TIME_MA.Items[1].Id, "01", "01");
            }
            else
            {
                var time_p_c = CL_TIME_MA.Items[0].Id.Split('-');
                if (time_p_c.Length == 2)
                {
                    int mul =
                        (FrequencyDominant == "M") ? 1 :
                        (FrequencyDominant == "Q") ? 3 :
                        (FrequencyDominant == "S") ? 6 : 0;

                    int t_fix = (int.Parse(time_p_c[1].Substring(1))) * mul;
                    time_min_normal = string.Format("{0}-{1}-{2}", time_p_c[0], (t_fix > 9) ? t_fix.ToString() : "0" + t_fix.ToString(), "01");
                    time_p_c = CL_TIME_MA.Items[1].Id.Split('-');
                    t_fix = (int.Parse(time_p_c[1].Substring(1))) * mul;
                    time_max_normal = string.Format("{0}-{1}-{2}", time_p_c[0], (t_fix > 9) ? t_fix.ToString() : "0" + t_fix.ToString(), "01");
                }
                if (CL_TIME_MA.Items[0].Id.Contains("S"))
                {
                    var time_p = CL_TIME_MA.Items[0].Id.Split('-');
                    int t_fix = (int.Parse(time_p[1].Substring(1))) * 6;
                    time_min_normal = string.Format("{0}-{1}-{2}", time_p[0], (t_fix > 9) ? t_fix.ToString() : "0" + t_fix.ToString(), "01");

                    time_p = CL_TIME_MA.Items[1].Id.Split('-');
                    t_fix = (int.Parse(time_p[1].Substring(1))) * 6;
                    time_max_normal = string.Format("{0}-{1}-{2}", time_p[0], (t_fix > 9) ? t_fix.ToString() : "0" + t_fix.ToString(), "01");
                }
                if (CL_TIME_MA.Items[0].Id.Contains("Q"))
                {
                    var time_p = CL_TIME_MA.Items[0].Id.Split('-');
                    int t_fix = ((int.Parse(time_p[1].Substring(1))) * 3);
                    time_min_normal = string.Format("{0}-{1}-{2}", time_p[0], (t_fix > 9) ? t_fix.ToString() : "0" + t_fix.ToString(), "01");

                    time_p = CL_TIME_MA.Items[1].Id.Split('-');
                    t_fix = ((int.Parse(time_p[1].Substring(1))) * 3);
                    time_max_normal = string.Format("{0}-{1}-{2}", time_p[0], (t_fix > 9) ? t_fix.ToString() : "0" + t_fix.ToString(), "01");
                }
                if (CL_TIME_MA.Items[0].Id.Contains("M"))
                {
                    var time_p = CL_TIME_MA.Items[0].Id.Split('-');
                    int t_fix = (int.Parse(time_p[1].Substring(1))) * 1;
                    time_min_normal = string.Format("{0}-{1}-{2}", time_p[0], (t_fix > 9) ? t_fix.ToString() : "0" + t_fix.ToString(), "01");

                    time_p = CL_TIME_MA.Items[1].Id.Split('-');
                    t_fix = (int.Parse(time_p[1].Substring(1))) * 1;
                    time_max_normal = string.Format("{0}-{1}-{2}", time_p[0], (t_fix > 9) ? t_fix.ToString() : "0" + t_fix.ToString(), "01");
                }
            }

               DateTime MinDate = DateTime.ParseExact(time_min_normal, "yyyy-MM-dd", CultureInfo.CurrentCulture, DateTimeStyles.None);
               DateTime MaxDate = DateTime.ParseExact(time_max_normal, "yyyy-MM-dd", CultureInfo.CurrentCulture, DateTimeStyles.None);
               //fabio baco
            //CultureInfo enEn = new CultureInfo("en");
            //DateTime MinDate = DateTime.ParseExact(time_min_normal, "yyyy-MM-dd", enEn, DateTimeStyles.None);
            //DateTime MaxDate = DateTime.ParseExact(time_max_normal, "yyyy-MM-dd", enEn, DateTimeStyles.None);

            ICodelistMutableObject CL_TIME = new CodelistMutableCore();
            CL_TIME.Id = CL_TIME_MA.Id;
            CL_TIME.AgencyId = CL_TIME_MA.AgencyId;
            CL_TIME.Version = CL_TIME_MA.Version;

            CL_TIME_MA.Names.ToList().ForEach(n => CL_TIME.AddName(n.Locale, n.Value));

            DateTime ActualDate = MinDate;
            switch (FrequencyDominant)
            {
                case "A":
                    #region Aggiungo gli Annual
                    while (ActualDate.CompareTo(MaxDate) <= 0)
                    {
                        ICodeMutableObject code = new CodeMutableCore();
                        code.Id = ActualDate.Year.ToString();
                        code.AddName("en", code.Id);
                        CL_TIME.AddItem(code);

                        ActualDate = ActualDate.AddYears(1);
                    }
                    #endregion
                    break;
                case "S":
                    #region Aggiungo gli Semestrali
                    while (ActualDate.CompareTo(MaxDate) <= 0)
                    {
                        ICodeMutableObject code = new CodeMutableCore();
                        code.Id = ActualDate.Year.ToString() + "-S" + (ActualDate.Month < 6 ? "1" : "2");
                        code.AddName("en", code.Id);
                        CL_TIME.AddItem(code);

                        ActualDate = ActualDate.AddMonths(6);
                    }
                    #endregion
                    break;
                case "Q":
                    #region Aggiungo i Quartely
                    while (ActualDate.CompareTo(MaxDate) <= 0)
                    {
                        ICodeMutableObject code = new CodeMutableCore();
                        code.Id = ActualDate.Year.ToString() + "-Q" + ((ActualDate.Month - 1) / 3 + 1).ToString();
                        code.AddName("en", code.Id);
                        CL_TIME.AddItem(code);

                        ActualDate = ActualDate.AddMonths(3);
                    }
                    #endregion
                    break;
                case "M":
                    #region Aggiungo i Mensili
                    while (ActualDate.CompareTo(MaxDate) <= 0)
                    {
                        ICodeMutableObject code = new CodeMutableCore();
                        code.Id = ActualDate.ToString("yyyy-MM");
                        code.AddName("en", code.Id);
                        CL_TIME.AddItem(code);

                        ActualDate = ActualDate.AddMonths(1);
                    }
                    #endregion
                    break;
                default:
                    break;
            }

            return CL_TIME.ImmutableInstance;
        }
        /// <summary>
        /// Get the Codes
        /// </summary>
        /// <param name="itemSchemeBean">
        /// The parent <see cref="ICodelistMutableObject"/>
        /// </param>
        /// <param name="parentSysId">
        /// The parent ItemScheme primary key in Mapping Store
        /// </param>
        /// <param name="subset">
        /// The list of items to retrieve
        /// </param>
        /// <returns>
        /// The <see cref="ICodelistMutableObject"/>.
        /// </returns>
        private ICodelistMutableObject FillCodesHash(ICodelistMutableObject itemSchemeBean, long parentSysId, IList<string> subset)
        {
            var allItems = new Dictionary<long, ICodeMutableObject>();
            var orderedItems = new List<KeyValuePair<long, ICodeMutableObject>>();
            var childItems = new Dictionary<long, long>();

            // TODO convert to Set<> in .NET 3.5
            var subsetSet = new HashSet<string>(StringComparer.Ordinal);
            for (int i = 0; i < subset.Count; i++)
            {
                subsetSet.Add(subset[i]);
            }

            using (DbCommand command = this.ItemCommandBuilder.Build(new ItemSqlQuery(this.ItemSqlQueryInfo, parentSysId)))
            {
                using (IDataReader dataReader = this.MappingStoreDb.ExecuteReader(command))
                {
                    int sysIdIdx = dataReader.GetOrdinal("SYSID");
                    int idIdx = dataReader.GetOrdinal("ID");
                    int parentIdx = dataReader.GetOrdinal("PARENT");
                    int txtIdx = dataReader.GetOrdinal("TEXT");
                    int langIdx = dataReader.GetOrdinal("LANGUAGE");
                    int typeIdx = dataReader.GetOrdinal("TYPE");
                    while (dataReader.Read())
                    {
                        string id = DataReaderHelper.GetString(dataReader, idIdx);
                        if (subsetSet.Contains(id))
                        {
                            long sysId = DataReaderHelper.GetInt64(dataReader, sysIdIdx);
                            ICodeMutableObject item;
                            if (!allItems.TryGetValue(sysId, out item))
                            {
                                item = new CodeMutableCore { Id = id };

                                orderedItems.Add(new KeyValuePair<long, ICodeMutableObject>(sysId, item));
                                allItems.Add(sysId, item);
                                long parentItemId = DataReaderHelper.GetInt64(dataReader, parentIdx);
                                if (parentItemId > long.MinValue)
                                {
                                    childItems.Add(sysId, parentItemId);
                                }
                            }

                            ReadLocalisedString(item, typeIdx, txtIdx, langIdx, dataReader);
                        }
                    }
                }
            }

            this.FillParentItems(itemSchemeBean, childItems, allItems, orderedItems);
            return itemSchemeBean;
        }
        /// <summary>
        /// Creates and returns a codelist with the specified <paramref name="id"/>, <paramref name="name"/> and
        ///     <paramref name="codes"/>
        /// </summary>
        /// <param name="id">
        /// The id.
        /// </param>
        /// <param name="name">
        /// The name.
        /// </param>
        /// <param name="codes">
        /// The codes.
        /// </param>
        /// <returns>
        /// The <see cref="ICodelistObject"/>.
        /// </returns>
        private static ICodelistObject CreateCodelist(string id, string name, params string[] codes)
        {
            var codelist = new CodelistMutableCore { Id = id, AgencyId = "TEST" };
            codelist.AddName("en", name);

            if (codes == null || codes.Length == 0)
            {
                for (int i = 0; i < 10; i++)
                {
                    string s = i.ToString(CultureInfo.InvariantCulture);
                    var code = new CodeMutableCore { Id = "CODE" + s };
                    code.AddName("en", "Description of " + s);
                    codelist.AddItem(code);
                }
            }
            else
            {
                foreach (string codeId in codes)
                {
                    var code = new CodeMutableCore { Id = codeId };
                    code.AddName("en", "Description of " + codeId);
                    codelist.AddItem(code);
                }
            }

            return codelist.ImmutableInstance;
        }
        public void TestWriteReadBigCodeList(int count)
        {
            string countStr = count.ToString(CultureInfo.InvariantCulture);
            ICodelistMutableObject codelist = new CodelistMutableCore();
            codelist.Id = "CL_K" + countStr;
            codelist.AgencyId = "TEST";
            codelist.AddName("en", "Test CL with " + countStr);
            for (int i = 0; i < count; i++)
            {
                ICodeMutableObject code = new CodeMutableCore();
                code.Id = i.ToString(CultureInfo.InvariantCulture);
                code.AddName("en", "Code " + code.Id);
                codelist.AddItem(code);
            }

            IMutableObjects mutableObjects = new MutableObjectsImpl();
            mutableObjects.AddCodelist(codelist);
            var sw = new Stopwatch();
            string output = string.Format(CultureInfo.InvariantCulture, "big-codelist-{0}.xml", countStr);
            sw.Start();
            using (XmlWriter writer = XmlWriter.Create(output, new XmlWriterSettings { CloseOutput = true, Indent = true }))
            {
                var structureWriter = new StructureWriterV2(writer);
                structureWriter.WriteStructure(mutableObjects, new HeaderImpl("ZZ9", "ZZ9"));
            }

            sw.Stop();
            Trace.WriteLine(string.Format(CultureInfo.InvariantCulture, "Writing {0} took {1}", countStr, sw.Elapsed));

            sw.Reset();
            sw.Start();
            XmlReaderSettings settings = XMLParser.GetSdmxXmlReaderSettings(SdmxSchemaEnumType.VersionTwo);
            settings.ValidationEventHandler += OnValidationEventHandler;
            var structureReader = new StructureReaderV2();
            settings.NameTable = NameTableCache.Instance.NameTable;
            using (XmlReader reader = XmlReader.Create(output, settings))
            {
                IMutableObjects res = structureReader.Read(reader);
                Assert.NotNull(res);
            }

            sw.Stop();
            Trace.WriteLine(string.Format(CultureInfo.InvariantCulture, "Reading {0} took {1}", countStr, sw.Elapsed));
        }
        private void ManageCode(csvCode code)
        {
            switch (_structureType)
            {
                case SdmxStructureEnumType.CategoryScheme:
                    break;
                case SdmxStructureEnumType.CodeList:
                    ICodeMutableObject tmpClCode = ucCodelist.GetCodeById(code.code);

                    if (tmpClCode == null)
                    {
                        tmpClCode = new CodeMutableCore();
                        tmpClCode.Id = code.code;
                        tmpClCode.ParentCode = code.parentCode;
                        tmpClCode.AddName(cmbLanguageForCsv.SelectedValue.ToString(), code.name);
                        tmpClCode.AddDescription(cmbLanguageForCsv.SelectedValue.ToString(), code.description);
                        ucCodelist.AddItem(tmpClCode);
                    }
                    else
                    {
                        tmpClCode.Id = code.code;
                        tmpClCode.ParentCode = code.parentCode;
                        tmpClCode.AddName(cmbLanguageForCsv.SelectedValue.ToString(), code.name);
                        tmpClCode.AddDescription(cmbLanguageForCsv.SelectedValue.ToString(), code.description);
                    }

                    break;
                case SdmxStructureEnumType.ConceptScheme:
                    break;
            }
        }
예제 #13
0
        private ICodelistObject GetTimeCodeList(ISdmxObjects sdmxObjects, ICodelistObject FreqCodelist, IDataStructureObject kf)
        {
            if (this.SessionObj.CodelistConstrained != null && this.SessionObj.CodelistConstrained.ContainsKey(Utils.MakeKey(kf))
                && this.SessionObj.CodelistConstrained[Utils.MakeKey(kf)].ContainsKey(kf.TimeDimension.Id))
            {
                ICodelistObject codes = this.SessionObj.CodelistConstrained[Utils.MakeKey(kf)][kf.TimeDimension.Id];
                if (codes != null)
                    return codes;
            }
            var codelist = (from c in sdmxObjects.Codelists where c.Id == kf.TimeDimension.Id select c).FirstOrDefault();
            ICodelistObject CL_TIME_MA = codelist;
            if (CL_TIME_MA == null
                || CL_TIME_MA.Items == null
                || CL_TIME_MA.Items.Count != 2)
                return CL_TIME_MA;

            //string format_time = (CL_TIME_MA.Items[0].Id.Contains("-")) ? "yyyy-MM-dd" : "yyyy";
            string time_min_normal = CL_TIME_MA.Items[0].Id;
            string time_max_normal = CL_TIME_MA.Items[1].Id;

            string FrequencyDominant = "A";
            if (FreqCodelist.Items.Count(c => c.Id.ToUpper() == "S") > 0) FrequencyDominant = "S";
            if (FreqCodelist.Items.Count(c => c.Id.ToUpper() == "Q") > 0) FrequencyDominant = "Q";
            if (FreqCodelist.Items.Count(c => c.Id.ToUpper() == "M") > 0) FrequencyDominant = "M";

            if (!CL_TIME_MA.Items[0].Id.Contains("-"))
            {
                time_min_normal = string.Format("{0}-{1}-{2}", CL_TIME_MA.Items[0].Id, "01", "01");
                time_max_normal = string.Format("{0}-{1}-{2}", CL_TIME_MA.Items[1].Id, "01", "01");
            }
            else
            {
                var time_p_c = CL_TIME_MA.Items[0].Id.Split('-');
                if (time_p_c.Length == 2)
                {
                    int mul =
                        (FrequencyDominant == "M") ? 1 :
                        (FrequencyDominant == "Q") ? 3 :
                        (FrequencyDominant == "S") ? 6 : 0;

                    int t_fix = (int.Parse(time_p_c[1].Substring(1))) * mul;
                    time_min_normal = string.Format("{0}-{1}-{2}", time_p_c[0], (t_fix > 9) ? t_fix.ToString() : "0" + t_fix.ToString(), "01");
                    time_p_c = CL_TIME_MA.Items[1].Id.Split('-');
                    t_fix = (int.Parse(time_p_c[1].Substring(1))) * mul;
                    time_max_normal = string.Format("{0}-{1}-{2}", time_p_c[0], (t_fix > 9) ? t_fix.ToString() : "0" + t_fix.ToString(), "01");
                }
                if (CL_TIME_MA.Items[0].Id.Contains("S"))
                {
                    var time_p = CL_TIME_MA.Items[0].Id.Split('-');
                    int t_fix = (int.Parse(time_p[1].Substring(1))) * 6;
                    time_min_normal = string.Format("{0}-{1}-{2}", time_p[0], (t_fix > 9) ? t_fix.ToString() : "0" + t_fix.ToString(), "01");

                    time_p = CL_TIME_MA.Items[1].Id.Split('-');
                    t_fix = (int.Parse(time_p[1].Substring(1))) * 6;
                    time_max_normal = string.Format("{0}-{1}-{2}", time_p[0], (t_fix > 9) ? t_fix.ToString() : "0" + t_fix.ToString(), "01");
                }
                if (CL_TIME_MA.Items[0].Id.Contains("Q"))
                {
                    var time_p = CL_TIME_MA.Items[0].Id.Split('-');
                    int t_fix = ((int.Parse(time_p[1].Substring(1))) * 3);
                    time_min_normal = string.Format("{0}-{1}-{2}", time_p[0], (t_fix > 9) ? t_fix.ToString() : "0" + t_fix.ToString(), "01");

                    time_p = CL_TIME_MA.Items[1].Id.Split('-');
                    t_fix = ((int.Parse(time_p[1].Substring(1))) * 3);
                    time_max_normal = string.Format("{0}-{1}-{2}", time_p[0], (t_fix > 9) ? t_fix.ToString() : "0" + t_fix.ToString(), "01");
                }
                if (CL_TIME_MA.Items[0].Id.Contains("M"))
                {
                    var time_p = CL_TIME_MA.Items[0].Id.Split('-');
                    int t_fix = (int.Parse(time_p[1].Substring(1))) * 1;
                    time_min_normal = string.Format("{0}-{1}-{2}", time_p[0], (t_fix > 9) ? t_fix.ToString() : "0" + t_fix.ToString(), "01");

                    time_p = CL_TIME_MA.Items[1].Id.Split('-');
                    t_fix = (int.Parse(time_p[1].Substring(1))) * 1;
                    time_max_normal = string.Format("{0}-{1}-{2}", time_p[0], (t_fix > 9) ? t_fix.ToString() : "0" + t_fix.ToString(), "01");
                }
            }

            DateTime MinDate = DateTime.ParseExact(time_min_normal, "yyyy-MM-dd", CultureInfo.CurrentCulture, DateTimeStyles.None);
            DateTime MaxDate = DateTime.ParseExact(time_max_normal, "yyyy-MM-dd", CultureInfo.CurrentCulture, DateTimeStyles.None);

            ICodelistMutableObject CL_TIME = new CodelistMutableCore();
            CL_TIME.Id = CL_TIME_MA.Id;
            CL_TIME.AgencyId = CL_TIME_MA.AgencyId;
            CL_TIME.Version = CL_TIME_MA.Version;

            CL_TIME_MA.Names.ToList().ForEach(n => CL_TIME.AddName(n.Locale, n.Value));

            DateTime ActualDate = MinDate;
            switch (FrequencyDominant)
            {
                case "A":
                    #region Aggiungo gli Annual
                    while (ActualDate.CompareTo(MaxDate) < 0)
                    {
                        ICodeMutableObject code = new CodeMutableCore();
                        code.Id = ActualDate.Year.ToString();
                        code.AddName("en", code.Id);
                        CL_TIME.AddItem(code);

                        ActualDate = ActualDate.AddYears(1);
                    }
                    #endregion
                    break;
                case "S":
                    #region Aggiungo gli Semestrali
                    while (ActualDate.CompareTo(MaxDate) < 0)
                    {
                        ICodeMutableObject code = new CodeMutableCore();
                        code.Id = ActualDate.Year.ToString() + "-S" + (ActualDate.Month < 6 ? "1" : "2");
                        code.AddName("en", code.Id);
                        CL_TIME.AddItem(code);

                        ActualDate = ActualDate.AddMonths(6);
                    }
                    #endregion
                    break;
                case "Q":
                    #region Aggiungo i Quartely
                    while (ActualDate.CompareTo(MaxDate) < 0)
                    {
                        ICodeMutableObject code = new CodeMutableCore();
                        code.Id = ActualDate.Year.ToString() + "-Q" + ((ActualDate.Month - 1) / 3 + 1).ToString();
                        code.AddName("en", code.Id);
                        CL_TIME.AddItem(code);

                        ActualDate = ActualDate.AddMonths(3);
                    }
                    #endregion
                    break;
                case "M":
                    #region Aggiungo i Mensili
                    while (ActualDate.CompareTo(MaxDate) < 0)
                    {
                        ICodeMutableObject code = new CodeMutableCore();
                        code.Id = ActualDate.ToString("yyyy-MM");
                        code.AddName("en", code.Id);
                        CL_TIME.AddItem(code);

                        ActualDate = ActualDate.AddMonths(1);
                    }
                    #endregion
                    break;
                default:
                    break;
            }

            return CL_TIME.ImmutableInstance;
        }
예제 #14
0
        /// <summary>
        /// Convert the specified <paramref name="conceptScheme"/> to CodeList.
        /// </summary>
        /// <param name="conceptScheme">The concept scheme.</param>
        /// <returns>The CodeList.</returns>
        public static ICodelistMutableObject ConvertToCodelist(this IConceptSchemeMutableObject conceptScheme)
        {
            ICodelistMutableObject codelist = new CodelistMutableCore()
            {
                Id = conceptScheme.Id,
                AgencyId = conceptScheme.AgencyId,
                Version = conceptScheme.Version,
                FinalStructure = conceptScheme.FinalStructure,
                IsPartial = conceptScheme.IsPartial,
            };
            codelist.Names.AddAll(conceptScheme.Names);
            codelist.Descriptions.AddAll(conceptScheme.Descriptions);
            foreach (var item in conceptScheme.Items)
            {
                ICodeMutableObject code = new CodeMutableCore { Id = item.Id, };

                code.Names.AddAll(item.Names);
                code.Descriptions.AddAll(item.Descriptions);

                codelist.AddItem(code);
            }

            return codelist;
        }
        protected void btnImportFromCsv_Click(object sender, EventArgs e)
        {
            if ( !csvFile.HasFile )
            {
                Utils.AppendScript( "openPopUp( 'importCsv' );" );
                Utils.AppendScript( "location.href='#codes'" );
                Utils.AppendScript( string.Format( "alert( '{0}' );", Resources.Messages.err_no_file_uploaded ) );
                return;
            }

            ICodelistMutableObject cl = GetCodeListFromSession();

            if (cl == null) return;

            List<csvCode> codes = new List<csvCode>();
            bool errorInUploading = false;
            StreamReader reader = null;
            StreamWriter logWriter = null;
            string wrongRowsMessage = string.Empty;
            string wrongRowsMessageForUser = string.Empty;
            string wrongFileLines = string.Empty;

            try
            {
                string filenameWithoutExtension = string.Format("{0}_{1}_{2}", Path.GetFileName(csvFile.FileName).Substring(0, csvFile.FileName.Length - 4), Session.SessionID, DateTime.Now.ToString().Replace('/', '_').Replace(':', '_').Replace(' ', '_'));
                string filename = string.Format("{0}.csv", filenameWithoutExtension);
                string logFilename = string.Format("{0}.log", filenameWithoutExtension);
                csvFile.SaveAs(Server.MapPath("~/csv_codelists_files/") + filename);

                reader = new StreamReader(Server.MapPath("~/csv_codelists_files/") + filename);
                logWriter = new StreamWriter(Server.MapPath("~/csv_codelists_import_logs/") + logFilename, true);
                logWriter.WriteLine(string.Format("LOG RELATIVO A CARICAMENTO DELLA CODELIST [ ID => \"{0}\"  AGENCY_ID => \"{1}\"  VERSION => \"{2}\" ]  |  LINGUA SELEZIONATA: {3}\n", cl.Id.ToString(), cl.AgencyId.ToString(), cl.Version.ToString(), cmbLanguageForCsv.SelectedValue.ToString()));
                logWriter.WriteLine("-----------------------------------------------------------------------------------------------------------------------------\n");
                reader.ReadLine();
                int currentRow = 1;

                char separator = txtSeparator.Text.Trim().Equals( string.Empty ) ? ';' : txtSeparator.Text.Trim().ElementAt( 0 );

                while (!reader.EndOfStream)
                {
                    string  currentFileLine = reader.ReadLine();
                    string[] fields = currentFileLine.Split( separator );
                    if (fields.Length != 4)
                    {
                        errorInUploading = true;
                        wrongRowsMessage += string.Format(Resources.Messages.err_csv_import_line_bad_format, currentRow + 1);
                        wrongRowsMessageForUser += string.Format(Resources.Messages.err_csv_import_line_bad_format_gui, currentRow + 1);
                        wrongFileLines += string.Format( "{0}\n", currentFileLine );
                        logWriter.WriteLine(string.Format(Resources.Messages.err_csv_import_line_bad_format, currentRow + 1));
                        logWriter.Flush();
                        currentRow++;
                        continue;
                    }
                    if (fields[0].Trim().Equals("\"\"") || fields[0].Trim().Equals( string.Empty ))
                    {
                        errorInUploading = true;
                        wrongRowsMessage += string.Format(Resources.Messages.err_csv_import_id_missing, currentRow + 1);
                        wrongRowsMessageForUser += string.Format(Resources.Messages.err_csv_import_id_missing_gui, currentRow + 1);
                        wrongFileLines += string.Format( "{0}\n", currentFileLine );
                        logWriter.WriteLine(string.Format(Resources.Messages.err_csv_import_id_missing, currentRow + 1));
                        logWriter.Flush();
                        currentRow++;
                        continue;
                    }
                    if (fields[1].Trim().Equals("\"\"") || fields[1].Trim().Equals( string.Empty ))
                    {
                        errorInUploading = true;
                        wrongRowsMessage += string.Format(Resources.Messages.err_csv_import_name_missing, currentRow + 1);
                        wrongRowsMessageForUser += string.Format(Resources.Messages.err_csv_import_name_missing_gui, currentRow + 1);
                        wrongFileLines += string.Format( "{0}\n", currentFileLine );
                        logWriter.WriteLine(string.Format(Resources.Messages.err_csv_import_name_missing, currentRow + 1));
                        logWriter.Flush();
                        currentRow++;
                        continue;
                    }
                    codes.Add(new csvCode(fields[0].ToString().Replace("\"", ""), fields[1].ToString().Replace("\"", ""), fields[2].ToString().Replace("\"", ""), fields[3].ToString().Replace("\"", "")));
                    currentRow++;
                }

            }
            catch (Exception ex)
            {
                Utils.AppendScript(string.Format("Upload status: The file could not be uploaded. The following error occured: {0}", ex.Message));
            }

            foreach (csvCode code in codes)
            {
                if ( !code.parentCode.Trim().Equals( string.Empty ) )
                {
                    int cont = (from myCode in cl.Items
                                where myCode.Id.Equals( code.parentCode )
                                select myCode).Count();
                    if ( cont == 0 )
                    {
                        errorInUploading = true;
                        wrongRowsMessageForUser += string.Format(Resources.Messages.err_csv_import_parent_code_error, code.parentCode, code.code, code.code );
                        continue;
                    }
                }
                ICodeMutableObject tmpCode = cl.GetCodeById(code.code);
                if (tmpCode == null)
                {
                    tmpCode = new CodeMutableCore();
                    tmpCode.Id = code.code;
                    tmpCode.ParentCode = code.parentCode;
                    tmpCode.AddName(cmbLanguageForCsv.SelectedValue.ToString(), code.name);
                    tmpCode.AddDescription(cmbLanguageForCsv.SelectedValue.ToString(), code.description);
                    cl.AddItem(tmpCode);
                }
                else
                {
                    tmpCode.Id = code.code;
                    tmpCode.ParentCode = code.parentCode;
                    tmpCode.AddName(cmbLanguageForCsv.SelectedValue.ToString(), code.name);
                    tmpCode.AddDescription(cmbLanguageForCsv.SelectedValue.ToString(), code.description);
                }
            }

            if ( errorInUploading )
            {
                lblImportCsvErrors.Text = wrongRowsMessageForUser;
                lblImportCsvWrongLines.Text = wrongFileLines;
                Utils.AppendScript("openP('importCsvErrors',500);");
            }

            logWriter.Close();
            reader.Close();

            if (!SaveInMemory(cl)) return;

            BindData();
            if ( !errorInUploading )
            {
                Utils.ShowDialog( Resources.Messages.succ_operation );
            }
            Utils.AppendScript("location.href='#codes'");
        }
        public void TestBuildErrorResponse(SdmxSchemaEnumType version)
        {
            var responseBuilder = new SubmitStructureResponseBuilder();
            ISdmxObjects sdmxObjects = new SdmxObjectsImpl();
            var codelist = new CodelistMutableCore() { Id = "CL_TEST", Version = "1.0", AgencyId = "TEST"};
            codelist.AddName("en", "Test Codelist");
            for (int i = 0; i < 10; i++)
            {
                ICodeMutableObject item = new CodeMutableCore() { Id = "TEST_" + i.ToString(CultureInfo.InvariantCulture) };
                item.AddName("en", "Name for " + item.Id);
                codelist.AddItem(item);
            }
            
            sdmxObjects.AddCodelist(codelist.ImmutableInstance);
            const string ErrorMessage = "Invalid syntax";
            var output = responseBuilder.BuildErrorResponse(new SdmxSyntaxException(ErrorMessage), new StructureReferenceImpl("TEST", "CL_TEST", "1.0", SdmxStructureEnumType.CodeList), SdmxSchema.GetFromEnum(version));
            var fileName = "TestBuildErrorResponse" + version + ".xml";
            output.Untyped.Save(fileName);
            using (IReadableDataLocation dataLocation = new FileReadableDataLocation(fileName))
            {
                XMLParser.ValidateXml(dataLocation, version);
            }

            Assert.IsTrue(File.ReadAllText(fileName).Contains(ErrorMessage));
        }
        protected void btnUpdateCode_Click(object sender, EventArgs e)
        {
            // Get Input field
            string code_id = txt_id_update.Text.Trim();
            IList<ITextTypeWrapperMutableObject> code_names = AddTextName_update.TextObjectList;
            IList<ITextTypeWrapperMutableObject> code_descs = AddTextDescription_update.TextObjectList;
            string code_parent_id = txt_parentid_update.Text.Trim();
            string code_order_str = txt_order_update.Text.Trim();

            // Get Current Object Session
            ICodelistMutableObject cl = cl = GetCodeListFromSession();
            IEnumerable<ICodeMutableObject> _rc = (from x in cl.Items where x.Id == code_id select x).OfType<ICodeMutableObject>();
            if (_rc.Count() == 0) return;

            ICodeMutableObject code = _rc.First();

            ICodeMutableObject _bCode = new CodeMutableCore();

            int indexCode = cl.Items.IndexOf(code);
            int indexOrder=0;
            try
            {

                #region CODE ID
                if (!code_id.Equals(string.Empty) && ValidationUtils.CheckIdFormat(code_id))
                {
                    _bCode.Id = code_id;
                }
                else
                {
                    lblErrorOnUpdate.Text = Resources.Messages.err_id_format;
                    Utils.AppendScript( "openPopUp('df-Dimension-update', 600 );" );
                    Utils.AppendScript("location.href= '#codes';");
                    return;
                }
                #endregion

                #region CODE NAMES
                if (code_names != null)
                {
                    foreach (var tmpName in code_names)
                    {
                        _bCode.AddName(tmpName.Locale, tmpName.Value);
                    }
                }
                else
                {
                    lblErrorOnUpdate.Text = Resources.Messages.err_list_name_format;
                    Utils.AppendScript( "openPopUp('df-Dimension-update', 600 );" );
                    Utils.AppendScript("location.href= '#codes';");
                    return;
                }
                #endregion

                #region CODE DESCRIPTIONS
                if (code_descs != null)
                {
                    foreach (var tmpDescription in code_descs)
                    {
                        _bCode.AddDescription(tmpDescription.Locale, tmpDescription.Value);
                    }
                }
                #endregion

                #region PARANT ID

                if ( code_id.Equals( code_parent_id ) )
                {
                    lblErrorOnUpdate.Text = Resources.Messages.err_parent_id_same_value;
                    Utils.AppendScript( "openPopUp('df-Dimension-update', 600 );" );
                    Utils.AppendScript("location.href= '#codes';");
                    return;
                }

                if (!code_parent_id.Equals(string.Empty) && ValidationUtils.CheckIdFormat(code_id))
                {
                    IEnumerable<ICodeMutableObject> parentCode = (from c in cl.Items where c.Id == code_parent_id select c).OfType<ICodeMutableObject>();
                    if (parentCode.Count() > 0)
                        _bCode.ParentCode = code_parent_id;
                    else
                    {
                        lblErrorOnUpdate.Text = Resources.Messages.err_parent_id_not_found;
                        Utils.AppendScript( "openPopUp('df-Dimension-update', 600 );" );
                        Utils.AppendScript("location.href= '#codes';");
                        return;
                    }
                }
                #endregion

                #region CODE ORDER
                int tmpOrder = 0;
                if (!code_order_str.Equals(string.Empty) && !int.TryParse( code_order_str, out tmpOrder ) )
                {
                    lblErrorOnUpdate.Text = Resources.Messages.err_order_format_invalid;
                    Utils.AppendScript( "openPopUp('df-Dimension-update', 600);" );
                    Utils.AppendScript("location.href= '#codes';");
                    return;
                }
                else
                {
                    if ( tmpOrder < 0 )
                    {
                        lblErrorOnUpdate.Text = Resources.Messages.err_order_less_than_zero;
                        Utils.AppendScript( "openPopUp('df-Dimension-update', 600);" );
                        Utils.AppendScript("location.href= '#codes';");
                        return;
                    }
                }
                #endregion
            #region ANNOTATIONS

                foreach ( IAnnotationMutableObject annotation in cl.Items.ElementAt(indexCode).Annotations )
                {
                    _bCode.AddAnnotation( annotation );
                }

            #endregion
                if (!int.TryParse(code_order_str, out indexOrder))
                    indexOrder = cl.Items.Count + 1;
                else { indexOrder--; }
                if (indexOrder < 0
                    || indexOrder >= cl.Items.Count) indexOrder = cl.Items.Count - 1;

                cl.Items.RemoveAt(indexCode);
                cl.Items.Insert(indexOrder, _bCode);

                // Ultimo controllo se ottengo Immutable istanze validazione completa
                var canRead = cl.ImmutableInstance;

            }
            catch (Exception ex)
            {
                cl.Items.RemoveAt(indexOrder);
                cl.Items.Insert(indexCode, code);
                if ( ex.Message.Contains( "- 706 -" ) )
                {
                    lblErrorOnUpdate.Text = Resources.Messages.err_parent_item_is_child;
                    Utils.AppendScript( "openPopUp('df-Dimension-update', 600);" );
                 }
                else
                {
                    lblErrorOnUpdate.Text = Resources.Messages.err_code_update;
                    Utils.AppendScript( "openPopUp('df-Dimension-update', 600);" );
                }
                Utils.AppendScript("location.href='#codes';");
                return;
            }

            if (!SaveInMemory(cl))
                return;

            BindData();
            Utils.AppendScript("location.href='#codes';");
        }
        public void TestWriteReadBigCodeListV21(int count)
        {
            string countStr = count.ToString(CultureInfo.InvariantCulture);
            ICodelistMutableObject codelist = new CodelistMutableCore();
            codelist.Id = "CL_K" + countStr;
            codelist.AgencyId = "TEST";
            codelist.AddName("en", "Test CL with " + countStr);
            for (int i = 0; i < count; i++)
            {
                ICodeMutableObject code = new CodeMutableCore();
                code.Id = i.ToString(CultureInfo.InvariantCulture);
                code.AddName("en", "Code " + code.Id);
                codelist.AddItem(code);
            }

            var sw = new Stopwatch();
            string output = string.Format(CultureInfo.InvariantCulture, "big-2.1-immutable-codelist-{0}.xml", countStr);
            var writingManager = new StructureWriterManager();
            sw.Start();
            ICodelistObject immutableInstance = codelist.ImmutableInstance;
            Trace.WriteLine(string.Format(CultureInfo.InvariantCulture, "To immutable {0} took {1}", countStr, sw.Elapsed));
            CollectionAssert.IsNotEmpty(immutableInstance.Items);
            sw.Restart();
            using (FileStream writer = File.Create(output))
            {
                writingManager.WriteStructure(immutableInstance, new HeaderImpl("ZZ9", "ZZ9"), new SdmxStructureFormat(StructureOutputFormat.GetFromEnum(StructureOutputFormatEnumType.SdmxV21StructureDocument)), writer);
            }

            sw.Stop();
            Trace.WriteLine(string.Format(CultureInfo.InvariantCulture, "Writing {0} took {1}", countStr, sw.Elapsed));

            sw.Reset();
            IStructureParsingManager parsingManager = new StructureParsingManager(SdmxSchemaEnumType.VersionTwoPointOne);
            sw.Start();
            using (IReadableDataLocation fileReadableDataLocation = new FileReadableDataLocation(output))
            {
                IStructureWorkspace structureWorkspace = parsingManager.ParseStructures(fileReadableDataLocation);
                Assert.NotNull(structureWorkspace);
                ISdmxObjects structureBeans = structureWorkspace.GetStructureObjects(false);
                Assert.NotNull(structureBeans);
            }

            sw.Stop();
            Trace.WriteLine(string.Format(CultureInfo.InvariantCulture, "Reading {0} took {1}", countStr, sw.Elapsed));
        }