Example #1
0
        public void Selector_SelectFiles()
        {
            Directory.SetCurrentDirectory(TopLevelDir);

            Trial[] trials = new Trial[]
                {
                    new Trial { Label = "name", C1 = "name = *.txt", C2 = "name = *.bin" },
                    new Trial { Label = "name (shorthand)", C1 = "*.txt", C2 = "*.bin" },
                    new Trial { Label = "size", C1 = "size < 7500", C2 = "size >= 7500" },
                    new Trial { Label = "size", C1 = "size = 8080", C2 = "size != 8080" },
                    new Trial { Label = "name & size",
                                C1 = "name = *.bin AND size > 7500",
                                C2 = "name != *.bin  OR  size <= 7500",
                    },
                    new Trial { Label = "name XOR name",
                                C1 = "name = *.bin XOR name = *4.*",
                                C2 = "(name != *.bin OR name = *4.*) AND (name = *.bin OR name != *4.*)",
                    },
                    new Trial { Label = "name XOR size",
                                C1 = "name = *.bin XOR size > 100k",
                                C2 = "(name != *.bin OR size > 100k) AND (name = *.bin OR size <= 100k)",
                    },
                    new Trial
                    {
                        Label = "mtime",
                        C1 = String.Format("mtime < {0}", twentyDaysAgo.ToString("yyyy-MM-dd")),
                        C2 = String.Format("mtime >= {0}", twentyDaysAgo.ToString("yyyy-MM-dd")),
                    },
                    new Trial
                    {
                        Label = "ctime",
                        C1 = String.Format("mtime < {0}", threeDaysAgo.ToString("yyyy-MM-dd")),
                        C2 = String.Format("mtime >= {0}", threeDaysAgo.ToString("yyyy-MM-dd")),
                    },
                    new Trial
                    {
                        Label = "atime",
                        C1 = String.Format("mtime < {0}", yesterdayAtMidnight.ToString("yyyy-MM-dd")),
                        C2 = String.Format("mtime >= {0}", yesterdayAtMidnight.ToString("yyyy-MM-dd")),
                    },
                    new Trial { Label = "size (100k)", C1="size > 100k", C2="size <= 100kb", },
                    new Trial { Label = "size (1mb)", C1="size > 1m", C2="size <= 1mb", },
                    new Trial { Label = "size (1gb)", C1="size > 1g", C2="size <= 1gb", },
                    new Trial { Label = "attributes (Hidden)", C1 = "attributes = H", C2 = "attributes != H" },
                    new Trial { Label = "attributes (ReadOnly)", C1 = "attributes = R", C2 = "attributes != R" },
                    new Trial { Label = "attributes (System)", C1 = "attributes = S", C2 = "attributes != S" },
                    new Trial { Label = "attributes (Archive)", C1 = "attributes = A", C2 = "attributes != A" },

                };


            string zipFileToCreate = Path.Combine(TopLevelDir, "Selector_SelectFiles.zip");
            Assert.IsFalse(File.Exists(zipFileToCreate), "The zip file '{0}' already exists.", zipFileToCreate);

            int count1, count2;
            //String filename = null;

            SetupFiles();
            var topLevelFiles = Directory.GetFiles(fodderDirectory, "*.*", SearchOption.TopDirectoryOnly);

            for (int m = 0; m < trials.Length; m++)
            {
                Ionic.FileSelector ff = new Ionic.FileSelector(trials[m].C1);
                var list = ff.SelectFiles(fodderDirectory);
                TestContext.WriteLine("=======================================================");
                TestContext.WriteLine("Selector: " + ff.ToString());
                TestContext.WriteLine("Criteria({0})", ff.SelectionCriteria);
                TestContext.WriteLine("Count({0})", list.Count);
                count1 = 0;
                foreach (string s in list)
                {
                    switch (m)
                    {
                        case 0:
                        case 1:
                            Assert.IsTrue(s.EndsWith(".txt"));
                            break;
                        case 2:
                            {
                                FileInfo fi = new FileInfo(s);
                                Assert.IsTrue(fi.Length < 7500);
                            }
                            break;
                        case 4:
                            {
                                FileInfo fi = new FileInfo(s);
                                bool x = s.EndsWith(".bin") && fi.Length > 7500;
                                Assert.IsTrue(x);
                            }
                            break;
                    }
                    count1++;
                }

                ff = new Ionic.FileSelector(trials[m].C2);
                list = ff.SelectFiles(fodderDirectory);
                TestContext.WriteLine("- - - - - - - - - - - - - - - - - - - - - - - - - - - -");
                TestContext.WriteLine("Criteria({0})", ff.SelectionCriteria);
                TestContext.WriteLine("Count({0})", list.Count);
                count2 = 0;
                foreach (string s in list)
                {
                    switch (m)
                    {
                        case 0:
                        case 1:
                            Assert.IsTrue(s.EndsWith(".bin"));
                            break;
                        case 2:
                            {
                                FileInfo fi = new FileInfo(s);
                                Assert.IsTrue(fi.Length >= 7500);
                            }
                            break;
                        case 4:
                            {
                                FileInfo fi = new FileInfo(s);
                                bool x = !s.EndsWith(".bin") || fi.Length <= 7500;
                                Assert.IsTrue(x);
                            }
                            break;
                    }
                    count2++;
                }
                Assert.AreEqual<Int32>(topLevelFiles.Length, count1 + count2);
            }
        }
Example #2
0
        private void _AddOrUpdateSelectedFiles(String selectionCriteria,
                                               String directoryOnDisk,
                                               String directoryPathInArchive,
                                               bool recurseDirectories,
                                               bool wantUpdate)
        {
            if (directoryOnDisk == null && (Directory.Exists(selectionCriteria)))
            {
                directoryOnDisk = selectionCriteria;
                selectionCriteria = "*.*";
            }
            else if (String.IsNullOrEmpty(directoryOnDisk))
            {
                directoryOnDisk = ".";
            }

            // workitem 9176
            while (directoryOnDisk.EndsWith("\\")) directoryOnDisk = directoryOnDisk.Substring(0, directoryOnDisk.Length - 1);
            if (Verbose) StatusMessageTextWriter.WriteLine("adding selection '{0}' from dir '{1}'...",
                                                               selectionCriteria, directoryOnDisk);
            Ionic.FileSelector ff = new Ionic.FileSelector(selectionCriteria,
                                                           AddDirectoryWillTraverseReparsePoints);
            var itemsToAdd = ff.SelectFiles(directoryOnDisk, recurseDirectories);

            if (Verbose) StatusMessageTextWriter.WriteLine("found {0} files...", itemsToAdd.Count);

            OnAddStarted();

            AddOrUpdateAction action = (wantUpdate) ? AddOrUpdateAction.AddOrUpdate : AddOrUpdateAction.AddOnly;
            foreach (var item in itemsToAdd)
            {
                // workitem 10153
                string dirInArchive = (directoryPathInArchive == null)
                    ? null
                    // workitem 12260
                    : ReplaceLeadingDirectory(Path.GetDirectoryName(item),
                                              directoryOnDisk,
                                              directoryPathInArchive);

                if (File.Exists(item))
                {
                    if (wantUpdate)
                        this.UpdateFile(item, dirInArchive);
                    else
                        this.AddFile(item, dirInArchive);
                }
                else
                {
                    // this adds "just" the directory, without recursing to the contained files
                    AddOrUpdateDirectoryImpl(item, dirInArchive, action, false, 0);
                }
            }

            OnAddCompleted();
        }
Example #3
0
 public void Selector_SelectFiles_BadSyntax19()
 {
     Ionic.FileSelector ff = new Ionic.FileSelector(null);
     var list = ff.SelectFiles(".");
 }
Example #4
0
 public void Selector_SelectFiles_DirName_wi8245()
 {
     // workitem 8245
     //Directory.SetCurrentDirectory(TopLevelDir);
     SetupFiles();
     var ff = new Ionic.FileSelector("*.*");
     var result = ff.SelectFiles(fodderDirectory);
     Assert.IsTrue(result.Count > 1);
 }
Example #5
0
        public void Selector_EdgeCases()
        {
            string Subdir = Path.Combine(TopLevelDir, "A");

            Ionic.FileSelector ff = new Ionic.FileSelector("name = *.txt");
            var list = ff.SelectFiles(Subdir);

            ff.SelectionCriteria = "name = *.bin";
            list = ff.SelectFiles(Subdir);
        }
Example #6
0
        private void _AddOrUpdateSelectedFiles(String selectionCriteria,
                                               String directoryOnDisk,
                                               String directoryPathInArchive,
                                               bool recurseDirectories,
                                               bool wantUpdate)
        {
            if (directoryOnDisk == null && (Directory.Exists(selectionCriteria)))
            {
                directoryOnDisk   = selectionCriteria;
                selectionCriteria = "*.*";
            }
            else if (String.IsNullOrEmpty(directoryOnDisk))
            {
                directoryOnDisk = ".";
            }

            // workitem 9176
            while (directoryOnDisk.EndsWith("\\"))
            {
                directoryOnDisk = directoryOnDisk.Substring(0, directoryOnDisk.Length - 1);
            }
            if (Verbose)
            {
                StatusMessageTextWriter.WriteLine("adding selection '{0}' from dir '{1}'...",
                                                  selectionCriteria, directoryOnDisk);
            }
            Ionic.FileSelector ff = new Ionic.FileSelector(selectionCriteria,
                                                           AddDirectoryWillTraverseReparsePoints);
            var itemsToAdd = ff.SelectFiles(directoryOnDisk, recurseDirectories);

            if (Verbose)
            {
                StatusMessageTextWriter.WriteLine("found {0} files...", itemsToAdd.Count);
            }

            OnAddStarted();

            AddOrUpdateAction action = (wantUpdate) ? AddOrUpdateAction.AddOrUpdate : AddOrUpdateAction.AddOnly;

            foreach (var item in itemsToAdd)
            {
                // workitem 10153
                string dirInArchive = (directoryPathInArchive == null)
                    ? null
                                      // workitem 12260
                    : ReplaceLeadingDirectory(Path.GetDirectoryName(item),
                                              directoryOnDisk,
                                              directoryPathInArchive);

                if (File.Exists(item))
                {
                    if (wantUpdate)
                    {
                        this.UpdateFile(item, dirInArchive);
                    }
                    else
                    {
                        this.AddFile(item, dirInArchive);
                    }
                }
                else
                {
                    // this adds "just" the directory, without recursing to the contained files
                    AddOrUpdateDirectoryImpl(item, dirInArchive, action, false, 0);
                }
            }

            OnAddCompleted();
        }
Example #7
0
        private void _AddOrUpdateSelectedFiles(String selectionCriteria,
                                     String directoryOnDisk,
                                     String directoryPathInArchive,
                                               bool recurseDirectories,
                                               bool wantUpdate)
        {
            //List<string> filesToAdd = null;
            if (directoryOnDisk == null && (Directory.Exists(selectionCriteria)))
            {
                //if (Verbose) StatusMessageTextWriter.WriteLine("adding selection '{0}' from dir '{1}'...",
                //selectionCriteria, directoryOnDisk);
                //Ionic.FileSelector ff = new Ionic.FileSelector("*.*");
                //filesToAdd = ff.SelectFiles(selectionCriteria, recurseDirectories);
                directoryOnDisk = selectionCriteria;
                selectionCriteria = "*.*";
            }
            else if (String.IsNullOrEmpty(directoryOnDisk))
            {
                directoryOnDisk = ".";
            }
            // workitem 9176
            while (directoryOnDisk.EndsWith("\\")) directoryOnDisk = directoryOnDisk.Substring(0, directoryOnDisk.Length - 1);
            if (Verbose) StatusMessageTextWriter.WriteLine("adding selection '{0}' from dir '{1}'...",
                                                               selectionCriteria, directoryOnDisk);
            Ionic.FileSelector ff = new Ionic.FileSelector(selectionCriteria,
                                                           AddDirectoryWillTraverseReparsePoints);
            var filesToAdd = ff.SelectFiles(directoryOnDisk, recurseDirectories);

            if (Verbose) StatusMessageTextWriter.WriteLine("found {0} files...", filesToAdd.Count);

            OnAddStarted();

            foreach (var f in filesToAdd)
            {
                if (directoryPathInArchive != null)
                {
                    string dirInArchive = Path.GetDirectoryName(f).Replace(directoryOnDisk, directoryPathInArchive);
                    if (wantUpdate)
                        this.UpdateFile(f, dirInArchive);
                    else
                        this.AddFile(f, dirInArchive);
                }
                else
                {
                    if (wantUpdate)
                        this.UpdateFile(f, null);
                    else
                        this.AddFile(f, null);
                }
            }

            OnAddCompleted();
        }