コード例 #1
0
        void s_ItemEvent(ItemEventArgs e)
        {
            //If you throw an exception here, the job will fail. It's probably better to set e.Cancel.

            if (HttpContext.Current == null) return; //When using async mode, there is no session, no request, nothing. You can send e-mails and hit the database using web.config settings.

            Response.Write("\n\n" + e.ToString());
            //This is normally where you would update the database on the job progress. You can also use this to cancel the job by setting e.Cancel= true;
            double percentComplete = (e.Stats.FailedItems + e.Stats.SuccessfulItems) / e.Stats.RequestedItems * 100;
            Response.Write("\n" + Math.Round(percentComplete) + "% complete");
            //Note, however, on a live server, that opening a file for writing may take much longer than reading, thus
            //even 90% of elapsed time could occur before the first item is resized. This is very much an I/O bound process, and
            //calculting a percentage complete is nearly worthless on a live server.
        }
コード例 #2
0
ファイル: BatchResizeWorker.cs プロジェクト: eakova/resizer
        /// <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);
        }
コード例 #3
0
ファイル: BatchResizeWorker.cs プロジェクト: eakova/resizer
        /// <summary>
        /// Called when an error occurs during Save() (Whitch 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;
        }
コード例 #4
0
ファイル: BatchResizeWorker.cs プロジェクト: eakova/resizer
        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
 protected internal void FireItemEvent(ItemEventArgs e)
 {
     if (ItemEvent != null) ItemEvent(e);
 }
コード例 #6
0
 void s_ItemEvent(ItemEventArgs e)
 {
     var itemDone = e.Result;
     bwResizeBatch.ReportProgress(0);
 }