Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
        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.");
        }
Exemplo n.º 3
0
        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;
 }
Exemplo n.º 7
0
        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);
        }
Exemplo n.º 8
0
        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);
        }
Exemplo n.º 9
0
 public FeedbackRepository(ICollection <Employee> databaseCollection)
 {
     if (databaseCollection == null)
     {
         throw new ArgumentNullException(nameof(databaseCollection));
     }
     employees   = databaseCollection.Load();
     binaryFiles = databaseCollection.CreateGridFSBucket();
 }
Exemplo n.º 10
0
        /// <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);
        }
Exemplo n.º 12
0
        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");
        }
Exemplo n.º 13
0
        static MongoGridFSAssetStoreTests()
        {
            var mongoClient   = new MongoClient("mongodb://localhost");
            var mongoDatabase = mongoClient.GetDatabase("Test");

            GridFSBucket = new GridFSBucket <string>(mongoDatabase, new GridFSBucketOptions
            {
                BucketName = "fs"
            });
        }
Exemplo n.º 14
0
        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);
        }
Exemplo n.º 15
0
        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");
        }
Exemplo n.º 16
0
        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);
        }
Exemplo n.º 17
0
        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);
        }
Exemplo n.º 18
0
        public Stream DownloadingFile(string id)
        {
            IGridFSBucket bucket = GetGridFSBucket();

            ObjectId objectId = new ObjectId(id);

            GridFSDownloadStream <ObjectId> stream = bucket.OpenDownloadStream(objectId);

            return(stream);
        }
Exemplo n.º 19
0
        public IEnumerable <GridFSFileInfo> GetFilesEnumerable()
        {
            IGridFSBucket bucket = GetGridFSBucket();

            FilterDefinition <GridFSFileInfo> filter = Builders <GridFSFileInfo> .Filter.Empty;

            var cursor = bucket.Find(filter).ToEnumerable();

            return(cursor);
        }
Exemplo n.º 20
0
        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);
        }
Exemplo n.º 21
0
        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",
            });
        }
Exemplo n.º 24
0
        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");
        }
Exemplo n.º 25
0
        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.");
        }
Exemplo n.º 26
0
        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 }
            });
        }
Exemplo n.º 27
0
        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");
        }
Exemplo n.º 28
0
        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;
 }
Exemplo n.º 30
0
        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;
            }
        }
Exemplo n.º 31
0
        // 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");
        }
Exemplo n.º 32
0
        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();
 }