2 /* -----------------------------------------------------------------------
3 * <copyright file="MessageView.xaml.cs" company="GRNet">
5 * Copyright 2011-2012 GRNET S.A. All rights reserved.
7 * Redistribution and use in source and binary forms, with or
8 * without modification, are permitted provided that the following
11 * 1. Redistributions of source code must retain the above
12 * copyright notice, this list of conditions and the following
15 * 2. Redistributions in binary form must reproduce the above
16 * copyright notice, this list of conditions and the following
17 * disclaimer in the documentation and/or other materials
18 * provided with the distribution.
21 * THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
22 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
23 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
24 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
25 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
28 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
29 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32 * POSSIBILITY OF SUCH DAMAGE.
34 * The views and conclusions contained in the software and
35 * documentation are those of the authors and should not be
36 * interpreted as representing official policies, either expressed
37 * or implied, of GRNET S.A.
39 * -----------------------------------------------------------------------
43 using System.Collections.Generic;
44 using System.Collections.ObjectModel;
45 using System.ComponentModel;
46 using System.ComponentModel.Composition;
48 using System.Linq.Expressions;
50 using System.Net.Mail;
53 using System.Windows.Controls;
54 using System.Windows.Data;
55 using System.Windows.Documents;
56 using System.Windows.Input;
57 using System.Windows.Media;
58 using System.Windows.Media.Imaging;
59 using System.Windows.Shapes;
61 using Pithos.Client.WPF.Shell;
64 namespace Pithos.Client.WPF
67 /// Interaction logic for MessageView.xaml
69 public partial class MessageView : Window, INotifyPropertyChanged
71 public ObservableCollection<UserMessage> UserMessages { get; set; }
73 private string _message;
83 NotifyOfPropertyChange(()=>Message);
88 public MessageView(IEnumerable<UserMessage> userMessages)
90 UserMessages = new ObservableCollection<UserMessage>(userMessages);
92 InitializeComponent();
97 public MessageView(WebException exception)
100 InitializeComponent();
102 var messages = new List<UserMessage>();
104 if ((exception.Response as HttpWebResponse).StatusCode == HttpStatusCode.Unauthorized)
106 Message = "Your authorization token has expired. Please renew the token and try again ";
107 Title = "Authorization expired";
111 messages.Add(new UserMessage
113 Message = exception.InnerException.Message,
114 Details = exception.InnerException.ToString(),
115 Severity = Severity.Warn
117 Message = "There was an error while retrieving the item's information";
120 UserMessages = new ObservableCollection<UserMessage>(messages);
123 public MessageView(RetryException exception)
126 InitializeComponent();
128 var messages = new List<UserMessage>{
130 Message = exception.InnerException.Message,
131 Details = exception.InnerException.ToString(),
132 Severity = Severity.Warn
136 Title = "Network error";
137 Message = "The connection to the server timed out. Please check your network connection and try again later";
139 UserMessages = new ObservableCollection<UserMessage>(messages);
142 public MessageView(Exception exception)
145 InitializeComponent();
147 var messages = new List<UserMessage>{
149 Message = exception.InnerException.Message,
150 Details = exception.InnerException.ToString(),
151 Severity = Severity.Warn
155 Title = "Unexpected error";
156 Message = "An unexpected error has occured";
158 UserMessages = new ObservableCollection<UserMessage>(messages);
162 /// Copies the messages to the clipboard
164 private void OnCopy(object sender, ExecutedRoutedEventArgs e)
166 var text = GetLogText();
167 Clipboard.SetText(text);
170 private string GetLogText()
172 StringBuilder logText = new StringBuilder()
174 .AppendLine("\r\nPithos")
178 foreach (var message in UserMessages)
182 .AppendFormat("\r\n[{0,5}]\t{1}", message.Severity, message.Message)
184 .AppendLine(message.Details)
188 var text = logText.ToString();
192 private void OnClose(object sender, ExecutedRoutedEventArgs e)
197 public event PropertyChangedEventHandler PropertyChanged;
199 private void NotifyOfPropertyChange<TProperty>(Expression<Func<TProperty>> property)
201 if (PropertyChanged!=null)
202 PropertyChanged(this,new PropertyChangedEventArgs(property.GetMemberInfo().Name));
205 private void OnSend(object sender, RoutedEventArgs e)
207 var manager=IoC.Get<IWindowManager>();
208 var logText = GetLogText();
209 var feedBack = IoC.Get<FeedbackViewModel>();
210 feedBack.AppendData(logText);
211 manager.ShowWindow(feedBack);
216 public class UserMessage
218 public string Message { get; set; }
220 public Severity Severity { get; set; }
221 public string Details { get; set; }