ImageResizer  3.4.0
 All Classes Namespaces Functions Variables Enumerations Enumerator Properties Events
Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
ImageResizer.Plugins.BatchZipper.BatchResizeWorker Class Reference

Synchronous worker class, not thread safe. Should be executed and touched by a single thread. More...

Collaboration diagram for ImageResizer.Plugins.BatchZipper.BatchResizeWorker:
Collaboration graph
[legend]

Public Member Functions

 BatchResizeWorker (BatchResizeSettings s)
 Creates a new worker instance. Do not modify the settings while executing the Work() method. More...
 
void Work ()
 Executes the job, and returns when it is complete or has failed. Exceptions are delivered by events registered in the BatchResizeSetting instance - throws no execptions, unless you throw an execption inside a job event handler. More...
 
bool wouldResize (BatchResizeItem i)
 Returns true if the specified item is going to be resized. More...
 
JobStats GetJobStats ()
 Returns a snapshots of the job statistics More...
 
Dictionary< string,
BatchResizeItem
BuildDict (IEnumerable< BatchResizeItem > files)
 Builds a dictionary from a collection of BatchResizeItems, using .targetFilename as the key. More...
 

Static Public Member Functions

static void CopyStreamTo (System.IO.Stream src, System.IO.Stream dest)
 Copies a read stream to a write stream. More...
 

Protected Member Functions

void WriteItemCallback (string entryName, System.IO.Stream stream)
 Called from ZipFile.Save as each queued entry is processed. More...
 
void z_SaveProgress (object sender, SaveProgressEventArgs e)
 
void z_ZipError (object sender, ZipErrorEventArgs e)
 
void CreateDestinationFolder ()
 If the parent folder of the destination archive is missing, this method will create it. More...
 

Protected Attributes

BatchResizeSettings s
 Stores the job settings. More...
 
Dictionary< string,
BatchResizeItem
items
 Used to map ZIP item names to instances. Required do to DotNetZipLib's callback system. More...
 
List< ItemResultresults = null
 Used to store the results of each resized item. More...
 
Stopwatch jobTimer
 
DateTime startedAt = DateTime.MaxValue
 When the job was started More...
 
DateTime finishedAt = DateTime.MaxValue
 When the job was finished More...
 
SaveProgressEventArgs savingCompletedEventArgs = null
 Stores the results of the Zip file saving betweent he time Saving_Completed fires, and we close the ZipFile instance and fire our own event More...
 
int successfulItems = 0
 How many items have been successfully resized and zipped More...
 
int failedItems = 0
 How many items failed to be resized and zipped More...
 

Detailed Description

Synchronous worker class, not thread safe. Should be executed and touched by a single thread.

Definition at line 21 of file BatchResizeWorker.cs.

Constructor & Destructor Documentation

ImageResizer.Plugins.BatchZipper.BatchResizeWorker.BatchResizeWorker ( BatchResizeSettings  s)
inline

Creates a new worker instance. Do not modify the settings while executing the Work() method.

Parameters
s

Definition at line 27 of file BatchResizeWorker.cs.

27  {
28  this.s = s;
29  }
BatchResizeSettings s
Stores the job settings.

Member Function Documentation

Dictionary<string,BatchResizeItem> ImageResizer.Plugins.BatchZipper.BatchResizeWorker.BuildDict ( IEnumerable< BatchResizeItem files)
inline

Builds a dictionary from a collection of BatchResizeItems, using .targetFilename as the key.

Parameters
files
Returns

Definition at line 311 of file BatchResizeWorker.cs.

311  {
312  Dictionary<string,BatchResizeItem> d = new Dictionary<string,BatchResizeItem>(StringComparer.OrdinalIgnoreCase);
313  foreach(BatchResizeItem i in files) d.Add(i.TargetFilename,i);
314  return d;
315  }
static void ImageResizer.Plugins.BatchZipper.BatchResizeWorker.CopyStreamTo ( System.IO.Stream  src,
System.IO.Stream  dest 
)
inlinestatic

Copies a read stream to a write stream.

Parameters
src
dest

Definition at line 177 of file BatchResizeWorker.cs.

178  {
179  int size = (src.CanSeek) ? Math.Min((int)(src.Length - src.Position), 0x2000) : 0x2000;
180  byte[] buffer = new byte[size];
181  int n;
182  do
183  {
184  n = src.Read(buffer, 0, buffer.Length);
185  dest.Write(buffer, 0, n);
186  } while (n != 0);
187  }
void ImageResizer.Plugins.BatchZipper.BatchResizeWorker.CreateDestinationFolder ( )
inlineprotected

If the parent folder of the destination archive is missing, this method will create it.

Definition at line 301 of file BatchResizeWorker.cs.

301  {
302  string dir = System.IO.Path.GetDirectoryName(s.destinationFile);
303  if (!System.IO.Directory.Exists(dir)) System.IO.Directory.CreateDirectory(dir);
304  }
JobStats ImageResizer.Plugins.BatchZipper.BatchResizeWorker.GetJobStats ( )
inline

Returns a snapshots of the job statistics

Returns

Definition at line 229 of file BatchResizeWorker.cs.

230  {
231  return new JobStats(items.Count, successfulItems, failedItems, jobTimer != null ? jobTimer.ElapsedMilliseconds : 0);
232  }
Dictionary< string, BatchResizeItem > items
Used to map ZIP item names to instances. Required do to DotNetZipLib&#39;s callback system.
int successfulItems
How many items have been successfully resized and zipped
int failedItems
How many items failed to be resized and zipped
void ImageResizer.Plugins.BatchZipper.BatchResizeWorker.Work ( )
inline

Executes the job, and returns when it is complete or has failed. Exceptions are delivered by events registered in the BatchResizeSetting instance - throws no execptions, unless you throw an execption inside a job event handler.

Definition at line 57 of file BatchResizeWorker.cs.

57  {
58  Work(s);
59  }
BatchResizeSettings s
Stores the job settings.
void Work()
Executes the job, and returns when it is complete or has failed. Exceptions are delivered by events r...
bool ImageResizer.Plugins.BatchZipper.BatchResizeWorker.wouldResize ( BatchResizeItem  i)
inline

Returns true if the specified item is going to be resized.

Parameters
i
Returns

Definition at line 140 of file BatchResizeWorker.cs.

141  {
142  //Can we resize it?
143  bool resize = s.conf.Pipeline.IsAcceptedImageType(i.PhysicalPath);
144  //Are we doing anything to it?
145  if (String.IsNullOrEmpty(i.ResizeQuerystring)) resize = false;
146  return resize;
147  }
void ImageResizer.Plugins.BatchZipper.BatchResizeWorker.WriteItemCallback ( string  entryName,
System.IO.Stream  stream 
)
inlineprotected

Called from ZipFile.Save as each queued entry is processed.

Parameters
entryName
stream

Definition at line 153 of file BatchResizeWorker.cs.

154  {
155  BatchResizeItem i = items[entryName];
156  if (wouldResize(i))
157  {
158  //Buffer in a memory stream to avoid stepping on CrcCalculatorStream's broken toes
159  using (MemoryStream ms = new MemoryStream()) {
160  s.conf.CurrentImageBuilder.Build(i.PhysicalPath, ms, new ResizeSettings(i.ResizeQuerystring));
161  ms.Position = 0;
162  StreamUtils.CopyTo(ms, stream);
163  }
164  return; //We're done!
165 
166  }
167 
168 
169  //For non-resizeable items, Just copy the stream.
170  using (System.IO.FileStream s = System.IO.File.OpenRead(i.PhysicalPath)) CopyStreamTo(s, stream);
171  }
bool wouldResize(BatchResizeItem i)
Returns true if the specified item is going to be resized.
Dictionary< string, BatchResizeItem > items
Used to map ZIP item names to instances. Required do to DotNetZipLib&#39;s callback system.
static void CopyStreamTo(System.IO.Stream src, System.IO.Stream dest)
Copies a read stream to a write stream.
Represents the settings which will be used to process the image. Extends NameValueCollection to provi...
BatchResizeSettings s
Stores the job settings.

Member Data Documentation

int ImageResizer.Plugins.BatchZipper.BatchResizeWorker.failedItems = 0
protected

How many items failed to be resized and zipped

Definition at line 223 of file BatchResizeWorker.cs.

DateTime ImageResizer.Plugins.BatchZipper.BatchResizeWorker.finishedAt = DateTime.MaxValue
protected

When the job was finished

Definition at line 51 of file BatchResizeWorker.cs.

Dictionary<string,BatchResizeItem> ImageResizer.Plugins.BatchZipper.BatchResizeWorker.items
protected

Used to map ZIP item names to instances. Required do to DotNetZipLib's callback system.

Definition at line 37 of file BatchResizeWorker.cs.

List<ItemResult> ImageResizer.Plugins.BatchZipper.BatchResizeWorker.results = null
protected

Used to store the results of each resized item.

Definition at line 41 of file BatchResizeWorker.cs.

BatchResizeSettings ImageResizer.Plugins.BatchZipper.BatchResizeWorker.s
protected

Stores the job settings.

Definition at line 33 of file BatchResizeWorker.cs.

SaveProgressEventArgs ImageResizer.Plugins.BatchZipper.BatchResizeWorker.savingCompletedEventArgs = null
protected

Stores the results of the Zip file saving betweent he time Saving_Completed fires, and we close the ZipFile instance and fire our own event

Definition at line 191 of file BatchResizeWorker.cs.

DateTime ImageResizer.Plugins.BatchZipper.BatchResizeWorker.startedAt = DateTime.MaxValue
protected

When the job was started

Definition at line 46 of file BatchResizeWorker.cs.

int ImageResizer.Plugins.BatchZipper.BatchResizeWorker.successfulItems = 0
protected

How many items have been successfully resized and zipped

Definition at line 219 of file BatchResizeWorker.cs.


The documentation for this class was generated from the following file: