示例#1
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);
        }
示例#2
0
        #pragma warning restore

        private TCommandResult RunCommandAs <TCommandResult>(
            IMongoCommand command,
            IBsonSerializer <TCommandResult> resultSerializer) where TCommandResult : CommandResult
        {
            var readerSettings = new BsonBinaryReaderSettings
            {
                Encoding           = _settings.ReadEncoding ?? MongoDefaults.ReadEncoding,
                GuidRepresentation = _settings.GuidRepresentation
            };
            var writerSettings = new BsonBinaryWriterSettings
            {
                Encoding           = _settings.WriteEncoding ?? MongoDefaults.WriteEncoding,
                GuidRepresentation = _settings.GuidRepresentation
            };
            var readPreference = _settings.ReadPreference;

            if (readPreference != ReadPreference.Primary)
            {
                if (_server.ProxyType == MongoServerProxyType.Unknown)
                {
                    _server.Connect();
                }
                if (_server.ProxyType == MongoServerProxyType.ReplicaSet && !CanCommandBeSentToSecondary.Delegate(command.ToBsonDocument()))
                {
                    readPreference = ReadPreference.Primary;
                }
            }
            var flags = (readPreference == ReadPreference.Primary) ? QueryFlags.None : QueryFlags.SlaveOk;

            var commandOperation = new CommandOperation <TCommandResult>(
                _name,
                readerSettings,
                writerSettings,
                command,
                flags,
                null, // options
                readPreference,
                resultSerializer);

            var connection = _server.AcquireConnection(readPreference);

            try
            {
                return(commandOperation.Execute(connection));
            }
            finally
            {
                _server.ReleaseConnection(connection);
            }
        }
示例#3
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";
        }
示例#4
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;
        }
示例#5
0
 public bool IsConnected()
 {
     if (m_Connected == false || m_Server.State != MongoServerState.Connected)
     {
         if (m_TryingToReconnect == false)
         {
             lock (m_Client)
             {
                 if (m_TryingToReconnect == true)
                 {
                     return(false);
                 }
                 else
                 {
                     m_TryingToReconnect = true;
                 }
             }
             m_Connected = false;
             (new System.Threading.Tasks.Task(() =>
             {
                 try
                 {
                     m_Server.Connect();
                     if (m_Server.State == MongoServerState.Connected)
                     {
                         m_Connected = true;
                     }
                 }
                 catch (Exception)
                 {
                 }
                 lock (m_Client)
                 {
                     m_TryingToReconnect = false;
                 }
             })).Start();
         }
     }
     return(m_Connected == true && m_Server.State == MongoServerState.Connected);
 }
示例#6
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);
        }
        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);
            }
        }
示例#8
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);
        }