StringDictionaryItem[] VisitStringDictionary(StringDictionaryItem[] stringDictionary)
        {
            StringDictionaryItem[] result = null;

            if (stringDictionary != null)
            {
                SortedDictionary<string, StringDictionaryItem> sortedItems = new SortedDictionary<string, StringDictionaryItem>();

                foreach (StringDictionaryItem dictionaryItem in stringDictionary)
                    sortedItems.Add(dictionaryItem.id, dictionaryItem);

                result = new StringDictionaryItem[sortedItems.Count];
                sortedItems.Values.CopyTo(result, 0);
            }

            return result;
        }
        void SetArchetypeDigest()
        {
            System.Diagnostics.Debug.Assert(_archetype != null, "archetype must not be null");
            System.Diagnostics.Debug.Assert(_archetype.description != null, "archetype description must not be null");

            XMLParser.ARCHETYPE canonicalArchetype = ArchetypeModelBuilder.CanonicalArchetype(_archetype);

            string archetypDigest = ArchetypeModelBuilder.ArchetypeDigest(canonicalArchetype);

            Dictionary<string, StringDictionaryItem> otherDetails = new Dictionary<string, StringDictionaryItem>();
            if (_archetype.description.other_details != null)
            {
                foreach (StringDictionaryItem item in _archetype.description.other_details)
                    otherDetails.Add(item.id, item);
            }
            if (!otherDetails.ContainsKey(ArchetypeModelBuilder.ARCHETYPE_DIGEST_ID))
            {
                StringDictionaryItem item = new StringDictionaryItem();
                item.id = ArchetypeModelBuilder.ARCHETYPE_DIGEST_ID;
                item.Value = archetypDigest;

                otherDetails.Add(ArchetypeModelBuilder.ARCHETYPE_DIGEST_ID, item);
            }
            else
            {
                StringDictionaryItem item = otherDetails[ArchetypeModelBuilder.ARCHETYPE_DIGEST_ID];
                item.Value = archetypDigest;
            }

            StringDictionaryItem[] sortedResult = new StringDictionaryItem[otherDetails.Count];
            otherDetails.Values.CopyTo(sortedResult, 0);

            _archetype.description.other_details = sortedResult;
        }
        protected virtual StringDictionaryItem[] CloneHashTableAny(EiffelStructures.table.HASH_TABLE_REFERENCE_REFERENCE o)
        {
            StringDictionaryItem[] result = null;

            if (o != null && o.count() > 0)
            {
                SortedList<string, StringDictionaryItem> dictionaryItem = new SortedList<string, StringDictionaryItem>();
                o.start();

                while (!o.off())
                {
                    StringDictionaryItem item = new StringDictionaryItem();
                    item.id = o.key_for_iteration().ToString();
                    item.Value = o.item_for_iteration().ToString();
                    dictionaryItem.Add(item.id, item);
                    o.forth();
                }

                result = new StringDictionaryItem[dictionaryItem.Count];
                dictionaryItem.Values.CopyTo(result, 0);
            }

            return result;
        }
Example #4
0
        public void AddLanguage(string language)
        {
            if (!string.IsNullOrEmpty(language) && !_languages_available.Contains(language))
            {
                _languages_available.Add(language);

                if (_languages_available.Count > 1)
                {
                    //populate a translation set from the original language
                    CodeDefinitionSet ls = TermDefinitions(_archetype.original_language.code_string);
                    CodeDefinitionSet new_ls = GetTermLanguageSet(language);
                    ARCHETYPE_TERM[] new_terms = Array.CreateInstance(typeof(ARCHETYPE_TERM), ls.items.Length) as ARCHETYPE_TERM[];

                    for(int i = 0; i < ls.items.Length; i++)
                    {
                        ARCHETYPE_TERM at = ls.items[i];
                        ARCHETYPE_TERM new_at = new ARCHETYPE_TERM();
                        new_at.code = at.code;
                        StringDictionaryItem[] new_items = Array.CreateInstance(typeof(StringDictionaryItem), at.items.Length) as StringDictionaryItem[];

                        for (int j = 0; j < at.items.Length; j++)
                        {
                            StringDictionaryItem di = at.items[j];
                            StringDictionaryItem new_di = new StringDictionaryItem();
                            new_di.id = di.id;
                            new_di.Value = string.Format("{0}{1}({2})", "*", di.Value, _archetype.original_language.code_string);
                            new_items[j] = new_di;
                        }

                        new_at.items = new_items;
                        new_terms[i] = new_at;
                    }

                    new_ls.items = new_terms;

                    //now get a translation set for constraint definitions
                    ls = ConstraintDefinitions(_archetype.original_language.code_string);

                    if (ls != null)  //May not be any Constraint definitions
                    {
                        new_ls = GetConstraintLanguageSet(language);
                        new_terms = Array.CreateInstance(typeof(ARCHETYPE_TERM), ls.items.Length) as ARCHETYPE_TERM[];

                        for (int i = 0; i < ls.items.Length; i++)
                        {
                            ARCHETYPE_TERM ac = ls.items[i];
                            ARCHETYPE_TERM new_ac = new ARCHETYPE_TERM();
                            new_ac.code = ac.code;
                            StringDictionaryItem[] new_items = Array.CreateInstance(typeof(StringDictionaryItem), ac.items.Length) as StringDictionaryItem[];

                            for (int j = 0; j < ac.items.Length; j++)
                            {
                                StringDictionaryItem di = ac.items[j];
                                StringDictionaryItem new_di = new StringDictionaryItem();
                                new_di.id = di.id;
                                new_di.Value = string.Format("{0}{1}({2})", "*", di.Value, _archetype.original_language.code_string);
                                new_items[j] = new_di;
                            }

                            new_ac.items = new_items;
                            new_terms[i] = new_ac;
                        }

                        new_ls.items = new_terms;
                    }
                }

                //populate a new description by raising an event
                LanguageAdded(this, language, _archetype.original_language.terminology_id.value);                
            }
        }