private void FileOperationProgressChanged(object sender, FileDataTransferEventArgs e)
		{
			var task = (Task)e.CustomnContext;
			
			if (task.IsCanceled)
			{
				e.Cancel = true;
			}
		}
        /// <summary>
        /// This method implements to clone interface to support a deep copy
        /// of everything what we use to report the progress of a operation
        /// </summary>
        /// <returns></returns>
        public object Clone()
        {
            FileDataTransferEventArgs e = new FileDataTransferEventArgs()
            {
                CurrentBytes        = this.CurrentBytes,
                CustomnContext      = this.CustomnContext,
                FileSystemEntry     = this.FileSystemEntry,
                OpenTransferTime    = this.OpenTransferTime,
                PercentageProgress  = this.PercentageProgress,
                TotalBytes          = this.TotalBytes,
                TransferRateCurrent = this.TransferRateCurrent,
                TransferRateTotal   = this.TransferRateTotal,
                Cancel = false
            };

            return(e);
        }
        /// <summary>
        /// This method implements to clone interface to support a deep copy
        /// of everything what we use to report the progress of a operation
        /// </summary>
        /// <returns></returns>
        public object Clone()
        {
            var e = new FileDataTransferEventArgs
            {
                CurrentBytes        = CurrentBytes,
                CustomnContext      = CustomnContext,
                FileSystemEntry     = FileSystemEntry,
                OpenTransferTime    = OpenTransferTime,
                PercentageProgress  = PercentageProgress,
                TotalBytes          = TotalBytes,
                TransferRateCurrent = TransferRateCurrent,
                TransferRateTotal   = TransferRateTotal,
                Cancel = false
            };

            return(e);
        }
        /// <summary>
        /// Just a helper for the stream copy process
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="pe"></param>
        /// <param name="data"></param>
        /// <returns></returns>
        internal static StreamHelperResultCodes FileStreamCopyCallback(object sender, StreamHelperProgressEvent pe, params Object[] data)
        {
            // check array
            if (data.Length != 3)
            {
                return(StreamHelperResultCodes.OK);
            }

            // get the progess delegate
            var pc = data[0] as FileOperationProgressChanged;

            if (pc == null)
            {
                return(StreamHelperResultCodes.OK);
            }

            // get the file
            var e = data[1] as ICloudFileSystemEntry;

            if (e == null)
            {
                return(StreamHelperResultCodes.OK);
            }

            // get the progress context
            var progressContext = data[2];

            // create the eventargs element
            var arg = new FileDataTransferEventArgs
            {
                FileSystemEntry     = e,
                CurrentBytes        = pe.ReadBytesTotal,
                CustomnContext      = progressContext,
                PercentageProgress  = pe.PercentageProgress,
                TransferRateTotal   = pe.TransferRateTotal,
                TransferRateCurrent = pe.TransferRateCurrent,
                TotalBytes          = pe.TotalLength == -1 ? e.Length : pe.TotalLength
            };

            // calc transfertime
            if (pe.TransferRateTotal != -1 && pe.TransferRateTotal > 0)
            {
                var bytesPerSecond = (arg.TransferRateTotal / 8) * 1000;

                if (bytesPerSecond > 0)
                {
                    var neededSeconds = (arg.TotalBytes - arg.CurrentBytes) / bytesPerSecond;
                    arg.OpenTransferTime = new TimeSpan(neededSeconds * TimeSpan.TicksPerSecond);
                }
                else
                {
                    arg.OpenTransferTime = new TimeSpan(long.MaxValue);
                }
            }
            else
            {
                arg.OpenTransferTime = new TimeSpan(long.MaxValue);
            }

            // call it
            pc(sender, arg);

            // create the ret value
            if (arg.Cancel)
            {
                return(StreamHelperResultCodes.Aborted);
            }

            return(StreamHelperResultCodes.OK);
        }
        /// <summary>
        /// This method implements to clone interface to support a deep copy 
        /// of everything what we use to report the progress of a operation
        /// </summary>
        /// <returns></returns>
        public object Clone()
        {
            FileDataTransferEventArgs e = new FileDataTransferEventArgs()
            {
                CurrentBytes = this.CurrentBytes,
                CustomnContext = this.CustomnContext,
                FileSystemEntry = this.FileSystemEntry,
                OpenTransferTime = this.OpenTransferTime,
                PercentageProgress = this.PercentageProgress,
                TotalBytes = this.TotalBytes,
                TransferRateCurrent = this.TransferRateCurrent,
                TransferRateTotal = this.TransferRateTotal,
                Cancel = false
            };

            return e;
        }
Example #6
0
 static void UploadDownloadProgress(Object sender, FileDataTransferEventArgs e)
 {
     _worker.ReportProgress(e.PercentageProgress, new ProgressInfo(ProgressTypeEnum.ProgressType.Upload, e.PercentageProgress, 100));
     Console.WriteLine(e.PercentageProgress);
     e.Cancel = false;
 }
        /// <summary>
        /// Just a helper for the stream copy process
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="pe"></param>        
        /// <param name="data"></param>
        /// <returns></returns>
        internal static StreamHelperResultCodes FileStreamCopyCallback(object sender, StreamHelperProgressEvent pe, params Object[] data)
        {
            // check array
            if (data.Length != 3)
                return StreamHelperResultCodes.OK;

            // get the progess delegate
            FileOperationProgressChanged pc = data[0] as FileOperationProgressChanged;
            if (pc == null)
                return StreamHelperResultCodes.OK;

            // get the file
            ICloudFileSystemEntry e = data[1] as ICloudFileSystemEntry;
            if (e == null)
                return StreamHelperResultCodes.OK;

            // get the progress context
            Object progressContext = data[2];
            
            // create the eventargs element
            FileDataTransferEventArgs arg = new FileDataTransferEventArgs();

            arg.FileSystemEntry = e;
            arg.CurrentBytes = pe.ReadBytesTotal;
            arg.CustomnContext = progressContext;

            if (pe.TotalLength == -1)
                arg.TotalBytes = e.Length;
            else
                arg.TotalBytes = pe.TotalLength;

            arg.PercentageProgress = pe.PercentageProgress;
            arg.TransferRateTotal = pe.TransferRateTotal;
            arg.TransferRateCurrent = pe.TransferRateCurrent;
            
            // calc transfertime            
            if (pe.TransferRateTotal != -1 && pe.TransferRateTotal > 0 )
            {
                long bytesPerSecond = (arg.TransferRateTotal / 8) * 1000;

                if (bytesPerSecond > 0)
                {
                    long neededSeconds = (arg.TotalBytes - arg.CurrentBytes) / bytesPerSecond;
                    arg.OpenTransferTime = new TimeSpan(neededSeconds * TimeSpan.TicksPerSecond);
                }
                else
                    arg.OpenTransferTime = new TimeSpan(long.MaxValue);                       
            }
            else
                arg.OpenTransferTime = new TimeSpan(long.MaxValue);                       

            // call it
            pc(sender, arg);
            
            // create the ret value
            if (arg.Cancel)
                return StreamHelperResultCodes.Aborted;
            else
                return StreamHelperResultCodes.OK;
        }
 private void DownloadProcessChnage(Object sender, FileDataTransferEventArgs e)
 {
     e.Cancel = IsCancel;
     DownloadProgress = e.PercentageProgress;
 }
 private void UploadProgressChange(Object sender, FileDataTransferEventArgs e)
 {
     e.Cancel = IsCancel;
     UploadProgress = e.PercentageProgress;
 }