Example #1
0
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();

            WebApiConfig.Register(GlobalConfiguration.Configuration);
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);
            //allow viewing json in the browser by default
            GlobalConfiguration.Configuration.Formatters[0].SupportedMediaTypes.Add(new MediaTypeHeaderValue("text/html"));

            var data= new programs();
            var connstr = @"mongodb://revolent:[email protected]:35607/revolentdata";
            var client = new MongoDB.Driver.MongoClient(connstr);
            var server = client.GetServer();
            var db = server.GetDatabase("revolentdata");
            var coll = db.GetCollection<programsProgram>("movies");
            var cursor = coll.FindAll();
            data.program = cursor.ToList().ToArray();
            Application["data"] = data;

            //factual api info
            Application["factkey"] = "UVz7N3cX8wHDYon4dHoVfmj8kzYL3sDVJ2SXn8Dl";
            Application["factsec"] = "Ok2lXgEde7JazbsbZBMSJ5bYmH0wbTLycB13TUZW";
        }
        private static MongoDB.Driver.MongoDatabase ConnectToDatabase()
        {
            MongoDB.Driver.MongoClient client = new MongoDB.Driver.MongoClient(mongoUrl);

            var server = client.GetServer();

            var db = server.GetDatabase(mongoDatabase);
            return db;
        }
Example #3
0
        // http://odetocode.com/blogs/scott/archive/2013/04/16/using-gridfs-in-mongodb-from-c.aspx
        public static void Test()
        {
            string fileName = "clip_image071.jpg";

            MongoDB.Driver.MongoClient client = new MongoDB.Driver.MongoClient();
            MongoDB.Driver.MongoServer server = client.GetServer();
            MongoDB.Driver.MongoDatabase database = server.GetDatabase("testdb");
            MongoGridFs gridFs = new MongoGridFs(database);

            MongoDB.Bson.ObjectId id = UploadFile(gridFs, fileName);
            byte[] baFile = DownloadFile(gridFs, id);
            DownloadFile(gridFs, id, @"d:\test.rar");
        }
Example #4
0
        protected void Unnamed1_Click(object sender, System.EventArgs e)
        {
            string fileName = @"D:\stefan.steiger\Downloads\keywords.xlsx";

            MongoDB.Driver.MongoClient client = new MongoDB.Driver.MongoClient("mongodb://localhost/27017/mydb");
            MongoDB.Driver.MongoServer server = client.GetServer();
            MongoDB.Driver.MongoDatabase database = server.GetDatabase("testdb");
            MongoGridFs gridFs = new MongoGridFs(database);

            MongoDB.Bson.ObjectId id = MongoGridFsUsage.UploadFile(gridFs, fileName);
            // byte[] baFile = DownloadFile(gridFs, id);
            // DownloadFile(gridFs, id, @"d:\test.rar");
        }
Example #5
0
        public AlertingRepository(string connection)
        {
            if (string.IsNullOrWhiteSpace(connection))
            {
                connection = "mongodb://localhost:27017";
            }

            _client = new MongoDB.Driver.MongoClient(connection);
            _database = _client.GetDatabase("local",  null);
            _alertTypes = _database.GetCollection<AlertType>("alerttypes");

            var filter = new MongoDB.Bson.BsonDocument();
            long count = _alertTypes.Count(filter);

            // AddTestData();
        }
 public static MongoDB.Driver.IMongoClient GeneratePoolMongodbClient(DataServerConfigSet configSet)
 {
     var settings = new MongoDB.Driver.MongoClientSettings()
     {
         MaxConnectionPoolSize = configSet.MaxPoolSize,
         MinConnectionPoolSize = configSet.MinPoolSize,
         Server = MongoDB.Driver.MongoServerAddress.Parse(configSet.Masters.First().serverUrl.Replace("mongodb://",""))
     };
     var client = new MongoDB.Driver.MongoClient(settings);
     return client;
 }