public override bool Process(ImageWI iwi) { logger.Info("task {0} start processing: {1}", this.Name, iwi); bool success = false; string nuName = Path.Combine(iwi.CurrentFile.DirectoryName ?? string.Empty, this.RenamedString(iwi)); try { if (File.Exists(nuName)) { logger.Debug("file {0} already existed, so we remove it", nuName); File.Delete(nuName); } // only in straight mode there is no copy if (WorkingStyle == TASKWORKINGSTYLE.STRAIGHT) { File.Move(iwi.CurrentFile.FullName, nuName); } else { File.Copy(iwi.CurrentFile.FullName, nuName); } // when straight or copyinput we need to let currentfile point to the new file if (WorkingStyle != TASKWORKINGSTYLE.COPYOUTPUT) { // save current file location iwi.CurrentFile = new FileInfo(nuName); } success = true; } catch (Exception ex) { logger.ErrorException(string.Format("error while moving (renaming) file {0} to: {1}", iwi.CurrentFile.Name, nuName), ex); } return success; }
public override bool Process(ImageWI iwi) { logger.Info("task {0} start processing: {1}", this.Name, iwi); iwi.CleanUp(); logger.Info("task {0} cleaned memory for: {1}", this.Name, iwi); return true; }
public override bool Process(ImageWI iwi) { bool success = false; if (iwi != null) { try { if (string.IsNullOrEmpty(this.currentDir) || this.pixInDir >= this.DirectoryFillCount) { // create new directory this.currentDir = this.createNewDirName(); if (iwi.CurrentFile != null) { if (iwi.CurrentFile.DirectoryName != null) { this.currentDirComplete = Path.Combine(iwi.CurrentFile.DirectoryName, this.currentDir); } if (!Directory.Exists(currentDirComplete)) { Directory.CreateDirectory(this.currentDirComplete); } // TODO: what about counting files in the dir? and use that count? pixInDir = 0; } } if (!string.IsNullOrEmpty(this.currentDir)) { // move file if (iwi.CurrentFile != null) { string nuLocation = Path.Combine(this.currentDirComplete, iwi.CurrentFile.Name); if (File.Exists(nuLocation)) { File.Delete(nuLocation); } // handle mode switch (WorkingStyle) { case TASKWORKINGSTYLE.STRAIGHT: File.Move(iwi.CurrentFile.FullName, nuLocation); break; case TASKWORKINGSTYLE.COPYOUTPUT: File.Copy(iwi.CurrentFile.FullName, nuLocation); break; case TASKWORKINGSTYLE.COPYINPUT: File.Copy(iwi.CurrentFile.FullName, nuLocation); // the handovered file is the file on the new location iwi.CleanUp(); iwi.CurrentFile = new FileInfo(nuLocation); break; default: throw new ArgumentOutOfRangeException(); } pixInDir++; } } success = true; } catch (Exception ex) { logger.Error("{0} got exception while processing {1}: {2}", this.Name, iwi.Name, ex); } } return success; }
public override bool Process(ImageWI iwi) { // what to do? switch (this.WorkingStyle) { case TASKWORKINGSTYLE.STRAIGHT: // destroy fib (will be reloaded by next task) iwi.CleanUp(); // save to temp file FileInfo tmpFI; if (iwi.ImageHandleWeak != null) { // when we hav a image handle save that to disk tmpFI = new FileInfo(Path.Combine(iwi.CurrentFile.DirectoryName ?? "./", DateTime.Now.Millisecond.ToString())); ImageWorker.SaveJPGImageHandle(iwi.ImageHandle, tmpFI); } else { // if we dont have a image handle use currentfileinfo tmpFI = iwi.CurrentFile; } // transform temp file ImageWorker.AutoRotateImageFI(tmpFI, this.nameExtension); // load into fib FIBITMAP? fibitmap = ImageWorker.GetJPGImageHandle(tmpFI); if (fibitmap != null) { iwi.ImageHandle = (FIBITMAP)fibitmap; } else { // tell anyone? } // remove tempfile tmpFI.Delete(); break; case TASKWORKINGSTYLE.COPYOUTPUT: // leave fib alone // save current version, if necessary if (iwi.ImageHandleWeak != null) { ImageWorker.SaveJPGImageHandle(iwi.ImageHandle, iwi.CurrentFile); } // transform current version to new name ImageWorker.AutoRotateImageFI(iwi.CurrentFile, this.nameExtension); break; case TASKWORKINGSTYLE.COPYINPUT: // destroy fib (will be reloaded by next task) // save current file // transform file to new name break; default: throw new ArgumentOutOfRangeException(); } ImageWorker.AutoRotateImageFI(iwi.CurrentFile, string.Empty); return true; }
public override bool Process(ImageWI iwi) { Size s = ImageWorker.GetCurrentSize(iwi); Size tileSize = new Size(); tileSize.Width = s.Width/this.XSliceCount; tileSize.Height = s.Height/this.YSliceCount; int i = 0; for (int x = 0; x < this.XSliceCount; x++) { for (int y = 0; y < this.YSliceCount; y++) { int left = x*tileSize.Width; int top = y*tileSize.Height; FIBITMAP aTile = FreeImage.Copy(iwi.ImageHandle, left, top, left + tileSize.Width, top + tileSize.Height); ImageWorker.SaveJPGImageHandle(aTile, new FileInfo(iwi.CurrentFile.AugmentFilename(string.Format("_tile_{0:000}", i)))); i++; } } return true; }
public override bool Process(ImageWI iwi) { if (!this.inited) { this.ftplib.port = 21; this.ftplib.user = this.UserName; this.ftplib.pass = this.Password; this.ftplib.server = this.Server; this.inited = true; } this.ftplib.OpenUpload(iwi.CurrentFile.FullName, this.ServerDirectory + "/" + iwi.CurrentFile.Name); int perc; while (this.ftplib.DoUpload() > 0) { perc = (int)(((this.ftplib.BytesTotal) * 100) / this.ftplib.FileSize); Console.Write("\rUpload: {0}/{1} {2}%", this.ftplib.BytesTotal, this.ftplib.FileSize, perc); Console.Out.Flush(); } Console.WriteLine(); return true; }
public static int CompareByFileName(ImageWI a, ImageWI b) { if (a != null && b != null) { return a.OriginalFile.Name.CompareTo(b.OriginalFile.Name); } return 0; }
public static int CompareByFileDate(ImageWI a, ImageWI b) { if (a != null && b != null) { return a.FileDate.CompareTo(b.FileDate); } return 0; }
public override bool Process(ImageWI iwi) { try { FIBITMAP shrinkedDib; FileInfo ftmp; switch (this.WorkingStyle) { case TASKWORKINGSTYLE.STRAIGHT: // do not save. just shrink // create shrinked image in memory shrinkedDib = ImageWorker.GetShrinkedDIB(iwi.ImageHandle, this.calcNewSize(iwi)); // cleanup old current handle ImageWorker.CleanUpResources(iwi.ImageHandle); // set shrinked version the new current iwi.ImageHandle = shrinkedDib; break; case TASKWORKINGSTYLE.COPYOUTPUT: ftmp = new FileInfo(iwi.CurrentFile.AugmentFilename(this.NameExtension)); // save shrinked version of image to file shrinkedDib = ImageWorker.GetShrinkedDIB(iwi.ImageHandle, this.calcNewSize(iwi)); ImageWorker.SaveJPGImageHandle(shrinkedDib, ftmp); // now we have the original and the shrinked version on disk // check which version should be handed over to the next task // after this the smaller image is the new current ImageWorker.CleanUpResources(iwi.ImageHandle); // set it the new current iwi.ImageHandle = shrinkedDib; iwi.CurrentFile = ftmp; break; case TASKWORKINGSTYLE.COPYINPUT: ftmp = new FileInfo(iwi.CurrentFile.AugmentFilename(this.NameExtension)); // save shrinked version of image to file shrinkedDib = ImageWorker.GetShrinkedDIB(iwi.ImageHandle, this.calcNewSize(iwi)); ImageWorker.SaveJPGImageHandle(shrinkedDib, ftmp); // now we have the original and the shrinked version on disk // check which version should be handed over to the next task // handle for shrinked version is not needed anymore ImageWorker.CleanUpResources(shrinkedDib); break; default: throw new ArgumentOutOfRangeException(); } } catch (Exception ex) { logger.ErrorException(string.Format("error while shrinking file {0}", iwi.CurrentFile.Name), ex); } return true; }
private void finishedProcessing(ImageWI wi) { // tell any interest that we processed a wi EventHandler<TaskEventArgs> temp = this.WIProcessed; if (temp != null) { temp(this, new TaskEventArgs(this, wi)); } this.ParentJob.HandOverWorkItemToNextEnabledTask(this, wi); }
private string RenamedString(ImageWI iwi) { // check for exif date...so we dont need to read exif data when it is not needed if (this.RenamePattern.Contains("{2}")) { return string.Format(this.RenamePattern, iwi.ProcessPosition, iwi.FileDate, iwi.ExifDate) + iwi.OriginalFile.Extension; } else { return string.Format(this.RenamePattern, iwi.ProcessPosition, iwi.FileDate, 0) + iwi.OriginalFile.Extension; } }
public static Size GetCurrentSize(ImageWI iwi) { return(new Size((int)FreeImage.GetWidth(iwi.ImageHandle), (int)FreeImage.GetHeight(iwi.ImageHandle))); }
public static Size GetCurrentSize(ImageWI iwi) { return new Size((int)FreeImage.GetWidth(iwi.ImageHandle), (int)FreeImage.GetHeight(iwi.ImageHandle)); }
private Size calcNewSize(ImageWI iwi) { Size oldSize = ImageWorker.GetCurrentSize(iwi); logger.Debug("oldsize of image {0}:{1}", iwi.Name, oldSize); float ratio = oldSize.Width*1f/oldSize.Height; Size newSize; if (this.AbsoluteSizing) { newSize = new Size(this.SizeX, (int) (this.SizeX/ratio)); logger.Debug("newsize (absolut) of image {0}:{1}", iwi.Name, newSize); } else { // suppose relativesizing newSize = new Size((int) (oldSize.Width*(this.SizePercent/100f)), (int) (oldSize.Height*(this.SizePercent/100f))); logger.Debug("newsize (percentage) of image {0}:{1}", iwi.Name, newSize); } return newSize; }
public bool Process(ImageWI iwi) { return true; }
private void copyOrMoveOneItem(ImageWI wi, string nuFile) { // do we want to delete? if yes move i good (performs better if on the same disk...) // check if we want to move or copy to ourselve... if (nuFile != wi.CurrentFile.FullName) { if (this.DeleteSource) { // check if file exists....eed to delete it first... if (File.Exists(nuFile)) { File.Delete(nuFile); } File.Move(wi.CurrentFile.FullName, nuFile); } else { File.Copy(wi.CurrentFile.FullName, nuFile, true); } } else { logger.Info("source and target are identical ({0}), do nothing", nuFile); } }
public override bool Process(ImageWI iwi) { if (!this.inited) { this.wayPointList = initGPXFiles(this.gpxFiles); this.inited = true; } // find WayPoint wp = findWaypoint4Date(iwi.ExifDate, this.wayPointList); if (wp != null) { ImageWorker.WriteGPSDateIntoImage(iwi.CurrentFile, null, wp); } else { // tell anyone we didnt found a suitable waypoint } return true; }
public abstract bool Process(ImageWI iwi);
private static void TestWriteGPS() { ImageWI iwi = new ImageWI(new FileInfo(@"..\..\..\testdata\gps\pic.jpg")); // tweak date to match the on in gpx file iwi.ExifDate = DateTime.Parse("01.09.2008"); var wpl = GEOTagTask.initGPXFiles(new List<FileInfo> {new FileInfo(@"..\..\..\testdata\gps\testdata.gpx")}); var wp = GEOTagTask.findWaypoint4Date(iwi.ExifDate, wpl); ImageWorker.WriteGPSDateIntoImage(iwi.CurrentFile, new FileInfo(iwi.CurrentFile.AugmentFilename("_withgps")), wp); }