///////////////////////////////////////////////////////////////////////////////////////////
 ///////////////////////////////////////////////////////////////////////////////////////////
 ///////////////////////////////////////////////////////////////////////////////////////////
 public MessageWindowDataWrapper(MessageType type, string time, MessageWindowTextDataWrapper message,
                                 IEnumerable<MessageDetailDataWrap> details)
 {
     _type = type;
     _time = time;
     _message = message;
     _details = (null == details) ? new List<MessageDetailDataWrap>() : details;
 }
Esempio n. 2
0
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            List <Inline> inlines = new List <Inline>();

            if (null != value)
            {
                MessageWindowTextDataWrapper description = (MessageWindowTextDataWrapper)value;
                Hyperlink hyperlink = MessageLinkHelper.CreateHiperlink(description.Link);
                if (null == hyperlink)
                {   // add simple text
                    inlines.Add(new Run(description.Message));
                }
                else
                {
                    MatchCollection mc = Regex.Matches(description.Message, @"({\d+})");
                    if (0 == mc.Count)
                    {
                        // add simple text
                        inlines.Add(new Run(description.Message));

                        // add link
                        inlines.Add(new Run(" "));
                        inlines.Add(hyperlink);
                    }
                    else
                    {
                        // add text before link
                        string stringLink = mc[0].Value;
                        int    startIndex = description.Message.IndexOf(stringLink, 0);
                        if (0 < startIndex)
                        {
                            inlines.Add(new Run(description.Message.Substring(0, startIndex)));
                        }
                        int position = startIndex + stringLink.Length;

                        // add link
                        inlines.Add(hyperlink);

                        // add text after all links
                        if (position < description.Message.Length)
                        {
                            inlines.Add(new Run(description.Message.Substring(position, description.Message.Length - position)));
                        }
                    }
                }
            }

            return(inlines);
        }
        private void _AddMessage(MessageType type, string timeMark, string message, Link link, IEnumerable<MessageDetail> details)
        {
            // convert to wrapper
            List<MessageDetailDataWrap> detailsWrap = null;
            if (null != details)
            {
                detailsWrap = new List<MessageDetailDataWrap>();

                IEnumerator<MessageDetail> enumerator = details.GetEnumerator();
                while((null != enumerator) && enumerator.MoveNext())
                {
                    MessageDetail detail = enumerator.Current;
                    detailsWrap.Add(new MessageDetailDataWrap(detail.Type, detail.Description));
                }
            }

            // add message
            MessageWindowTextDataWrapper textWrapper = new MessageWindowTextDataWrapper(message, link);
            MessageWindowDataWrapper wrapper = new MessageWindowDataWrapper(type, timeMark, textWrapper, detailsWrap);
            if (0 == _data.Count)
                _data.Add(wrapper);
            else
                _data.Insert(0, wrapper);

            _collectionSource.Source = _data;

            // NOTE: XceedGrid issue - refresh logical children
            if (null != _collectionSource.View)
                _collectionSource.View.Refresh();

            // auto open window
            if (MessageType.Error == type)
            {   // error - open the message window
                _timer.Enabled = false;
                _timer.Stop();
                _isAutoOpened = false;
                _isNeedClose = false;
                if (Visibility.Visible != this.Visibility)
                    App.Current.MainWindow.ToggleMessageWindowState();

                // expand error details
                if (null != details)
                {
                    DataGridContext dgc = xceedGrid.CurrentContext;
                    xceedGrid.ExpandDetails(dgc.Items.GetItemAt(0));
                }
            }

            else if (MessageType.Warning == type)
            {   // warning - pop the message window
                if (Visibility.Visible != this.Visibility)
                {
                    App.Current.MainWindow.ToggleMessageWindowState();
                    _isAutoOpened = true;

                    _timer.Interval = SHOW_POPUP_MESSAGE_TIMER_INTERVAL;
                    _timer.Start();
                    _timer.Enabled = true;
                    _isNeedClose = false;
                }
                else if (_isAutoOpened)
                {   // reinit timer
                    _timer.Enabled = false;
                    _timer.Stop();

                    _timer.Interval = SHOW_POPUP_MESSAGE_TIMER_INTERVAL;
                    _timer.Start();
                    _timer.Enabled = true;
                    _isNeedClose = false;
                }

                // Expand error details.
                if (null != details)
                {
                    DataGridContext dgc = xceedGrid.CurrentContext;
                    xceedGrid.ExpandDetails(dgc.Items.GetItemAt(0));
                }
            }
            // else info don't change state of the message window
        }
        private void _AddMessage(MessageType type, string timeMark, string message, Link link, IEnumerable <MessageDetail> details)
        {
            // convert to wrapper
            List <MessageDetailDataWrap> detailsWrap = null;

            if (null != details)
            {
                detailsWrap = new List <MessageDetailDataWrap>();

                IEnumerator <MessageDetail> enumerator = details.GetEnumerator();
                while ((null != enumerator) && enumerator.MoveNext())
                {
                    MessageDetail detail = enumerator.Current;
                    detailsWrap.Add(new MessageDetailDataWrap(detail.Type, detail.Description));
                }
            }

            // add message
            MessageWindowTextDataWrapper textWrapper = new MessageWindowTextDataWrapper(message, link);
            MessageWindowDataWrapper     wrapper     = new MessageWindowDataWrapper(type, timeMark, textWrapper, detailsWrap);

            if (0 == _data.Count)
            {
                _data.Add(wrapper);
            }
            else
            {
                _data.Insert(0, wrapper);
            }

            _collectionSource.Source = _data;

            // NOTE: XceedGrid issue - refresh logical children
            if (null != _collectionSource.View)
            {
                _collectionSource.View.Refresh();
            }

            // auto open window
            if (MessageType.Error == type)
            {   // error - open the message window
                _timer.Enabled = false;
                _timer.Stop();
                _isAutoOpened = false;
                _isNeedClose  = false;
                if (Visibility.Visible != this.Visibility)
                {
                    App.Current.MainWindow.ToggleMessageWindowState();
                }

                // expand error details
                if (null != details)
                {
                    DataGridContext dgc = xceedGrid.CurrentContext;
                    xceedGrid.ExpandDetails(dgc.Items.GetItemAt(0));
                }
            }

            else if (MessageType.Warning == type)
            {   // warning - pop the message window
                if (Visibility.Visible != this.Visibility)
                {
                    App.Current.MainWindow.ToggleMessageWindowState();
                    _isAutoOpened = true;

                    _timer.Interval = SHOW_POPUP_MESSAGE_TIMER_INTERVAL;
                    _timer.Start();
                    _timer.Enabled = true;
                    _isNeedClose   = false;
                }
                else if (_isAutoOpened)
                {   // reinit timer
                    _timer.Enabled = false;
                    _timer.Stop();

                    _timer.Interval = SHOW_POPUP_MESSAGE_TIMER_INTERVAL;
                    _timer.Start();
                    _timer.Enabled = true;
                    _isNeedClose   = false;
                }

                // Expand error details.
                if (null != details)
                {
                    DataGridContext dgc = xceedGrid.CurrentContext;
                    xceedGrid.ExpandDetails(dgc.Items.GetItemAt(0));
                }
            }
            // else info don't change state of the message window
        }