Statistics
| Branch: | Revision:

root / trunk / Pithos.Client.WPF / MessageView.xaml.cs @ ff26eb71

History | View | Annotate | Download (2.6 kB)

1
´╗┐using System;
2
using System.Collections.Generic;
3
using System.Collections.ObjectModel;
4
using System.ComponentModel;
5
using System.ComponentModel.Composition;
6
using System.Linq;
7
using System.Linq.Expressions;
8
using System.Text;
9
using System.Windows;
10
using System.Windows.Controls;
11
using System.Windows.Data;
12
using System.Windows.Documents;
13
using System.Windows.Input;
14
using System.Windows.Media;
15
using System.Windows.Media.Imaging;
16
using System.Windows.Shapes;
17
using Caliburn.Micro;
18

    
19
namespace Pithos.Client.WPF
20
{
21
    /// <summary>
22
    /// Interaction logic for MessageView.xaml
23
    /// </summary>
24
    public partial class MessageView : Window, INotifyPropertyChanged
25
    {
26
        public ObservableCollection<UserMessage> UserMessages { get; set; }
27

    
28
        private string _message;
29
        public string Message
30
        {
31
            get
32
            {
33
                return _message;
34
            }
35
            set
36
            {
37
                _message = value;
38
                NotifyOfPropertyChange(()=>Message);
39
            }
40
        }
41

    
42

    
43
        public MessageView(IEnumerable<UserMessage> userMessages)
44
        {
45
            UserMessages = new ObservableCollection<UserMessage>(userMessages);
46
            DataContext = this;
47
            InitializeComponent();            
48
        }
49

    
50
        /// <summary>
51
        /// Copies the messages to the clipboard
52
        /// </summary>
53
        public void OnCopy(object sender, RoutedEventArgs e)
54
        {
55
            StringBuilder clipText = new StringBuilder()
56
                .Append('-', 30)
57
                .AppendLine("\r\nProduct Map")
58
                .Append('-', 30)
59
                .AppendLine()
60
                .AppendLine();
61
            foreach (var message in UserMessages)
62
            {
63
                clipText
64
                    .Append('-', 20)
65
                    .AppendFormat("\r\n[{0,5}]\t{1}", message.Severity, message.Message)
66
                    .AppendLine()
67
                    .AppendLine(message.Details)
68
                    .AppendLine();
69
            }
70

    
71
            Clipboard.SetText(clipText.ToString());
72
        }
73

    
74

    
75
        public event PropertyChangedEventHandler PropertyChanged;
76

    
77
        private void NotifyOfPropertyChange<TProperty>(Expression<Func<TProperty>> property)
78
        {
79
            if (PropertyChanged!=null)
80
                PropertyChanged(this,new PropertyChangedEventArgs(property.GetMemberInfo().Name));
81
        }
82
    }
83

    
84
    public class UserMessage
85
    {
86
        public string Message { get; set; }
87

    
88
        public Severity Severity { get; set; }
89
        public string Details { get; set; }
90
    }
91

    
92
    public enum Severity
93
    {
94
        Info,
95
        Warn,
96
        Error
97
    }
98
}