/// <summary> /// Filter source output with Key and SubKey /// </summary> /// <param name="source"></param> /// <param name="Key"></param> /// <param name="SubKey"></param> /// <returns></returns> public static IEnumerable <RedisInfo> FilterKeySubKey(this System.Collections.Generic.IEnumerable <RedisInfo> source, RedisInfoKeyType[] Key, RedisInfoSubkeyType[] SubKey) { return(source.Select(item => { RedisInfo values = null; if (Key == null & SubKey == null) { // When both Key and Subkey not specified values = item; } else if (Key != null & SubKey == null) { // when Key specify and output contains it if (Key.Where(x => x.ToString() == item.Key).Any()) { values = item; } } else if (Key == null & SubKey != null) { // when Subkey specify and output contains it if (SubKey.Where(x => x.ToString() == item.SubKey).Any()) { values = item; } } else if (Key.Where(x => x.ToString() == item.Key).Any() & SubKey.Where(x => x.ToString() == item.SubKey).Any()) { // when Key and Subkey specify and output contains both values = item; } return values; })); }
public int InitializeDataStoreManager(string DBCnnString, CompanyInfoEx companyInfo, DeviceInfoEx deviceInfo) { _cnnDB = DBCnnString; _redisInfo = companyInfo.Redis; _redisTableName = $"[{companyInfo.CompanyCode}]-[{deviceInfo.DeviceCode}]"; return(0); }
/// <summary> /// 操作 /// </summary> /// <param name="item"></param> /// <returns></returns> public IActionResult OnPostBusinessDetailsForm(Data_Business_Details item) { var info = new WriteReturn(); using (var db = new DataContext(AppEtl.Db)) { var table = IFast.Query <Data_Business>(a => a.Id == item.Id).ToItem <Data_Business>(db); var source = IFast.Query <Data_Source>(a => a.Id == item.DataSourceId).ToItem <Data_Source>(db); var key = string.Format(AppEtl.CacheKey.Column, source.Host, item.TableName); var colunm = RedisInfo.Get <List <CacheColumn> >(key, AppEtl.CacheDb).Find(a => a.Name == item.ColumnName); db.BeginTrans(); if (IFast.Query <Data_Business_Details>(a => a.FieldId == item.FieldId).ToCount(db) == 0) { item.FieldId = Guid.NewGuid().ToStr(); info = IFast.Add(item); if (info.IsSuccess) { info = DataSchema.AddColumn(db, table, item, colunm, source); if (info.IsSuccess) { DataSchema.UpdateColumnComment(db, table, item, colunm, source); } } } else { info = IFast.Update <Data_Business_Details>(item, a => a.FieldId == item.FieldId); if (info.IsSuccess) { info.IsSuccess = DataSchema.UpdateColumn(db, table, item, colunm, source); if (info.IsSuccess) { DataSchema.UpdateColumnComment(db, table, item, colunm, source); } } } if (info.IsSuccess) { db.SubmitTrans(); return(new JsonResult(new { success = true, msg = "操作成功" })); } else { db.RollbackTrans(); return(new JsonResult(new { success = false, msg = "操作失败" })); } } }
private void ConvertClientList(List <PSObject> objects, RedisInfo info) { info.Clients = new List <RedisClient>(); foreach (var obj in objects) { var strData = obj.ToString(); var data = strData.Split(' ').Select(x => { var fieldData = x.Split('='); return(new KeyValuePair <string, string>(fieldData[0].Trim(), fieldData[1].Trim())); }).ToDictionary(x => x.Key, x => x.Value); var client = new RedisClient(); Map(data, client); info.Clients.Add(client); } }
/// <summary> /// 获取列的信息 /// </summary> /// <returns></returns> public static void InitColumn(Data_Source item, bool IsLoad, string tableName) { var key = string.Format(AppEtl.CacheKey.Column, item.Host, tableName); if (RedisInfo.Exists(key, AppEtl.CacheDb) && IsLoad) { return; } var list = new List <CacheColumn>(); var dt = new DataTable(); using (var conn = DbProviderFactories.GetFactory(item.Type).CreateConnection()) { conn.ConnectionString = AppCommon.GetConnStr(item); conn.Open(); var cmd = conn.CreateCommand(); cmd.CommandText = ColumnSql(item, tableName); if (cmd.CommandText == "") { return; } var rd = cmd.ExecuteReader(); dt.Load(rd); rd.Close(); } foreach (DataRow row in dt.Rows) { var column = new CacheColumn(); column.Name = (row.ItemArray[0] == DBNull.Value ? "" : row.ItemArray[0].ToString()); column.Type = row.ItemArray[1] == DBNull.Value ? "" : row.ItemArray[1].ToString(); column.Length = row.ItemArray[2] == DBNull.Value ? 0 : int.Parse(row.ItemArray[2].ToString()); column.Comments = row.ItemArray[3] == DBNull.Value ? "" : row.ItemArray[3].ToString(); column.IsKey = row.ItemArray[4].ToString() != "0" ? true : false; column.Precision = row.ItemArray[7] == DBNull.Value ? 0 : int.Parse(row.ItemArray[7].ToString()); column.ShowName = string.Format("{0}({1})", column.Name, column.Comments); list.Add(column); } RedisInfo.Set <List <CacheColumn> >(key, list, 8640, AppEtl.CacheDb); }
/// <summary> /// 获取数据库Info信息 /// </summary> /// <returns></returns> public static RedisInfo GetInfo() { var server = GetServer(); var infos = server.Info(); var result = new RedisInfo(); result.Keys = new Dictionary <int, long>(); var keys = infos[(int)InfoSection.KeySpace]; foreach (var item in keys.AsEnumerable()) { var dbIndex = int.Parse(item.Key.Replace("db", "")); var keyInfo = item.Value.Split(','); var keyCount = keyInfo[0].Split('=')[1]; result.Keys.Add(dbIndex, long.Parse(keyCount)); } return(result); }
/// <summary> /// 表说明 /// </summary> /// <returns></returns> public static void InitTable(Data_Source item, bool IsLoad) { var key = string.Format(AppEtl.CacheKey.Table, item.Host); if (RedisInfo.Exists(key, AppEtl.CacheDb) && IsLoad) { return; } var list = new List <CacheTable>(); var dt = new DataTable(); using (var conn = DbProviderFactories.GetFactory(item.Type).CreateConnection()) { conn.ConnectionString = AppCommon.GetConnStr(item); conn.Open(); var cmd = conn.CreateCommand(); cmd.CommandText = TableSql(item); if (cmd.CommandText == "") { return; } var rd = cmd.ExecuteReader(); dt.Load(rd); rd.Close(); } foreach (DataRow row in dt.Rows) { var table = new CacheTable(); table.Comments = row.ItemArray[1] == DBNull.Value ? "" : row.ItemArray[1].ToString(); table.Name = row.ItemArray[0] == DBNull.Value ? "" : row.ItemArray[0].ToString(); list.Add(table); Parallel.Invoke(() => { InitColumn(item, IsLoad, table.Name); }); } RedisInfo.Set <List <CacheTable> >(key, list, 8640, AppEtl.CacheDb); }
private RedisInfo ConvertInfoFromRaw(List <PSObject> objects) { var info = new RedisInfo { Server = new RedisServerInfo(), Statistic = new RedisStatisticInfo(), Persistance = new RedisPersistanceInfo(), Client = new RedisClientInfo(), Cpu = new RedisCpuInfo(), Memory = new RedisMemoryInfo(), Replication = new RedisReplicationInfo() }; var raw = new Dictionary <string, string>(); foreach (var psObject in objects) { var line = psObject.ToString().Trim(); if (!string.IsNullOrEmpty(line) && !line.StartsWith("#")) { var data = line.Split(':'); raw.Add(data[0].Trim(), string.Join(":", data.Skip(1))); } } Map(raw, info.Server); Map(raw, info.Statistic); Map(raw, info.Persistance); Map(raw, info.Client); Map(raw, info.Cpu); Map(raw, info.Memory); Map(raw, info.Replication); return(info); }
public void TestParseLogic() { var rawInfo = new[] #region Input Data { new[] { "Server", "redis_mode", "cluster" }, new[] { "Server", "os", "Windows" }, new[] { "Server", "arch_bits", "64" }, new[] { "Server", "multiplexing_api", "winsock_IOCP" }, new[] { "Server", "run_id", "4e69f04207bcb78d183c548b18cfc63a8a402f76" }, new[] { "Server", "uptime_in_seconds", "1823367" }, new[] { "Server", "uptime_in_days", "21" }, new[] { "Server", "hz", "10" }, new[] { "Clients", "connected_clients", "318" }, new[] { "Clients", "maxclients", "15000" }, new[] { "Clients", "client_longest_output_list", "0" }, new[] { "Clients", "client_biggest_input_buf", "0" }, new[] { "Clients", "client_total_writes_outstanding", "0" }, new[] { "Clients", "client_total_sent_bytes_outstanding", "0" }, new[] { "Clients", "blocked_clients", "0" }, new[] { "Memory", "used_memory", "2535297272" }, new[] { "Memory", "used_memory_human", "2.36G" }, new[] { "Memory", "used_memory_rss", "4328046592" }, new[] { "Memory", "used_memory_rss_human", "4.03G" }, new[] { "Memory", "used_memory_peak", "5429977272" }, new[] { "Memory", "used_memory_peak_human", "5.06G" }, new[] { "Memory", "used_memory_lua", "71680" }, new[] { "Memory", "maxmemory", "13100000000" }, new[] { "Memory", "maxmemory_reservation", "99000000" }, new[] { "Memory", "maxfragmentationmemory_reservation", "124000000" }, new[] { "Memory", "maxmemory_desired_reservation", "99000000" }, new[] { "Memory", "maxfragmentationmemory_desired_reservation", "124000000" }, new[] { "Memory", "maxmemory_human", "12.20G" }, new[] { "Memory", "maxmemory_policy", "volatile-lru" }, new[] { "Memory", "mem_allocator", "jemalloc-3.6.0" }, new[] { "Stats", "total_connections_received", "6706554" }, new[] { "Stats", "total_commands_processed", "13921081759" }, new[] { "Stats", "instantaneous_ops_per_sec", "234" }, new[] { "Stats", "bytes_received_per_sec", "26915" }, new[] { "Stats", "bytes_sent_per_sec", "15009" }, new[] { "Stats", "bytes_received_per_sec_human", "26.28K" }, new[] { "Stats", "bytes_sent_per_sec_human", "14.66K" }, new[] { "Stats", "rejected_connections", "0" }, new[] { "Stats", "expired_keys", "16950287" }, new[] { "Stats", "evicted_keys", "0" }, new[] { "Stats", "keyspace_hits", "4597475110" }, new[] { "Stats", "keyspace_misses", "77539312" }, new[] { "Stats", "pubsub_channels", "1" }, new[] { "Stats", "pubsub_patterns", "0" }, new[] { "Stats", "total_oom_messages", "0" }, new[] { "Replication", "role", "master" }, new[] { "CPU", "used_cpu_sys", "52129.64" }, new[] { "CPU", "used_cpu_user", "105675.72" }, new[] { "CPU", "used_cpu_avg_ms_per_sec", "2" }, new[] { "CPU", "server_load", "0.74" }, new[] { "CPU", "event_wait", "48" }, new[] { "CPU", "event_no_wait", "113" }, new[] { "CPU", "event_wait_count", "56" }, new[] { "CPU", "event_no_wait_count", "60" }, new[] { "Cluster", "cluster_enabled", "1" }, new[] { "Cluster", "cluster_myself_name", "c5030a3471981cfd2e2c51715ceaff915f91168a" }, new[] { "Keyspace", "db0", "keys=4599962,expires=4599960,avg_ttl=266217318" }, } .GroupBy(a => a[0], a => new KeyValuePair <string, string>(a[1], a[2])) .ToArray(); #endregion Input Data var info = new RedisInfo(rawInfo); var stringInfo = info.ToString(); _output.WriteLine(stringInfo); Assert.DoesNotContain("<Unknown>", stringInfo); }
public IActionResult OnPostDropList(DropListModel item) { using (var db = new DataContext(AppEtl.Db)) { if (item.Type.ToLower() == "source") { var param = new List <DbParameter>(); var temp = DbProviderFactories.GetFactory(db.config.DbType).CreateParameter(); temp.ParameterName = "Key"; temp.Value = item.Key.ToUpper(); param.Add(temp); var data = IFast.Query("DropList.Source", param.ToArray(), db); if (data.Count > 0) { return(new JsonResult(new { success = true, data = data })); } else { return(new JsonResult(new { success = true, data = IFast.Query <Data_Source>(a => a.Id != "").Take(10).ToDics(db) })); } } if (item.Type.ToLower() == "table") { var host = IFast.Query <Data_Source>(a => a.Id == item.HostId, a => new { a.Host }).ToDic(db).GetValue("host").ToStr(); var key = string.Format(AppEtl.CacheKey.Table, host); var data = RedisInfo.Get <List <CacheTable> >(key, AppEtl.CacheDb); data = data.FindAll(a => a.Name.ToUpper().Contains(item.Key.ToUpper())); if (data.Count > 0) { return(new JsonResult(new { success = true, data = data })); } else { return(new JsonResult(new { success = true, data = RedisInfo.Get <List <CacheTable> >(key, AppEtl.CacheDb).Take(10) })); } } if (item.Type.ToLower() == "field") { var host = IFast.Query <Data_Source>(a => a.Id == item.HostId, a => new { a.Host }).ToDic(db).GetValue("host").ToStr(); var key = string.Format(AppEtl.CacheKey.Column, host, item.Table); var data = RedisInfo.Get <List <CacheColumn> >(key, AppEtl.CacheDb); data = data.FindAll(a => a.Name.ToUpper().Contains(item.Key.ToUpper())); if (data.Count > 0) { return(new JsonResult(new { success = true, data = data })); } else { return(new JsonResult(new { success = true, data = RedisInfo.Get <List <CacheColumn> >(key, AppEtl.CacheDb).Take(10) })); } } if (item.Type.ToLower() == "dic") { var param = new List <DbParameter>(); var temp = DbProviderFactories.GetFactory(db.config.DbType).CreateParameter(); temp.ParameterName = "Key"; temp.Value = item.Key.ToUpper(); param.Add(temp); var data = IFast.Query("DropList.Dic", param.ToArray(), db); if (data.Count > 0) { return(new JsonResult(new { success = true, data = data })); } else { return(new JsonResult(new { success = true, data = IFast.Query <Data_Dic>(a => a.Id != "").Take(10).ToDics(db) })); } } return(new JsonResult(new { success = false })); } }
/// <summary> /// 操作 /// </summary> /// <param name="item"></param> /// <returns></returns> public IActionResult OnPostBusinessFormList(Data_Business_List item) { var result = new WriteReturn(); result.IsSuccess = true; using (var db = new DataContext(AppEtl.Db)) { if (IFast.Query <Data_Source>(a => a.Id == item.DataId).ToCount(db) == 0) { return(new JsonResult(new { success = false, msg = "数据源不存在" })); } var data = IFast.Query <Data_Source>(a => a.Id == item.DataId).ToItem <Data_Source>(db); var tableKey = string.Format(AppEtl.CacheKey.Table, data.Host); if (!RedisInfo.Exists(tableKey, AppEtl.CacheDb)) { DataSchema.InitTable(data, false); } var tableList = RedisInfo.Get <List <CacheTable> >(tableKey, AppEtl.CacheDb); foreach (var table in tableList) { var columnKey = string.Format(AppEtl.CacheKey.Column, data.Host, table.Name); if (!RedisInfo.Exists(columnKey, AppEtl.CacheDb)) { DataSchema.InitColumn(data, false, table.Name); } var tableModel = BaseMap.CopyModel <Data_Business, Data_Business_List>(item); tableModel.Id = Guid.NewGuid().ToStr(); tableModel.Name = string.IsNullOrEmpty(table.Comments) ? table.Name : table.Comments; tableModel.TableName = table.Name; if (result.IsSuccess) { result = db.Add(tableModel).writeReturn; } if (result.IsSuccess) { result = DataSchema.CreateTable(db, tableModel); } var columnList = RedisInfo.Get <List <CacheColumn> >(columnKey, AppEtl.CacheDb); var keyName = columnList.Find(a => a.IsKey == true)?.Name; var keyList = columnList.FindAll(a => a.IsKey == true); columnList.ForEach(column => { var columnModel = new Data_Business_Details(); columnModel.FieldId = Guid.NewGuid().ToStr(); columnModel.Id = tableModel.Id; columnModel.DataSourceId = data.Id; columnModel.TableName = table.Name; columnModel.ColumnName = column.Name; columnModel.FieldName = column.Name; columnModel.Key = keyName; if (result.IsSuccess) { result = db.Add(columnModel).writeReturn; } else { BaseLog.SaveLog(string.Format("tableName:{0},error:", table.Name, result.Message), "Error_CreateTable"); } if (result.IsSuccess) { if ((keyList.Count > 1 && keyList.Exists(a => a.Name == columnModel.FieldName))) { result = DataSchema.AddColumn(db, tableModel, columnModel, column, data, false); } else { result = DataSchema.AddColumn(db, tableModel, columnModel, column, data); } if (result.IsSuccess) { DataSchema.UpdateColumnComment(db, tableModel, columnModel, column, data); } } result.IsSuccess = true; }); if (keyList.Count > 1) { DataSchema.AddColumnMoreKey(db, tableModel, keyList); } } if (result.IsSuccess) { return(new JsonResult(new { success = true, msg = "操作成功" })); } else { return(new JsonResult(new { success = false, msg = result.Message })); } } }