private async void buttonShare_Click(object sender, RoutedEventArgs e)
        {
            var popup = new ToolTip();

            popup.BorderBrush     = new SolidColorBrush(Colors.LightGray);
            popup.BorderThickness = new Thickness(2);
            popup.Background      = new SolidColorBrush(Colors.Black);
            var stack = new StackPanel();

            stack.Margin = new Thickness(5);
            var text = new TextBlock()
            {
                Text = "Uploading image...", Foreground = new SolidColorBrush(Colors.White), FontSize = 20, Margin = new Thickness(0, 5, 0, 5)
            };
            var progress = new ProgressBar()
            {
                Foreground = Foreground = new SolidColorBrush(Colors.SteelBlue), Margin = new Thickness(0, 5, 0, 5), Height = 15
            };

            stack.Children.Add(text);
            stack.Children.Add(progress);
            popup.Content         = stack;
            popup.PlacementTarget = this;
            popup.Placement       = PlacementMode.Center;
            popup.IsOpen          = true;
            var client = new System.Net.WebClient();

            client.UploadProgressChanged += (send, arg) => {
                progress.Value = arg.ProgressPercentage;
            };
#if DEBUG
            var url = "https://localhost:44355/ImageShare";
#else
            var url = "https://lucency.co/ImageShare";
#endif
            byte[] response = new byte[0];
            try
            {
                response = await client.UploadFileTaskAsync(new Uri(url), SaveFilePath);
            }
            catch (System.Net.WebException)
            {
                popup.IsOpen = false;
                MessageBox.Show("There was a problem uploading the image.  Your internet connection may not be working, or the web service may be temporarily unavailable.", "Upload Error", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }
            var strResponse = Encoding.UTF8.GetString(response);
            popup.IsOpen = false;
            Process.Start(strResponse);
        }
        private async void ScanFileButton_Click(object sender, RoutedEventArgs e)
        {
            OpenFileDialog openFileDialog = new OpenFileDialog();

            openFileDialog.Filter = "(Support Files)|*.doc;*.docx;*.odf;*.pdf;*.ppt;*.pptx;*.ps;*.rtf;*.txt;*.xls;*.xlsx";
            if (openFileDialog.ShowDialog() == true)
            {
                string filePath = openFileDialog.FileName;
                string fileName = Path.GetFileNameWithoutExtension(filePath);

                ProgressDialogController progressDialog = await this.ShowProgressAsync("Processing...", "Always smile and happy :)");

                progressDialog.SetIndeterminate();
                try
                {
                    if (progressDialog.IsOpen)
                    {
                        using (System.Net.WebClient webClient = new System.Net.WebClient())
                        {
                            byte[] response = await webClient.UploadFileTaskAsync(new Uri("https://translate.googleusercontent.com/translate_f?tl=" + LanguageDictionary.GetTranslateLanguageCode(TranslateLanguageSelected)), filePath);

                            string dataFilePath = Path.Combine(App.SCANFILE_PATH, fileName + "_" + LanguageDictionary.GetTranslateLanguageCode(TranslateLanguageSelected) + ".html");
                            File.WriteAllBytes(dataFilePath, response);
                            await Task.Delay(4000);

                            Process.Start(dataFilePath);
                            await progressDialog.CloseAsync();
                        }
                    }
                }
                catch (OperationCanceledException ex)
                {
                    await progressDialog.CloseAsync();

                    MessageBox.Show("Scan file Error: " + ex.Message, "Error", MessageBoxButton.OK);
                }
                catch (Exception ex)
                {
                    await progressDialog.CloseAsync();

                    MessageBox.Show("Scan file Error: " + ex.Message, "Error", MessageBoxButton.OK);
                }
            }
        }
Exemple #3
0
        public async Task UploadWorld(CommandContext ctx, string world)
        {
            if (ctx.Message.Attachments.Count == 0)
            {
                throw new ArgumentNullException("Attachments", "The world must have an attachment");
            }

            if (string.IsNullOrWhiteSpace(world))
            {
                throw new ArgumentNullException("world");
            }

            //We are working
            await ctx.TriggerTypingAsync();

            //Download the file, then upload it again
            var url = ctx.Message.Attachments[0].Url;

            using (var client = new System.Net.WebClient())
            {
                string tmpname = Path.GetTempFileName();
                try
                {
                    //Throws unauth
                    await client.DownloadFileTaskAsync(new Uri(url), tmpname);

                    byte[] response = await client.UploadFileTaskAsync(new Uri($"http://localhost:8000/world/{world}"), tmpname);

                    await ctx.ReplyAsync(content : Encoding.UTF8.GetString(response));
                }
                catch (Exception e)
                {
                    await ctx.ReplyExceptionAsync(e);
                }
                finally
                {
                    if (File.Exists(tmpname))
                    {
                        File.Delete(tmpname);
                    }
                }
            }
        }