Esempio n. 1
0
 static Database()
 {
     mongodb = MongoDB.Driver.MongoServer.Create(
         string.Format("mongodb://127.0.0.1:{0}/?safe=true;connectTimeoutMS=10000",
                       StationRegistry.GetValue("dbPort", 10319)));                                           // TODO: Remove Hard code
     wammer = mongodb.GetDatabase("wammer");
 }
Esempio n. 2
0
        static void Main(string[] args)
        {
            var sw = new System.Diagnostics.Stopwatch();

            sw.Start();
            var settings = new MongoDB.Driver.MongoServerSettings();

            var address = new MongoDB.Driver.MongoServerAddress(Properties.Settings.Default.Server, Properties.Settings.Default.Port);

            settings.Server = address;

            MongoDB.Driver.MongoServer server = new MongoDB.Driver.MongoServer(settings);


            var           client   = new MongoDB.Driver.MongoClient();
            MongoDatabase database = server.GetDatabase("mc2db");

            Console.WriteLine("Aloitetaan...");
            var now    = MC2DateTimeValue.Now().ToLocalTime();
            var nowStr = string.Format("{0:0000}-{1:00}-{2:00}-{3:00}-{4:00}-{5:00}",
                                       now.Year, now.Month, now.Day, now.Hour, now.Minute, now.Second);

            var logFile = Path.Combine(string.Format("{0}_{1}.txt", Properties.Settings.Default.ExcelPath + "\\Log", nowStr));

            if (!Directory.Exists(Path.GetDirectoryName(logFile)))
            {
                Directory.CreateDirectory(Path.GetDirectoryName(logFile));
            }
            var x = new PayrollExport(logFile, database);

            x.ExportDocuments();
            Console.WriteLine("Valmis...aikaa kului {0} minuuttia", sw.Elapsed.TotalMinutes);
        }
Esempio n. 3
0
        } // End Sub CreateIndex

        // Following example show how to save file and read back from gridfs(using official mongodb driver):
        // http://www.mongovue.com/
        public void Test()
        {
            MongoDB.Driver.MongoServer   server   = MongoServer.Create("mongodb://localhost:27020");
            MongoDB.Driver.MongoDatabase database = server.GetDatabase("tesdb");

            string fileName    = "D:\\Untitled.png";
            string newFileName = "D:\\new_Untitled.png";

            using (System.IO.FileStream fs = new System.IO.FileStream(fileName, System.IO.FileMode.Open))
            {
                MongoDB.Driver.GridFS.MongoGridFSFileInfo gridFsInfo = database.GridFS.Upload(fs, fileName);
                BsonValue fileId = gridFsInfo.Id;

                ObjectId oid = new ObjectId(fileId.AsByteArray);
                MongoDB.Driver.GridFS.MongoGridFSFileInfo file = database.GridFS.FindOne(Query.EQ("_id", oid));

                using (System.IO.Stream stream = file.OpenRead())
                {
                    byte[] bytes = new byte[stream.Length];
                    stream.Read(bytes, 0, (int)stream.Length);
                    using (System.IO.FileStream newFs = new System.IO.FileStream(newFileName, System.IO.FileMode.Create))
                    {
                        newFs.Write(bytes, 0, bytes.Length);
                    } // End Using newFs
                }     // End Using stream
            }         // End using fs
        }             // End Sub Test
Esempio n. 4
0
        /// <summary>
        /// Dispose(bool disposing) executes in two distinct scenarios.
        /// If disposing equals true, the method has been called directly
        /// or indirectly by a user's code. Managed and unmanaged resources
        /// can be disposed.
        /// If disposing equals false, the method has been called by the
        /// runtime from inside the finalizer and you should not reference
        /// other objects. Only unmanaged resources can be disposed.
        /// </summary>
        protected virtual void Dispose(bool disposing)
        {
            // Check to see if Dispose has already been called.
            if (!this._disposed)
            {
                // Note disposing has been done.
                _disposed = true;

                // If disposing equals true, dispose all managed
                // and unmanaged resources.
                if (disposing)
                {
                    if (_server != null)
                    {
                        try
                        {
                            // Disconnect from the server.
                            _server.Disconnect();
                        }
                        catch { }
                    }
                }

                // Call the appropriate methods to clean up
                // unmanaged resources here.
                _server         = null;
                _client         = null;
                _serverAddress  = null;
                _clientSettings = null;
            }
        }
Esempio n. 5
0
        public ActionResult JsonAction2()
        {
            var mongoServSettings = new MongoDB.Driver.MongoServerSettings();

            mongoServSettings.Server = new MongoDB.Driver.MongoServerAddress("localhost");

            var mongoServer = new MongoDB.Driver.MongoServer(mongoServSettings);

            mongoServer.Connect();

            var db = mongoServer.GetDatabase("monitera");

            var collection = db.GetCollection<db>("dbo.post");
            //collection.Insert(new db { gender = "m"});

            var pozitif = Query<db>.Where(f => f.sentimentid == 1);
            var notr = Query<db>.Where(f => f.sentimentid == 2);
            var negatif = Query<db>.Where(f => f.sentimentid == 3);
            var poznotr = Query<db>.Where(f => f.sentimentid == 4);
            var negnotr = Query<db>.Where(f => f.sentimentid == 5);

            var poz = collection.Count(pozitif);
            var no = collection.Count(notr);
            var ne = collection.Count(negatif);
            var pn = collection.Count(poznotr);
            var nn = collection.Count(negnotr);

            var oranlar = (new[]{
                                 new{
                                     Durum = "Pozitif",
                                     value = poz
                                 },

               new {
                Durum = "Nötr",
                value = no

            },
            new {
                Durum = "Negatif",
                value = ne

            },
            new {
                Durum = "Pozitif - Nötr",
                value = pn

            },
            new {
                Durum = "Negatif - Nötr",
                value = nn

            }
            }
            );

            return Json(oranlar, JsonRequestBehavior.AllowGet);
        }
Esempio n. 6
0
        static MongoDBCurrentInfoMgr()
        {
            ip = ConfigHelper.GetConfig("mongodbserverIP");
            port = int.Parse(ConfigHelper.GetConfig("mongodbserverPort"));

            MongoDB.Driver.MongoConnectionSettings setting = new MongoDB.Driver.MongoConnectionSettings();
            setting.Address = new MongoDB.Driver.MongoServerAddress(ip, port);
            setting.DatabaseName = dbName;
            mongo = new MongoDB.Driver.MongoServer(setting);
        }
Esempio n. 7
0
 /// <summary> Mongo服务器 </summary>
 /// <returns></returns>
 private MongoDatabase Server()
 {
     var server = new MongoServer(new MongoServerSettings
     {
         Servers = Contains.Config.Mongo.Servers.Select(t => new MongoServerAddress(t.Host, t.Port)),
         Credentials =
             Contains.Config.Mongo.Credentials.Select(
                 t => MongoCredential.CreateCredential(t.DataBase, t.User, t.Pwd))
     });
     return server.GetDatabase(_database);
 }
Esempio n. 8
0
        /// <summary> Mongo服务器 </summary>
        /// <returns></returns>
        private MongoDatabase Server()
        {
            var server = new MongoServer(new MongoServerSettings
            {
                Servers     = Contains.Config.Mongo.Servers.Select(t => new MongoServerAddress(t.Host, t.Port)),
                Credentials =
                    Contains.Config.Mongo.Credentials.Select(
                        t => MongoCredential.CreateCredential(t.DataBase, t.User, t.Pwd))
            });

            return(server.GetDatabase(_database));
        }
Esempio n. 9
0
        protected void btnGetConnlections_Click(object sender, EventArgs e)
        {
            BsonDocument docFind = new BsonDocument();

            MongoDB.Driver.MongoServer server = MongoDB.Driver.MongoServer.Create(ConfigurationManager.AppSettings["mongoDBConfig"]);
            server.Connect();
            //获取指定数据库
            MongoDB.Driver.MongoDatabase db = server.GetDatabase(ConfigurationManager.AppSettings["mongoDBName"].ToString());
            string collection = txtCollection.Text.Trim();

            //获取表
            MongoDB.Driver.MongoCollection <BsonDocument> col = db.GetCollection <BsonDocument>(collection);
            lblCollections.Text = "表大小:" + col.GetTotalDataSize() / (1024 * 1024) + "M";//db['119004logs'].totalIndexSize()+db['119004logs'].dataSize()
            this.listBoxCollections.DataSource = col.Database.GetCollectionNames();
            listBoxCollections.DataBind();

            lblDataBaseCount.Text = "数据库大小为:" + db.GetStats().StorageSize / (1024 * 1024) + "M";
        }
Esempio n. 10
0
        protected void btnGetIndex_Click(object sender, EventArgs e)
        {
            BsonDocument docFind = new BsonDocument();

            MongoDB.Driver.MongoServer server = MongoDB.Driver.MongoServer.Create(ConfigurationManager.AppSettings["mongoDBConfig"]);
            server.Connect();
            //获取指定数据库
            MongoDB.Driver.MongoDatabase db = server.GetDatabase(ConfigurationManager.AppSettings["mongoDBName"].ToString());
            string collection = txtCollection.Text.Trim();

            //获取表
            MongoDB.Driver.MongoCollection <BsonDocument> col = db.GetCollection <BsonDocument>(collection);
            GetIndexesResult indexsResult = col.GetIndexes();
            string           strIndexs    = string.Empty;

            for (int i = 0; i < indexsResult.Count; i++)
            {
                strIndexs += indexsResult[i].Key.ToString() + ";";
            }
            txtGetIndexs.Text = strIndexs;
        }
Esempio n. 11
0
        public ActionResult JsonAction()
        {
            var mongoServSettings = new MongoDB.Driver.MongoServerSettings();

            mongoServSettings.Server = new MongoDB.Driver.MongoServerAddress("localhost");

            var mongoServer = new MongoDB.Driver.MongoServer(mongoServSettings);

            mongoServer.Connect();

            var db = mongoServer.GetDatabase("monitera");

            var collection = db.GetCollection<db>("dbo.post");
               //collection.Insert(new db { gender = "m"});

            var erkek = Query<db>.Where( f => f.gender == "e");
            var kadin = Query<db>.Where( f => f.gender == "k");

            var erk = collection.Count(erkek);
            var k = collection.Count(kadin);

            var chartData = (new[]{
                                 new{
                                     Gender = "Male",
                                     value = erk
                                 },

               new {
                Gender = "Female",
                value = k

            }
            }
            );

            return Json(chartData, JsonRequestBehavior.AllowGet);
        }
Esempio n. 12
0
        public ActionResult JsonAction3()
        {
            var mongoServSettings = new MongoDB.Driver.MongoServerSettings();

            mongoServSettings.Server = new MongoDB.Driver.MongoServerAddress("localhost");

            var mongoServer = new MongoDB.Driver.MongoServer(mongoServSettings);

            mongoServer.Connect();

            var db = mongoServer.GetDatabase("monitera");

            var collection = db.GetCollection<db>("dbo.post");
            //collection.Insert(new db { gender = "m"});

            var cs = Query<db>.Where(f => f.sourceid == 1);
            var cs1 = Query<db>.Where(f => f.sourceid == 2);
            var cs2 = Query<db>.Where(f => f.sourceid == 25);
            var cs3 = Query<db>.Where(f => f.sourceid == 31);
            var cs4 = Query<db>.Where(f => f.sourceid== 19);

            var tw = collection.Count(cs);
            var ff = collection.Count(cs1);
            var face = collection.Count(cs2);
            var rss = collection.Count(cs3);
            var blog = collection.Count(cs4);

            var kaynaklar = (new[]{
                                 new{
                                     Kaynak = "Twitter",
                                     value = tw
                                 },

               new {
               Kaynak = "FriendFeed",
                value = ff

            },
            new {
                Kaynak = "Facebook",
                value = face

            },
            new {
                Kaynak = "HaberRss",
                value = rss

            },
            new {
                Kaynak = "Blog",
                value = blog

            }
            }
            );

            return Json(kaynaklar, JsonRequestBehavior.AllowGet);
        }
Esempio n. 13
0
        public MongoServer GetServer()
        {
            var serverSettings = MongoServerSettings.FromClientSettings(_settings);

            return(MongoServer.Create(serverSettings));
        }
 public MongoCursorConnectionProvider(MongoServer server, ReadPreference readPreference)
 {
     _server         = server;
     _readPreference = readPreference;
 }
Esempio n. 15
0
        public override void ActivateOptions()
        {
            try
            {

                var mongoConnectionString = new StringBuilder(string.Format("Server={0}:{1}", Host, Port));
                if (!string.IsNullOrEmpty(UserName) && !string.IsNullOrEmpty(Password))
                {
                    // use MongoDB authentication
                    mongoConnectionString.AppendFormat(";Username={0};Password={1}", UserName, Password);
                }

                connection = MongoServer.Create(mongoConnectionString.ToString());
                connection.Connect();
                var db = connection.GetDatabase(DatabaseName);
                collection = db.GetCollection(CollectionName);
            }
            catch (Exception e)
            {
                ErrorHandler.Error("Exception while initializing MongoDB Appender", e, ErrorCode.GenericFailure);
            }
        }
Esempio n. 16
0
 public static void MyClassInitialize(TestContext testContext)
 {
     mongodb = MongoDB.Driver.MongoServer.Create("mongodb://localhost:10319/?safe=true");
 }
Esempio n. 17
0
 public MongoDatabase(MongoServer server, string name, MongoDatabaseSettings settings)
     : this(server, name, settings, new DefaultLegacyOperationExecutor())
 {
 }
Esempio n. 18
0
        public static MongoServer GetServer(this MongoClient client)
        {
            var serverSettings = MongoServerSettings.FromClientSettings(client.Settings);

            return(MongoServer.Create(serverSettings, client.OperationExecutor));
        }
 // constructors
 public RequestStartResult(MongoServer server)
 {
     _server = server;
 }
Esempio n. 20
0
 public MongoDatabase(MongoServer server, MongoDatabaseSettings settings)
     : this(server, settings.DatabaseName, settings)
 {
 }
Esempio n. 21
0
 public MongoDatabase(string _IPAddress, string _DatabaseName)
 {
     m_Client   = new MongoDB.Driver.MongoClient("mongodb://" + _IPAddress);
     m_Server   = m_Client.GetServer();
     m_Database = m_Server.GetDatabase(_DatabaseName);
 }