private void uxSelectFiles_Click(object sender, RoutedEventArgs e)
		{
			var of = new OpenFileDialog();
			of.Multiselect = true;
			of.Filter = "All Files (*.*)|*.*";
			if (of.ShowDialog() ?? false)
			{
				long total = 0;
				if (currentSettings.UploadFilesIndividually)
					total = of.Files.Max(o => o.Length);
				else
					total = of.Files.Sum(o => o.Length);

				//this amount doesn't consider message overhead size; so really we could probably add 200-300 bytes to the file sizes and compare against that. 
				total += 300; //this is just an arbitrary amount; semi-safe guess.
				total /= 1024; //convert to KB

				if (total <= currentSettings.MaxUploadSize)
				{
					try
					{
						IHttpUtility utility = null;
						if (currentSettings.UploadChunked)
							utility = new HttpChunkUtility(currentSettings.ChunkSize);
						else
							utility = new HttpUtility();

						utility.UploadCompleted += new Action<UploadCompletedEventArgs>(utility_UploadCompleted);
						utility.FileSequenceProgressReport += new Action<ProgressReportEventArgs>(utility_FileSequenceProgressReport);
						utility.FileContentProgressReport += new Action<ProgressReportEventArgs>(utility_FileContentProgressReport);

						callScriptStartup();
						utility.PostFileContents(currentSettings.PostUrl,
							of.Files, currentSettings.UploadFilesIndividually ? FilePostBehavior.OneAtATime : FilePostBehavior.AllAtOnce,
							currentSettings.CustomData,
							this.Dispatcher); //default chunk
					}
					catch (Exception ex)
					{
						utility_UploadCompleted(new UploadCompletedEventArgs() { Success = false, Message = ex.Message });
					}
				}
				else
					utility_UploadCompleted(new UploadCompletedEventArgs() { Success = false, Message = string.Format("File size too large. The current files size limit is, {0} MB" , (currentSettings.MaxUploadSize / 1024 ).ToString("N2"))});
			}
		}
Beispiel #2
0
        private void uxSelectFiles_Click(object sender, RoutedEventArgs e)
        {
            var of = new OpenFileDialog();

            of.Multiselect = true;
            of.Filter      = "All Files (*.*)|*.*";
            if (of.ShowDialog() ?? false)
            {
                long total = 0;
                if (currentSettings.UploadFilesIndividually)
                {
                    total = of.Files.Max(o => o.Length);
                }
                else
                {
                    total = of.Files.Sum(o => o.Length);
                }

                //this amount doesn't consider message overhead size; so really we could probably add 200-300 bytes to the file sizes and compare against that.
                total += 300;                 //this is just an arbitrary amount; semi-safe guess.
                total /= 1024;                //convert to KB

                if (total <= currentSettings.MaxUploadSize)
                {
                    try
                    {
                        IHttpUtility utility = null;
                        if (currentSettings.UploadChunked)
                        {
                            utility = new HttpChunkUtility(currentSettings.ChunkSize);
                        }
                        else
                        {
                            utility = new HttpUtility();
                        }

                        utility.UploadCompleted            += new Action <UploadCompletedEventArgs>(utility_UploadCompleted);
                        utility.FileSequenceProgressReport += new Action <ProgressReportEventArgs>(utility_FileSequenceProgressReport);
                        utility.FileContentProgressReport  += new Action <ProgressReportEventArgs>(utility_FileContentProgressReport);

                        callScriptStartup();
                        utility.PostFileContents(currentSettings.PostUrl,
                                                 of.Files, currentSettings.UploadFilesIndividually ? FilePostBehavior.OneAtATime : FilePostBehavior.AllAtOnce,
                                                 currentSettings.CustomData,
                                                 this.Dispatcher);        //default chunk
                    }
                    catch (Exception ex)
                    {
                        utility_UploadCompleted(new UploadCompletedEventArgs()
                        {
                            Success = false, Message = ex.Message
                        });
                    }
                }
                else
                {
                    utility_UploadCompleted(new UploadCompletedEventArgs()
                    {
                        Success = false, Message = string.Format("File size too large. The current files size limit is, {0} MB", (currentSettings.MaxUploadSize / 1024).ToString("N2"))
                    });
                }
            }
        }