コード例 #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
 public void Exists1Test(string assemblyString, string loadfileName, bool throwException)
 {
     try
     {
         bool results = EmbeddedResourceLoader.Exists(assemblyString, loadfileName, throwException);
         Assert.True(results);
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.StackTrace);
         throw;
     }
 }
コード例 #3
0
        /// <summary>コンストラクタ</summary>
        public TransactionControl()
        {
            // トランザクション定義をロードする。

            // リソース ローダでチェック(ここで落とすとハンドルされないので落とさない。)
            if (EmbeddedResourceLoader.Exists(
                    GetConfigParameter.GetConfigValue(FxLiteral.XML_TC_DEFINITION), false))
            {
                // トランザクション定義(XmlDocument)のロード
                this.XMLTCD.LoadXml(
                    EmbeddedResourceLoader.LoadXMLAsString(
                        GetConfigParameter.GetConfigValue(FxLiteral.XML_TC_DEFINITION)));
            }
            else if (ResourceLoader.Exists(
                         GetConfigParameter.GetConfigValue(FxLiteral.XML_TC_DEFINITION), false))
            {
                // トランザクション定義(XmlDocument)のロード
                this.XMLTCD.Load(
                    PubCmnFunction.BuiltStringIntoEnvironmentVariable(
                        GetConfigParameter.GetConfigValue(FxLiteral.XML_TC_DEFINITION)));
            }
            else
            {
                // チェック
                if (GetConfigParameter.GetConfigValue(FxLiteral.XML_TC_DEFINITION) == null ||
                    GetConfigParameter.GetConfigValue(FxLiteral.XML_TC_DEFINITION) == "")
                {
                    // 定義が無い(offの扱い)。

                    // トランザクション定義(XmlDocument)を空で初期化
                    this.XMLTCD.LoadXml("<?xml version=\"1.0\" encoding=\"utf-8\" ?><TCD></TCD>");
                }
                else
                {
                    // 定義が間違っている(エラー)。

                    // エラーをスロー
                    throw new FrameworkException(
                              FrameworkExceptionMessage.ERROR_IN_WRITING_OF_FX_PATH2[0],
                              String.Format(FrameworkExceptionMessage.ERROR_IN_WRITING_OF_FX_PATH2[1],
                                            FxLiteral.XML_TC_DEFINITION));
                }
            }
        }
コード例 #4
0
        /// <summary>コンストラクタ</summary>
        /// <remarks>CallController、ServiceInterfaceから利用するので、public</remarks>
        public InProcessNameService()
        {
            // インプロセス呼び出しの名前解決定義をロードする。

            #region  埋め込まれたリソース ローダでチェック(ここで落とすとハンドルされないので落とさない。)

            if (EmbeddedResourceLoader.Exists(
                    GetConfigParameter.GetConfigValue(FxLiteral.XML_TM_INPROCESS_DEFINITION), false))
            {
                // インプロセス呼び出しの名前解決定義(XmlDocument)を[埋め込まれたリソース]で初期化
                this.XMLTMD_InProcess.LoadXml(EmbeddedResourceLoader.LoadXMLAsString(
                                                  GetConfigParameter.GetConfigValue(FxLiteral.XML_TM_INPROCESS_DEFINITION)));

                // 戻す
                return;
            }
            else
            {
                // 何もしない。
            }

            #endregion

            #region リソース ローダでチェック(ここで落とすとハンドルされないので落とさない。)

            if (ResourceLoader.Exists(
                    GetConfigParameter.GetConfigValue(FxLiteral.XML_TM_INPROCESS_DEFINITION), false))
            {
                // インプロセス呼び出しの名前解決定義(XmlDocument)を[リソース]で初期化
                this.XMLTMD_InProcess.Load(
                    PubCmnFunction.BuiltStringIntoEnvironmentVariable(
                        GetConfigParameter.GetConfigValue(FxLiteral.XML_TM_INPROCESS_DEFINITION)));

                // 戻す
                return;
            }
            else
            {
                // 何もしない。
            }

            #endregion

            #region チェック(定義の有無や、定義の誤り)

            if (GetConfigParameter.GetConfigValue(FxLiteral.XML_TM_INPROCESS_DEFINITION) == null ||
                GetConfigParameter.GetConfigValue(FxLiteral.XML_TM_INPROCESS_DEFINITION) == "")
            {
                // 定義が無い(offの扱い)。

                // インプロセス呼び出しの名前解決定義(XmlDocument)を空で初期化
                this.XMLTMD_InProcess.LoadXml("<?xml version=\"1.0\" encoding=\"utf-8\" ?><TMD></TMD>");
            }
            else
            {
                // 定義が間違っている(エラー)。

                // 例外をスロー
                throw new FrameworkException(
                          FrameworkExceptionMessage.ERROR_IN_WRITING_OF_FX_PATH2[0],
                          String.Format(FrameworkExceptionMessage.ERROR_IN_WRITING_OF_FX_PATH2[1],
                                        FxLiteral.XML_TM_INPROCESS_DEFINITION));
            }

            #endregion
        }
コード例 #5
0
            /// <summary>コンストラクタ</summary>
            /// <remarks>インナークラス</remarks>
            public SharedPropertyManager()
            {
                // 共有情報定義をロードする。
                XmlDocument xMLSP = new XmlDocument();

                if (GetConfigParameter.GetConfigValue(FxLiteral.XML_SP_DEFINITION) == null ||
                    GetConfigParameter.GetConfigValue(FxLiteral.XML_SP_DEFINITION) == "")
                {
                    // 定義が無い(offの扱い)。

                    // 共有情報定義(XmlDocument)を空で初期化
                    xMLSP.LoadXml("<?xml version=\"1.0\" encoding=\"utf-8\" ?><SPD></SPD>");
                }
                else
                {
                    //// 定義が間違っている(エラー)。

                    //// エラーをスロー
                    //throw new FrameworkException(
                    //    FrameworkExceptionMessage.ERROR_IN_WRITING_OF_FX_PATH2[0],
                    //    String.Format(FrameworkExceptionMessage.ERROR_IN_WRITING_OF_FX_PATH2[1],
                    //                    FxLiteral.XML_SP_DEFINITION));

                    #region  埋め込まれたリソース ローダでチェック(ここで落とすとハンドルされないので落とさない。)

                    if (EmbeddedResourceLoader.Exists(
                            GetConfigParameter.GetConfigValue(FxLiteral.XML_SP_DEFINITION), false))
                    {
                        // 共有情報定義(XmlDocument)を[埋め込まれたリソース]で初期化
                        xMLSP.LoadXml(EmbeddedResourceLoader.LoadXMLAsString(
                                          GetConfigParameter.GetConfigValue(FxLiteral.XML_SP_DEFINITION)));

                        //// 戻す
                        //return;
                    }
                    else
                    {
                        // 何もしない。
                    }

                    #endregion

                    #region リソース ローダでチェック(ここで落とすとハンドルされないので落とさない。)

                    if (ResourceLoader.Exists(
                            GetConfigParameter.GetConfigValue(FxLiteral.XML_SP_DEFINITION), false))
                    {
                        // 共有情報定義(XmlDocument)を[リソース]で初期化
                        xMLSP.Load(
                            PubCmnFunction.BuiltStringIntoEnvironmentVariable(
                                GetConfigParameter.GetConfigValue(FxLiteral.XML_SP_DEFINITION)));

                        //// 戻す
                        //return;
                    }
                    else
                    {
                        // 何もしない。
                    }

                    #endregion
                }

                #region すべてのSHAREDPROPタグをDictionary化

                // すべてのSHAREDPROPタグを取得、大文字・小文字は区別する。
                XmlNodeList xmlNodeList = xMLSP.GetElementsByTagName(FxLiteral.XML_SP_TAG_SHARED_PROPERTY);

                foreach (XmlNode xmlNodeSP in xmlNodeList)
                {
                    // 属性の取得
                    XmlNode xmlNodeKey = xmlNodeSP.Attributes.GetNamedItem(FxLiteral.XML_CMN_ATTR_KEY);
                    XmlNode xmlNodeVal = xmlNodeSP.Attributes.GetNamedItem(FxLiteral.XML_CMN_ATTR_VALUE);

                    if (xmlNodeKey == null)
                    {
                        // id属性なしの場合

                        throw new FrameworkException(
                                  FrameworkExceptionMessage.SHAREDPROPERTY_XML_FORMAT_ERROR[0],
                                  String.Format(FrameworkExceptionMessage.SHAREDPROPERTY_XML_FORMAT_ERROR[1],
                                                String.Format(FrameworkExceptionMessage.SHAREDPROPERTY_XML_FORMAT_ERROR_ATTR, FxLiteral.XML_CMN_ATTR_KEY, "-")));
                    }

                    if (xmlNodeVal == null)
                    {
                        // description属性なしの場合

                        throw new FrameworkException(
                                  FrameworkExceptionMessage.SHAREDPROPERTY_XML_FORMAT_ERROR[0],
                                  String.Format(FrameworkExceptionMessage.SHAREDPROPERTY_XML_FORMAT_ERROR[1],
                                                String.Format(FrameworkExceptionMessage.SHAREDPROPERTY_XML_FORMAT_ERROR_ATTR, FxLiteral.XML_CMN_ATTR_VALUE, xmlNodeKey.Value)));
                    }

                    this.DicSP.Add(xmlNodeKey.Value, xmlNodeVal.Value);
                }

                #endregion
            }
コード例 #6
0
ファイル: LogManager.cs プロジェクト: shamohai/OpenTouryo
        /// <summary>
        /// log4net.ILogインスタンスの取得
        /// </summary>
        /// <param name="loggerName">ロガー名</param>
        /// <returns>log4netのインターフェイス</returns>
        public static log4net.ILog GetLog4netIf(string loggerName)
        {
            lock (LogManager._lock)
            {
                // null対策
                if (LogManager._logIfHt == null)
                {
                    LogManager._logIfHt = new Dictionary <string, log4net.ILog>();
                }

                // すでにlog4net.ILogインスタンスが存在する。
                if (LogManager._logIfHt.ContainsKey(loggerName)) // Dic化でnullチェック変更
                {
                    // 生成済みのlog4net.ILogインスタンスを返す。
                    return((log4net.ILog)LogManager._logIfHt[loggerName]);
                }
                else
                {
                    // #12-start

                    // 定義ファイル
                    string log4netConfFile = GetConfigParameter.GetConfigValue(PubLiteral.LOG4NET_CONF_FILE);

                    // log4netの設定ファイルのパス
                    if (log4netConfFile == null || log4netConfFile == "")
                    {
                        // 定義ファイルのパスが無い場合

                        // 空のロガーを返す(エラーにはならない)
                        return(log4net.LogManager.GetLogger(""));
                    }
                    else
                    {
                        // 埋め込まれたリソース ローダで存在チェック
                        if (EmbeddedResourceLoader.Exists(log4netConfFile, false))
                        {
                            // ログ定義 [埋め込まれたリソース]
                            XmlDocument xmlDef = new XmlDocument();

                            // Exceptionが上がり得る。
                            xmlDef.LoadXml(EmbeddedResourceLoader.LoadXMLAsString(log4netConfFile));

                            if (xmlDef["log4net"] == null)
                            {
                                // XmlElement(log4net)が無い場合
                                throw new ArgumentException(String.Format(
                                                                PublicExceptionMessage.XML_ELEMENT_ERROR,
                                                                PublicExceptionMessage.XML_ELEMENT_ERROR_LOG4NET));
                            }

                            // log4net
                            XmlConfigurator.Configure(xmlDef["log4net"]);
                        }
                        else
                        {
                            // リソース ローダで存在チェック(存在しなければエラー)
                            ResourceLoader.Exists(log4netConfFile, true);

                            // ログ定義 [リソース ファイル] → ストリームを開く
                            FileStream s = new FileStream(
                                PubCmnFunction.BuiltStringIntoEnvironmentVariable(log4netConfFile),
                                FileMode.Open, FileAccess.Read, FileShare.Read);

                            // log4netのXML形式の設定ファイルを読み込む。
                            XmlConfigurator.Configure(s);
                            s.Close();
                        }

                        // log4net.ILogインスタンスを初期化する。
                        LogManager._logIfHt.Add(loggerName, log4net.LogManager.GetLogger(loggerName));

                        // 生成したlog4net.ILogインスタンスを返す。
                        return((log4net.ILog)LogManager._logIfHt[loggerName]);
                    }

                    // #12-end
                }
            }
        }
コード例 #7
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
            }
        }