예제 #1
0
        /// <summary>
        /// Lists a tree of tiles within a directory by the specified filter.
        /// </summary>
        /// <param name="filter">Instance to filter by.</param>
        /// <returns>Returns a filtered list of files.</returns>
        public override IFile[] ListTreeFiltered(IFileFilter filter)
        {
            ArrayList files   = new ArrayList();
            ZipFile   zipFile = this.OpenZipFile();

            try {
                if (this.IsDirectory)
                {
                    foreach (ZipEntry entry in zipFile)
                    {
                        if (entry.Name.StartsWith(this.InnerPath.Substring(1) + "/") && entry.Name != this.InnerPath.Substring(1) + "/")
                        {
                            if (entry.IsDirectory)
                            {
                                files.Add(new ZipFileImpl(this.manager, "zip://" + this.zipPath + "/" + entry.Name.Substring(0, entry.Name.Length - 1), null, FileType.Unknown));
                            }
                            else
                            {
                                files.Add(new ZipFileImpl(this.manager, "zip://" + this.zipPath + "/" + entry.Name, null, FileType.Unknown));
                            }
                        }
                    }
                }
            } finally {
                zipFile.Close();
            }

            return((IFile[])files.ToArray(typeof(ZipFileImpl)));
        }
 public RequestManager(IAppSettings appSettings, IWebHostEnvironment webHostEnvironment, ITinfoilIndexBuilder tinfoilIndexBuilder, IFileFilter fileFilter)
 {
     _appSettings         = appSettings ?? throw new ArgumentNullException(nameof(appSettings));
     _webHostEnvironment  = webHostEnvironment ?? throw new ArgumentNullException(nameof(webHostEnvironment));
     _tinfoilIndexBuilder = tinfoilIndexBuilder ?? throw new ArgumentNullException(nameof(tinfoilIndexBuilder));
     _fileFilter          = fileFilter ?? throw new ArgumentNullException(nameof(fileFilter));
 }
예제 #3
0
        /// <summary>List files by the specified filter.</summary>
        /// <param name="filter">Instance to filter by.</param>
        /// <returns>Filter list of files.</returns>
        public override IFile[] ListFilesFiltered(IFileFilter filter)
        {
            ArrayList files = new ArrayList();
            int       slashes;
            string    entryPath, listPrefix = "/";

            if (this.innerPath != "/")
            {
                listPrefix = this.innerPath + "/";
            }

            slashes = CountChar(listPrefix, '/');

            ZipFile zipFile = this.OpenZipFile();

            foreach (ZipEntry entry in zipFile)
            {
                entryPath = "/" + (entry.IsDirectory ? entry.Name.Substring(0, entry.Name.Length - 1) : entry.Name);

                //Debug("entryPath: " + entryPath +",listPrefix: "+ listPrefix +",CountChar:"+ CountChar(entryPath, '/') +",slashes:"+ slashes + ",indexof:" + entryPath.IndexOf(listPrefix));

                if (entryPath.StartsWith(listPrefix) && CountChar(entryPath, '/') == slashes)
                {
                    ZipFileImpl file = new ZipFileImpl(this.manager, this.zipPath, entryPath.Substring(1), FileType.Unknown);

                    file.ZipEntry = entry;

                    files.Add(file);
                }
            }

            zipFile.Close();

            return((IFile[])files.ToArray(typeof(ZipFileImpl)));
        }
예제 #4
0
        public void TestParseFileFilter()
        {
            IFileFilter fileFilter = FileFilterHelper.ParseFileFilter("Test", "*.cs");

            Assert.AreEqual("Test", fileFilter.Label);
            Assert.AreEqual("*.cs", fileFilter.Filters);
        }
 public ProjectFileProject(IConfigurationSectionProvider configurationSectionProvider, FullPathName rootPath)
 {
     _rootPath = rootPath;
       _directoryFilter = new DirectoryFilter(configurationSectionProvider);
       _fileFilter = new FileFilter(configurationSectionProvider);
       _searchableFilesFilter = new SearchableFilesFilter(configurationSectionProvider);
 }
예제 #6
0
        public async void Generete_Test()
        {
            List <string> expectedData = new List <string>
            {
                @"f\bla\ra\t.dat",
                @"books\csharp\csharp.pdf",
                @"proj\tools\utils.cpp",
                @"proj\timer\main.cpp"
            };

            int expectedLength = 4;

            IDirectory iDirectory = Substitute.For <IDirectory>();

            iDirectory.GetFilesAsync("", SearchOption.AllDirectories).Returns(expectedData);

            IFileFilter iFileFilter = Substitute.For <IFileFilter>();

            iFileFilter.GetFilteredFiles(iDirectory).Returns(expectedData.ToArray());


            ResultGenerator resultGenerator = new ResultGenerator(iDirectory, iFileFilter);
            IStreamWriter   actual          = await resultGenerator.Generate();


            Assert.Equal(expectedLength, actual.Data.Length);
            Assert.Equal(expectedData.ToArray(), actual.Data);
        }
예제 #7
0
        public void TestRegularExpressionAny()
        {
            IFileFilter fileFilter = FileFilterHelper.ParseFileFilter("Test", "*.*");
            string      filename   = "Test.cs";

            Assert.AreEqual(true, fileFilter.IsMatch(filename));
        }
예제 #8
0
 public ProjectFileProject(IConfigurationSectionProvider configurationSectionProvider, FullPathName rootPath)
 {
     _rootPath              = rootPath;
     _directoryFilter       = new DirectoryFilter(configurationSectionProvider);
     _fileFilter            = new FileFilter(configurationSectionProvider);
     _searchableFilesFilter = new SearchableFilesFilter(configurationSectionProvider);
 }
예제 #9
0
파일: Form1.cs 프로젝트: aaustin9/MHDAC
        /// <summary>
        /// Create the File Dialog and set it's basic properties
        /// </summary>
        private IAgtFileSelectionDialog CreateFileDialogAndSetParameters(bool allowMultiSelect,
                                                                         string dialogTitle,
                                                                         DialogMode dialogMode,
                                                                         string initialDirectory,
                                                                         bool showSampleInfo,
                                                                         IFileFilter iFileFilter)
        {
            AgtDialog agtDialog = new AgtDialog();
            IAgtFileSelectionDialog fileDialog = agtDialog as IAgtFileSelectionDialog;

            fileDialog.AllowMultiSelect      = allowMultiSelect;
            fileDialog.HelpId                = "0";
            fileDialog.DialogTitle           = dialogTitle;
            fileDialog.OpenOrSave            = dialogMode;
            fileDialog.InitialDirectory      = initialDirectory;
            fileDialog.ShowSampleInformation = showSampleInfo;
            fileDialog.AppPlugIn             = iFileFilter;
            fileDialog.Initialize(dialogMode);

            // set some basic Form properties
            agtDialog.Owner         = this;
            agtDialog.ShowIcon      = false;
            agtDialog.ShowInTaskbar = true;
            agtDialog.BringToFront();
            return(fileDialog);
        }
예제 #10
0
        public static MediaFile[] GetFromFolder(string path, IFileFilter filter, string[] extensions)
        {
            MediaFileScanner scaner = new MediaFileScanner(filter, extensions);

            scaner.scannFolder(path);
            return(scaner.mFiles.ToArray());
        }
예제 #11
0
        public virtual IList <Tree> ReadBinarizedTreebank(string treebankPath, IFileFilter treebankFilter)
        {
            Treebank     treebank  = ReadTreebank(treebankPath, treebankFilter);
            IList <Tree> binarized = BinarizeTreebank(treebank, op);

            log.Info("Converted trees to binarized format");
            return(binarized);
        }
 public TibcoBWDirectoryProcessorService(IFileProcessorService tibcoFileProcessorService, IFileProcessorService xsdFileProcessorService, IFileProcessorService globalVariableProcessor, IFileProcessorService adapterSchemaProcessor, IFileFilter fileFilter)
 {
     this.tibcoFileProcessorService = tibcoFileProcessorService;
     this.xsdFileProcessorService   = xsdFileProcessorService;
     this.globalVariableProcessor   = globalVariableProcessor;
     this.adapterSchemaProcessor    = adapterSchemaProcessor;
     this.filter = fileFilter;
 }
예제 #13
0
        /// <summary>
        /// Lists a tree of tiles within a directory by the specified filter.
        /// </summary>
        /// <param name="filter">Instance to filter by.</param>
        /// <returns>Returns a filtered list of files.</returns>
        public IFile[] ListTreeFiltered(IFileFilter filter)
        {
            this.fileTree = new ArrayList();

            this.ListTree(this, filter, 0);

            return((IFile[])this.fileTree.ToArray(typeof(LocalFile)));
        }
예제 #14
0
 public Project(IConfigurationSectionProvider configurationSectionProvider, FullPath rootPath)
 {
     _rootPath = rootPath;
       _configurationToken = configurationSectionProvider.WhenUpdated();
       _directoryFilter = new DirectoryFilter(configurationSectionProvider);
       _fileFilter = new FileFilter(configurationSectionProvider);
       _searchableFilesFilter = new SearchableFilesFilter(configurationSectionProvider);
 }
예제 #15
0
        public FileScavenger(FileProcessorEndpoint endpoint, IFileFilter fileFilter, string instanceId)
        {
            this.endpoint = endpoint;
            this.fileFilter = fileFilter;
            this.instanceId = instanceId;

            this.timer = new Timer(endpoint.ScavengeInterval.TotalMilliseconds) { AutoReset = true };
            this.timer.Elapsed += this.TimerElapsed;
        }
예제 #16
0
        public virtual Treebank ReadTreebank(string treebankPath, IFileFilter treebankFilter)
        {
            log.Info("Loading trees from " + treebankPath);
            Treebank treebank = op.tlpParams.MemoryTreebank();

            treebank.LoadPath(treebankPath, treebankFilter);
            log.Info("Read in " + treebank.Count + " trees from " + treebankPath);
            return(treebank);
        }
예제 #17
0
        public void TestConvertFileFilterToString()
        {
            IFileFilter fileFilter = FileFilter.Create("Test", "*.cs");
            string      filterStr1 = FileFilterHelper.ConvertFileFilterToString(fileFilter);
            string      filterStr2 = filterStr1.ToString();

            Assert.AreEqual("Test|*.cs", filterStr1);
            Assert.AreEqual("Test|*.cs", filterStr2);
        }
예제 #18
0
        public Bundle Directory(string relativeDirectory, Encoding encoding = null, string searchPattern = "*.*", SearchOption option = SearchOption.AllDirectories, IFileFilter filter = null)
        {
            relativeDirectory.ThrowIfNull("relativeDirectory");
            searchPattern.ThrowIfNull("searchPattern");

            _assets.Add(new DirectoryAsset(relativeDirectory, encoding, searchPattern, option, filter));

            return this;
        }
        public PollingBasedFileProcessor(FileProcessorEndpoint fileProcessorEndpoint, IHandleFiles fileHandler, IFileFilter additionalFilter)
        {
            if (fileProcessorEndpoint == null) { throw new ArgumentNullException("fileProcessorEndpoint"); }
            if (fileHandler == null) { throw new ArgumentNullException("fileHandler"); }
            if (additionalFilter == null) { throw new ArgumentNullException("additionalFilter"); }

            this.fileProcessorEndpoint = fileProcessorEndpoint;
            this.fileHandler = fileHandler;
            this.additionalFilter = additionalFilter;
        }
예제 #20
0
        public DirectoryAsset(string relativeDirectory, Encoding encoding = null, string searchPattern = "*.*", SearchOption option = SearchOption.AllDirectories, IFileFilter filter = null)
        {
            relativeDirectory.ThrowIfNull("relativeDirectory");

            _relativeDirectory = relativeDirectory;
            _encoding          = encoding;
            _searchPattern     = searchPattern;
            _searchOption      = option;
            _filter            = filter;
        }
예제 #21
0
        public static bool LogIfFilteredOut(string fileName, IFileFilter filter, ILogger logger)
        {
            if (filter != null && false == filter.IsPassedThrough(fileName))
            {
                logger.Log("File '{0}' has been filtered out.", fileName);
                return(false);
            }

            return(true);
        }
예제 #22
0
        public DirectoryAsset(string relativeDirectory, Encoding encoding = null, string searchPattern = "*.*", SearchOption option = SearchOption.AllDirectories, IFileFilter filter = null)
        {
            relativeDirectory.ThrowIfNull("relativeDirectory");

            _relativeDirectory = relativeDirectory;
            _encoding = encoding;
            _searchPattern = searchPattern;
            _searchOption = option;
            _filter = filter;
        }
예제 #23
0
        public static bool LogIfFilteredOut(string fileName, IFileFilter filter, ITaskContext taskContext)
        {
            if (filter != null && false == filter.IsPassedThrough(fileName))
            {
                taskContext.WriteDebug("File '{0}' has been filtered out.", fileName);
                return(false);
            }

            return(true);
        }
예제 #24
0
        private void FileFiltersChangedHandler(IList <IFileFilter> newFilters, int newFilterIndex)
        {
            IFileFilter fileFilter = null;

            if (newFilters != null && newFilterIndex >= 0 && newFilterIndex < newFilters.Count)
            {
                fileFilter = newFilters[FilterIndex];
            }

            m_controller.SetFileFilter(newFilters, fileFilter);
        }
 /// <summary>Load trees from given directory.</summary>
 /// <remarks>
 /// Load trees from given directory.  This version just records
 /// the paths to be processed, and actually processes them at apply time.
 /// </remarks>
 /// <param name="path">file or directory to load from</param>
 /// <param name="filt">a FilenameFilter of files to load</param>
 public override void LoadPath(File path, IFileFilter filt)
 {
     if (path.Exists())
     {
         filePaths.Add(path);
         fileFilters.Add(filt);
     }
     else
     {
         System.Console.Error.Printf("%s: File/path %s does not exist. Skipping.%n", this.GetType().FullName, path.GetPath());
     }
 }
예제 #26
0
 public Project(
   FullPath rootPath,
   IFileFilter fileFilter,
   IDirectoryFilter directoryFilter,
   ISearchableFilesFilter searchableFilesFilter,
   string hash) {
   _rootPath = rootPath;
   _directoryFilter = directoryFilter;
   _fileFilter = fileFilter;
   _searchableFilesFilter = searchableFilesFilter;
   _hash = hash;
 }
예제 #27
0
        public FileScavenger(FileProcessorEndpoint endpoint, IFileFilter fileFilter, string instanceId)
        {
            this.endpoint   = endpoint;
            this.fileFilter = fileFilter;
            this.instanceId = instanceId;

            this.timer = new Timer(endpoint.ScavengeInterval.TotalMilliseconds)
            {
                AutoReset = true
            };
            this.timer.Elapsed += this.TimerElapsed;
        }
예제 #28
0
        public static Triple <string, IFileFilter, double> GetWeightedTreebankDescription(string[] args, int argIndex, string flag)
        {
            string      path   = null;
            IFileFilter filter = null;
            double      weight = 1.0;
            // the next arguments are the treebank path and maybe the range for testing
            int numSubArgs = NumSubArgs(args, argIndex);

            if (numSubArgs > 0 && numSubArgs < 4)
            {
                argIndex++;
                path = args[argIndex++];
                bool hasWeight = false;
                if (numSubArgs > 1 && DoublePattern.Matcher(args[argIndex + numSubArgs - 2]).Matches())
                {
                    weight    = double.Parse(args[argIndex + numSubArgs - 2]);
                    hasWeight = true;
                    numSubArgs--;
                }
                if (numSubArgs == 2)
                {
                    filter = new NumberRangesFileFilter(args[argIndex++], true);
                }
                else
                {
                    if (numSubArgs == 3)
                    {
                        try
                        {
                            int low  = System.Convert.ToInt32(args[argIndex]);
                            int high = System.Convert.ToInt32(args[argIndex + 1]);
                            filter    = new NumberRangeFileFilter(low, high, true);
                            argIndex += 2;
                        }
                        catch (NumberFormatException)
                        {
                            // maybe it's a ranges expression?
                            filter = new NumberRangesFileFilter(args[argIndex++], true);
                        }
                    }
                }
                if (hasWeight)
                {
                    argIndex++;
                }
            }
            else
            {
                throw new ArgumentException("Bad arguments after " + flag);
            }
            return(Triple.MakeTriple(path, filter, weight));
        }
예제 #29
0
 public Project(
     FullPath rootPath,
     IFileFilter fileFilter,
     IDirectoryFilter directoryFilter,
     ISearchableFilesFilter searchableFilesFilter,
     string hash)
 {
     _rootPath              = rootPath;
     _directoryFilter       = directoryFilter;
     _fileFilter            = fileFilter;
     _searchableFilesFilter = searchableFilesFilter;
     _hash = hash;
 }
예제 #30
0
 /// <summary>
 /// Creates a new <see cref="FileSystemController" />.
 /// </summary>
 public FileSystemController()
 {
     m_currentDirectory          = null;
     m_currentFile               = null;
     m_currentFileFullName       = null;
     m_currentDirectoryPathParts = null;
     m_directories               = null;
     m_files = null;
     m_showHiddenFilesAndDirectories = false;
     m_showSystemFilesAndDirectories = false;
     m_fileFilters       = null;
     m_fileFilterToApply = null;
 }
예제 #31
0
 public RequestManager(
     IAppSettings appSettings, ICachedTinfoilIndexBuilder cachedTinfoilIndexBuilder,
     IFileFilter fileFilter, IPhysicalPathConverter physicalPathConverter,
     IServedDirAliasMap servedDirAliasMap, IJsonSerializer jsonSerializer,
     IUrlCombinerFactory urlCombinerFactory)
 {
     _appSettings = appSettings ?? throw new ArgumentNullException(nameof(appSettings));
     _cachedTinfoilIndexBuilder = cachedTinfoilIndexBuilder ?? throw new ArgumentNullException(nameof(cachedTinfoilIndexBuilder));
     _fileFilter            = fileFilter ?? throw new ArgumentNullException(nameof(fileFilter));
     _physicalPathConverter = physicalPathConverter ?? throw new ArgumentNullException(nameof(physicalPathConverter));
     _servedDirAliasMap     = servedDirAliasMap ?? throw new ArgumentNullException(nameof(servedDirAliasMap));
     _jsonSerializer        = jsonSerializer ?? throw new ArgumentNullException(nameof(jsonSerializer));
     _urlCombinerFactory    = urlCombinerFactory ?? throw new ArgumentNullException(nameof(urlCombinerFactory));
 }
예제 #32
0
        public static bool LogIfFilteredOut(string fileName, IFileFilter filter, ITaskContextInternal taskContext, bool logFiles)
        {
            if (filter != null && !filter.IsPassedThrough(fileName))
            {
                if (logFiles)
                {
                    taskContext.LogInfo($"File '{fileName}' has been filtered out.");
                }

                return(false);
            }

            return(true);
        }
예제 #33
0
        public void TestGetFileExtensionsFromFilter()
        {
            IFileFilter          fileFilter     = FileFilterHelper.ParseFileFilter("Test", "*.cs;file.*;cs*.*;*.xaml;test;*.txt.bak");
            IEnumerable <string> fileExtensions = FileFilterHelper.GetFileExtensionsFromFilter(fileFilter);

            Assert.IsNotNull(fileExtensions);
            Assert.AreEqual(3, fileExtensions.Count());
            Assert.IsTrue(fileExtensions.Any(fileExtension => fileExtension == "cs"));
            Assert.IsTrue(fileExtensions.Any(fileExtension => fileExtension == "xaml"));
            Assert.IsTrue(fileExtensions.Any(fileExtension => fileExtension == "bak"));

            fileExtensions = FileFilterHelper.GetFileExtensionsFromFilter(null);

            Assert.IsTrue(fileExtensions == null || !fileExtensions.Any());
        }
        /// <summary>
        /// Extracts the file extensions out of the file filter.
        /// </summary>
        /// <param name="fileFilter"></param>
        /// <returns></returns>
        public static IEnumerable <string> GetFileExtensionsFromFilter(IFileFilter fileFilter)
        {
            if (fileFilter == null)
            {
                return(null);
            }

            string[] split = fileFilter.Filters.Split(';');

            return(fileFilter.Filters.Split(';')
                   .Select(filterStr => filterStr.Trim())
                   .Where(filterStr => filterStr.Length > 1 && filterStr.Contains(".") && !filterStr.EndsWith("."))
                   .Select(filterStr => filterStr.Substring(filterStr.LastIndexOf(".") + 1).Replace("*", string.Empty))
                   .Where(fileExtension => !string.IsNullOrWhiteSpace(fileExtension)));
        }
 /// <summary>
 /// Creates a
 /// <c>FileSequentialCollection</c>
 /// from the passed in
 /// <c>Collection</c>
 /// .  The constructor iterates through the
 /// collection.  For each element, if it is a
 /// <c>File</c>
 /// or
 /// <c>String</c>
 /// then these file paths are processed as
 /// explained below.
 /// If the argument is of some other type, an
 /// <c>IllegalArgumentException</c>
 /// is thrown.  For the files
 /// specified, if they are not directories, they are included in the
 /// collection.  If they are directories, files inside them are
 /// included iff they match the
 /// <c>FileFilter</c>
 /// .  This will
 /// include recursive directory descent iff the
 /// <c>FileFilter</c>
 /// accepts directories.
 /// If the path is a directory then only
 /// files within the directory (perhaps recursively) that satisfy the
 /// filter are processed.  If the
 /// <c>path</c>
 /// is a file, then
 /// that file is processed regardless of whether it satisfies the
 /// filter.  (This semantics was adopted, since otherwise there was no
 /// easy way to go through all the files in a directory without
 /// descending recursively via the specification of a
 /// <c>FileFilter</c>
 /// .)
 /// </summary>
 /// <param name="c">
 /// The collection of file or directory to load from.  An
 /// argument of
 /// <see langword="null"/>
 /// is interpreted like an
 /// empty collection.
 /// </param>
 /// <param name="filt">
 /// A FileFilter of files to load.  This may be
 /// <see langword="null"/>
 /// , in which case all files are accepted
 /// </param>
 /// <param name="includeDirs">Whether to include directory names in the file list</param>
 public FileSequentialCollection(ICollection <object> c, IFileFilter filt, bool includeDirs)
     : base()
 {
     // store the arguments.  They are expanded by the iterator
     if (c == null)
     {
         coll = new List <object>();
     }
     else
     {
         coll = c;
     }
     this.filt        = filt;
     this.includeDirs = includeDirs;
 }
        /// <summary>
        /// Creates a new <see cref="FileSystemController" />.
        /// </summary>
        public FileSystemController()
        {
            m_currentDirectory          = null;
            m_currentFile               = null;
            m_currentFileFullName       = null;
            m_currentDirectoryPathParts = null;
            m_directories               = null;
            m_files = null;
            m_showHiddenFilesAndDirectories = false;
            m_showSystemFilesAndDirectories = false;
            m_fileFilters       = null;
            m_fileFilterToApply = null;
            m_forceFileExtensionOfFileFilter = false;

            m_selectedDirectories = new HashSet <DirectoryInfo>();
            m_selectedFiles       = new HashSet <FileInfo>();
        }
예제 #37
0
        private static Treebank MakeTreebank(string treebankPath, Options op, IFileFilter filt)
        {
            log.Info("Training a segmenter from treebank dir: " + treebankPath);
            Treebank trainTreebank = op.tlpParams.MemoryTreebank();

            log.Info("Reading trees...");
            if (filt == null)
            {
                trainTreebank.LoadPath(treebankPath);
            }
            else
            {
                trainTreebank.LoadPath(treebankPath, filt);
            }
            Timing.Tick("done [read " + trainTreebank.Count + " trees].");
            return(trainTreebank);
        }
예제 #38
0
        protected FileProcessorBase(FileProcessorEndpoint endpoint, IFileHandler handler, IFilePostProcessor postProcessor, IFileFilter additionalFilter)
        {
            if (endpoint == null)
            {
                throw new ArgumentException("endpoint");
            }

            if (handler == null)
            {
                throw new ArgumentException("handler");
            }

            if (postProcessor == null)
            {
                throw new ArgumentNullException("postProcessor");
            }

            if (additionalFilter == null)
            {
                throw new ArgumentNullException("additionalFilter");
            }

            this.instanceId = Guid.Empty;
            this.Endpoint = endpoint;
            this.Handler = handler;
            this.PostProcessor = postProcessor;
            this.AdditionalFilter = additionalFilter;
            this.scavenger = new FileScavenger(endpoint, additionalFilter, this.InstanceId);
            this.scavenger.RestartFileChecking += (o, e) => this.RestartNewFileChecking();


            this.pendingFiles = new ConcurrentQueue<string>();
            this.eventHandle = new AutoResetEvent(false);
            this.quitHandle = new ManualResetEvent(false);
            this.quitting = false;

            Logger.DebugFormat("Scavenger interval set at {0:0.0} seconds", endpoint.ScavengeInterval.TotalSeconds);
        }
        public EventBasedFileProcessor(FileProcessorEndpoint endpoint, IFileHandler handler, IFilePostProcessor postProcessor, IFileFilter additionalFilter)
        {
            if (endpoint == null)
            {
                throw new ArgumentException("endpoint");
            }

            if (handler == null)
            {
                throw new ArgumentException("handler");
            }

            if (postProcessor == null)
            {
                throw new ArgumentNullException("postProcessor");
            }

            if (additionalFilter == null)
            {
                throw new ArgumentNullException("additionalFilter");
            }

            this.instanceId = Guid.Empty;
            this.Endpoint = endpoint;
            this.Handler = handler;
            this.PostProcessor = postProcessor;
            this.AdditionalFilter = additionalFilter;

            this.timer = new Timer(this.Endpoint.ScavengeInterval.TotalMilliseconds) { AutoReset = true };
            this.timer.Elapsed += this.TimerElapsed;

            this.pendingFiles = new ConcurrentQueue<string>();
            this.eventHandle = new AutoResetEvent(false);
            this.quitHandle = new ManualResetEvent(false);
            this.quitting = false;

            Logger.DebugFormat("Scavenger interval set at {0:0.0} seconds", endpoint.ScavengeInterval.TotalSeconds);
        }
예제 #40
0
 public void SetUp()
 {
     _fileFilter = MockRepository.GenerateMock<IFileFilter>();
     _fileFilter.Stub(arg => arg.Filter("file1")).Return(FilterResult.Include);
     _fileFilter.Stub(arg => arg.Filter("file2")).Return(FilterResult.Exclude);
     _directoryAsset = new DirectoryAsset("directory", Encoding.UTF8, "*.txt", SearchOption.TopDirectoryOnly, _fileFilter);
     _fileSystem = MockRepository.GenerateMock<IFileSystem>();
     _fileSystem.Stub(arg => arg.AbsolutePath("directory")).Return("directory");
     _fileSystem.Stub(arg => arg.GetDirectoryFiles("directory", "*.txt", SearchOption.TopDirectoryOnly)).Return(new[] { "file1", "file2" });
     _resolveAssetFiles = _directoryAsset.ResolveAssetFiles(_fileSystem).ToArray();
 }
예제 #41
0
        /// <summary>List files by the specified filter.</summary>
        /// <param name="filter">Instance to filter by.</param>
        /// <returns>Filter list of files.</returns>
        public IFile[] ListFilesFiltered(IFileFilter filter)
        {
            DirectoryInfo dirInfo = new DirectoryInfo(PathUtils.ToOSPath(this.AbsolutePath));
             	DirectoryInfo[] dirInfos = dirInfo.GetDirectories();
             	FileInfo[] fileInfos = dirInfo.GetFiles();
             	string accessFile = this.Config["filesystem.local.access_file_name"];
            ArrayList files = new ArrayList();

            // Add directories
            foreach (DirectoryInfo info in dirInfos) {
                LocalFile file = (LocalFile) this.manager.GetFile(PathUtils.ToUnixPath(info.FullName));

                if (filter != null && !filter.Accept(file))
                    continue;

                files.Add(file);
            }

            // Add files
            foreach (FileInfo info in fileInfos) {
                if (info.Name == accessFile)
                    continue;

                LocalFile file = (LocalFile) this.manager.GetFile(PathUtils.ToUnixPath(info.FullName));

                if (filter != null && !filter.Accept(file))
                    continue;

                files.Add(file);
            }

            return (IFile[]) files.ToArray(typeof(LocalFile));
        }
예제 #42
0
파일: BaseFile.cs 프로젝트: nhtera/CrowdCMS
 /// <summary>List files by the specified filter.</summary>
 /// <param name="filter">Instance to filter by.</param>
 /// <returns>Filter list of files.</returns>
 public virtual IFile[] ListFilesFiltered(IFileFilter filter)
 {
     return null;
 }
예제 #43
0
 public static Bundle FromDirectory(string relativeDirectory, Encoding encoding = null, string searchPattern = "*.*", SearchOption option = SearchOption.AllDirectories, IFileFilter filter = null)
 {
     return new Bundle().Directory(relativeDirectory, encoding, searchPattern, option, filter);
 }
예제 #44
0
파일: BaseFile.cs 프로젝트: nhtera/CrowdCMS
        /// <summary>
        /// Lists a tree of tiles within a directory by the specified filter.
        /// </summary>
        /// <param name="filter">Instance to filter by.</param>
        /// <returns>Returns a filtered list of files.</returns>
        public virtual IFile[] ListTreeFiltered(IFileFilter filter)
        {
            this.fileTree = new ArrayList();

            this.ListTree(this, filter, 0);

            return (IFile[]) this.fileTree.ToArray(typeof(LocalFile));
        }
 public EventBasedFileProcessor(FileProcessorEndpoint endpoint, IFileHandler handler, IFilePostProcessor postProcessor, IFileFilter additionalFilter)
     : base(endpoint, handler, postProcessor, additionalFilter)
 {
 }
예제 #46
0
파일: ZipFile.cs 프로젝트: nhtera/CrowdCMS
        /// <summary>List files by the specified filter.</summary>
        /// <param name="filter">Instance to filter by.</param>
        /// <returns>Filter list of files.</returns>
        public override IFile[] ListFilesFiltered(IFileFilter filter)
        {
            ArrayList files = new ArrayList();
            int slashes;
            string entryPath, listPrefix = "/";

            if (this.innerPath != "/")
                listPrefix = this.innerPath + "/";

            slashes = CountChar(listPrefix, '/');

            ZipFile zipFile = this.OpenZipFile();
            foreach (ZipEntry entry in zipFile) {
                entryPath = "/" + (entry.IsDirectory ? entry.Name.Substring(0, entry.Name.Length - 1) : entry.Name);

                //Debug("entryPath: " + entryPath +",listPrefix: "+ listPrefix +",CountChar:"+ CountChar(entryPath, '/') +",slashes:"+ slashes + ",indexof:" + entryPath.IndexOf(listPrefix));

                if (entryPath.StartsWith(listPrefix) && CountChar(entryPath, '/') == slashes) {
                    ZipFileImpl file = new ZipFileImpl(this.manager, this.zipPath, entryPath.Substring(1), FileType.Unknown);

                    file.ZipEntry = entry;

                    files.Add(file);
                }
            }

            zipFile.Close();

            return (IFile[]) files.ToArray(typeof(ZipFileImpl));
        }
예제 #47
0
 /// <summary>
 /// Determines whether the <see cref="T:System.Collections.Generic.ICollection`1"/> contains a specific value.
 /// </summary>
 /// <param name="item">The object to locate in the <see cref="T:System.Collections.Generic.ICollection`1"/>.</param>
 /// <returns>
 /// true if <paramref name="item"/> is found in the <see cref="T:System.Collections.Generic.ICollection`1"/>; otherwise, false.
 /// </returns>
 public bool Contains(IFileFilter item)
 {
     return _filters.Contains(item);
 }
예제 #48
0
 /// <summary>
 /// Copies the elements of the <see cref="T:System.Collections.Generic.ICollection`1"/> to an <see cref="T:System.Array"/>,
 /// starting at a particular <see cref="T:System.Array"/> index.
 /// </summary>
 /// <param name="array">The one-dimensional <see cref="T:System.Array"/> that is the destination of the elements copied from
 /// <see cref="T:System.Collections.Generic.ICollection`1"/>. The <see cref="T:System.Array"/> must have zero-based indexing.</param>
 /// <param name="arrayIndex">The zero-based index in <paramref name="array"/> at which copying begins.</param>
 /// <exception cref="T:System.ArgumentNullException"><paramref name="array"/> is null.</exception>
 /// <exception cref="T:System.ArgumentOutOfRangeException"><paramref name="arrayIndex"/> is less than 0.</exception>
 /// <exception cref="T:System.ArgumentException"><paramref name="array"/> is multidimensional.-or-The number of elements in the source
 /// <see cref="T:System.Collections.Generic.ICollection`1"/> is greater than the available space from <paramref name="arrayIndex"/>
 /// to the end of the destination <paramref name="array"/>.-or-Type <see cref="IFileFilter"/> cannot be cast automatically to the type
 /// of the destination <paramref name="array"/>.</exception>
 public void CopyTo(IFileFilter[] array, int arrayIndex)
 {
     _filters.CopyTo(array, arrayIndex);
 }
예제 #49
0
        public override IFile[] ListFilesFiltered(IFileFilter filter)
        {
            HttpCookie cookie = HttpContext.Current.Request.Cookies["hist"];
            ArrayList files = new ArrayList();

            if (cookie != null && cookie.Value != null) {
                foreach (string path in cookie.Value.Split(new char[]{','})) {
                    try {
                        IFile file = this.manager.GetFile(this.manager.DecryptPath(path));

                        if (filter.Accept(file))
                            files.Add(file);
                    } catch {
                        // Ignore
                    }
                }
            }

            return (IFile[]) files.ToArray(typeof(IFile));
        }
예제 #50
0
        /// <summary>
        /// Adds an item to the <see cref="T:System.Collections.Generic.ICollection`1"/>.
        /// </summary>
        /// <param name="item">The object to add to the <see cref="T:System.Collections.Generic.ICollection`1"/>.</param>
        /// <exception cref="T:System.NotSupportedException">The <see cref="T:System.Collections.Generic.ICollection`1"/> is read-only.</exception>
        public void Add(IFileFilter item)
        {
            if (!_filters.Contains(item))
            {
                if (log.IsDebugEnabled)
                    log.DebugFormat("Adding IFileFilter `{0}` to `{1}` failed: object already in collection.", item, this);

                _filters.Add(item);
            }
            else
            {
                if (log.IsDebugEnabled)
                    log.DebugFormat("Added IFileFilter `{0}` to `{1}`.", item, this);
            }
        }
예제 #51
0
 /// <summary>
 /// Removes the first occurrence of a specific object from the <see cref="T:System.Collections.Generic.ICollection`1"/>.
 /// </summary>
 /// <param name="item">The object to remove from the <see cref="T:System.Collections.Generic.ICollection`1"/>.</param>
 /// <returns>
 /// true if <paramref name="item"/> was successfully removed from the <see cref="T:System.Collections.Generic.ICollection`1"/>;
 /// otherwise, false. This method also returns false if <paramref name="item"/> is not found in the original
 /// <see cref="T:System.Collections.Generic.ICollection`1"/>.
 /// </returns>
 /// <exception cref="T:System.NotSupportedException">The <see cref="T:System.Collections.Generic.ICollection`1"/> is read-only.</exception>
 public bool Remove(IFileFilter item)
 {
     return _filters.Remove(item);
 }
 public PollingBasedv2FileProcessor(FileProcessorEndpoint endpoint, IFileHandler handler, IFilePostProcessor postProcessor, IFileFilter additionalFilter)
     : base(endpoint, handler, postProcessor, additionalFilter)
 {
     this.pollingTimer = new Timer(Endpoint.PollingInterval) { AutoReset = true };
     this.pollingTimer.Elapsed += this.TimerElapsed;
 }
예제 #53
0
파일: BaseFile.cs 프로젝트: nhtera/CrowdCMS
        private int ListTree(IFile target_file, IFileFilter file_filter, int level)
        {
            IFile[] files = target_file.ListFilesFiltered(file_filter);

             	foreach (IFile file in files) {
             		// Go deeper
             		if (file.IsDirectory) {
             			level++;
             			this.ListTree(file, file_filter, level);
             			level--;
             		}

             		this.fileTree.Add(file);
             	}

             	return 0;
        }
예제 #54
0
파일: ZipFile.cs 프로젝트: nhtera/CrowdCMS
        /// <summary>
        /// Lists a tree of tiles within a directory by the specified filter.
        /// </summary>
        /// <param name="filter">Instance to filter by.</param>
        /// <returns>Returns a filtered list of files.</returns>
        public override IFile[] ListTreeFiltered(IFileFilter filter)
        {
            ArrayList files = new ArrayList();
            ZipFile zipFile = this.OpenZipFile();

            try {
                if (this.IsDirectory) {
                    foreach (ZipEntry entry in zipFile) {
                        if (entry.Name.StartsWith(this.InnerPath.Substring(1) + "/") && entry.Name != this.InnerPath.Substring(1) + "/") {
                            if (entry.IsDirectory)
                                files.Add(new ZipFileImpl(this.manager, "zip://" + this.zipPath + "/" + entry.Name.Substring(0, entry.Name.Length - 1), null, FileType.Unknown));
                            else
                                files.Add(new ZipFileImpl(this.manager, "zip://" + this.zipPath + "/" + entry.Name, null, FileType.Unknown));
                        }
                    }
                }
            } finally {
                zipFile.Close();
            }

            return (IFile[]) files.ToArray(typeof(ZipFileImpl));
        }
예제 #55
0
        /// <summary>
        ///  
        /// </summary>
        /// <param name="filter"></param>
        /// <returns></returns>
        public new IFile[] ListFilesFiltered(IFileFilter filter)
        {
            ArrayList files = new ArrayList();

            foreach (string rootPath in base.manager.RootPaths) {
                IFile rootFile = this.manager.GetFile(rootPath);

                if (!rootFile.Exists)
                    throw new Exception("Root path: " + rootPath + ", does not exists.");

                files.Add(rootFile);
            }

            return (IFile[]) files.ToArray(typeof(IFile));
        }