예제 #1
0
        public static BaseCollector CreateInstance(string configKey, BaseParamter paramter)
        {
            string configValue = configKey;
            var    array       = configValue.Split(',');
            string assblyName  = array[0];
            string typeName    = array[1];
            Type   t           = Assembly.Load(assblyName).GetType(typeName);

            return((BaseCollector)Activator.CreateInstance(t, paramter));
        }
예제 #2
0
        public BaseCollector GetCollectorByParam(CollectorType itemtype, BaseParamter baseParamter)
        {
            BaseCollector collector = null;

            string collectType      = EnumExtension.GetCollectorType(itemtype);
            string collectNameSpace = collectType.Substring(0, collectType.LastIndexOf("."));

            collector = CollectorFactory.CreateInstance(collectNameSpace + "," + collectType, baseParamter);
            return(collector);
        }
예제 #3
0
        //public bool Insert(BaseCollector collector)
        //{
        //    try
        //    {
        //        BaseParamter paramter = collector.Paramter;

        //        //string typeStr =paramter.GetType().ToString();

        //        using (MySql.Data.MySqlClient.MySqlConnection conn = new MySql.Data.MySqlClient.MySqlConnection())
        //        {
        //            conn.ConnectionString = ConfigurationManager.AppSettings["MySqlConnectionStr"];
        //            MySql.Data.MySqlClient.MySqlCommand cmd = new MySql.Data.MySqlClient.MySqlCommand();
        //            cmd.CommandText = "insert into tb_monitoritem(name,ip,note,itemtype,paramter) values(@name,@ip,@note,@itemtype,@paramter)";
        //            cmd.CommandType = CommandType.Text;
        //            cmd.Parameters.Add("@name", MySql.Data.MySqlClient.MySqlDbType.VarChar);
        //            cmd.Parameters.Add("@ip", MySql.Data.MySqlClient.MySqlDbType.VarChar);
        //            cmd.Parameters.Add("@note", MySql.Data.MySqlClient.MySqlDbType.VarChar);
        //            cmd.Parameters.Add("@itemtype", MySql.Data.MySqlClient.MySqlDbType.Int32);
        //            cmd.Parameters.Add("@paramter", MySql.Data.MySqlClient.MySqlDbType.VarBinary);

        //            cmd.Parameters[0].Value = Guid.NewGuid();
        //            cmd.Parameters[1].Value = paramter.Host;
        //            cmd.Parameters[2].Value = cmd.Parameters[0].Value;
        //            cmd.Parameters[3].Value = 1;
        //            cmd.Parameters[4].Value = _ser.Serialize(paramter);
        //            cmd.Connection = conn;
        //            conn.Open();

        //            int affectedrows = cmd.ExecuteNonQuery();

        //            cmd.Dispose();//此处可以不用调用,
        //            conn.Close();// 离开 using 块, connection 会自行关闭
        //        }
        //        return true;
        //    }
        //    catch (Exception ex)
        //    {
        //        throw new Exception(ex.Message);
        //    }
        //}

        //public List<CollectorInfo> GetList(string condition)
        //{
        //    List<CollectorInfo> list = new List<CollectorInfo>();

        //    using (MySql.Data.MySqlClient.MySqlConnection conn = new MySql.Data.MySqlClient.MySqlConnection())
        //    {
        //        conn.ConnectionString = ConfigurationManager.AppSettings["MySqlConnectionStr"];
        //        conn.Open();

        //        MySql.Data.MySqlClient.MySqlCommand cmd = new MySql.Data.MySqlClient.MySqlCommand();
        //        cmd.CommandType = CommandType.Text;
        //        cmd.CommandText = "select name,ip,note,itemtype,paramter from tb_monitoritem";
        //        cmd.Connection = conn;

        //        System.Data.Common.DbDataReader reader = cmd.ExecuteReader();
        //        byte[] buffer = null;
        //        if (reader.HasRows)
        //        {
        //            while (reader.Read())
        //            {
        //                CollectorInfo info = new CollectorInfo();
        //                int itemtype = reader.GetInt32(3);

        //                long len = reader.GetBytes(4, 0, null, 0, 0);
        //                buffer = new byte[len];
        //                len = reader.GetBytes(4, 0, buffer, 0, (int)len);

        //                info.Collector = GetCollectorByBytes(itemtype, buffer);
        //                info.LastTime = DateTime.MinValue;
        //                list.Add(info);
        //            }
        //        }
        //    }

        //    return list;
        //}
        #endregion

        public BaseCollector GetCollectorByBytes(CollectorType itemtype, byte[] bytes)
        {
            BaseCollector collector = null;

            string collectType      = EnumExtension.GetCollectorType(itemtype);
            string collectNameSpace = collectType.Substring(0, collectType.LastIndexOf("."));

            BaseParamter baseParamter = (BaseParamter)Activator.CreateInstance(EnumExtension.GetParamterType((CollectorType)itemtype));

            baseParamter = (DBParamter)_ser.Deserialize(bytes);

            collector = CollectorFactory.CreateInstance(collectNameSpace + "," + collectType, baseParamter);

            return(collector);
        }
예제 #4
0
        private string GetParamterStr(HttpRequestBase request, MonitorItemType type)
        {
            BaseParamter paramter = null;

            switch (type)
            {
            case MonitorItemType.DB:
                paramter = new Common.Model.DBParamter()
                {
                    Username = request.Form["Username"].ToString().Trim(),
                    Password = request.Form["Password"].ToString().Trim(),
                    Port     = Convert.ToInt32(request.Form["Port"]),
                    Host     = request.Form["Host"].ToString().Trim(),
                    DBName   = request.Form["DBName"].ToString().Trim(),
                    Interval = Convert.ToInt32(request.Form["Interval"])


                               //DeviceId = Convert.ToInt32(request.Form["DeviceId"])
                };
                break;

            case MonitorItemType.DEMS:
                paramter = new Common.Model.DEMSParamter()
                {
                    Host     = request.Form["Host"].ToString().Trim(),
                    Interval = Convert.ToInt32(request.Form["Interval"]),
                    //DeviceId = Convert.ToInt32(request.Form["DeviceId"]),
                    DEMSName = request.Form["DEMSName"].ToString().Trim()
                };
                break;

            case MonitorItemType.Web:
                paramter = new Common.Model.WebParamter()
                {
                    Host     = request.Form["Host"].ToString().Trim(),
                    Interval = Convert.ToInt32(request.Form["Interval"]),
                    //DeviceId = Convert.ToInt32(request.Form["DeviceId"]),
                    Port = Convert.ToInt32(request.Form["Port"])
                };
                break;

            default:
                break;
            }
            return(Newtonsoft.Json.JsonConvert.SerializeObject(paramter));
        }
예제 #5
0
 public void Add(CollectorType type, BaseParamter paramter)
 {
     lock (_listlock)
     {
         try
         {
             if (_collectorList.Where(n => n.Collector.Paramter.DeviceId == paramter.DeviceId).FirstOrDefault() == null)
             {
                 _collectorList.Add(new CollectorInfo()
                 {
                     Collector = CollectorFactory.CreateInstance(type.GetCollectorType(), paramter),
                     LastTime  = DateTime.MinValue
                 });
             }
         }
         catch (Exception)
         {
             throw;
         }
     }
 }
예제 #6
0
 public ActionResult Edit(BaseParamter Model)
 {
     try
     {
         MonitorItemDBModel model = new MonitorItemDBModel();
         model.Id            = Convert.ToInt32(Request.Form["Id"]);
         model.Name          = Request.Form["Name"].ToString().Trim();
         model.Note          = Request.Form["Note"].ToString().Trim();
         model.Host          = Request.Form["MHost"].ToString().Trim();
         model.CollectorHost = Request.Form["CollectorHost"].ToString().Trim();
         model.ItemType      = (MonitorItemType)int.Parse(Request.Form["ItemType"]);
         model.Paramter      = GetParamterStr(Request, model.ItemType);
         bool b = _business.Edit(model);
         return(Json(new { State = b }));
     }
     catch (AppException ex)
     {
         return(Json(new { State = false, Message = ex.Message }));
     }
     catch (Exception)
     {
         return(Json(new { State = false, Message = "未知错误,请联系管理人员" }));
     }
 }
예제 #7
0
 public void Updata(long id, CollectorType type, BaseParamter paramter)
 {
     Remove(id);
     Add(type, paramter);
 }
예제 #8
0
 public BaseCollector(BaseParamter paramter)
 {
     _host    = paramter.Host;
     Paramter = paramter;
 }