root / trunk / Pithos.Client.WPF / Shell / MessageView.xaml.cs @ d53bbdf0
History | View | Annotate | Download (2.9 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.Net.Mail; |
9 |
using System.Text; |
10 |
using System.Windows; |
11 |
using System.Windows.Controls; |
12 |
using System.Windows.Data; |
13 |
using System.Windows.Documents; |
14 |
using System.Windows.Input; |
15 |
using System.Windows.Media; |
16 |
using System.Windows.Media.Imaging; |
17 |
using System.Windows.Shapes; |
18 |
using Caliburn.Micro; |
19 |
|
20 |
namespace Pithos.Client.WPF |
21 |
{ |
22 |
/// <summary> |
23 |
/// Interaction logic for MessageView.xaml |
24 |
/// </summary> |
25 |
public partial class MessageView : Window, INotifyPropertyChanged |
26 |
{ |
27 |
public ObservableCollection<UserMessage> UserMessages { get; set; } |
28 |
|
29 |
private string _message; |
30 |
public string Message |
31 |
{ |
32 |
get |
33 |
{ |
34 |
return _message; |
35 |
} |
36 |
set |
37 |
{ |
38 |
_message = value; |
39 |
NotifyOfPropertyChange(()=>Message); |
40 |
} |
41 |
} |
42 |
|
43 |
|
44 |
public MessageView(IEnumerable<UserMessage> userMessages) |
45 |
{ |
46 |
UserMessages = new ObservableCollection<UserMessage>(userMessages); |
47 |
DataContext = this; |
48 |
InitializeComponent(); |
49 |
} |
50 |
|
51 |
/// <summary> |
52 |
/// Copies the messages to the clipboard |
53 |
/// </summary> |
54 |
private void OnCopy(object sender, ExecutedRoutedEventArgs e) |
55 |
{ |
56 |
StringBuilder clipText = new StringBuilder() |
57 |
.Append('-', 30) |
58 |
.AppendLine("\r\nProduct Map") |
59 |
.Append('-', 30) |
60 |
.AppendLine() |
61 |
.AppendLine(); |
62 |
foreach (var message in UserMessages) |
63 |
{ |
64 |
clipText |
65 |
.Append('-', 20) |
66 |
.AppendFormat("\r\n[{0,5}]\t{1}", message.Severity, message.Message) |
67 |
.AppendLine() |
68 |
.AppendLine(message.Details) |
69 |
.AppendLine(); |
70 |
} |
71 |
|
72 |
Clipboard.SetText(clipText.ToString()); |
73 |
} |
74 |
|
75 |
private void OnClose(object sender, ExecutedRoutedEventArgs e) |
76 |
{ |
77 |
this.Close(); |
78 |
} |
79 |
|
80 |
public event PropertyChangedEventHandler PropertyChanged; |
81 |
|
82 |
private void NotifyOfPropertyChange<TProperty>(Expression<Func<TProperty>> property) |
83 |
{ |
84 |
if (PropertyChanged!=null) |
85 |
PropertyChanged(this,new PropertyChangedEventArgs(property.GetMemberInfo().Name)); |
86 |
} |
87 |
|
88 |
private void OnSend(object sender, RoutedEventArgs e) |
89 |
{ |
90 |
SmtpClient client=new SmtpClient(); |
91 |
} |
92 |
} |
93 |
|
94 |
public class UserMessage |
95 |
{ |
96 |
public string Message { get; set; } |
97 |
|
98 |
public Severity Severity { get; set; } |
99 |
public string Details { get; set; } |
100 |
} |
101 |
|
102 |
public enum Severity |
103 |
{ |
104 |
Info, |
105 |
Warn, |
106 |
Error |
107 |
} |
108 |
} |