Exemple #1
0
        }       //	getAD_Language

        /// <summary>
        ///	    Import Translation.
        //	Uses TranslationHandler to update translation
        /// </summary>
        /// <param name="directory">file</param>
        /// <param name="Trl_Table">table</param>
        /// <returns>status message</returns>
        public String ImportTrl(String directory, String Trl_Table)
        {
            String fileName = directory + "\\" + Trl_Table + "_" + _AD_Language + ".xml";

            log.Info(fileName);
            FileInfo inn = new FileInfo(fileName);

            if (!inn.Exists)
            {
                String msg = "File does not exist: " + fileName;
                log.Log(Level.SEVERE, msg);
                return(msg);
            }

            int       words  = _wordCount;
            XmlReader parser = null;

            try
            {
                bool   _isBaseLanguage = false;
                string _tableName      = "";

                TranslationHandler handler = new TranslationHandler(_AD_Client_ID);
                handler.SetByExportD(_InsertExportID);

                XmlReaderSettings factory = new XmlReaderSettings();

                factory.IgnoreComments = true;
                factory.IgnoreProcessingInstructions = true;
                factory.IgnoreWhitespace             = true;
                parser = XmlReader.Create(inn.FullName, factory);                       //
                while (parser.Read())
                {
                    try
                    {
                        switch (parser.NodeType)
                        {
                        case XmlNodeType.Element:
                            bool isEmptyElement = false;
                            isEmptyElement = parser.IsEmptyElement;
                            string        strURI   = parser.NamespaceURI;
                            string        strName  = parser.Name;
                            string        strlocal = parser.LocalName;
                            List <string> att      = new List <string>();
                            if (parser.HasAttributes)
                            {
                                for (int i = 0; i < parser.AttributeCount; i++)
                                {
                                    att.Add(parser.GetAttribute(i));
                                }
                            }

                            if (strURI.Equals(Translation.XML_TAG) || strURI.Equals(Translation.XML_TAG_Vienna) || strURI.Equals(Translation.XML_TAG_Adam))
                            {
                                string lang = att[0];               //attributes[Translation.XML_ATTRIBUTE_LANGUAGE].Value;
                                _isBaseLanguage = Language.IsBaseLanguage(lang);
                                _tableName      = att[1].ToUpper(); //attributes[Translation.XML_ATTRIBUTE_TABLE].Value;
                            }



                            handler.StartElement(strURI, strlocal, strName, att);
                            if (strName == "value")
                            {
                                if (att[1] != "")
                                {
                                    //preventive Check skip Name column updation for some tables
                                    if (_isBaseLanguage && lstTableHasDisplayCol.Contains(_tableName))
                                    {
                                        if (att[0].ToUpper() == "NAME")
                                        {
                                            break;
                                        }
                                    }

                                    if (parser.Read())
                                    {
                                        switch (parser.NodeType)
                                        {
                                        case XmlNodeType.Text:

                                            string trlValue = parser.Value;
                                            if (!String.IsNullOrEmpty(trlValue))
                                            {
                                                char[] ch = trlValue.ToCharArray();
                                                handler.Characters(ch);
                                            }
                                            break;
                                        }
                                    }
                                }
                            }
                            break;

                        case XmlNodeType.EndElement:
                            string URI  = parser.NamespaceURI;
                            string Name = parser.Name;
                            handler.EndElement(URI, "", Name);
                            break;
                        }
                    }
                    catch (Exception ec)
                    {
                        log.Info("error in importing record...Invalid Record.. in table " + Trl_Table + " error=>" + ec.Message);
                    }
                }
                _wordCount += handler.GetWordCount();
                log.Info("Updated=" + handler.GetUpdateCount() + ", Words=" + (_wordCount - words));
                if (parser != null)
                {
                    parser.Close();
                }
                return(Msg.GetMsg(_ctx, "Updated") + "=" + handler.GetUpdateCount());
            }
            catch (Exception e)
            {
                log.Log(Level.SEVERE, "importTrl", e);
                if (parser != null)
                {
                    parser.Close();
                }
                return(e.ToString());
            }
        }       //	importTrl