Event arguments during processing of a single file or directory.
Inheritance: System.EventArgs
Example #1
0
 void ShowProgress(object sender, ProgressEventArgs e)
 {
     // Very ugly but this is a sample!
     Console.WriteLine("{0}%", e.PercentComplete);
 }
		/// <summary>
		/// Copy the contents of one <see cref="Stream"/> to another.
		/// </summary>
		/// <param name="source">The stream to source data from.</param>
		/// <param name="destination">The stream to write data to.</param>
		/// <param name="buffer">The buffer to use during copying.</param>
		/// <param name="progressHandler">The <see cref="ProgressHandler">progress handler delegate</see> to use.</param>
		/// <param name="updateInterval">The minimum <see cref="TimeSpan"/> between progress updates.</param>
		/// <param name="sender">The source for this event.</param>
		/// <param name="name">The name to use with the event.</param>
		/// <param name="fixedTarget">A predetermined fixed target value to use with progress updates.
		/// If the value is negative the target is calculated by looking at the stream.</param>
		/// <remarks>This form is specialised for use within #Zip to support events during archive operations.</remarks>
		static public void Copy(Stream source, Stream destination,
			byte[] buffer, 
			ProgressHandler progressHandler, TimeSpan updateInterval, 
			object sender, string name, long fixedTarget)
		{
			if (source == null) {
				throw new ArgumentNullException("source");
			}

			if (destination == null) {
				throw new ArgumentNullException("destination");
			}

			if (buffer == null) {
				throw new ArgumentNullException("buffer");
			}

			// Ensure a reasonable size of buffer is used without being prohibitive.
			if (buffer.Length < 128) {
				throw new ArgumentException("Buffer is too small", "buffer");
			}

			if (progressHandler == null) {
				throw new ArgumentNullException("progressHandler");
			}

			bool copying = true;

			DateTime marker = DateTime.Now;
			long processed = 0;
			long target = 0;

			if (fixedTarget >= 0) {
				target = fixedTarget;
			}
			else if (source.CanSeek) {
				target = source.Length - source.Position;
			}

			// Always fire 0% progress..
			ProgressEventArgs args = new ProgressEventArgs(name, processed, target);
			progressHandler(sender, args);

			bool progressFired = true;

			while (copying) {
				int bytesRead = source.Read(buffer, 0, buffer.Length);
				if (bytesRead > 0) {
					processed += bytesRead;
					progressFired = false;
					destination.Write(buffer, 0, bytesRead);
				}
				else {
					destination.Flush();
					copying = false;
				}

				if (DateTime.Now - marker > updateInterval) {
					progressFired = true;
					marker = DateTime.Now;
					args = new ProgressEventArgs(name, processed, target);
					progressHandler(sender, args);

					copying = args.ContinueRunning;
				}
			}

			if (!progressFired) {
				args = new ProgressEventArgs(name, processed, target);
				progressHandler(sender, args);
			}
		}
Example #3
0
        /// <summary>
        /// Copy the contents of one <see cref="Stream"/> to another.
        /// </summary>
        /// <param name="source">The stream to source data from.</param>
        /// <param name="destination">The stream to write data to.</param>
        /// <param name="buffer">The buffer to use during copying.</param>
        /// <param name="progressHandler">The <see cref="ProgressHandler">progress handler delegate</see> to use.</param>
        /// <param name="updateInterval">The minimum <see cref="TimeSpan"/> between progress updates.</param>
        /// <param name="sender">The source for this event.</param>
        /// <param name="name">The name to use with the event.</param>
        /// <param name="fixedTarget">A predetermined fixed target value to use with progress updates.
        /// If the value is negative the target is calculated by looking at the stream.</param>
        /// <remarks>This form is specialised for use within #Zip to support events during archive operations.</remarks>
        static public void Copy(Stream source, Stream destination,
                                byte[] buffer,
                                ProgressHandler progressHandler, TimeSpan updateInterval,
                                object sender, string name, long fixedTarget)
        {
            if (source == null)
            {
                throw new ArgumentNullException("source");
            }

            if (destination == null)
            {
                throw new ArgumentNullException("destination");
            }

            if (buffer == null)
            {
                throw new ArgumentNullException("buffer");
            }

            // Ensure a reasonable size of buffer is used without being prohibitive.
            if (buffer.Length < 128)
            {
                throw new ArgumentException("Buffer is too small", "buffer");
            }

            if (progressHandler == null)
            {
                throw new ArgumentNullException("progressHandler");
            }

            bool copying = true;

            //DateTime marker = DateTime.Now;
            long processed = 0;
            long target    = 0;

            if (fixedTarget >= 0)
            {
                target = fixedTarget;
            }
            else if (source.CanSeek)
            {
                target = source.Length - source.Position;
            }

            // Always fire 0% progress..
            ProgressEventArgs args = new ProgressEventArgs(name, processed, target);

            progressHandler(sender, args);

            bool progressFired = true;

            while (copying)
            {
                int bytesRead = source.Read(buffer, 0, buffer.Length);
                if (bytesRead > 0)
                {
                    processed    += bytesRead;
                    progressFired = false;
                    destination.Write(buffer, 0, bytesRead);
                }
                else
                {
                    destination.Flush();
                    copying = false;
                }

                /*jordenwu
                 *              if (DateTime.Now - marker > updateInterval) {
                 *                      progressFired = true;
                 *                      marker = DateTime.Now;
                 *                      args = new ProgressEventArgs(name, processed, target);
                 *                      progressHandler(sender, args);
                 *                      copying = args.ContinueRunning;
                 *              }*/
                copying = true;
            }

            if (!progressFired)
            {
                args = new ProgressEventArgs(name, processed, target);
                progressHandler(sender, args);
            }
        }
Example #4
0
 private static void DummyProgressHandler(object sender, ProgressEventArgs e)
 {
 }
Example #5
0
        public static void Copy(Stream source, Stream destination, byte[] buffer, ProgressHandler progressHandler, TimeSpan updateInterval, object sender, string name, long fixedTarget)
        {
            if (source == null)
            {
                throw new ArgumentNullException("source");
            }
            if (destination == null)
            {
                throw new ArgumentNullException("destination");
            }
            if (buffer == null)
            {
                throw new ArgumentNullException("buffer");
            }
            if (buffer.Length < 128)
            {
                throw new ArgumentException("Buffer is too small", "buffer");
            }
            if (progressHandler == null)
            {
                throw new ArgumentNullException("progressHandler");
            }
            bool     flag   = true;
            DateTime now    = DateTime.Now;
            long     num    = 0L;
            long     target = 0L;

            if (fixedTarget >= 0L)
            {
                target = fixedTarget;
            }
            else if (source.CanSeek)
            {
                target = source.Length - source.Position;
            }
            ProgressEventArgs progressEventArgs = new ProgressEventArgs(name, num, target);

            progressHandler(sender, progressEventArgs);
            bool flag2 = true;

            while (flag)
            {
                int num2 = source.Read(buffer, 0, buffer.Length);
                if (num2 > 0)
                {
                    num  += (long)num2;
                    flag2 = false;
                    destination.Write(buffer, 0, num2);
                }
                else
                {
                    destination.Flush();
                    flag = false;
                }
                if (DateTime.Now - now > updateInterval)
                {
                    flag2             = true;
                    now               = DateTime.Now;
                    progressEventArgs = new ProgressEventArgs(name, num, target);
                    progressHandler(sender, progressEventArgs);
                    flag = progressEventArgs.ContinueRunning;
                }
            }
            if (!flag2)
            {
                progressEventArgs = new ProgressEventArgs(name, num, target);
                progressHandler(sender, progressEventArgs);
            }
        }