public UploadCompletedEventArgs(SingleFileUploadStatus uploadResult, string serverFilePath)
     : base()
 {
     this.UploadResult   = uploadResult;
     this.ServerFilePath = serverFilePath;
 }
Beispiel #2
0
        private void WriteCallback(IAsyncResult asynchronousResult)
        {
            Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo(CPApplication.Current.LanguageCode);
            if (this.Status == UploadStatus.Canceling || cancel)
            {
                this.Status = UploadStatus.Canceled;
                return;
            }
            string responseString = "";
            SingleFileUploadStatus uploadResult = SingleFileUploadStatus.Success;

            try
            {
                HttpWebRequest  webrequest = (HttpWebRequest)asynchronousResult.AsyncState;
                HttpWebResponse response   = (HttpWebResponse)webrequest.EndGetResponse(asynchronousResult);
                using (StreamReader reader = new StreamReader(response.GetResponseStream()))
                {
                    responseString = reader.ReadToEnd();
                }
            }
            catch (System.Security.SecurityException ex)
            {
                this.Owner.ShowMessage(ex.Message, Newegg.Oversea.Silverlight.Controls.Components.MessageType.Error);
                this.TipsInfo = ResUploader.Uploader_SecurityError;
                this.Status   = UploadStatus.Error;
                uploadResult  = SingleFileUploadStatus.Failed;
                this.cancel   = true;
            }
            catch (Exception ex)
            {
                this.Owner.ShowMessage(ex.Message, Newegg.Oversea.Silverlight.Controls.Components.MessageType.Error);
                this.TipsInfo = ex.Message;
                this.Status   = UploadStatus.Error;
                uploadResult  = SingleFileUploadStatus.Failed;
                this.cancel   = true;
            }

            BytesUploaded += this.bytes;

            if (UploadProgressChanged != null)
            {
                int percent = (int)(((double)BytesUploaded / (double)FileLength) * 100);

                UploadPercent = percent;
                UploadProgressChangedEventArgs args = new UploadProgressChangedEventArgs(percent, bytesUploaded, BytesUploaded, FileLength, file.Name);
                this.Dispatcher.BeginInvoke(delegate()
                {
                    UploadProgressChanged(this, args);
                });
            }

            if (uploadResult == SingleFileUploadStatus.Failed)
            {
                this.Status   = UploadStatus.Error;
                this.TipsInfo = ResUploader.Uploader_UploadFailed;
            }
            else if (cancel)
            {
                if (remove)
                {
                    Status = UploadStatus.Removed;
                }
                else
                {
                    Status = UploadStatus.Canceled;
                }
            }
            else if (BytesUploaded < FileLength)
            {
                LoopUploadFile();
            }
            else
            {
                Status = UploadStatus.Complete;
            }

            if (Status == UploadStatus.Complete || Status == UploadStatus.Error || Status == UploadStatus.Canceled)
            {
                if (UploadCompleted != null)
                {
                    UploadCompleted(this, new UploadCompletedEventArgs(uploadResult, this.FileIdentity));
                }
            }
        }