Esempio n. 1
0
        /// <summary>
        /// Set any new label for a metacolumn
        /// </summary>
        /// <param name="mc"></param>

        public static void SetAnyNewMetaColumnLabel(
            MetaColumn mc)
        {
            string       name    = mc.MetaTable.Name + "." + mc.Name;
            DictionaryMx newDict = DictionaryMx.Get("NewNameDict");

            if (newDict == null)
            {
                return;
            }
            string newLabel = newDict.LookupDefinition(name);

            if (newLabel == null)
            {
                return;
            }

            DictionaryMx originalDict = DictionaryMx.Get("OriginalNameDict");

            if (originalDict == null)
            {
                return;
            }
            originalDict.Add(mc.MetaTable.Name + "." + mc.Name, mc.Label);             // save original label

            mc.Label = newLabel;
            mc.Units = "";             // prevent addition of units
        }
Esempio n. 2
0
        /// <summary>
        /// Assign any new label for metatable
        /// </summary>
        /// <param name="mt"></param>

        public static void SetAnyNewMetaTableLabel(
            MetaTable mt)
        {
            DictionaryMx newDict = DictionaryMx.Get("NewNameDict");

            if (newDict == null)
            {
                return;
            }
            string newLabel = newDict.LookupDefinition(mt.Name);

            if (newLabel == null)
            {
                return;
            }

            DictionaryMx originalDict = DictionaryMx.Get("OriginalNameDict");

            if (originalDict == null)
            {
                return;
            }
            originalDict.Add(mt.Name, mt.Label);             // save original label
            mt.Label = newLabel;
        }
Esempio n. 3
0
        /// <summary>
        /// Read dictionary from Oracle table
        /// </summary>
        /// <param name="dict"></param>
        /// <returns></returns>

        static DictionaryMx ReadDictionaryFromOracle(
            DictionaryMx dict)
        {
            DbCommandMx drd = null;
            int         t0, t1, i1;

            try
            {
                //if (Lex.Eq(dict.Name, "DIT_PERSON")) dict = dict; // debug
                DbDataReader dr = null;

                drd = new DbCommandMx();
                drd.Prepare(dict.Sql);
                dr = drd.ExecuteReader();

                t0 = TimeOfDay.Milliseconds();
                while (drd.Read())
                {
                    if (!dr.IsDBNull(0))
                    {
                        string word = dr.GetValue(0).ToString();
                        if (Lex.IsNullOrEmpty(word))
                        {
                            continue;
                        }
                        string definition = null;
                        if (!dr.IsDBNull(1))
                        {
                            definition = dr.GetValue(1).ToString();
                        }
                        dict.Add(word, definition);
                        t1 = TimeOfDay.Milliseconds();
                        //						if (t1-t0 > 2000) break; // limit time for development
                    }
                }
                drd.CloseReader();
                drd.Dispose();

                t1 = TimeOfDay.Milliseconds() - t0;

                //				DebugLog.Message("ReadDictionaryFromOracle " + dict.Name + " Time: " + t1.ToString());
                return(dict);
            }
            catch (Exception ex)
            {
                if (drd != null)
                {
                    drd.Dispose();
                }
                return(null);
            }
        }
Esempio n. 4
0
        static bool ReadDictionaryFromCacheFile(
            string fileName,
            DictionaryMx dict)
        {
            StreamReader sr = null;
            string       rec, word, definition;

            string[] sa;

            try
            {
                sr = new StreamReader(fileName);
                while (true)
                {
                    rec = sr.ReadLine();
                    if (rec == null)
                    {
                        break;
                    }
                    sa = rec.Split('\t');
                    if (sa.Length != 2)
                    {
                        continue;
                    }

                    word = sa[0];
                    if (Lex.IsNullOrEmpty(word))
                    {
                        continue;
                    }

                    definition = sa[1];
                    dict.Add(word, definition);
                }

                sr.Close();

                return(true);
            }

            catch (Exception ex)
            {
                try { sr.Close(); } catch { }
                DebugLog.Message(ex.Message);
                return(false);
            }
        }
Esempio n. 5
0
        /// <summary>
        /// Load metadata describing dictionaries
        /// </summary>
        /// <param name="dictFileName"></param>
        /// <returns></returns>

        public Dictionary <string, DictionaryMx> LoadDictionaries()
        {
            XmlAttributeCollection atts;

            Dictionaries = new Dictionary <string, DictionaryMx>();

            //UalUtil is assumed to have been initialized
            // and UalUtil.MetaDataDir set
            string       dictFileName = ServicesDirs.MetaDataDir + @"\" + "Dictionaries.xml";
            StreamReader sr           = new StreamReader(dictFileName);
            XmlDocument  doc          = new XmlDocument();

            doc.Load(sr);
            XmlNode dictsNode = doc.FirstChild;

            while (dictsNode != null)
            {
                if (dictsNode.NodeType == XmlNodeType.Element)
                {
                    break;
                }
                dictsNode = dictsNode.NextSibling;
                if (dictsNode == null)
                {
                    throw new Exception("No initial element found");
                }
            }

            if (!Lex.Eq(dictsNode.Name, "Dictionaries"))
            {
                throw new Exception("Expected Dictionaries node: " + dictsNode.Name);
            }

            XmlNode dictNode = dictsNode.FirstChild;

            while (dictNode != null)             // loop through dictionaries
            {
                if (dictNode.NodeType != XmlNodeType.Element)
                {
                    ;                                                         // ignore non-elements
                }
                else if (Lex.Eq(dictNode.Name, "Dictionary"))                 // dictionary element
                {
                    DictionaryMx dict = new DictionaryMx();

                    atts = dictNode.Attributes;
                    for (int i = 0; i < atts.Count; i++)
                    {
                        XmlNode att = atts.Item(i);

                        if (Lex.Eq(att.Name, "Name"))
                        {
                            dict.Name = att.Value.ToLower();
                        }

                        else if (Lex.Eq(att.Name, "Sql"))
                        {
                            dict.Sql = att.Value;
                        }

                        else if (Lex.Eq(att.Name, "Cache"))
                        {
                            bool.TryParse(att.Value, out dict.Cache);
                        }

                        else
                        {
                            DebugLog.Message("Unexpected Dictionary (" + dict.Name + ") attribute: " + att.Name);
                        }
                    }

                    if (dict.Name == "")
                    {
                        throw new Exception("Connection is missing name");
                    }
                    if (Lex.EndsWith(dict.Name, "_cache"))
                    {
                        dict.Cache = true;                                                        // alternate way to indicate cached dictionary (avoid unexpected attribute exception in older clients)
                    }
                    Dictionaries[dict.Name] = dict;

                    XmlNode entryNode = dictNode.FirstChild;
                    while (entryNode != null)                     // loop through dict entries
                    {
                        if (entryNode.NodeType != XmlNodeType.Element)
                        {
                            ;                                                             // ignore non-elements
                        }
                        else if (Lex.Eq(entryNode.Name, "Entry"))                         // word entry
                        {
                            string word = "";
                            string def  = "";
                            atts = entryNode.Attributes;
                            for (int i = 0; i < atts.Count; i++)
                            {
                                XmlNode att = atts.Item(i);

                                if (Lex.Eq(att.Name, "Word"))
                                {
                                    word = att.Value.Trim();
                                }

                                else if (Lex.Eq(att.Name, "Def") ||
                                         Lex.Eq(att.Name, "Definition"))
                                {
                                    def = att.Value.Trim();
                                }

                                else
                                {
                                    DebugLog.Message("Unexpected Dictionary (" + dict.Name + ") entry attribute: " + att.Name);
                                }
                            }

                            if (word == "")
                            {
                                throw new Exception("Dictionary entry is missing Word attribute");
                            }
                            dict.Add(word, def);
                        }

                        else
                        {
                            throw new Exception("Expected Entry element but saw " +
                                                dictNode.Name);
                        }

                        entryNode = entryNode.NextSibling;
                    }                     // end of entry loop
                }

                else
                {
                    throw new Exception("Expected Dictionary element but saw " +
                                        dictNode.Name);
                }

                dictNode = dictNode.NextSibling;
            }             // end of dictionary loop

            sr.Close();

            return(Dictionaries);
        }