Work in progress for the Jira backport. [skip ci]

This commit is contained in:
Robin 2016-08-16 16:53:37 +02:00
commit a3f3c20d71
12 changed files with 402 additions and 4290 deletions

View file

@ -30,8 +30,8 @@ namespace GreenshotPlugin.Controls {
/// </summary>
public partial class PleaseWaitForm : Form {
private static readonly ILog LOG = LogManager.GetLogger(typeof(PleaseWaitForm));
private Thread waitFor;
private string title;
private Thread _waitFor;
private string _title;
public PleaseWaitForm() {
//
// The InitializeComponent() call is required for Windows Forms designer support.
@ -60,7 +60,7 @@ namespace GreenshotPlugin.Controls {
/// <param name="text">The text in the form</param>
/// <param name="waitDelegate">delegate { with your code }</param>
public void ShowAndWait(string title, string text, ThreadStart waitDelegate) {
this.title = title;
_title = title;
Text = title;
label_pleasewait.Text = text;
cancelButton.Text = Language.GetString("CANCEL");
@ -72,23 +72,29 @@ namespace GreenshotPlugin.Controls {
Exception threadException = null;
try {
// Wrap the passed delegate in a try/catch which makes it possible to save the exception
waitFor = new Thread(new ThreadStart(
delegate {
try {
waitDelegate.Invoke();
} catch (Exception ex) {
LOG.Error("invoke error:", ex);
threadException = ex;
}
})
);
waitFor.Name = title;
waitFor.IsBackground = true;
waitFor.SetApartmentState(ApartmentState.STA);
waitFor.Start();
_waitFor = new Thread(new ThreadStart(
delegate
{
try
{
waitDelegate.Invoke();
}
catch (Exception ex)
{
LOG.Error("invoke error:", ex);
threadException = ex;
}
})
)
{
Name = title,
IsBackground = true
};
_waitFor.SetApartmentState(ApartmentState.STA);
_waitFor.Start();
// Wait until finished
while (!waitFor.Join(TimeSpan.FromMilliseconds(100))) {
while (!_waitFor.Join(TimeSpan.FromMilliseconds(100))) {
Application.DoEvents();
}
LOG.DebugFormat("Finished {0}", title);
@ -110,9 +116,9 @@ namespace GreenshotPlugin.Controls {
/// <param name="sender"></param>
/// <param name="e"></param>
void CancelButtonClick(object sender, EventArgs e) {
LOG.DebugFormat("Cancel clicked on {0}", title);
LOG.DebugFormat("Cancel clicked on {0}", _title);
cancelButton.Enabled = false;
waitFor.Abort();
_waitFor.Abort();
}
}
}

View file

@ -555,6 +555,8 @@ namespace GreenshotPlugin.Core {
string ToBase64String(Base64FormattingOptions formattingOptions);
byte[] ToByteArray();
void Upload(HttpWebRequest webRequest);
string ContentType { get; }
}
/// <summary>
@ -634,6 +636,8 @@ namespace GreenshotPlugin.Core {
WriteToStream(requestStream);
}
}
public string ContentType => _contentType;
}
/// <summary>
@ -686,7 +690,7 @@ namespace GreenshotPlugin.Core {
boundary,
name,
_fileName ?? name,
"image/" + _outputSettings.Format);
ContentType);
formDataStream.Write(Encoding.UTF8.GetBytes(header), 0, Encoding.UTF8.GetByteCount(header));
ImageOutput.SaveToStream(_bitmap, null, formDataStream, _outputSettings);
@ -711,6 +715,8 @@ namespace GreenshotPlugin.Core {
WriteToStream(requestStream);
}
}
public string ContentType => "image/" + _outputSettings.Format;
}
/// <summary>
@ -763,7 +769,7 @@ namespace GreenshotPlugin.Core {
boundary,
name,
_fileName ?? name,
"image/" + _outputSettings.Format);
ContentType);
formDataStream.Write(Encoding.UTF8.GetBytes(header), 0, Encoding.UTF8.GetByteCount(header));
ImageOutput.SaveToStream(_surface, formDataStream, _outputSettings);
@ -783,10 +789,12 @@ namespace GreenshotPlugin.Core {
/// </summary>
/// <param name="webRequest"></param>
public void Upload(HttpWebRequest webRequest) {
webRequest.ContentType = "image/" + _outputSettings.Format.ToString();
webRequest.ContentType = ContentType;
using (var requestStream = webRequest.GetRequestStream()) {
WriteToStream(requestStream);
}
}
public string ContentType => "image/" + _outputSettings.Format;
}
}