#region /* ----------------------------------------------------------------------- * * * Copyright 2011-2012 GRNET S.A. All rights reserved. * * Redistribution and use in source and binary forms, with or * without modification, are permitted provided that the following * conditions are met: * * 1. Redistributions of source code must retain the above * copyright notice, this list of conditions and the following * disclaimer. * * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials * provided with the distribution. * * * THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * * The views and conclusions contained in the software and * documentation are those of the authors and should not be * interpreted as representing official policies, either expressed * or implied, of GRNET S.A. * * ----------------------------------------------------------------------- */ #endregion using System.Collections.Specialized; using System.ComponentModel.Composition; using System.Diagnostics; using System.Diagnostics.Contracts; using System.IO; using System.Net; using System.Reflection; using System.Windows; using Caliburn.Micro; using Pithos.Client.WPF.Properties; namespace Pithos.Client.WPF.Shell { using System; using System.Collections.Generic; using System.Linq; using System.Text; /// /// TODO: Update summary. /// [Export(typeof(FeedbackViewModel))] public class FeedbackViewModel:Screen { public string Message { get; set; } public string Data { get; set; } private IWindowManager _windowManager; private static readonly log4net.ILog Log = log4net.LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); [ImportingConstructor] public FeedbackViewModel(IWindowManager windowManager) { DisplayName = "Send Feedback"; _windowManager = windowManager; Data = GetBasicData() ; } public void AppendData(string data) { Data = Data + "\r\n" + data; } private string GetBasicData() { Assembly assembly = Assembly.GetExecutingAssembly(); var attributes = assembly.GetCustomAttributes(false); var versionAtt = attributes.OfType().First(); var fileVersion = FileVersionInfo.GetVersionInfo(assembly.Location); var released = DateTime.Parse(versionAtt.InformationalVersion); var builder = new StringBuilder(); builder.AppendLine("Pithos+ Windows Client") .Append('-', 30) .AppendLine() .AppendFormat("Released: {0}\r\n", released) .AppendFormat("File Version: {0}\r\n", fileVersion.FileVersion) .AppendFormat("Assembly Version: {0}\r\n", assembly.GetName().Version) .AppendFormat("OS: {0} 64Bit: {1}\r\n",Environment.OSVersion,Environment.Is64BitOperatingSystem) .AppendFormat("Wokring Set: {0} bytes\r\n", Environment.WorkingSet) .AppendFormat("Processors: {0} \r\n", Environment.ProcessorCount) .Append('=', 30) .AppendLine(); var basicData = builder.ToString(); return basicData; } public void Send() { var message = "Pithos+ Windows Client Feedback:\r\n" +Message; var fields = new Dictionary { { "feedback-msg", message }, { "feedback-data", Data } }; string token="0007"; if (Settings.Default.Accounts.Count>0) token = Settings.Default.Accounts[0].ApiKey; try { PostForm(Settings.Default.FeedbackUri, token,fields); } catch (Exception exc) { Log.Error("Failed to submit feedback",exc); MessageBox.Show("There was an error while submitting your feedback. The error was logged", "Failed to submit feedback", MessageBoxButton.OK, MessageBoxImage.Error); } TryClose(); } private void PostForm(string formUrl, string token,Dictionary fields) { if (String.IsNullOrWhiteSpace(formUrl)) throw new ArgumentNullException("formUrl"); if (String.IsNullOrWhiteSpace(token)) throw new ArgumentNullException("token"); if (fields == null) throw new ArgumentNullException("fields"); Contract.EndContractBlock(); var client = new WebClient(); client.Headers.Add("X-Auth-Token", token); var values=new NameValueCollection(); fields.Apply(field => values.Add(field.Key, Uri.EscapeDataString(field.Value))); try { client.UploadValues(formUrl, values); } catch (WebException exc) { Log.WarnFormat("Unexpected status returned from feedback form: {0} - {1}", exc.Status,exc.Message); } } } }