Пример #1
0
        /// <summary>XmlDocumentをLoad</summary>
        /// <param name="filePath">string</param>
        /// <returns>
        /// 真 : ロードできた
        /// 偽 : ロードできなかった
        /// </returns>
        private static bool LoadFromFile(string filePath)
        {
            if (EmbeddedResourceLoader.Exists(filePath, false))
            {
                XmlDocument xMLMSG = new XmlDocument();

                // Load
                xMLMSG.LoadXml(EmbeddedResourceLoader.LoadXMLAsString(filePath));
                // Save
                GetMessage.DicMSG[filePath] = GetMessage.FillDictionary(xMLMSG);

                return(true);
            }
            else if (ResourceLoader.Exists(filePath, false))
            {
                XmlDocument xMLMSG = new XmlDocument();

                // Load
                xMLMSG.Load(PubCmnFunction.BuiltStringIntoEnvironmentVariable(filePath));
                // Save
                GetMessage.DicMSG[filePath] = GetMessage.FillDictionary(xMLMSG);

                return(true);
            }
            else
            {
                return(false);
            }
        }
Пример #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
            }
        }