Example #1
0
 public DateTime GetLastModified(IEnumerable <string> filenames)
 {
     return(gfs
            .Find(Query.In("filename", new BsonArray(filenames)))
            .SetSortOrder(SortBy.Descending("uploadDate"))
            .SetLimit(1)
            .Select(x => x.UploadDate).FirstOrDefault());
 }
Example #2
0
        public int FindFiles(string filename, ArrayList files, DokanFileInfo info)
        {
            Trace.TraceInformation("FindFiles: {0}", filename);
            filename = GetPath(filename).TrimEnd('\\') + "\\";

            var regex         = String.Format(@"{0}[^\\]+\\?(?=.*)$", Regex.Escape(filename));
            var matchingFiles = _gridFs.Find(
                Query.Matches("filename", new BsonRegularExpression(regex, "i"))
                );

            foreach (var fsFileInfo in matchingFiles)
            {
                files.Add(fsFileInfo.GetFileInformation());
            }
            var directoryNames = _gridFs.Files.MapReduce(
                String.Format(
                    @"var match = /^{0}([^\\]+)\\/i.exec(this.filename);", Regex.Escape(filename)) +
                @"if(match != null && match.length > 1){
                        emit(match[1],this._id);
                    }
                ",
                "function(){}",
                new MapReduceOptionsBuilder()
                .SetFinalize("function(key,values){return key;}")
                .SetOutput(new MapReduceOutput("GridDirectories"))
                );

            foreach (var matchingDirectory in directoryNames.GetResults())
            {
                files.Add(Extensions.NewDirectory(matchingDirectory.GetValue("value").AsString));
            }
            return(0);
        }
        public IEnumerable <FileModel> GetFilesForPatient(PatientModel patient)
        {
            var cursor = _gridFS.Find(Query.EQ("metadata.PatientID", patient.ID));

            foreach (var result in cursor)
            {
                yield return(FileModelFromGridFSMetadata(result));
            }
        }
Example #4
0
        public void FindByNameTest()
        {
            gridFS.Delete(Query.Null);
            Assert.IsFalse(gridFS.Exists(UploadFileName));

            var fileInfo = UploadHelloWord();

            gridFS.Find(UploadFileName).RunEach(fi => fi.Should().Be(fileInfo));
        }
        public void TestFindByName()
        {
            _gridFS.Delete(Query.Null);
            Assert.IsFalse(_gridFS.Exists("HelloWorld.txt"));

            var fileInfo = UploadHelloWorld();

            foreach (var foundInfo in _gridFS.Find("HelloWorld.txt"))
            {
                Assert.AreEqual(fileInfo, foundInfo);
            }
        }
Example #6
0
        /// <summary>
        /// finds all files
        /// </summary>
        /// <param name="startsWithPath"></param>
        /// <param name="includeTempFiles"></param>
        /// <param name="skip"></param>
        /// <param name="limit"></param>
        /// <returns></returns>
        public List <IStorageFile> FindAll(string startsWithPath = null, bool includeTempFiles = false, int?skip = null, int?limit = null)
        {
            //all filepaths are lowercase and all starts with folder separator
            if (!string.IsNullOrWhiteSpace(startsWithPath))
            {
                startsWithPath = startsWithPath.ToLowerInvariant();

                if (!startsWithPath.StartsWith(FOLDER_SEPARATOR))
                {
                    startsWithPath = FOLDER_SEPARATOR + startsWithPath;
                }
            }

            List <IMongoQuery> queries = new List <IMongoQuery>();

            if (!includeTempFiles)
            {
                IMongoQuery tmpFolderQuery        = Query.Matches("filename", new BsonRegularExpression("^(/" + TMP_FOLDER_NAME + "/)", "i"));
                IMongoQuery tmpFolderExclideQuery = Query.Not(tmpFolderQuery);
                queries.Add(tmpFolderExclideQuery);
            }

            if (!string.IsNullOrWhiteSpace(startsWithPath))
            {
                //TODO change to starts with - now is contains
                var regex = new BsonRegularExpression(string.Format(".*{0}.*", startsWithPath), "i");
                queries.Add(Query.Matches("filename", regex));
            }

            IMongoQuery finalQuery = queries.Count > 0 ? Query.And(queries) : Query.Null;
            var         cursor     = gfs.Find(finalQuery);

            if (skip.HasValue)
            {
                cursor.SetSkip(skip.Value);
            }

            if (limit.HasValue)
            {
                cursor.SetLimit(limit.Value);
            }

            IEnumerable <MongoGridFSFileInfo> files = cursor.ToList();

            return(cursor.AsQueryable().Select(f => (IStorageFile)(new MongoStorageFile(f))).ToList());
        }
Example #7
0
        public void DeleteDirectory(string virtualPath)
        {
            string      fixedPath   = FixPath(virtualPath);
            MongoGridFS mongoGridFs = GetGridFS();
            var         fileInfos   = mongoGridFs.Find(Query.Matches("metadata.directory_name", new BsonRegularExpression(new Regex(@"^" + fixedPath))));

            foreach (var fi in fileInfos)
            {
                mongoGridFs.DeleteById(fi.Id);
            }

            mongoGridFs.Delete(fixedPath);

            if (DirectoryDeleted != null)
            {
                DirectoryDeleted.Invoke(this, new FileEventArgs(virtualPath, null));
            }
        }
Example #8
0
        public void MoveDirectory(string fromVirtualPath, string destinationVirtualPath)
        {
            string      fixedPath   = FixPath(fromVirtualPath);
            MongoGridFS mongoGridFs = GetGridFS();
            var         fileInfos   = mongoGridFs.Find(Query.Matches("metadata.directory_name", new BsonRegularExpression(new Regex(@"^" + fixedPath))));

            foreach (var fi in fileInfos)
            {
                string newFileName = FixPath(destinationVirtualPath + "/" + fi.Name.Substring(fromVirtualPath.Length));
                InternalMoveFile(fi.Name, newFileName);
            }

            InternalMoveFile(fromVirtualPath, destinationVirtualPath);

            if (DirectoryMoved != null)
            {
                DirectoryMoved.Invoke(this, new FileEventArgs(destinationVirtualPath, fromVirtualPath));
            }
        }
Example #9
0
        public void TestReadAllGridFS2Text()
        {
            var         server       = MongoServer.Create("mongodb://localhost:27017");
            var         db           = server.GetDatabase("dcm");
            var         gridSettings = new MongoGridFSSettings();
            MongoGridFS fs           = db.GetGridFS(gridSettings);
            var         fileInfo     = fs.Find(Query.EQ("filename", "D:\\Download\\FileTestUpload\\Hello2.txt"));

            int index = 0;

            foreach (var item in fileInfo)
            {
                MongoGridFSStream readerFS = item.Open(System.IO.FileMode.Open);

                StreamReader reader = new StreamReader(readerFS);
                string       text   = reader.ReadToEnd();
                Console.WriteLine("####### {0}", ++index);
                Console.WriteLine(text);
            }
        }