상속: 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
 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
        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
 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();
        }
        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
 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);
     }
 }
        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
 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
 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
        /// <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
        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
        /// <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
        /// <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
 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
        /// <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
 /// <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
 public GridFile(Database db)
     : this(db,"fs")
 {
 }