using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Net; using System.Net.Browser; using System.Reflection; using System.Text; using System.Windows; using System.Windows.Controls; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Animation; using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Resources; using System.Windows.Shapes; using Juick.Classes; using Microsoft.Phone.Controls; using Microsoft.Phone.Tasks; using Microsoft.Xna.Framework.Media; using RestSharp; namespace Juick { public partial class NewPostView : PhoneApplicationPage { private PhotoChooserTask chooser; public NewPostView() { InitializeComponent(); } // When page is navigated to set data context to selected item in list protected override void OnNavigatedTo(NavigationEventArgs e) { string _rid, _mid; if (NavigationContext.QueryString.TryGetValue("mid", out _mid)) { PageTitle.Text = "reply"; button1.Content = "reply"; textBox1.Text = "#" + _mid; } if (NavigationContext.QueryString.TryGetValue("rid", out _rid)) { textBox1.Text += "/" + _rid; } } private void button1_Click(object sender, RoutedEventArgs e) { var request = new RestRequest("/post", Method.POST); request.AddParameter("body", textBox1.Text); if (image1.Source != null) { using (var ms = new MemoryStream()) { var wb = new WriteableBitmap(image1, null); wb.SaveJpeg(ms, (int) image1.Width, (int) image1.Height, 0, 100); request.AddFile("attach", ms.ToArray(), "file.jpg"); } } App.Client.ExecuteAsync(request, response => { if (response.StatusCode != HttpStatusCode.OK) { MessageBox.Show(response.StatusCode.ToString()); } }); NavigationService.Navigate(new Uri("/MainPage.xaml", UriKind.Relative)); Dispatcher.BeginInvoke(() => NavigationService.RemoveBackEntry()); } private void button2_Click(object sender, RoutedEventArgs e) { chooser = new PhotoChooserTask {ShowCamera = true}; chooser.Completed += (o, result) => { if (result.TaskResult == TaskResult.OK) { BinaryReader reader = new BinaryReader(result.ChosenPhoto); image1.Source = new BitmapImage(new Uri(result.OriginalFileName)); } }; chooser.Show(); } } }