Пример #1
0
        /// <summary>
        /// Returns true if the specified item is going to be resized.
        /// </summary>
        /// <param name="i"></param>
        /// <returns></returns>
        public bool wouldResize(BatchResizeItem i)
        {
            //Can we resize it?
            bool resize = s.conf.Pipeline.IsAcceptedImageType(i.PhysicalPath);

            //Are we doing anything to it?
            if (String.IsNullOrEmpty(i.ResizeQuerystring))
            {
                resize = false;
            }
            return(resize);
        }
Пример #2
0
        /// <summary>
        /// Called when ZipFile.AddEntry fails. (Most errors should NOT happen here).
        /// </summary>
        /// <param name="i"></param>
        /// <param name="ex"></param>
        private void ItemFailed(BatchResizeItem i, Exception ex)
        {
            failedItems++;

            //Fire off the event
            ItemEventArgs args = new ItemEventArgs(s.jobId, new ItemResult(i, false, ex), GetJobStats());

            s.FireItemEvent(args);

            //Store for later
            results.Add(args.Result);

            //If a cancel is requested, fire an exception for Work to catch.
            throw new JobCancelledException("An event handler requested that the job be cancelled. The event handler was sent notification " +
                                            "that an item (\"" + i.TargetFilename + "\") could not be added to the zip file.", ex);
        }
Пример #3
0
        /// <summary>
        /// Called from ZipFile.Save as each queued entry is processed.
        /// </summary>
        /// <param name="entryName"></param>
        /// <param name="stream"></param>
        protected void WriteItemCallback(string entryName, System.IO.Stream stream)
        {
            BatchResizeItem i = items[entryName];

            if (wouldResize(i))
            {
                //Buffer in a memory stream to avoid stepping on CrcCalculatorStream's broken toes
                using (MemoryStream ms = new MemoryStream()) {
                    s.conf.CurrentImageBuilder.Build(i.PhysicalPath, ms, new ResizeSettings(i.ResizeQuerystring));
                    ms.Position = 0;
                    ms.CopyToStream(stream);
                }
                return; //We're done!
            }


            //For non-resizable items, just copy the stream.
            using (System.IO.FileStream s = System.IO.File.OpenRead(i.PhysicalPath)) CopyStreamTo(s, stream);
        }
Пример #4
0
        private void ItemCompleted(SaveProgressEventArgs e)
        {
            successfulItems++;

            BatchResizeItem i = items[e.CurrentEntry.FileName];

            //Fire off the event again..
            ItemEventArgs args = new ItemEventArgs(s.jobId, new ItemResult(i, true, null), GetJobStats());

            s.FireItemEvent(args);

            //Store for later
            results.Add(args.Result);

            //If an event handler wants to cancel the job, do so.
            if (args.Cancel)
            {
                e.Cancel = true;
            }
        }
Пример #5
0
        /// <summary>
        /// Called when an error occurs during Save() (which executes WriteItemCallback)
        /// </summary>
        /// <param name="e"></param>
        private void ItemFailed(ZipErrorEventArgs e)
        {
            failedItems++;

            e.CurrentEntry.ZipErrorAction = ZipErrorAction.Skip; //Prevent the item from crashing the job.

            BatchResizeItem i  = items[e.CurrentEntry.FileName];
            Exception       ex = e.Exception;
            //Fire off the event again..
            ItemEventArgs args = new ItemEventArgs(s.jobId, new ItemResult(i, false, ex), GetJobStats());

            s.FireItemEvent(args);

            //Store for later
            results.Add(args.Result);

            //If an event handler wants to cancel the job, do so.
            if (args.Cancel)
            {
                e.Cancel = true;
            }
        }
 public ItemResult(BatchResizeItem item, bool successful, Exception itemError)
 {
     this.item = item; this.successful = successful; this.itemError = itemError;
 }
Пример #7
0
 public ItemResult(BatchResizeItem item, bool successful, Exception itemError)
 {
     this.item = item; this.successful = successful; this.itemError = itemError;
 }
Пример #8
0
        /// <summary>
        /// Called when ZipFile.AddEntry fails. (Most errors should NOT happen here).
        /// </summary>
        /// <param name="i"></param>
        /// <param name="ex"></param>
        private void ItemFailed(BatchResizeItem i, Exception ex)
        {
            failedItems++;

            //Fire off the event
            ItemEventArgs args = new ItemEventArgs(s.jobId, new ItemResult(i,false, ex), GetJobStats());
            s.FireItemEvent(args);

            //Store for later
            results.Add(args.Result);

            //If a cancel is requested, fire an execption for Work to catch.
            throw new JobCancelledException("An event handler requested that the job be cancelled. The event handler was sent notification " +
                "that an item (\"" + i.TargetFilename +"\") could not be added to the zip file.",ex);
        }
Пример #9
0
 /// <summary>
 /// Returns true if the specified item is going to be resized.
 /// </summary>
 /// <param name="i"></param>
 /// <returns></returns>
 public bool wouldResize(BatchResizeItem i)
 {
     //Can we resize it?
     bool resize = s.conf.Pipeline.IsAcceptedImageType(i.PhysicalPath);
     //Are we doing anything to it?
     if (String.IsNullOrEmpty(i.ResizeQuerystring)) resize = false;
     return resize;
 }