1 // -----------------------------------------------------------------------
2 // <copyright file="FeedbackViewModel.cs" company="Microsoft">
3 // TODO: Update copyright text.
5 // -----------------------------------------------------------------------
7 using System.Collections.Specialized;
8 using System.ComponentModel.Composition;
9 using System.Diagnostics;
10 using System.Diagnostics.Contracts;
13 using System.Reflection;
16 using Pithos.Client.WPF.Properties;
18 namespace Pithos.Client.WPF.Shell
21 using System.Collections.Generic;
26 /// TODO: Update summary.
28 [Export(typeof(FeedbackViewModel))]
29 public class FeedbackViewModel:Screen
31 public string Message { get; set; }
33 public string Data { get; set; }
35 private IWindowManager _windowManager;
37 private static readonly log4net.ILog Log = log4net.LogManager.GetLogger("Pithos");
40 [ImportingConstructor]
41 public FeedbackViewModel(IWindowManager windowManager)
43 _windowManager = windowManager;
44 Data = GetBasicData() ;
47 public void AppendData(string data)
49 Data = Data + "\r\n" + data;
52 private string GetBasicData()
54 Assembly assembly = Assembly.GetExecutingAssembly();
56 var attributes = assembly.GetCustomAttributes(false);
57 var versionAtt = attributes.OfType<AssemblyInformationalVersionAttribute>().First();
58 var fileVersion = FileVersionInfo.GetVersionInfo(assembly.Location);
59 var released = DateTime.Parse(versionAtt.InformationalVersion);
62 var builder = new StringBuilder();
64 builder.AppendLine("Pithos Windows Client")
67 .AppendFormat("Released: {0}\r\n", released)
68 .AppendFormat("File Version: {0}\r\n", fileVersion.FileVersion)
69 .AppendFormat("Assembly Version: {0}\r\n", assembly.GetName().Version)
70 .AppendFormat("OS: {0} 64Bit: {1}\r\n",Environment.OSVersion,Environment.Is64BitOperatingSystem)
71 .AppendFormat("Wokring Set: {0} bytes\r\n", Environment.WorkingSet)
72 .AppendFormat("Processors: {0} \r\n", Environment.ProcessorCount)
75 var basicData = builder.ToString();
82 var message = "Pithos Windows Client Feedback:\r\n" +Message;
83 var fields = new Dictionary<string, string> { { "feedback-msg", message }, { "feedback-data", Data } };
85 if (Settings.Default.Accounts.Count>0)
86 token = Settings.Default.Accounts[0].ApiKey;
89 PostForm(Settings.Default.FeedbackUri, token,fields);
93 Log.Error("Failed to submit feedback",exc);
94 MessageBox.Show("There was an error while submitting your feedback. The error was logged", "Failed to submit feedback",
95 MessageBoxButton.OK, MessageBoxImage.Error);
101 private void PostForm(string formUrl, string token,Dictionary<string, string> fields)
104 if (String.IsNullOrWhiteSpace(formUrl))
105 throw new ArgumentNullException("formUrl");
106 if (String.IsNullOrWhiteSpace(token))
107 throw new ArgumentNullException("token");
109 throw new ArgumentNullException("fields");
110 Contract.EndContractBlock();
113 var client = new WebClient();
114 client.Headers.Add("X-Auth-Token", token);
116 var values=new NameValueCollection();
117 fields.Apply(field => values.Add(field.Key, Uri.EscapeDataString(field.Value)));
120 client.UploadValues(formUrl, values);
122 catch (WebException exc)
124 Log.WarnFormat("Unexpected status returned from feedback form: {0} - {1}", exc.Status,exc.Message);