Ejemplo n.º 1
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);
        }
        /// <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;
 }
        /// <summary>
        /// Handles the Structure top level elements
        ///     This includes Codelist
        /// </summary>
        /// <param name="parent">
        /// The parent <see cref="IMutableObjects"/>
        /// </param>
        /// <param name="localName">
        /// The name of the current xml element
        /// </param>
        /// <returns>
        /// The <see cref="StructureReaderBaseV20.ElementActions"/>.
        /// </returns>
        protected override ElementActions HandleTopLevel(IMutableObjects parent, object localName)
        {
            ElementActions actions = null;
            if (NameTableCache.IsElement(localName, ElementNameTable.CodeList))
            {
                ICodelistMutableObject codelist = new CodelistMutableCore();
                ParseAttributes(codelist, this.Attributes);
                parent.AddCodelist(codelist);
                actions = this.AddNameableAction(codelist, this.HandleChildElements);
            }

            return actions;
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Builds the country codelist.
        /// </summary>
        /// <returns>
        /// The <see cref="ICodelistObject" />.
        /// </returns>
        public ICodelistObject BuildCountryCodelist()
        {
            ICodelistMutableObject codelistMutable = new CodelistMutableCore();
            codelistMutable.AgencyId = "SDMXSOURCE";
            codelistMutable.Id = "CL_COUNTRY";
            codelistMutable.Version = "1.0";
            codelistMutable.AddName("en", "Country");

            codelistMutable.CreateItem("UK", "United Kingdom");
            codelistMutable.CreateItem("FR", "France");
            codelistMutable.CreateItem("DE", "Germany");

            return codelistMutable.ImmutableInstance;
        }
        /// <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 static ICodelistMutableObject BuildMutable(int size)
        {
            var codelist = new CodelistMutableCore() { Id = "TEST", AgencyId = "TEST_AGENCY", Version = "1.0" };
            codelist.AddName("en", "Test name");
            string lastCode = null;
            for (int i = 0; i < size; i++)
            {
                string codeId = string.Format(CultureInfo.InvariantCulture, "ID{0}", i);
                var code = codelist.CreateItem(codeId, codeId);
                if (lastCode != null && (i % 2) == 0)
                {
                    code.ParentCode = lastCode;
                }

                if ((i % 6) == 0)
                {
                    lastCode = codeId;
                }
            }

            return codelist;
        }
 /// <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;
 }
Ejemplo n.º 10
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;
        }
Ejemplo n.º 11
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>
        /// Create a ImmutableInstance of Codelist
        /// </summary>
        /// <param name="AgencyId">Agency Id</param>
        /// <param name="Version">Artefact Version</param>
        /// <returns>ICodelistObject</returns>
        public ICodelistMutableObject BuildCodelist(string AgencyId, string Version)
        {
            try
            {
                ICodelistMutableObject codelist = new CodelistMutableCore();
                codelist.Id       = this.Code;
                codelist.AgencyId = AgencyId;
                codelist.Version  = Version;
                if (this.Names == null)
                {
                    this.Names = new List <SdmxObjectNameDescription>();
                    this.Names.Add(new SdmxObjectNameDescription()
                    {
                        Lingua = "en", Name = Code
                    });
                }
                else
                {
                    foreach (SdmxObjectNameDescription item in this.Names)
                    {
                        codelist.AddName(item.Lingua, item.Name);
                    }
                }



                if (!this.ParsingObject.ReturnStub)
                {
                    Dictionary <string, int> Idduples = new Dictionary <string, int>();
                    //List<string> Idduples = new List<string>();
                    //try
                    //{//ci sono i duplicati ID sotto padri diversi e SDMX scoppia....
                    //    if (CodesObjects != null)
                    //        Idduples = (from c in CodesObjects
                    //                    where CodesObjects.Count(comp => comp.Id == c.Id) > 1
                    //                    select c.Id).Distinct().ToList();
                    //}
                    //catch (Exception)
                    //{
                    //    //Errore nella ricerca dei duplicati ma non fa niente
                    //}
                    foreach (ICodeMutableObject cl in CodesObjects)
                    {
                        if (!Idduples.ContainsKey(cl.Id))
                        {
                            Idduples[cl.Id] = 1;
                        }
                        else
                        {
                            Idduples[cl.Id]++;
                        }

                        if (Idduples[cl.Id] == 1)// && codelist.Items.Count(presentCode => presentCode.Id == cl.Id) == 0)
                        {
                            codelist.AddItem(cl);
                        }
                    }

                    codelist.FinalStructure = TertiaryBool.ParseBoolean(true);
                    codelist.IsPartial      = true;
                }


                if (this.ParsingObject.isReferenceOf || this.ParsingObject.ReturnStub)
                {
                    codelist.ExternalReference = TertiaryBool.ParseBoolean(true);
                    codelist.StructureURL      = RetreivalStructureUrl.Get(this, codelist.Id, codelist.AgencyId, codelist.Version);
                }
                return(codelist);
            }
            catch (SdmxException) { throw; }
            catch (Exception ex)
            {
                throw new SdmxException(this, FlyExceptionObject.FlyExceptionTypeEnum.CreateImmutable, ex);
            }
        }
        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);
        }
        /// <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 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));
        }
        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));
        }
Ejemplo n.º 17
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;
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            _localizedUtils = new LocalizedUtils(Utils.LocalizedCulture);
            _epe = (EndPointElement)Session[SESSION_KEYS.CURRENT_ENDPOINT_OBJECT];

            CSVImporter1.OperationComplete += CSVImporter1_OperationComplete;

            SetAction();

            if (!IsPostBack)
            {
                if (!_epe.PartialArtefact)
                {
                    Utils.PopulateCmbAgencies(cmb_agencies, true);
                    //Utils.PopulateCmbLanguages(cmbLanguageForCsv, AVAILABLE_MODES.MODE_FOR_ADD_TEXT);
                }

                ClearSessionPage();
                ViewState["SortExpr"] = SortDirection.Ascending;
                txtNumberOfRows.Text = Utils.DetailsCodelistGridNumberRow.ToString();
            }

            ICodelistMutableObject cl;

            switch (_action)
            {
                case Action.INSERT:

                    //ClearSessionPage();
                    AspConfirmationExit = "true";

                    SetInitControls();
                    SetInsertForm();

                    lblNumberOfRows.Visible = false;
                    txtNumberOfRows.Visible = false;
                    btnChangePaging.Visible = false;

                    chk_isFinal.Checked = false;
                    chk_isFinal.Enabled = false;

                    AddTextName_update.ucOpenTabName = "codes";
                    AddTextName_update.ucOpenPopUpWidth = 600;
                    AddTextName_update.ucOpenPopUpName = "df-Dimension-update";

                    AddTextDescription_update.ucOpenTabName = "codes";
                    AddTextDescription_update.ucOpenPopUpWidth = 600;
                    AddTextDescription_update.ucOpenPopUpName = "df-Dimension-update";

                    AddTextName_new.ucOpenTabName = "codes";
                    AddTextName_new.ucOpenPopUpWidth = 600;
                    AddTextName_new.ucOpenPopUpName = "df-Dimension";

                    AddTextDescription_new.ucOpenTabName = "codes";
                    AddTextDescription_new.ucOpenPopUpWidth = 600;
                    AddTextDescription_new.ucOpenPopUpName = "df-Dimension";

                    if (!Page.IsPostBack)
                    {
                        cmb_agencies.Items.Insert(0, new ListItem(String.Empty, String.Empty));
                        cmb_agencies.SelectedIndex = 0;

                        FileDownload31.Visible = false;
                    }

                    cl = GetCodeListFromSession();
                    if (cl == null) cl = GetCodelistForm(true);
                    else cl = GetCodelistForm(cl);

                    if (cl == null)
                    {
                        cl = new CodelistMutableCore();
                        cl.Id = "@fitt@";
                        cl.AgencyId = "@fitt@";
                        cl.Version = "1.0";
                        cl.AddName("it", "@fitt@");

                    }

                    CSVImporter1.ucCodelist = cl;

                    break;
                case Action.UPDATE:

                    _artIdentity = Utils.GetIdentityFromRequest(Request);

                    SetInitControls();
                    SetEditForm();

                    AddTextName_update.ucOpenTabName = "codes";
                    AddTextName_update.ucOpenPopUpWidth = 600;
                    AddTextName_update.ucOpenPopUpName = "df-Dimension-update";

                    AddTextDescription_update.ucOpenTabName = "codes";
                    AddTextDescription_update.ucOpenPopUpWidth = 600;
                    AddTextDescription_update.ucOpenPopUpName = "df-Dimension-update";

                    AddTextName_new.ucOpenTabName = "codes";
                    AddTextName_new.ucOpenPopUpWidth = 600;
                    AddTextName_new.ucOpenPopUpName = "df-Dimension";

                    AddTextDescription_new.ucOpenTabName = "codes";
                    AddTextDescription_new.ucOpenPopUpWidth = 600;
                    AddTextDescription_new.ucOpenPopUpName = "df-Dimension";

                    Categorisations.ucArtefactType = AvailableStructures.CODELIST;
                    Categorisations.ucArtIdentity = _artIdentity;

                    // NEW
                    bool b = (bool)_artIdentity.IsFinal;

                    cl = GetCodeListFromSession();
                    if (cl == null) cl = GetCodelistForm(b);
                    else cl = GetCodelistForm(cl,b);
                    CSVImporter1.ucCodelist = cl;

                    /*if (gvCodelistsItem.Rows.Count > 0 )
                    {
                        chk_isFinal.Enabled = true;
                    }
                    else
                    {
                        chk_isFinal.Enabled = false;
                    }*/
                    break;
                case Action.VIEW:

                    _artIdentity = Utils.GetIdentityFromRequest(Request);
                    ClearSessionPage();
                    SetViewForm();

                    AddTextName_update.ucOpenTabName = "codes";
                    AddTextName_update.ucOpenPopUpWidth = 600;
                    AddTextName_update.ucOpenPopUpName = "df-Dimension-update";

                    AddTextDescription_update.ucOpenTabName = "codes";
                    AddTextDescription_update.ucOpenPopUpWidth = 600;
                    AddTextDescription_update.ucOpenPopUpName = "df-Dimension-update";

                    AddTextName_new.ucOpenTabName = "codes";
                    AddTextName_new.ucOpenPopUpWidth = 600;
                    AddTextName_new.ucOpenPopUpName = "df-Dimension";

                    AddTextDescription_new.ucOpenTabName = "codes";
                    AddTextDescription_new.ucOpenPopUpWidth = 600;
                    AddTextDescription_new.ucOpenPopUpName = "df-Dimension";

                    FileDownload31.ucID = _artIdentity.ID;
                    FileDownload31.ucAgency = _artIdentity.Agency;
                    FileDownload31.ucVersion = _artIdentity.Version;
                    FileDownload31.ucArtefactType = "CodeList";

                    Categorisations.ucArtefactType = AvailableStructures.CODELIST;
                    Categorisations.ucArtIdentity = _artIdentity;

                    break;
            }

            if (!_epe.PartialArtefact)
            {
                DuplicateArtefact1.ucStructureType = SdmxStructureEnumType.CodeList;
                DuplicateArtefact1.ucMaintanableArtefact = GetCodeListFromSession();
            }
            else
                DuplicateArtefact1.ucDisable = true;

            lbl_id.DataBind();
            lbl_agency.DataBind();
            lbl_version.DataBind();
            lbl_isFinal.DataBind();
            lbl_uri.DataBind();
            lbl_urn.DataBind();
            lbl_valid_from.DataBind();
            lbl_valid_to.DataBind();
            lbl_name.DataBind();
            lbl_description.DataBind();
            lbl_annotation.DataBind();
            btnChangePaging.DataBind();
            //lblImportCsvTitle.DataBind();
            //lblCsvLanguage.DataBind();
            //lblcsvFile.DataBind();
            lblNoItemsPresent.DataBind();
            lbl_title_popup_code.DataBind();

            lbl_id_update.DataBind();
            lbl_order_update.DataBind();
            lbl_parentid_update.DataBind();
            lbl_description_update.DataBind();
            lbl_name_update.DataBind();
            lbl_title_update.DataBind();
            lbl_id_new.DataBind();
            lbl_order_new.DataBind();
            lbl_parentid_new.DataBind();
            lbl_description_new.DataBind();
            lbl_name_new.DataBind();
            btnClearFields.DataBind();
            btnClearFieldForUpdate.DataBind();
            //imgImportCsv.DataBind();
            btnAddNewCode.DataBind();
            btnSaveMemoryCodeList.DataBind();
            //btnImportFromCsv.DataBind();
            btnSaveAnnotationCode.DataBind();
            btnUpdateCode.DataBind();
            btnNewCode.DataBind();
            lblNumberOfRows.DataBind();
            //lblSeparator.DataBind();
            btnNewCodeOnFinalStructure.DataBind();
            lblYouAreWorkingOnAFinal.DataBind();
        }
Ejemplo n.º 19
0
        private ICodelistObject GetTimeCodeList(ICodelistObject FreqCodelist)
        {
            ICodelistObject CL_TIME_MA = FreqCodelist;// GetCodeListCostraint(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*/

            //DA FARE
            //string FrequencyDominant = "A";
            string          FrequencyDominant = null;
            ICodelistObject codelistFreq      = this._codelistCache.GetArtefact(_keyFamily.FrequencyDimension);


            if (codelistFreq != null)
            {
                FrequencyDominant = codelistFreq.Items.First().Id;
            }
            //FrequencyDominant = this._codelistCache[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);

            /*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>
        /// The build indicator codelist.
        /// </summary>
        /// <returns>
        /// The <see cref="ICodelistObject"/>.
        /// </returns>
        public ICodelistObject BuildIndicatorCodelist()
        {
            ICodelistMutableObject codelistMutable = new CodelistMutableCore();
            codelistMutable.AgencyId = "SDMXSOURCE";
            codelistMutable.Id = "CL_INDICATOR";
            codelistMutable.Version = "1.0";
            codelistMutable.AddName("en", "World Developement Indicators");

            ICodeMutableObject code;
            codelistMutable.CreateItem("E", "Environment");
            code = codelistMutable.CreateItem("E_A", "Agriculture land");
            code.ParentCode = "E";
            code = codelistMutable.CreateItem("E_P", "Population");
            code.ParentCode = "E";

            codelistMutable.CreateItem("H", "HEALTH");
            code = codelistMutable.CreateItem("H_B", "Birth Rate");
            code.ParentCode = "H";
            code = codelistMutable.CreateItem("H_C", "Children (0-14) living with HIV");
            code.ParentCode = "H";

            return codelistMutable.ImmutableInstance;
        }
        private ICodelistMutableObject GetCodelistForm()
        {
            bool isInError = false;                 // Indicatore di errore
            string messagesGroup = string.Empty;    // Stringa di raggruppamento errori
            int errorCounter = 1;                   // Contatore errori

            #region CODELIST ID
            if (!ValidationUtils.CheckIdFormat(txt_id.Text.Trim()))
            {
                messagesGroup += Convert.ToString(errorCounter) + ") "+Resources.Messages.err_id_format+"<br /><br />";
                errorCounter++;
                isInError = true;
            }
            #endregion

            #region CODELIST AGENCY
            if ( cmb_agencies.Text.Trim().Equals( string.Empty ) )
            {
                messagesGroup += Convert.ToString(errorCounter) + ") " + Resources.Messages.err_agency_missing + "<br /><br />";
                errorCounter++;
                isInError = true;
            }
            #endregion

            #region CODELIST VERSION
            if (!ValidationUtils.CheckVersionFormat(txt_version.Text.Trim()))
            {
                messagesGroup += Convert.ToString(errorCounter) + ") " + Resources.Messages.err_version_format + "<br /><br />";
                errorCounter++;
                isInError = true;
            }
            #endregion

            /* URI NOT REQUIRED */
            #region CODELLIST URI
            if ((txt_uri.Text != string.Empty) && !ValidationUtils.CheckUriFormat(txt_uri.Text))
            {
                messagesGroup += Convert.ToString(errorCounter) + ") " + Resources.Messages.err_uri_format + "<br /><br />";
                errorCounter++;
                isInError = true;
            }
            #endregion

            #region CODELIST NAMES
            if (AddTextName.TextObjectList == null || AddTextName.TextObjectList.Count == 0)
            {
                messagesGroup += Convert.ToString(errorCounter) + ") " + Resources.Messages.err_list_name_format + "<br /><br />";
                errorCounter++;
                isInError = true;
            }
            #endregion

            #region CODELIST START END DATE
            bool checkForDatesCombination = true;

            if (!txt_valid_from.Text.Trim().Equals(string.Empty) && !ValidationUtils.CheckDateFormat(txt_valid_from.Text))
            {
                messagesGroup += Convert.ToString(errorCounter) + ") " + Resources.Messages.err_date_from_format + "<br /><br />";
                errorCounter++;
                checkForDatesCombination = false;
                isInError = true;
            }

            if (!txt_valid_to.Text.Trim().Equals(string.Empty) && !ValidationUtils.CheckDateFormat(txt_valid_to.Text))
            {
                messagesGroup += Convert.ToString(errorCounter) + ") " + Resources.Messages.err_date_to_format + "<br /><br />";
                errorCounter++;
                checkForDatesCombination = false;
                isInError = true;
            }

            if (!txt_valid_from.Text.Trim().Equals(string.Empty) && !txt_valid_to.Text.Trim().Equals(string.Empty))
            {
                // Controllo congruenza date
                if (checkForDatesCombination)
                {
                    if (!ValidationUtils.CheckDates(txt_valid_from.Text, txt_valid_to.Text))
                    {
                        messagesGroup += Convert.ToString(errorCounter) + ") " + Resources.Messages.err_date_diff + "<br /><br />";
                        errorCounter++;
                        isInError = true;
                    }
                }
            }
            #endregion

            if (isInError)
            {
                Utils.ShowDialog(messagesGroup, 300);
                return null;
            }

            ICodelistMutableObject tmpCodelist = new CodelistMutableCore();

            #region CREATE CODELIST FROM FORM

            tmpCodelist.AgencyId = GetAgencyValue();
            tmpCodelist.Id = txt_id.Text;
            tmpCodelist.Version = txt_version.Text;
            tmpCodelist.FinalStructure = TertiaryBool.ParseBoolean(chk_isFinal.Checked);
            tmpCodelist.Uri = (!txt_uri.Text.Trim().Equals( string.Empty ) && ValidationUtils.CheckUriFormat(txt_uri.Text)) ? new Uri(txt_uri.Text) : null;
            if (!txt_valid_from.Text.Trim().Equals(string.Empty))
            {
                tmpCodelist.StartDate = DateTime.ParseExact(txt_valid_from.Text, "dd/MM/yyyy", CultureInfo.InvariantCulture);
            }
            if (!txt_valid_to.Text.Trim().Equals(string.Empty))
            {
                tmpCodelist.EndDate = DateTime.ParseExact(txt_valid_to.Text, "dd/MM/yyyy", CultureInfo.InvariantCulture);
            }
            foreach (var tmpName in AddTextName.TextObjectList)
            {
                tmpCodelist.AddName(tmpName.Locale, tmpName.Value);
            }
            if (AddTextDescription.TextObjectList != null)
                foreach (var tmpDescription in AddTextDescription.TextObjectList)
                {
                    tmpCodelist.AddDescription(tmpDescription.Locale, tmpDescription.Value);
                }
            if (AnnotationGeneralControl.AnnotationObjectList != null)
                foreach (var annotation in AnnotationGeneralControl.AnnotationObjectList)
                {
                    tmpCodelist.AddAnnotation(annotation);
                }
            #endregion

            return tmpCodelist;
        }
        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));
        }