Пример #1
0
        ///////////////////////////////////////////////////////////////////////////////////////////////////
        ////////////BUILD FROM MUTABLE OBJECTS             //////////////////////////////////////////////////
        ///////////////////////////////////////////////////////////////////////////////////////////////////
        #region Constructors and Destructors

        /// <summary>
        /// Initializes a new instance of the <see cref="CategoryCore"/> class.
        /// </summary>
        /// <param name="parent">
        /// The parent. 
        /// </param>
        /// <param name="itemMutableObject">
        /// The sdmxObject. 
        /// </param>
        public CategoryCore(IIdentifiableObject parent, ICategoryMutableObject itemMutableObject)
            : base(itemMutableObject, parent)
        {
            this._categories = new List<ICategoryObject>();
            if (itemMutableObject.Items != null)
            {
                foreach (ICategoryMutableObject currentCat in itemMutableObject.Items)
                {
                    this._categories.Add(new CategoryCore(this, currentCat));
                }
            }
        }
Пример #2
0
        private void AddRecursiveChilds(ICategoryMutableObject cat, DataTable dtCatNames, DataTable dtCS, string idCat)
        {
            string filter = " IDParent = " + idCat;

            DataRow[] dRows = dtCS.Select(filter);

            ICategoryMutableObject catChild;

            foreach (DataRow row in dRows)
            {
                catChild    = new CategoryMutableCore();
                catChild.Id = row["CatCode"].ToString();

                SetNames(dtCatNames.Select("IDCat = " + row["IDCat"].ToString()), catChild);

                AddRecursiveChilds(catChild, dtCatNames, dtCS, row["IDCat"].ToString());

                cat.Items.Add(catChild);
            }
        }
 /// <summary>
 /// Handles the Category element child elements
 /// </summary>
 /// <param name="parent">
 /// The parent category of this category element
 /// </param>
 /// <param name="localName">
 /// The name of the current xml element
 /// </param>
 /// <returns>
 /// The <see cref="StructureReaderBaseV20.ElementActions"/>.
 /// </returns>
 private ElementActions HandleChildElements(ICategoryMutableObject parent, object localName)
 {
     ElementActions actions = null;
     if (NameTableCache.IsElement(localName, ElementNameTable.Category))
     {
         ICategoryMutableObject category = HandleCategory(this.Attributes);
         parent.AddItem(category);
         actions = this.AddNameableAction(category, this.HandleChildElements);
     }
     else if (NameTableCache.IsElement(localName, ElementNameTable.DataflowRef))
     {
         IReferenceInfo reference = new ReferenceInfo(SdmxStructureEnumType.Dataflow) { ReferenceFrom = parent };
         this._currentDataflowReference = reference;
         actions = this.AddSimpleAction(reference, this.HandleTextChildElement);
     }
     
     return actions;
 }
Пример #4
0
 /// <summary>
 /// The add item.
 /// </summary>
 /// <param name="item">
 /// The item. 
 /// </param>
 public void AddItem(ICategoryMutableObject item)
 {
     this._categories.Add(item);
 }
        /// <summary>
        /// Traverse the category hierarchy tree and write each category starting from
        ///     the given ICategoryMutableObject object.
        /// </summary>
        /// <param name="item">
        /// The root ICategoryMutableObject object
        /// </param>
        /// <param name="categorisationMap">
        /// The categorisation map
        /// </param>
        private void TraverseCategoryTree(
            ICategoryMutableObject item, IDictionary<string, IList<ICategorisationMutableObject>> categorisationMap)
        {
            var parents = new Stack<ICategoryMutableObject>();
            var open = new Dictionary<ICategoryMutableObject, Queue<ICategoryMutableObject>>();
            this.WriteCategory(item, categorisationMap);

            parents.Push(item);
            open.Add(item, new Queue<ICategoryMutableObject>(item.Items));
            while (parents.Count > 0)
            {
                ICategoryMutableObject parent = parents.Peek();
                Queue<ICategoryMutableObject> remainingCategories = open[parent];
                while (remainingCategories.Count > 0)
                {
                    ICategoryMutableObject current = remainingCategories.Dequeue();
                    this.WriteCategory(current, categorisationMap);
                    parents.Push(current);
                    remainingCategories = new Queue<ICategoryMutableObject>(current.Items);
                    open.Add(current, remainingCategories);

                    // parent = parents.Peek();
                }

                parent = parents.Pop();
                this.WriteAnnotations(ElementNameTable.Annotations, parent.Annotations);
                this.WriteEndElement();
            }
        }