예제 #1
0
        /// <summary>
        /// 顯示訊息視窗或設置結果(測試時),從信使身上讀取輸入資料
        /// </summary>
        /// <param name="message">訊息</param>
        /// <param name="owner">父表單</param>
        /// <returns>結果</returns>
        public static DialogResult ShowNewMessageOrSetResult(ArMessage message, IWin32Window owner)
        {
            if (!Registered)
            {
                if (owner == null)
                {
                    return(MessageBox.Show(message.Content, message.Title,
                                           (MessageBoxButtons)(byte)message.ChoiceOption,
                                           (MessageBoxIcon)(byte)message.LevelOfEergency,
                                           (MessageBoxDefaultButton)((message.DefaultResponse - 1) * 256)));
                }
                else
                {
                    return(MessageBox.Show(owner, message.Content, message.Title,
                                           (MessageBoxButtons)(byte)message.ChoiceOption,
                                           (MessageBoxIcon)(byte)message.LevelOfEergency,
                                           (MessageBoxDefaultButton)((message.DefaultResponse - 1) * 256)));
                }
            }

            DialogResult dr = (DialogResult)Enum.Parse(typeof(DialogResult), message.GetDefaultResponse());
            string       record;

            Courier.Package = message;
            record          = message.ToString();
            Courier.MessageReceived.Add(record);
            Archivist.WriteRecord(record);

            string response = Courier.GetResponse(message.ID);

            if (!string.IsNullOrEmpty(response))
            {
                dr = (DialogResult)Enum.Parse(typeof(DialogResult), response);
            }

            if (!message.ChoiceOption.ToString().Contains(dr.ToString()))
            {
                throw new InvalidCastException("DialogResult");
            }

            record = $"DialogResult = [{dr}]";
            Courier.MessageReceived.Add(record);
            Archivist.WriteRecord(record);

            return(dr);
        }