Inheritance: IDatabase
コード例 #1
0
 public CollectionMetaData(string dbName, string name, Connection conn)
 {
     this.connection = conn;
     this.fullName = dbName + "." + name;
     this.name = name;
     this.db = new Database(conn, dbName);
 }
コード例 #2
0
 public void Init()
 {
     db.Connect();
     initDB();
     tests = db["tests"];
     js = tests.JS;
 }
コード例 #3
0
        /// <summary>
        /// Create a new request token from a database request token.
        /// </summary>
        /// <param name="requestToken">The database request token to create a new request token from.</param>
        /// <param name="consumer">The consumer for the request token.</param>
        /// <returns>A new request token created from the database request token.</returns>
        /// <exception cref="ArgumentNullException">Thrown if a parameter is null.</exception>
        internal static RequestToken FromAccessToken(Database.RequestToken requestToken, ConsumerStub consumer)
        {
            if (requestToken == null)
            {
                throw new ArgumentNullException("requestToken", "requestToken is null");
            }

            if (consumer == null)
            {
                throw new ArgumentNullException("consumer", "consumer is null");
            }

            return new RequestToken
            {
                Callback = requestToken.Callback,
                Consumer = consumer,
                Created = requestToken.Created,
                ConsumerVersion = requestToken.ConsumerVersion != null ? requestToken.ConsumerVersion.ToString() : null,
                Id = requestToken.Id != null ? new BsonObjectId(requestToken.Id) : null,
                Scope = requestToken.Scope,
                Token = requestToken.Token,
                TokenSecret = requestToken.TokenSecret,
                Username = requestToken.Username,
                VerificationCode = requestToken.VerificationCode,
            };
        }
コード例 #4
0
ファイル: GridFile.cs プロジェクト: kvnsmth/mongodb-csharp
 public GridFile(Database db, string bucket)
 {
     this.db = db;
     this.files = db[bucket + ".files"];
     this.chunks = db[bucket + ".chunks"];
     this.chunks.MetaData.CreateIndex(new Document().Append("files_id", 1).Append("n", 1),true);
     this.name = bucket;
 }
コード例 #5
0
 public GridFileInfo(Database db, string filename)
 {
     this.db = db;
     this.bucket = "fs";
     this.gridFile = new GridFile(db);
     SetFileDataDefaults(filename);
     if(gridFile.Exists(filename)) this.LoadFileData();
 }
コード例 #6
0
ファイル: MaintenanceTools.cs プロジェクト: ctukc-nt/UPPY_v2
        public MaintenanceTools()
        {
            var conStr = ConfigurationManager.ConnectionStrings["mongoServer"].ToString();
            var dbName = ConfigurationManager.ConnectionStrings["dbName"].ToString();

            _connection = new MongoDbConnection(conStr, dbName);
            _database = new Database(new TicketAutUser(string.Empty, string.Empty), _connection);
        }
コード例 #7
0
ファイル: GridFS.cs プロジェクト: kupetto/mongodb-csharp
 public GridFS(Mongo mongo, Database db, string bucketName)
     : this()
 {
     this.mongo = mongo;
     this.bucketName = bucketName;
     chunks = db[this.bucketName + ".chunks"];
     files = db[this.bucketName + ".files"];
     this.mongo.SetCurrentDB(db);
 }
コード例 #8
0
        public void Init()
        {
            db.Connect();
            tests = db["tests"];
            mrcol = (Collection)tests["mr"];

            CleanDB();
            SetupCollection();
        }
コード例 #9
0
        public void TestSetUp()
        {
            mongo.Connect();
            db = mongo["TestAuth"];
            admindb = mongo["admin"];

            admindb.MetaData.AddUser(adminuser, adminpass);
            admindb.Authenticate(adminuser, adminpass);
            db.MetaData.AddUser(testuser, testpass);
            admindb.Logout();
        }
コード例 #10
0
        protected void InitializeEnvironment()
        {
            Sitecore.Context.IsUnitTesting = true;
            _mongoTestDbConnectionString = ConfigurationManager.ConnectionStrings["nosqlmongotest"].ConnectionString;
            _mongoServer = MongoServer.Create(_mongoTestDbConnectionString);

            InitializeMongoConnection();
            RemoveAllItemsFromMongoTestDatabase();
            _sqlServerSourceDb = Factory.GetDatabase("master");
            _mongoTargetDb = Factory.GetDatabase("nosqlmongotest");
        }
コード例 #11
0
ファイル: Main.cs プロジェクト: rodolfograve/mongodb-csharp
 static void DoBulkInsert(Database db, string col, Document doc, int size)
 {
     for(int i = 0; i < perTrial / size; i++){
         Document[] docs = new Document[size];
         for(int f = 0; f < docs.Length; f++){
             Document ins = new Document();
             doc.CopyTo(ins);
             docs[f] = ins;
         }
         db[col].Insert(docs);
     }
 }
コード例 #12
0
        public override void OnInit()
        {
            IMongoCollection its = DB["indextests"];
            its.Insert(createDoc("S","A","Anderson","OH"));
            its.Insert(createDoc("T","B","Delhi","OH"));
            its.Insert(createDoc("F","B","Cincinnati","OH"));
            its.Insert(createDoc("U","D","Newtown","OH"));
            its.Insert(createDoc("J","E","Newport","KY"));

            adminDb = DB.GetSisterDatabase("admin");
            //adminDb.MetaData.AddUser(adminuser, adminpass);
        }
コード例 #13
0
 public void Initialize()
 {
     should_not_already_be_initialized();
     lock (_syncRoot)
     {
         should_not_already_be_initialized();
         _mongo = new Mongo();
         _mongo.Connect();
         _db = _mongo.getDB("FubuDinner");
         _isInitialized = true;
     }
 }
コード例 #14
0
ファイル: Collection.cs プロジェクト: qjlee/mongodb-csharp
 public long Count(Document spec)
 {
     Database db = new Database(this.connection, this.dbName);
     try{
         Document ret = db.SendCommand(new Document().Append("count",this.Name).Append("query",spec));
         double n = (double)ret["n"];
         return Convert.ToInt64(n);
     }catch(MongoCommandException){
         //FIXME This is an exception condition when the namespace is missing. -1 might be better here but the console returns 0.
         return 0;
     }
 }
コード例 #15
0
ファイル: Collection.cs プロジェクト: sbos/mongodb-csharp
 public long Count(Document spec)
 {
     Database db = new Database(this.connection, this.dbName);
     Collection cmd = db["$cmd"];
     Document ret = cmd.FindOne(new Document().Append("count",this.Name).Append("query",spec));
     if(ret.Contains("ok") && (double)ret["ok"] == 1){
         double n = (double)ret["n"];
         return Convert.ToInt64(n);
     }else{
         //FIXME This is an exception condition when the namespace is missing. -1 might be better here but the console returns 0.
         return 0;
     }
 }
コード例 #16
0
ファイル: Nonces.cs プロジェクト: Glipho/oauth-providers
        /// <summary>
        /// Adds a nonce to the database.
        /// </summary>
        /// <param name="nonce">Details of the nonce to add.</param>
        /// <returns>true if nonce was successful added; else false.</returns>
        /// <exception cref="ArgumentNullException">Thrown if a parameter is null.</exception>
        /// <exception cref="Glipho.OAuth.OAuthException">Thrown if an error occurs while executing the requested command.</exception>
        public bool Add(Database.Nonce nonce)
        {
            if (nonce == null)
            {
                throw new ArgumentNullException("nonce", "nonce is null");
            }

            try
            {
                var result = this.noncesCollection.Insert(Nonce.FromNonce(nonce), WriteConcern.WMajority);
                return result.Ok;
            }
            catch (MongoException ex)
            {
                throw new OAuthException("Unable to add nonce to the database. A database error has occurred.", ex, ErrorCode.Database);
            }
        }
コード例 #17
0
ファイル: UserFavorite.cs プロジェクト: ningliaoyuan/Antaeus
        public UserFavorite(Database db, string username)
        {
            DB = db;
            UserFavoriteCollection = DB["UserFavorite"];

            // initial from db
            var spec = new Document() {
                    { "username", username }
                };

            InternalDocument = UserFavoriteCollection.FindOne(spec);

            if (InternalDocument == null)
            {
                InternalDocument = new Document { { "username", username } };
                DB["UserFavorite"].Insert(InternalDocument);
            }
        }
コード例 #18
0
ファイル: Consumers.cs プロジェクト: Glipho/oauth-providers
        /// <summary>
        /// Create a new consumer.
        /// </summary>
        /// <param name="newConsumer">The <see cref="Database.Consumer"/> to create.</param>
        /// <returns>The created <see cref="Database.Consumer"/>.</returns>
        /// <exception cref="ArgumentException">Thrown if a parameter is not valid.</exception>
        /// <exception cref="Glipho.OAuth.OAuthException">Thrown if an error occurs while executing the requested command.</exception>
        public Database.Consumer Create(Database.Consumer newConsumer)
        {
            if (newConsumer == null)
            {
                throw new ArgumentNullException("newConsumer", "newConsumer is null");
            }

            try
            {
                var dataConsumer = Consumer.FromConsumer(newConsumer);
                this.consumersCollection.Insert(dataConsumer, WriteConcern.WMajority);
                return dataConsumer.ToConsumer();
            }
            catch (MongoException ex)
            {
                throw new OAuthException("Unable to create a consumer. A database error has occurred.", ex, ErrorCode.Database);
            }
        }
コード例 #19
0
        /// <summary>
        /// Create a new token.
        /// </summary>
        /// <param name="issuedToken">The details of the token to create.</param>
        /// <returns>Identifier of the newly created token.</returns>
        /// <exception cref="ArgumentNullException">Thrown if a parameter is null.</exception>
        /// <exception cref="Glipho.OAuth.OAuthException">Thrown if an error occurs while executing the requested command.</exception>
        public string Create(Database.IssuedToken issuedToken)
        {
            if (issuedToken == null)
            {
                throw new ArgumentNullException("issuedToken", "issuedToken is null");
            }

            try
            {
                var mongoToken = IssuedToken.FromIssuedToken(issuedToken, this.GetConsumerStub(issuedToken.ConsumerKey));
                this.tokensCollection.Insert(mongoToken, WriteConcern.WMajority);
                return mongoToken.Id.ToString();
            }
            catch (MongoException ex)
            {
                throw new OAuthException("Unable to token in the database. A database error has occurred.", ex, ErrorCode.Database);
            }
        }
コード例 #20
0
ファイル: AccessToken.cs プロジェクト: Glipho/oauth-providers
        /// <summary>
        /// Create a new access token from a database access token.
        /// </summary>
        /// <param name="accessToken">The database access token to create a new access token from.</param>
        /// <param name="consumer">The consumer for the access token.</param>
        /// <returns>A new access token created from the database access token.</returns>
        /// <exception cref="ArgumentNullException">Thrown if a parameter is null.</exception>
        internal static AccessToken FromAccessToken(Database.AccessToken accessToken, ConsumerStub consumer)
        {
            if (accessToken == null)
            {
                throw new ArgumentNullException("accessToken", "accessToken is null");
            }

            if (consumer == null)
            {
                throw new ArgumentNullException("consumer", "consumer is null");
            }

            return new AccessToken
            {
                Consumer = consumer,
                Created = accessToken.Created,
                Id = accessToken.Id != null ? new BsonObjectId(accessToken.Id) : null,
                Scope = accessToken.Scope,
                Token = accessToken.Token,
                TokenSecret = accessToken.TokenSecret,
                Username = accessToken.Username,
            };
        }
コード例 #21
0
 public void Init()
 {
     mongo.Connect();
     db = mongo["tests"];
     cleanDB();
 }
コード例 #22
0
ファイル: GridFS.cs プロジェクト: kupetto/mongodb-csharp
 public GridFS(Mongo mongo, Database db)
     : this(mongo, db, DEFAULT_ROOT)
 {
 }
コード例 #23
0
        /// <summary>
        /// Update an existing token.
        /// </summary>
        /// <param name="token">The token of the issued token to update.</param>
        /// <param name="updatedToken">Details to update the token with.</param>
        /// <returns>true if update was successful; else false.</returns>
        /// <exception cref="ArgumentException">Thrown if a parameter is not valid.</exception>
        /// <exception cref="ArgumentNullException">Thrown if a parameter is null.</exception>
        /// <exception cref="Glipho.OAuth.OAuthException">Thrown if an error occurs while executing the requested command.</exception>
        public bool Update(string token, Database.IssuedToken updatedToken)
        {
            if (string.IsNullOrWhiteSpace(token))
            {
                throw new ArgumentException("token does not have a value.", "token");
            }

            if (updatedToken == null)
            {
                throw new ArgumentNullException("updatedToken", "updatedToken is null");
            }

            try
            {
                var mongoToken = IssuedToken.FromIssuedToken(updatedToken, this.GetConsumerStub(updatedToken.ConsumerKey));
                var query = Query<IssuedToken>.EQ(t => t.Token, token);
                var sort = SortBy<IssuedToken>.Ascending(t => t.Id);
                var existingToken = this.tokensCollection.FindOne(query);
                mongoToken.Id = existingToken.Id;
                var result = this.tokensCollection.FindAndModify(query, sort, mongoToken.GetUpdateStatement(), true, false);
                return result.Ok;
            }
            catch (MongoException ex)
            {
                throw new OAuthException(string.Format("Unable to update token with token of \"{0}\" in the database. A database error has occurred.", token), ex, ErrorCode.Database);
            }
        }
コード例 #24
0
ファイル: Server.cs プロジェクト: automatonic/mongodb-net
        /// <summary>
        /// Gets an interface for the named database.
        /// </summary>
        /// <param name="binding">The binding.</param>
        /// <returns></returns>
        public IDatabase GetDatabase(IDBBinding binding)
        {
            IDatabase db = null;
            _DatabaseLookup.TryGetValue(binding.DatabaseName.ToString(), out db);
            if (db != null)
                return db;

            lock (_DatabaseLookup)
            {
                _DatabaseLookup.TryGetValue(binding.DatabaseName.ToString(), out db);
                if (db != null)
                    return db;

                db = new Database(this, binding);

                _DatabaseLookup[binding.DatabaseName.ToString()] = db;
                return db;
            }
        }
コード例 #25
0
ファイル: Collection.cs プロジェクト: henon/mongodb-csharp
 /// <summary>
 /// Entrypoint into executing a map/reduce query against the collection. 
 /// </summary>
 /// <returns>
 /// A <see cref="MapReduce"/>
 /// </returns>
 public MapReduce MapReduce()
 {
     Database db = new Database(this.connection, this.dbName);
     return new MapReduce(db, this.Name);
 }
コード例 #26
0
 public Document QueryMaster()
 {
     Database admin = new Database(this,"admin");
     Document master = admin["$cmd"].FindOne(new Document().Append("ismaster", 1.0));
     return master;
 }
コード例 #27
0
        public void save()
        {
            Database dataBase = new Database();
            WriteConcernResult result;

            if(string.IsNullOrWhiteSpace(Id))
            {
                this.dateTime = System.DateTime.Now;
                result = dataBase.TrackingEvents.Insert<Domain.TrackingEvent>(this);
                //writeImage(this.imgData1);
            }
            else
            {
                result = dataBase.TrackingEvents.Update(Query.EQ("_id", Id),
                        Update.Combine(
                            Update.Set("parcelNum", parcelNum),
                            Update.Set("address", address),
                            Update.Set("latitude", latitude),
                            Update.Set("longitude", longitude),
                            Update.Set("accuracy", accuracy),
                            Update.Set("comments", comments),
                            Update.Set("dateTime", dateTime),
                            Update.Set("imgData1", imgData1),
                            Update.Set("imgData2", imgData2),
                            Update.Set("imgData3", imgData3)));
            }

            if (!result.Ok)
            {
                throw new Exception(result.ErrorMessage);
            }
        }
 public void AddDatabase(Database database)
 {
     Assert.ArgumentNotNull(database, "database");
     Sitecore.Diagnostics.Log.Info(string.Format("MongoOplogCacheClearer: Monitoring {0}", database.Name), this);
     _databases.Add(database);
 }
コード例 #29
0
 public DatabaseMetaData(string name, Connection conn)
 {
     this.connection = conn;
     this.name = name;
     this.db = new Database(conn, name);
 }
コード例 #30
0
ファイル: GridFile.cs プロジェクト: kvnsmth/mongodb-csharp
 public GridFile(Database db)
     : this(db,"fs")
 {
 }