Esempio n. 1
0
        private void Demo_Loaded(object sender, RoutedEventArgs e)
        {
            string[] ary = new string[] { "xml", "sql" };

            MessageFactory messageFactory = new MessageFactory();

            foreach (string key in ary)
            {
                AbstractMessage messageObject = messageFactory.GetMessageObject(key);

                lblMsg.AppendLine(messageObject.Insert(new MessageModel("插入", DateTime.Now)).ToString());
                lblMsg.AppendLine(messageObject.Get()[0].Message + " " + messageObject.Get()[0].PublishTime.ToString());
            }
        }
Esempio n. 2
0
        /// <summary>
        /// 获取Message对象
        /// </summary>
        /// <param name="key">key</param>
        /// <returns></returns>
        public AbstractMessage GetMessageObject(string key)
        {
            AbstractMessage messageObject = null;

            if (_messageObjects.ContainsKey(key))
            {
                messageObject = _messageObjects[key];
            }
            else
            {
                switch (key)
                {
                case "xml": messageObject = new SqlMessage(); break;

                case "sql": messageObject = new XmlMessage(); break;
                }

                _messageObjects.Add(key, messageObject);
            }

            return(messageObject);
        }