Exemple #1
0
        void WorkerDoWork(object sender, DoWorkEventArgs e)
        {
            processworker.ReportProgress(0, "Creating files....");

            List <Picture> pictures = (List <Picture>)e.Argument;

            ImageProcessor process = new ImageProcessor();

            process.ProgessUpdated += ProcessProgessUpdated;

            string path = this.outPathText.Text;
            string name = this.outFileName.Text;

            ImageProcessor.FileFormat flag = ImageProcessor.FileFormat.None;

            if (this.outTab.Checked && this.outMIF.Checked)
            {
                flag = ImageProcessor.FileFormat.MIF | ImageProcessor.FileFormat.TAB;
            }
            else if (!this.outTab.Checked && this.outMIF.Checked)
            {
                flag = ImageProcessor.FileFormat.MIF;
            }
            else if (this.outTab.Checked && !this.outMIF.Checked)
            {
                flag = ImageProcessor.FileFormat.TAB;
            }


            process.ProcessPictures(path, name, pictures, flag);

            // Clear the list of files.
            this.Invoke(new Action(this.fileListBox.Items.Clear));
        }
Exemple #2
0
        static void Main(string[] args)
        {
            log4net.Config.XmlConfigurator.Configure(new FileInfo("log4net.config"));
            bool   help      = false;
            bool   about     = false;
            string name      = "";
            bool   recursive = false;
            bool   timed     = false;

            ImageProcessor.FileFormat format = ImageProcessor.FileFormat.None;
            var p = new OptionSet()
            {
                { "f|format=", "output format.  Can be 'mif','tab' or 'mif&tab' ", v =>
                  {
                      switch (v)
                      {
                      case "mif":
                          format = ImageProcessor.FileFormat.MIF;
                          break;

                      case "tab":
                          format = ImageProcessor.FileFormat.TAB;
                          break;

                      case "mif&tab":
                          format = ImageProcessor.FileFormat.MIF | ImageProcessor.FileFormat.TAB;
                          break;

                      default:
                          format = ImageProcessor.FileFormat.None;
                          break;
                      }
                  } },
                { "n|name=", "name of the output file", v => name = v },
                { "r|recursive", "process all photo in the current directory and all sub folders.", v => recursive = v != null },
                { "v", "increase debug message verbosity", v => { if (v != null)
                                                                  {
                                                                      ++verbosity;
                                                                  }
                  } },
                { "t|timed", "enable timing of processing.", v => timed = v != null },
                { "A|about", "ouptut info about this program and exit.", v => about = v != null },
                { "h|?|help", "show this message and exit.", v => help = v != null },
            };

            List <String> extra;

            try
            {
                extra = p.Parse(args);
            }
            catch (OptionException e)
            {
                Error("PhotoMapper.Cmd: \n" + e.Message + "Try `PhotoMapper.Cmd --help' for more information.");
#if DEBUG
                Console.Read();
#endif
                return;
            }

            if (help)
            {
                PrintHelp(p);
            }
            if (about)
            {
                PrintAbout();
            }

            if (help || about)
#if DEBUG
            { Console.Read(); }
#else
            { return; }
#endif

            if (extra.Count < 2)
            {
                Error("Missing input and output folder");
                PrintHelp(p);
            }

            else if (extra.Count == 2 && !String.IsNullOrEmpty(name) &&
                     format != ImageProcessor.FileFormat.None)
            {
                var            infolder  = extra[0] == "." ? expandCurrentPath() : extra[0];
                var            outfolder = extra[1] == "." ? expandCurrentPath() : extra[1];
                List <Picture> pictures  = GetPhotos(infolder, recursive);
                if (pictures == null)
                {
                    Error("No images found to process");
#if DEBUG
                    Console.Read();
#endif
                    return;
                }

                StringBuilder builder = new StringBuilder();
                Stopwatch     timer   = new Stopwatch();
                if (timed)
                {
                    timer.Start();
                }

                ImageProcessor proc = new ImageProcessor();
                proc.ProgessUpdated += Debug;
                proc.ProcessPictures(outfolder, name, pictures, format);

                if (timer.IsRunning)
                {
                    timer.Stop();
                    builder.Append("# Process time: " + timer.Elapsed);
                    Debug(builder.ToString());
                }
            }
#if DEBUG
            Console.Read();
#endif
            return;
        }