コード例 #1
0
        public override bool Upload(UploadService activeService, ExtendedScreenshot screenshot)
        {
            if (InProgress)
                return false;

            Trace.WriteLine("Starting upload process...", string.Format("FormsUploader.Upload [{0}]", System.Threading.Thread.CurrentThread.Name));

            this.ActiveService = activeService;
            this.InProgress = true;
            OnUploadStarted(new EventArgs());

            try
            {
                using (var wc = new WebClient())
                {
                    wc.UploadProgressChanged += UploadProgressChanged;
                    wc.UploadValuesCompleted += UploadValuesCompleted;

                    var bg = new BackgroundWorker();
                    bg.DoWork += (o, a) =>
                        {
                            Trace.WriteLine("Starting stream conversion... ", string.Format("FormsUploader.Upload.DoWork [{0}]", System.Threading.Thread.CurrentThread.Name));

                            var ImageData = string.Empty;
                            using (var ms = screenshot.EditedScreenshotPNGImageStream())
                                ImageData = Convert.ToBase64String(ms.ToArray());

                            var CurrentUploadValues = new NameValueCollection();
                            foreach (var k in activeService.UploadValues.AllKeys.ToList())
                                CurrentUploadValues.Add(k, activeService.UploadValues[k].Replace("%i", ImageData));

                            Trace.WriteLine("Stream conversion complete.", string.Format("FormsUploader.Upload.DoWork [{0}]", System.Threading.Thread.CurrentThread.Name));
                            Trace.WriteLine("Starting async upload...", string.Format("FormsUploader.Upload.DoWork [{0}]", System.Threading.Thread.CurrentThread.Name));

                            wc.UploadValuesAsync(new Uri(activeService.EndpointUrl), CurrentUploadValues);

                            Trace.WriteLine("Upload start complete.", string.Format("FormsUploader.Upload.DoWork [{0}]", System.Threading.Thread.CurrentThread.Name));
                        };
                    bg.RunWorkerAsync();
                }

                return true;
            }
            catch (Exception ex)
            {
                Trace.WriteLine(string.Format("Exception occurred during upload: {0}", ex.GetBaseException()), string.Format("FormsUploader.Upload [{0}]", System.Threading.Thread.CurrentThread.Name));

                InProgress = false;
                OnUploadEnded(new UploaderEndedEventArgs(ex.GetBaseException()));

                return false;
            }
        }
コード例 #2
0
        public UploadServiceProperties(UploadService selectedUploadService)
        {
            InitializeComponent();

            this.MinimumSize = this.Size;
            this.SelectedUploadService = selectedUploadService;

            tbUploadServiceName.Text = SelectedUploadService.Name;
            tbUploadServiceUrl.Text = SelectedUploadService.EndpointUrl;

            foreach (var k in SelectedUploadService.UploadValues.Keys)
            {
                dataGridView1.Rows.Add(new [] { k, selectedUploadService.UploadValues[(string)k] });
            }

            tbImageLinkXPath.Text = SelectedUploadService.ImageLinkXPath;
            tbDeleteLinkXPath.Text = SelectedUploadService.DeleteLinkXPath;
        }
コード例 #3
0
 public abstract bool Upload(UploadService activeService, ExtendedScreenshot screenshot);