private void TriggerUploadItemComplete(UploadItemResult result) { if (this.UploadItemComplete != null) { this.UploadItemComplete.Invoke(this, result); } }
public void UploadItem(String editorId, String key, String filename, Stream data) { UriBuilder ub = new UriBuilder(UPLOAD_ITEM_URL); ub.Query = string.Format("filename={0}&key={1}&editor_id={2}", filename, key, editorId); HttpWebRequest request = (HttpWebRequest)WebRequest.Create(ub.Uri); request.Method = "POST"; try { ThreadPool.QueueUserWorkItem((object state) => { request.BeginGetRequestStream(delegate(IAsyncResult result) { HttpWebRequest reqstate = (HttpWebRequest)result.AsyncState; Stream postStream = reqstate.EndGetRequestStream(result); PushData(data, postStream); postStream.Close(); reqstate.BeginGetResponse(delegate(IAsyncResult result2) { WebResponse response = ((HttpWebRequest)result2.AsyncState).EndGetResponse(result2); StreamReader reader = new StreamReader(response.GetResponseStream()); string responseString = reader.ReadToEnd(); reader.Close(); response.Close(); UploadItemResult resultItems = JsonConvert.DeserializeObject <UploadItemResult>(responseString); Debug.WriteLine("UploadItem operation successful: " + resultItems); this.TriggerUploadItemComplete(resultItems); } , reqstate); }, request); }); } catch (Exception e) { Debug.WriteLine("Failed to submit task to thread pool: " + e.Message); this.TriggerUploadItemFailed(e); } }