internal DeliveryFileDownloadOperation(DeliveryFile file, FileDownloadOperation operation)
        {
            this.DeliveryFile = file;

            _innerOperation             = operation;
            _innerOperation.Progressed += new EventHandler <ProgressEventArgs>(_innerOperation_Progressed);
            _innerOperation.Ended      += new EventHandler <EndedEventArgs>(_innerOperation_Ended);
        }
        /// <summary>
        /// Downloads a file from a raw stream.
        /// </summary>
        public static FileDownloadOperation Download(Stream sourceStream, string targetLocation, bool async = true, long length = -1)
        {
            Uri uri;

            try
            {
                //check how to ensure that targetLocation is relative
                uri = new Uri(targetLocation, UriKind.Relative);
            }
            catch (Exception ex)
            {
                throw new ArgumentException("Invalid target location - path must be relative. See inner exception for details.", "targetLocation", ex);
            }

            // Get full path
            string fullPath = Path.Combine(AppSettings.Get(typeof(FileManager), "RootPath"), uri.ToString());

            // Get length from stream only if length was not specified
            if (length <= 0 && sourceStream.CanSeek)
            {
                length = sourceStream.Length;
            }

            // Object returned to caller for monitoring progress
            FileDownloadOperation fileDownLoadOperation = new FileDownloadOperation()
            {
                IsAsync  = async,
                FileInfo = new FileInfo()
                {
                    Location   = uri.ToString(),
                    TotalBytes = length
                },
                Stream     = sourceStream,
                TargetPath = fullPath
            };

            return(fileDownLoadOperation);
        }