예제 #1
0
        /// <summary>
        /// Releases the unmanaged resources used by the <see cref="MongoInputAdapter"/> object and optionally releases the managed resources.
        /// </summary>
        /// <param name="disposing">true to release both managed and unmanaged resources; false to release only unmanaged resources.</param>
        protected override void Dispose(bool disposing)
        {
            if (!m_disposed)
            {
                try
                {
                    if (disposing)
                    {
                        if (m_mongo != null)
                        {
                            m_mongo.Dispose();
                        }

                        m_mongo = null;

                        if (m_timer != null)
                        {
                            m_timer.Dispose();
                        }

                        m_timer = null;
                    }
                }
                finally
                {
                    m_disposed = true;          // Prevent duplicate dispose.
                    base.Dispose(disposing);    // Call base class Dispose().
                }
            }
        }
예제 #2
0
 public void TestDoesNotThrowIfDisposeIsCalledTwice()
 {
     using (var m = new Mongo(_connectionString))
     {
         m.Dispose();
     }
 }
예제 #3
0
 /// <summary>
 /// IDisposabl 接口的实现 用于释放资源
 /// </summary>
 public void Dispose()
 {
     mongo.Disconnect();
     if (mongo != null)
     {
         mongo.Dispose();
     }
 }
예제 #4
0
 /// <summary>
 ///
 /// </summary>
 public void Dispose()
 {
     if (mongo != null)
     {
         mongo.Dispose();
         mongo = null;
     }
 }
예제 #5
0
 /// <summary>
 /// 释放资源
 /// </summary>
 public void Dispose()
 {
     if (_mongo != null)
     {
         _mongo.Dispose();
         _mongo = null;
     }
 }
예제 #6
0
 public void Close()
 {
     factory.Disconnect();
     factory.Dispose();
 }
예제 #7
0
        public string MongoTest()
        {
            string connectionString = "mongodb://";
            string dbServer         = this["DbServer"] as string;
            string dbName           = this["DbName"] as string;
            string userId           = this["UserName"] as string;
            string password         = this["Password"] as string;

            //分割
            string[] dbServers  = dbServer.Split('|');
            bool     success    = true;
            string   errIP      = string.Empty;
            string   connection = connectionString;

            foreach (string item in dbServers)
            {
                string connstr = string.Empty;
                if (!userId.IsNullOrEmpty() && !password.IsNullOrEmpty())
                {
                    connection = connection + userId + ":" + password + "@" + item + "|";
                    connstr    = connectionString + userId + ":" + password + "@" + item + "/" + dbName;
                }
                else
                {
                    connection = connection + item + "|";
                    connstr    = connectionString + item + "/" + dbName;
                }
                Mongo mongo = new Mongo(connstr);
                try
                {
                    // 打开连接
                    mongo.Connect();
                    // 切换到指定的数据库
                    IMongoDatabase database = mongo.GetDatabase(dbName);
                    if (database.Javascript.Contains("异常"))
                    {
                    }
                }
                catch (Exception e)
                {
                    errIP   = item;
                    success = false;
                }
                finally
                {
                    mongo.Dispose();
                }
            }
            if (success)
            {
                var appDomainConfigFile        = HttpContext.Current.Server.MapPath("~/") + "Web.config";
                Acctrue.TTS.Util.Config config = new Acctrue.TTS.Util.Config(appDomainConfigFile);
                config.SetValue(ConfigInfo.MongoDBConnection, connection.Remove(connection.Length - 1) + "/" + dbName, false);
                config.SetValue(ConfigInfo.MongoDBHosts, dbServer, false);
                config.SaveConfig();
                WriteJson(new { Success = "1", Message = "MongoDB数据库连接成功" });
                return;
            }
            else
            {
                WriteJson(new { Success = "0", Message = "MongoDB" + errIP + "连接失败,请检查配置是否正确" });
                return;
            }
        }
예제 #8
0
 public void TestDoesNotThrowIfDisposeIsCalledTwice(){
     using(var m = new Mongo(_connectionString))
     {
         m.Dispose();
     }
 }
예제 #9
0
        public static ResultSet ShowLogs(string message, int pageSize, int pageNum, string appid, string ip, DateTime begtime, DateTime endtime, string lev, string classname, string method, string traceid)
        {
            long resultCount = 0;

            List <Log4NetEntiy> docResultSet = new List <Log4NetEntiy>();

            Mongo mongoDBLog = null;

            try
            {
                mongoDBLog = new Mongo(ConfigurationManager.AppSettings["mongoDBConfig"]);
                mongoDBLog.Connect();


                var dbLog = mongoDBLog.GetDatabase(ConfigurationManager.AppSettings["mongoDBName"].ToString());

                var collection = dbLog.GetCollection <Log4NetEntiy>(ConfigurationManager.AppSettings["mongoDBCollection"].ToString());

                // resultCount = collection.Count();

                if (!string.IsNullOrEmpty(appid.Trim()))
                {
                    #region appid is not null
                    switch (lev)
                    {
                    case "ALL":
                        var queryResultSet = from p in (collection.Linq().Skip(pageSize * (pageNum - 1)).Take(pageSize))
                                             where p.timestamp >= begtime && p.timestamp <= endtime &&
                                             p.message.Contains(message) && p.ip.Contains(ip) && p.appid == appid.Trim() && p.method.Contains(method.Trim()) && p.className.Contains(classname) && p.traceId.Contains(traceid)
                                             orderby p.timestamp descending
                                             select new
                        {
                            p._id,
                            p.appid,
                            p.ip,
                            p.level,
                            p.method,
                            p.timestamp
                        };

                        var list = queryResultSet.ToList();

                        foreach (var item in list)
                        {
                            Log4NetEntiy ent = new Log4NetEntiy();
                            ent._id       = item._id;
                            ent.appid     = item.appid;
                            ent.ip        = item.ip;
                            ent.level     = item.level;
                            ent.timestamp = item.timestamp;
                            ent.method    = item.method;
                            docResultSet.Add(ent);
                        }
                        break;

                    default:
                        queryResultSet = from p in (collection.Linq().Skip(pageSize * (pageNum - 1)).Take(pageSize))
                                         where p.timestamp >= begtime && p.timestamp <= endtime && p.level == lev.Trim() &&
                                         p.message.Contains(message) && p.ip.Contains(ip) && p.appid == appid.Trim() && p.method.Contains(method.Trim()) && p.className.Contains(classname) && p.traceId.Contains(traceid)
                                         orderby p.timestamp descending
                                         select new
                        {
                            p._id,
                            p.appid,
                            p.ip,
                            p.level,
                            p.method,
                            p.timestamp
                        };

                        list = queryResultSet.ToList();


                        foreach (var item in list)
                        {
                            Log4NetEntiy ent = new Log4NetEntiy();
                            ent._id       = item._id;
                            ent.appid     = item.appid;
                            ent.ip        = item.ip;
                            ent.level     = item.level;
                            ent.timestamp = item.timestamp;
                            ent.method    = item.method;
                            docResultSet.Add(ent);
                        }
                        break;
                    }

                    #endregion
                }
                else
                {
                    #region appid is null
                    switch (lev)
                    {
                    case "ALL":
                        var queryResultSet = from p in (collection.Linq().Skip(pageSize * (pageNum - 1)).Take(pageSize))
                                             where p.timestamp >= begtime && p.timestamp <= endtime &&
                                             p.message.Contains(message) && p.ip.Contains(ip) && p.method.Contains(method.Trim()) && p.className.Contains(classname) && p.traceId.Contains(traceid)
                                             orderby p.timestamp descending
                                             select new
                        {
                            p._id,
                            p.appid,
                            p.ip,
                            p.level,
                            p.method,
                            p.timestamp
                        };
                        var list = queryResultSet.ToList();

                        foreach (var item in list)
                        {
                            Log4NetEntiy ent = new Log4NetEntiy();
                            ent._id       = item._id;
                            ent.appid     = item.appid;
                            ent.ip        = item.ip;
                            ent.level     = item.level;
                            ent.timestamp = item.timestamp;
                            ent.method    = item.method;
                            docResultSet.Add(ent);
                        }
                        break;

                    default:
                        queryResultSet = from p in (collection.Linq().Skip(pageSize * (pageNum - 1)).Take(pageSize))
                                         where p.timestamp >= begtime && p.timestamp <= endtime && p.level == lev.Trim() &&
                                         p.message.Contains(message) && p.ip.Contains(ip) && p.method.Contains(method.Trim()) && p.className.Contains(classname) && p.traceId.Contains(traceid)
                                         orderby p.timestamp descending
                                         select new
                        {
                            p._id,
                            p.appid,
                            p.ip,
                            p.level,
                            p.method,
                            p.timestamp
                        };
                        list = queryResultSet.ToList();

                        foreach (var item in list)
                        {
                            Log4NetEntiy ent = new Log4NetEntiy();
                            ent._id       = item._id;
                            ent.appid     = item.appid;
                            ent.ip        = item.ip;
                            ent.level     = item.level;
                            ent.timestamp = item.timestamp;
                            ent.method    = item.method;
                            docResultSet.Add(ent);
                        }
                        break;
                    }
                    #endregion
                }
            }
            catch
            {
                //do something
            }
            finally
            {
                if (mongoDBLog != null)
                {
                    mongoDBLog.Disconnect();
                    mongoDBLog.Dispose();
                }
            }


            return(new ResultSet {
                resultCount = resultCount, result = docResultSet
            });
        }
예제 #10
0
 public void Dispose()
 {
     _provider.Dispose();
 }