• R/O
  • HTTP
  • SSH
  • HTTPS

标签
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

File Info

Rev. 86e26ecde9d36b0074e6fb8a2a2b26250bb81d51
大小 3,592 字节
时间 2022-11-30 01:06:13
作者 yoshy
Log Message

[MOD] UserDialogProxy の名前空間を UI 配下から UI.Dialog 配下に移動
[FIX] JsonHelper.ToJsonString のメソッド名が破損していた不具合を修正
[MOD] キャプション書式化機能でキャプションの取得と書式化を行う機能の区別を明確にした
[MOD] MessageRepository の基底処理を CleanAuLait 側と同様に AbstractMessageRepository クラスに分割
[ADD] CleanAuLait 側で追加された機能の取り込み(PathHelper, DateTimeHelper, ログ系)

Content

using CleanAuLait48.Adaptor.Gateway.UI;
using System;

namespace CleanAuLait48.Core.Resource
{
    public class CaptionFormatter : ICaptionFormatter
    {
        public const string MSG_KEY_CAPTION = "Caption";

        public const string MSG_KEY_PREFIX_CAPTION_FORMAT = "Caption.Format.";

        public const string MSG_KEY_CAPTION_FORMAT_INFO = MSG_KEY_PREFIX_CAPTION_FORMAT + "Info";
        public const string MSG_KEY_CAPTION_FORMAT_WARN = MSG_KEY_PREFIX_CAPTION_FORMAT + "Warn";
        public const string MSG_KEY_CAPTION_FORMAT_ERROR = MSG_KEY_PREFIX_CAPTION_FORMAT + "Error";
        public const string MSG_KEY_CAPTION_FORMAT_CONFIRM = MSG_KEY_PREFIX_CAPTION_FORMAT + "Confirm";
        public const string MSG_KEY_CAPTION_FORMAT_EXCEPTION = MSG_KEY_PREFIX_CAPTION_FORMAT + "Exception";

        protected readonly IMessageRepository repo;

        public CaptionFormatter(IMessageRepository repo)
        {
            this.repo = repo;
        }

        public string GetDefaultCaption()
        {
            return GetCaption(MSG_KEY_CAPTION);
        }

        public string GetCaption(string captionKey)
        {
            return this.repo.Get(captionKey);
        }

        public string GetInfoCaption()
        {
            return FormatDefaultCaption(MSG_KEY_CAPTION_FORMAT_INFO);
        }

        public string FormatInfoCaption(string captionKey)
        {
            return FormatCaption(MSG_KEY_CAPTION_FORMAT_INFO, captionKey);
        }

        public string GetWarnCaption()
        {
            return FormatDefaultCaption(MSG_KEY_CAPTION_FORMAT_WARN);
        }

        public string FormatWarnCaption(string captionKey)
        {
            return FormatCaption(MSG_KEY_CAPTION_FORMAT_WARN, captionKey);
        }

        public string GetErrorCaption()
        {
            return FormatDefaultCaption(MSG_KEY_CAPTION_FORMAT_ERROR);
        }

        public string FormatErrorCaption(string captionKey)
        {
            return FormatCaption(MSG_KEY_CAPTION_FORMAT_ERROR, captionKey);
        }

        public string GetConfirmCaption()
        {
            return FormatDefaultCaption(MSG_KEY_CAPTION_FORMAT_ERROR);
        }

        public string FormatConfirmCaption(string captionKey)
        {
            return FormatCaption(MSG_KEY_CAPTION_FORMAT_CONFIRM, captionKey);
        }

        public string GetExceptionCaption(Exception e)
        {
            return FormatExceptionCaption(e, null);
        }

        public string FormatExceptionCaption(Exception e, string captionKey)
        {
            string caption;

            if (string.IsNullOrEmpty(captionKey))
            {
                caption = GetDefaultCaption();
            }
            else
            {
                caption = GetCaption(captionKey);
            }

            string format = GetCaption(MSG_KEY_CAPTION_FORMAT_EXCEPTION);

            return string.Format(format, caption, e.GetType().Name);
        }

        protected string FormatDefaultCaption(string captionFormatKey)
        {
            return FormatCaption(captionFormatKey, null);
        }

        protected string FormatCaption(string captionFormatKey, string captionKey)
        {
            string caption;

            if (string.IsNullOrEmpty(captionKey))
            {
                caption = GetDefaultCaption();
            }
            else
            {
                caption = GetCaption(captionKey);
            }

            string format = GetCaption(captionFormatKey);

            return string.Format(format, caption);
        }

    }
}