protected virtual void OnUploadCompleted(UploadCompleteEventArgs e)
        {
            UploadCompleteEventHandler handler = UploadComplete;

            if (handler != null)
            {
                handler(this, e);
            }
        }
예제 #2
0
 void server_UploadComplete(object sender, UploadCompleteEventArgs e)
 {
     if (e.success)
     {
         if (File.Exists(GetSaveFolder() + e.frame.FileName))
         {
             File.Delete(GetSaveFolder() + e.frame.FileName);
             logInstance.Debug("Deleting {0}", e.frame.FileName);
         }
     }
 }
        /// <summary>
        /// Posts a JSON representation of a frame to the "/frames" page of the website
        /// </summary>
        /// <param name="pFrame">Frame to upload</param>
        private void UploadFrame(Frame pFrame)
        {
            logInstance.Debug("Attempting to Upload " + pFrame.FileName);
            Uri fullurl = new Uri(url + "/frames");

            bool success = false;
            int  retries = 5;


            while (retries > 0 && success == false)
            {
                retries--;

                try
                {
                    using (var client = new HttpClient())
                        using (var content = new StringContent(pFrame.GetJSON()))
                        {
                            client.Timeout = new TimeSpan(0, 0, 30);
                            content.Headers.Remove("Content-type");
                            content.Headers.Add("Content-type", "application/json");

                            logInstance.Debug("Attempting to Send " + pFrame.FileName);
                            var response = client.PostAsync(fullurl, content).Result;

                            logInstance.Debug("Post Completed or Timed Out");
                            logInstance.Debug(pFrame.FileName + " Upload Response: " + response.StatusCode);
                            if (response.IsSuccessStatusCode)
                            {
                                success = true;
                            }
                        }
                }
                catch (Exception ex)
                {
                    logInstance.ErrorException(pFrame.FileName + " Upload Error", ex);
                }
            }

            UploadCompleteEventArgs args = new UploadCompleteEventArgs(pFrame, success);

            OnUploadCompleted(args);
        }