Esempio n. 1
0
        /// <summary>
        /// Get message description from message ID
        /// </summary>
        /// <param name="messageID">
        /// messageID
        /// </param>
        /// <param name="uiCulture">
        /// uiCulture
        /// </param>
        /// <returns>
        /// Get message description
        /// </returns>
        public static string GetMessageDescription(string messageID, CultureInfo uiCulture)
        {
            // defaultFile
            string defaultFilePath = GetConfigParameter.GetConfigValue(FxLiteral.XML_MSG_DEFINITION);
            string defaultFileName = "";

            // culture
            CultureInfo currentUICulture = null;
            string      uICultureName    = "";

            // cultureWiseFile
            string cultureWiseFilePath = "";
            string cultureWiseFileName = "";

            string content = "";

            lock (GetMessage._lock)
            {
                do
                {
                    if (currentUICulture == null)
                    {
                        // 初回
                        currentUICulture = uiCulture;
                    }
                    else
                    {
                        // フォールバック
                        currentUICulture = currentUICulture.Parent;
                    }

                    // uICultureName
                    uICultureName = currentUICulture.Name;

                    // リソース名の国際化
                    defaultFileName = GetMessage.GetCultureWiseFile(
                        uICultureName, defaultFilePath, out cultureWiseFilePath, out cultureWiseFileName);

                    if (GetMessage.DicMSG.ContainsKey(cultureWiseFilePath))
                    {
                        // ロード済み
                        if (GetMessage.DicMSG[cultureWiseFilePath].ContainsKey(messageID))
                        {
                            content = GetMessage.DicMSG[cultureWiseFilePath][messageID];
                        }
                    }
                    else
                    {
                        // 未ロード
                        if (GetMessage.LoadFromFile(cultureWiseFilePath))
                        {
                            // ロードできた。
                            if (GetMessage.DicMSG[cultureWiseFilePath].ContainsKey(messageID))
                            {
                                content = GetMessage.DicMSG[cultureWiseFilePath][messageID];
                            }
                        }
                        else
                        {
                            // ロードできなかった。
                            // フォールバック
                        }
                    }
                }while (
                    !string.IsNullOrEmpty(uICultureName) && // フォールバックが終わった。
                    string.IsNullOrEmpty(content)           // ファイルを読み取れなかった。
                    );

                if (string.IsNullOrEmpty(content)) // 既定(英語)
                {
                    if (GetMessage.DicMSG.ContainsKey(defaultFilePath))
                    {
                        // ロード済み
                        if (GetMessage.DicMSG[defaultFilePath].ContainsKey(messageID))
                        {
                            content = GetMessage.DicMSG[defaultFilePath][messageID];
                        }
                    }
                    else
                    {
                        // 未ロード
                        if (GetMessage.LoadFromFile(defaultFilePath))
                        {
                            // ロードできた。
                            if (GetMessage.DicMSG[defaultFilePath].ContainsKey(messageID))
                            {
                                content = GetMessage.DicMSG[defaultFilePath][messageID];
                            }
                        }
                        else
                        {
                            // ロードできなかった。
                            // → 終了
                        }
                    }
                }
            }

            return(content);
        }
Esempio n. 2
0
        /// <summary>
        /// Get message description from message ID
        /// </summary>
        /// <param name="messageID">
        /// messageID
        /// </param>
        /// <param name="cultureName">
        /// cultureName
        /// </param>
        /// <param name="useChildUICulture">
        /// 子カルチャを使用している場合:true<br/>
        /// use ChildUICulture : true
        /// </param>
        /// <param name="notExist">
        /// 子カルチャを使用している場合で、<br/>
        /// ファイルを発見できなかった場合はtrueを返す。<br/>
        /// if useChildUICulture == true<br/>
        /// then If the file is not found, return true.
        /// </param>
        /// <returns>
        /// メッセージ記述<br/>
        /// Get message description
        /// </returns>
        private static string GetMessageDescription(
            string messageID, string cultureName,
            bool useChildUICulture, out bool notExist)
        {
            #region local

            //bool xmlfilenotExist = false;
            notExist = false;

            string tempXMLFileName = string.Empty;
            string tempXMLFilePath = string.Empty;

            string defaultXMLFileName     = string.Empty;
            string defaultXMLFilePath     = string.Empty;
            string cultureWiseXMLFileName = string.Empty;
            string cultureWiseXMLFilePath = string.Empty;

            string cultureWiseXMLParentFileName = string.Empty;
            string cultureWiseXMLParentFilePath = string.Empty;

            bool defaultXMLFilePath_ResourceLoaderExists             = false;
            bool defaultXMLFilePath_EmbeddedResourceLoaderExists     = false;
            bool cultureWiseXMLFilePath_ResourceLoaderExists         = false;
            bool cultureWiseXMLFilePath_EmbeddedResourceLoaderExists = false;

            #endregion

            defaultXMLFilePath = GetConfigParameter.GetConfigValue(FxLiteral.XML_MSG_DEFINITION);

            GetMessage.GetCultureWiseXMLFileName(
                cultureName, defaultXMLFilePath, out defaultXMLFileName, out cultureWiseXMLFilePath, out cultureWiseXMLFileName);

            // This has been added for Threadsafe
            lock (thisLock)
            {
                #region ContainsKey

                // Check that XML file is already loaded.
                if (GetMessage.DicMSG.ContainsKey(cultureWiseXMLFileName))
                {
                    // culture wise XML file is already loaded.
                    if (GetMessage.DicMSG[cultureWiseXMLFileName].ContainsKey(messageID))
                    {
                        return(GetMessage.DicMSG[cultureWiseXMLFileName][messageID]);
                    }
                    else
                    {
                        return(string.Empty);
                    }
                }
                else
                {
                    // culture wise XML file isn't loaded.
                }

                if (GetMessage.DicMSG.ContainsKey(defaultXMLFileName))
                {
                    // default XML file is already loaded.

                    if (useChildUICulture)
                    {
                        // next, try load.
                    }
                    else
                    {
                        // default XML
                        if (DicMSG[defaultXMLFileName].ContainsKey(messageID))
                        {
                            return(GetMessage.DicMSG[defaultXMLFileName][messageID]);
                        }
                        else
                        {
                            return(string.Empty);
                        }
                    }
                }
                else
                {
                    // default XML file isn't loaded.
                }

                #endregion

                #region FillDictionary

                // cultureWiseXMLFilePath
                if (EmbeddedResourceLoader.Exists(cultureWiseXMLFilePath, false))
                {
                    // Exists cultureWiseXMLFile
                    cultureWiseXMLFilePath_EmbeddedResourceLoaderExists = true;
                }
                else
                {
                    // not exists
                    if (ResourceLoader.Exists(cultureWiseXMLFilePath, false))
                    {
                        // Exists cultureWiseXMLFile
                        cultureWiseXMLFilePath_ResourceLoaderExists = true;
                    }
                    else
                    {
                        // not exists

                        // defaultXMLFilePath
                        if (EmbeddedResourceLoader.Exists(defaultXMLFilePath, false))
                        {
                            // Exists defaultXMLFilePath
                            defaultXMLFilePath_EmbeddedResourceLoaderExists = true;
                        }
                        else
                        {
                            if (ResourceLoader.Exists(defaultXMLFilePath, false))
                            {
                                // Exists defaultXMLFilePath
                                defaultXMLFilePath_ResourceLoaderExists = true;
                            }
                        }
                    }
                }

                // select file path
                if (cultureWiseXMLFilePath_ResourceLoaderExists ||
                    cultureWiseXMLFilePath_EmbeddedResourceLoaderExists)
                {
                    // cultureWiseXMLFile
                    tempXMLFileName = cultureWiseXMLFileName;
                    tempXMLFilePath = cultureWiseXMLFilePath;
                }
                else
                {
                    // If the file is not found,
                    if (useChildUICulture)
                    {
                        // Look for use the culture info of the parent.
                        notExist = true;
                        return(string.Empty);
                    }
                    else
                    {
                        if (defaultXMLFilePath_ResourceLoaderExists ||
                            defaultXMLFilePath_EmbeddedResourceLoaderExists)
                        {
                            // defaultXMLFilePath
                            tempXMLFileName = defaultXMLFileName;
                            tempXMLFilePath = defaultXMLFilePath;
                        }
                        else
                        {
                            // use empty XML.
                        }
                    }
                }

                // select load method.
                XmlDocument xMLMSG = new XmlDocument();
                Dictionary <string, string> innerDictionary = new Dictionary <string, string>();

                if (defaultXMLFilePath_EmbeddedResourceLoaderExists ||
                    cultureWiseXMLFilePath_EmbeddedResourceLoaderExists)
                {
                    // Use EmbeddedResourceLoader
                    xMLMSG.LoadXml(EmbeddedResourceLoader.LoadXMLAsString(tempXMLFilePath));

                    //added by ritu
                    GetMessage.FillDictionary(xMLMSG, innerDictionary);

                    // and initialize DicMSG[tempXMLFileName]
                    DicMSG[tempXMLFileName] = innerDictionary;
                }
                else if (defaultXMLFilePath_ResourceLoaderExists ||
                         cultureWiseXMLFilePath_ResourceLoaderExists)
                {
                    // Load normally.
                    xMLMSG.Load(PubCmnFunction.BuiltStringIntoEnvironmentVariable(tempXMLFilePath));

                    //added by ritu
                    GetMessage.FillDictionary(xMLMSG, innerDictionary);
                    // and initialize DicMSG[tempXMLFileName]
                    DicMSG[tempXMLFileName] = innerDictionary;
                }
                else
                {
                    // If the file is not found, initialized as empty XML
                    xMLMSG.LoadXml("<?xml version=\"1.0\" encoding=\"utf-8\" ?><MSGD></MSGD>");

                    //added by ritu
                    GetMessage.FillDictionary(xMLMSG, innerDictionary);

                    // and initialize DicMSG[tempXMLFileName]
                    DicMSG[tempXMLFileName] = innerDictionary;
                    //xmlfilenotExist = true;
                }

                // and return GetMessageDescription.
                if (DicMSG[tempXMLFileName].ContainsKey(messageID))
                {
                    return(GetMessage.DicMSG[tempXMLFileName][messageID]);
                }
                else
                {
                    return(string.Empty);
                }

                #endregion
            }
        }