Пример #1
0
        public static string CreateJpeg2000(string file)
        {
            var source_file = String.Format("{0}{1}", ImageDirectory, file);
            var dest_file   = String.Format("{0}{1}.jp2", Jpeg2000Directory, StripFileExtension(file));

            var files = new KeyValuePair <string, string>(source_file, dest_file);

            var db       = new DjatokaDataContext();
            var resource = db.DjatokaResources.SingleOrDefault(r => r.imageFile == dest_file);

            // check file doesn't exist physically, and also not present in database linked to an identifier, trying to avoid duplicate encoding here
            if (resource == null)
            {
                if (File.Exists(dest_file) == false)
                {
                    if (!_bwFiles.Contains(files))
                    {
                        _bwFiles.Add(files);
                    }

                    if (!IsBwBusy)
                    {
                        _bw.RunWorkerAsync();
                    }
                }
                else
                {
                    LogHelper.StatsLog(null, "CreateJpeg2000", "WARNING! Skipped file creation, destination file exists already, but no database entry: " + dest_file, null, null);
                }

                return("");
            }

            LogHelper.StatsLog(null, "CreateJpeg2000", "skipped file creation, database entry exists for: " + source_file, null, null);
            return(resource.identifier);
        }
Пример #2
0
        private static void createJpeg2000(string input_file, string output_file)
        {
            try
            {
                var p = new Process
                {
                    StartInfo =
                    {
                        UseShellExecute        = false,
                        RedirectStandardError  = true,
                        RedirectStandardOutput = true
                    },
                    EnableRaisingEvents = true
                };

                string KAKADU_HOME = String.Format("{0}\\bin\\Win32", DjatokaHome);

                string JAVA_OPTS = String.Format("-Djava.awt.headless=true  -Xmx512M -Xms64M -Dkakadu.home=\"{0}\" -Djava.library.path=\"{0}\"", KAKADU_HOME);
                string CLASSPATH = String.Format(@".;{0}\lib\adore-djatoka-1.1.jar;{0}\lib\commons-cli-1.1.jar;{0}\lib\ij.jar;{0}\lib\jai_codec.jar;{0}\lib\jai_core.jar;{0}\lib\kdu_jni.jar;{0}\lib\log4j-1.2.8.jar;{0}\lib\mlibwrapper_jai.jar;{0}\lib\oom.jar;{0}\lib\oomRef.jar;{0}\lib\uk.co.mmscomputing.imageio.tiff.jar;{0}\lib\ij-ImageIO.jar", DjatokaHome);
                string cmd       = String.Format(@"""{0}""", JavaHome);

                p.StartInfo.FileName  = cmd;
                p.StartInfo.Arguments = String.Format("{2} -classpath {3} gov.lanl.adore.djatoka.DjatokaCompress -i\"{0}\" -o\"{1}\"", input_file, output_file, JAVA_OPTS, CLASSPATH);

                try
                {
                    p.Start();
                }
                catch (Exception exp)
                {
                    LogHelper.StatsLog(null, "createJpeg2000() process start failed: " + exp.Message, String.Format("{0} {1}", p.StartInfo.FileName, p.StartInfo.Arguments), null, null);
                }

                LogHelper.StatsLog(null, "createJpeg2000()", String.Format("{0} {1}", p.StartInfo.FileName, p.StartInfo.Arguments), null, null);

                using (StreamReader error = p.StandardError)
                {
                    var error_output = error.ReadToEnd();
                    p.WaitForExit();

                    if ((error_output.Length > 0) && (error_output.Length != 153))
                    {
                        throw new Exception("error detected: " + error_output);
                    }


                    LogHelper.StatsLog(null, "createJpeg2000()", "Ok!: " + output_file, null, null);
                }

                var jpeg2000_identifier = String.Format("{0}{1}", Jpeg2000Namespace,
                                                        Path.GetFileNameWithoutExtension(output_file));

                var db = new DjatokaDataContext();
                var r  = new DjatokaResource {
                    identifier = jpeg2000_identifier, imageFile = output_file
                };
                db.DjatokaResources.InsertOnSubmit(r);
                db.SubmitChanges();
            }
            catch (Exception ex)
            {
                LogHelper.StatsLog(null, "createJpeg2000()", "createJpeg2000() failed: " + ex.Message, null, null);
                throw new Exception("createJpeg2000() error", ex.InnerException);
            }
        }