Example #1
0
        private void captureAndUploadScreenShot()
        {
            this.Topmost = false;
            this.Width = 1;
            this.Height = 1;

            var rect = getRectFromXY();
            var bitmap = ScreenCaptureUtil.CaptureScreenShot(rect);

            var uploadConfig = new UploadConfig();
            foreach (var name in imageUploaders.Select(x => x.GetType().Name))
            {
                uploadConfig.UploaderTypeNameList.Add(name);
            }

            loadConfig(uploadConfig);
            if (string.IsNullOrEmpty(uploadConfig.UploaderTypeName) ||
                !imageUploaders.Where(x => x.GetType().Name == uploadConfig.UploaderTypeName).Any())
            {
                uploadConfig.UploaderTypeName = typeof (MediaWikiUploader).Name;
            }

            var infoWindow = new UploadInfoWindow();
            infoWindow.DataContext = uploadConfig;
            infoWindow.Owner = this;
            infoWindow.ShowDialog();

            if (!infoWindow.ClosedWithUploadButton)
            {
                Application.Current.Shutdown();
            }

            var uploader = imageUploaders.Where(x => x.GetType().Name == uploadConfig.UploaderTypeName).First();

            Uri uri = null;
            try
            {
                uri = uploader.UploadImage(bitmap, uploadConfig);
            }
            catch (UploadFailedException ex)
            {
                MessageBox.Show(this, "An error ocurred when uploading: " + ex.Message);
            } catch (Exception ex) {
                MessageBox.Show(this, "An error ocurred when uploading: " + ex.ToString());
            }
            saveConfig(uploadConfig);

            if (uri != null)
                System.Diagnostics.Process.Start(uri.ToString());
        }
Example #2
0
        private void saveConfig(UploadConfig config)
        {
            Settings.Default.UploaderTypeName = config.UploaderTypeName;
            Settings.Default.Url = config.Url;
            Settings.Default.UserName = config.UserName;
            Settings.Default.SavePassword = config.SavePassword;

            // FIXME: insecure
            if (config.SavePassword)
            {
                Settings.Default.Password = Convert.ToBase64String(Encoding.UTF8.GetBytes(config.Password));
            }
            else
            {
                Settings.Default.Password = "";
            }

            Settings.Default.Save();
        }
Example #3
0
        private void loadConfig(UploadConfig config)
        {
            config.UploaderTypeName = Settings.Default.UploaderTypeName;
            config.Url = Settings.Default.Url;
            config.UserName = Settings.Default.UserName;
            config.SavePassword = Settings.Default.SavePassword;

            // FIXME: insecure
            string passwordStr = Settings.Default.Password;
            if (!String.IsNullOrEmpty(passwordStr))
            {
                config.Password = Encoding.UTF8.GetString(Convert.FromBase64String(passwordStr));
            }
        }