public FileWorkerAgentImpl(ITransportSender transport, ILogger <FileWorkerAgentImpl> logger) : base(transport, AgentType.FileManager, "", MessageType.FileRequest, MessageType.CreateFile, MessageType.DeleteFile) { _logger = logger; var client = new MongoClient("mongodb://*****:*****@localhost"); var database = client.GetDatabase("tasks"); _gridFs = new GridFSBucket(database); }
private readonly IGridFSBucket _gridFS; //файловое хранилище public ProductPhotoRepository(MediaContext db) { Log.Instance.LogAsInfo($"{nameof(ProductPhotoRepository)}.{nameof(ProductPhotoRepository)}: Constructor is tratring."); _database = db.Database; _gridFS = db.GridFsBucket; CreateProductIdIndex().GetAwaiter().GetResult(); Log.Instance.LogAsInfo($"{nameof(ProductPhotoRepository)}.{nameof(ProductPhotoRepository)}: Constructor is ended."); }
public SrtService(IHostingEnvironment env, IDatabaseSettings settings) { _env = env; var client = new MongoClient(settings.ConnectionString); var database = client.GetDatabase(settings.DatabaseName); bucket = new GridFSBucket(database); _users = database.GetCollection <User>("users"); }
public void Setup() { ICollection<Employee> dbEmployees = Substitute.For<ICollection<Employee>>(); employees = Substitute.For<IMongoCollection<Employee>>(); binaryFiles = Substitute.For<IGridFSBucket>(); dbEmployees.Load().Returns(employees); dbEmployees.CreateGridFSBucket().Returns(binaryFiles); sut = new FeedbackRepository(dbEmployees); }
public FeedbackRepository(ICollection<Employee> databaseCollection) { if (databaseCollection == null) { throw new ArgumentNullException(nameof(databaseCollection)); } employees = databaseCollection.Load(); binaryFiles = databaseCollection.CreateGridFSBucket(); }
// constructors protected GridFSDownloadStreamBase( IGridFSBucket <TFileId> bucket, IReadBinding binding, GridFSFileInfo <TFileId> fileInfo) { _bucket = bucket; _binding = binding; _fileInfo = fileInfo; }
public ProductService(ICapstoneDatabaseSettings settings) { var client = new MongoClient(settings.ConnectionString); var database = client.GetDatabase(settings.DatabaseName); _products = database.GetCollection <Product>(settings.CapstoneCollectionName); GridFsBucket = new GridFSBucket(database); }
public MongoContext() { string connectionString = Resources.ConnectionString; MongoUrlBuilder connection = new MongoUrlBuilder(url: connectionString); MongoClient client = new MongoClient(connectionString: connectionString); database = client.GetDatabase(name: connection.DatabaseName); gridFS = new GridFSBucket(database: database); }
public FeedbackRepository(ICollection <Employee> databaseCollection) { if (databaseCollection == null) { throw new ArgumentNullException(nameof(databaseCollection)); } employees = databaseCollection.Load(); binaryFiles = databaseCollection.CreateGridFSBucket(); }
/// <summary> /// Use the Delete or DeleteAsync methods to delete a single file identified by its Id. /// </summary> public void DeletingFiles(ObjectId id) { //For example, to find the newest revision of the file named “securityvideo” uploaded in January 2015: IGridFSBucket bucket = GetGridFSBucket(); bucket.Delete(id); //await bucket.DeleteAsync(id); }
public MongoImageStore(IMongoDatabase database) { var db = database ?? throw new System.ArgumentNullException(nameof(database)); var options = new GridFSBucketOptions { BucketName = "productImages" }; _bucket = new GridFSBucket(db, options); }
public ProductService() { const string connectionString = "mongodb://localhost:27017/ShowcaseDB"; var connection = new MongoUrlBuilder(connectionString); var client = new MongoClient(connectionString); var database = client.GetDatabase(connection.DatabaseName); gridFS = new GridFSBucket(database); products = database.GetCollection <Product>("products"); }
static MongoGridFSAssetStoreTests() { var mongoClient = new MongoClient("mongodb://localhost"); var mongoDatabase = mongoClient.GetDatabase("Test"); GridFSBucket = new GridFSBucket <string>(mongoDatabase, new GridFSBucketOptions { BucketName = "fs" }); }
public void Setup() { ICollection <Employee> dbEmployees = Substitute.For <ICollection <Employee> >(); employees = Substitute.For <IMongoCollection <Employee> >(); binaryFiles = Substitute.For <IGridFSBucket>(); dbEmployees.Load().Returns(employees); dbEmployees.CreateGridFSBucket().Returns(binaryFiles); sut = new FeedbackRepository(dbEmployees); }
IMongoCollection <Book> Books; // коллекция в базе данных public ProductService() { // строка подключения var client = new MongoClient("mongodb+srv://mongotest_user:[email protected]/myFirstDatabase?retryWrites=true&w=majority"); var database = client.GetDatabase("test"); gridFS = new GridFSBucket(database); // обращаемся к коллекции Products Books = database.GetCollection <Book>("Books"); }
public MongoGridFsAssetStore(IGridFSBucket <string> bucket, string path) { Guard.NotNull(bucket, nameof(bucket)); Guard.NotNullOrEmpty(path, nameof(path)); this.bucket = bucket; this.path = path; directory = new DirectoryInfo(path); }
public ImgService(IConfiguration config) { var url = MongoUrl.Create(config.GetConnectionString("StoreDb")); var client = new MongoClient(url); var db = client.GetDatabase(url.DatabaseName); _topics = db.GetCollection <Topic>("topic"); _employers = db.GetCollection <Employer>("employer"); bucket = new GridFSBucket(db); }
public Stream DownloadingFile(string id) { IGridFSBucket bucket = GetGridFSBucket(); ObjectId objectId = new ObjectId(id); GridFSDownloadStream <ObjectId> stream = bucket.OpenDownloadStream(objectId); return(stream); }
public IEnumerable <GridFSFileInfo> GetFilesEnumerable() { IGridFSBucket bucket = GetGridFSBucket(); FilterDefinition <GridFSFileInfo> filter = Builders <GridFSFileInfo> .Filter.Empty; var cursor = bucket.Find(filter).ToEnumerable(); return(cursor); }
public IGridFSBucket gridFS; //File repository public MongoContext() { string connectionString = ConfigurationManager.ConnectionStrings["MongoDb"].ConnectionString; var connection = new MongoUrlBuilder(connectionString); MongoClient client = new MongoClient(connectionString); database = client.GetDatabase(connection.DatabaseName); gridFS = new GridFSBucket(database); }
public MusicService(IConfiguration config) { var url = MongoUrl.Create(config.GetConnectionString("StoreDb")); var client = new MongoClient(url); var db = client.GetDatabase(url.DatabaseName); bucket = new GridFSBucket(db); _music = db.GetCollection <Music>("music"); //_users = db.GetCollection<User>("users"); }
public MongoContext() { ConnectionString = ConfigurationManager.ConnectionStrings["MongoDbConnection"].ConnectionString; var connnection = new MongoUrlBuilder(ConnectionString); MongoClient client = new MongoClient(); Database = client.GetDatabase(connnection.DatabaseName); GridFS = new GridFSBucket(Database); SupplerCompaniesCollection = Database.GetCollection <SupplerCompanies>("SupplerCompanies"); }
public GenericRepository(IMongoClient mongoClient, string dbName, string collectionName) { var mongoDatabase = mongoClient.GetDatabase(dbName); mongoCollection = mongoDatabase.GetCollection <TModel>(collectionName); gridFs = new GridFSBucket(mongoDatabase, new GridFSBucketOptions() { BucketName = collectionName + "FS", }); }
public Context() { GetConnection(); var connention = new MongoUrlBuilder(ConnectionString); MongoClient client = new MongoClient(); IMongoDatabase db = client.GetDatabase(connention.DatabaseName); GridFS = new GridFSBucket(db); ProductsList = db.GetCollection <Product>("Products"); CategoriesList = db.GetCollection <Category>("Categories"); }
public MediaContext(string connectionString) { Log.Instance.LogAsInfo($"{nameof(MediaContext)}.{nameof(MediaContext)}: Constructor is tratring."); var connection = new MongoUrlBuilder(connectionString); MongoClient client = new MongoClient(connectionString); Database = client.GetDatabase(connection.DatabaseName); GridFsBucket = new GridFSBucket(Database); Log.Instance.LogAsInfo($"{nameof(MediaContext)}.{nameof(MediaContext)}: Constructor is completed."); }
internal static MessageEncoderSettings GetMessageEncoderSettings <TFileId>(this IGridFSBucket <TFileId> bucket) { var databaseSettings = bucket.Database.Settings; return(new MessageEncoderSettings { { MessageEncoderSettingsName.GuidRepresentation, databaseSettings.GuidRepresentation }, { MessageEncoderSettingsName.ReadEncoding, databaseSettings.ReadEncoding ?? Utf8Encodings.Strict }, { MessageEncoderSettingsName.WriteEncoding, databaseSettings.WriteEncoding ?? Utf8Encodings.Strict } }); }
public UsersService() { string connectionString = "mongodb://127.0.0.1:27017/test"; var connection = new MongoUrlBuilder(connectionString); var client = new MongoClient(connectionString); IMongoDatabase db = client.GetDatabase(connection.DatabaseName); gridFs = new GridFSBucket(db); Users = db.GetCollection <User>("users"); }
public LinkService() { string connectionString = "mongodb://localhost:27017/Users"; var connection = new MongoUrlBuilder(connectionString); MongoClient client = new MongoClient(connectionString); IMongoDatabase database = client.GetDatabase(connection.DatabaseName); gridFS = new GridFSBucket(database); Links = database.GetCollection <Link>("links"); Visits = database.GetCollection <CounterOfVisits>("counter"); }
public UnifiedGridFsUploadOperation( IGridFSBucket bucket, string filename, byte[] source, GridFSUploadOptions options) { _bucket = bucket; _filename = filename; _source = source; _options = options; }
public FolderDbContext(IOptions <MongoSettings> settings) { var client = new MongoClient(settings.Value.ConnectionString); if (client != null) { _database = client.GetDatabase(settings.Value.Databases[0]); _bucket = new GridFSBucket(_database); collections = settings.Value.FileCollections; } }
// constructor public BlobService(MongoClient client) { // Get database (if it does not exists it will be created) var database = client.GetDatabase("db"); // Get blobs bucket _databaseBlobs = new GridFSBucket(database); // Get collections (if it does not exists it will be created) BlobMetadata = database.GetCollection<BsonDocument>("fs.files"); }
public async Task <StoredFileInfo> StoreAsync(IFormFile file, CancellationToken cancellationToken = default) { _ = file ?? throw new ArgumentNullException(nameof(file)); var fileId = Guid.NewGuid().ToString(); IGridFSBucket bucket = getBucket(_dbClient); StoredFileInfo fileInfo = await uploadFile(fileId, file, bucket, cancellationToken); return(fileInfo); }
/// <summary> /// Initialize scan result service. /// </summary> /// <param name="db">Mongo database.</param> /// <param name="bucket">GridFS bucket.</param> /// <param name="consulClient">Consul client.</param> /// <param name="backgroundJobClient">Background job client.</param> public ScanResultService( IMongoDatabase db, IGridFSBucket bucket, IConsulClient consulClient, IBackgroundJobClient backgroundJobClient) { _bucket = bucket; _consulClient = consulClient; _backgroundJobClient = backgroundJobClient; _collection = db.GetCollection <ScanResult>(CollectionName); }
private ObjectId CreateGridFSFile(IGridFSBucket bucket, byte[] content) { return bucket.UploadFromBytes("filename", content); }
public MongoMessageDataRepository(IMongoMessageUriResolver mongoMessageUriResolver, IGridFSBucket gridFsBucket, IFileNameCreator randomFileNameCreator) { _mongoMessageUriResolver = mongoMessageUriResolver; _gridFsBucket = gridFsBucket; _randomFileNameCreator = randomFileNameCreator; }
private void EnsureBucketExists(IGridFSBucket bucket) { bucket.UploadFromBytes("filename", new byte[0]); }
public MongoDbMessageDataRepository(IMessageDataResolver resolver, IGridFSBucket bucket, IFileNameGenerator fileNameGenerator) { _resolver = resolver; _bucket = bucket; _fileNameGenerator = fileNameGenerator; }
private void DropBucket(IGridFSBucket bucket) { bucket.Drop(); }