Beispiel #1
0
        public virtual void testBig()
        {
            hf = new HotFolder(theHF, null, new MyListener(true));
            FileInfo file = new FileInfo(theHF + Path.DirectorySeparatorChar.ToString() + "f1.txt");

            SupportClass.FileSupport.CreateNewFile(file);
            file.Refresh();
            Assert.IsTrue(file.Exists);

            FileStream fos = new FileStream(file.FullName, FileMode.Open);

            byte[] ba = new byte[1];
            for (int i = 0; i < 20; i++) // incrementally fill file
            {
                ba[0] = (byte)i;
                fos.Write(ba, 0, 1);
                fos.Flush();

                StatusCounter.sleep(10);
            }
            file.Refresh();
            Assert.IsTrue(file.Exists);
            fos.Close();

            StatusCounter.sleep(3000);
            file.Refresh();
            Assert.IsFalse(file.Exists);
        }
Beispiel #2
0
        public virtual void teststopStart()
        {
            MyListener myListener = new MyListener();
            FileInfo   file       = new FileInfo(theHF + Path.DirectorySeparatorChar.ToString() + "f1.txt");
            FileInfo   stFile     = new FileInfo(theStorage + Path.DirectorySeparatorChar.ToString() + "f1.txt");

            SupportClass.FileSupport.CreateNewFile(file);
            file.Refresh();
            Assert.IsTrue(file.Exists);
            Assert.IsFalse(stFile.Exists);
            hf = new QueueHotFolder(theHF, theStorage, null, myListener, null);
            hf.stop();
            StatusCounter.sleep(3000);
            file.Refresh();
            Assert.IsTrue(file.Exists);
            stFile.Refresh();
            Assert.IsFalse(stFile.Exists, "FileInfo is still there after stop");
            Assert.AreEqual(0, myListener.vJMF.Count);
            hf.restart();
            StatusCounter.sleep(3000);
            file.Refresh();
            Assert.IsFalse(file.Exists, "FileInfo is gone after stop");
            stFile.Refresh();
            Assert.IsTrue(stFile.Exists);
            Assert.AreEqual(1, myListener.vJMF.Count);
            JDFJMF elementAt = (JDFJMF)myListener.vJMF[0];

            Assert.AreEqual(JDFMessage.EnumType.SubmitQueueEntry, elementAt.getCommand(0).getEnumType());
            Assert.AreEqual(UrlUtil.fileToUrl(stFile, false), elementAt.getCommand(0).getQueueSubmissionParams(0).getURL());
        }
Beispiel #3
0
        public virtual void testExtension()
        {
            hf = new HotFolder(theHF, ".txt,.xml", new MyListener(true));
            StatusCounter.sleep(1000); // time to start up
            FileInfo file  = new FileInfo(theHF + Path.DirectorySeparatorChar.ToString() + "f1.txt");
            FileInfo file1 = new FileInfo(theHF + Path.DirectorySeparatorChar.ToString() + "f1.xml");
            FileInfo file2 = new FileInfo(theHF + Path.DirectorySeparatorChar.ToString() + "f1.foo");

            SupportClass.FileSupport.CreateNewFile(file);
            file.Refresh();
            Assert.IsTrue(file.Exists);
            SupportClass.FileSupport.CreateNewFile(file1);
            file1.Refresh();
            Assert.IsTrue(file1.Exists);
            SupportClass.FileSupport.CreateNewFile(file2);
            file2.Refresh();
            Assert.IsTrue(file2.Exists);
            StatusCounter.sleep(4000);
            file.Refresh();
            file1.Refresh();
            file2.Refresh();
            Assert.IsFalse(file.Exists);
            Assert.IsFalse(file1.Exists);
            Assert.IsTrue(file2.Exists);
        }
Beispiel #4
0
        public virtual void testStopStart()
        {
            hf = new HotFolder(theHF, null, new MyListener(true));
            FileInfo file = new FileInfo(theHF + Path.DirectorySeparatorChar.ToString() + "f1.txt");

            SupportClass.FileSupport.CreateNewFile(file);
            file.Refresh();
            Assert.IsTrue(file.Exists);
            StatusCounter.sleep(3000);
            file.Refresh();
            Assert.IsFalse(file.Exists, "First delete attempt.");
            hf.Stop();
            hf.Stop();
            SupportClass.FileSupport.CreateNewFile(file);
            file.Refresh();
            Assert.IsTrue(file.Exists);
            StatusCounter.sleep(3000);
            file.Refresh();
            Assert.IsTrue(file.Exists);
            hf.restart();
            hf.restart();
            hf.restart();
            StatusCounter.sleep(5000);
            file.Refresh();
            Assert.IsFalse(file.Exists, "Second delete attempt.");
        }
Beispiel #5
0
        public virtual void testStartNull()
        {
            hf = new HotFolder(theHF, null, new MyListener(false));
            FileInfo file = new FileInfo(theHF + Path.DirectorySeparatorChar.ToString() + "f1.txt");

            SupportClass.FileSupport.CreateNewFile(file);
            file.Refresh();
            Assert.IsTrue(file.Exists);
            StatusCounter.sleep(3000);
            file.Refresh();
            Assert.IsTrue(file.Exists);
        }
Beispiel #6
0
        public virtual void testDir()
        {
            hf = new HotFolder(theHF, ".txt,.xml", new MyListener(true));
            FileInfo file  = new FileInfo(theHF + Path.DirectorySeparatorChar.ToString() + "f1.txt");
            FileInfo file1 = new FileInfo(theHF + Path.DirectorySeparatorChar.ToString() + "f2.xml"
                                          + Path.DirectorySeparatorChar.ToString() + "f1.xml");
            DirectoryInfo file2 = new DirectoryInfo(theHF + Path.DirectorySeparatorChar.ToString() + "f2.xml");

            SupportClass.FileSupport.CreateNewFile(file);
            file.Refresh();
            file2.Create();
            file2.Refresh();
            SupportClass.FileSupport.CreateNewFile(file1);
            file1.Refresh();
            Assert.IsTrue(file.Exists);
            StatusCounter.sleep(5000);
            file.Refresh();
            file1.Refresh();
            file2.Refresh();
            Assert.IsFalse(file.Exists);
            Assert.IsTrue(file1.Exists, "in subdir");
            Assert.IsTrue(file2.Exists);
        }
Beispiel #7
0
        //
        //	 * (non-Javadoc)
        //	 *
        //	 * @see java.lang.Runnable#run()
        //
        public virtual void Run()
        {
            while (!interrupt)
            {
                dir.Refresh();
                DateTime lastMod = dir.LastWriteTime;
                if (lastMod > lastModified || lastFileTime.Count > 0) // has the
                // directory
                // been
                // touched?
                {
                    lastModified = lastMod;
                    FileInfo[] files          = FileUtil.listFilesWithExtension(dir, extension);
                    int        fileListLength = files != null ? files.Length : 0;

                    for (int i = lastFileTime.Count - 1; i >= 0; i--)
                    {
                        bool found = false;
                        for (int j = 0; j < fileListLength; j++)
                        // loop over all matching files in the directory
                        {
                            if (files != null)
                            {
                                FileTime lftAt = lastFileTime[i];
                                if (files[j] != null && files[j].FullName.Equals(lftAt.f.FullName))
                                {
                                    found = true;
                                    if (files[j].LastWriteTime == lftAt.modified)
                                    {
                                        if (files[j].Exists)
                                        {
                                            hfl.hotFile(files[j]); // exists and stabilized - call callback
                                        }
                                        else
                                        {
                                            found = false;
                                        }
                                    }
                                    else
                                    {
                                        lftAt.modified = files[j].LastWriteTime;
                                    }

                                    files[j] = null; // this file has been processed,
                                    // remove from list for performance
                                }
                            }
                        }

                        if (!found)
                        {
                            lastFileTime.Remove(lastFileTime[i]); // not there anymore
                        }
                    }

                    if (files != null)
                    {
                        for (int i = 0; i < fileListLength; i++) // the file is new -
                        // add to list for nextr check
                        {
                            if (files[i] != null)
                            {
                                lastFileTime.Add(new FileTime(files[i]));
                            }
                        }
                    }
                }

                StatusCounter.sleep(stabilizeTime);
            }

            Thread.CurrentThread.Interrupt();
        }