private void InitAddr(ServiceEntity model) { ServiceCfg cfg = JsonConvert.DeserializeObject <ServiceCfg>(model.RegContent); ViewBag.InList = cfg.InAddr; ViewBag.OutList = cfg.OutAddr; }
//////////////////////////////////////////////////////////////////////////////////////////////////// /// <summary> Gets service configuration. </summary> /// /// <remarks> Th, 2017/6/13. </remarks> /// /// <param name="serName"> Name of the ser. </param> /// <param name="version"> The version. </param> /// /// <returns> The service configuration. </returns> //////////////////////////////////////////////////////////////////////////////////////////////////// public static ServiceCfg GetServiceCfg(string serName, string version) { if (SerCfg.ContainsKey(serName)) { return(SerCfg[serName]); } ServiceCfg entity = Client.Common.CommonHelper.GetServiceEntity(UserName, Token.AccessToken, serName.Replace(".", "/"), version); return(entity); }
//////////////////////////////////////////////////////////////////////////////////////////////////// /// <summary> Gets service configuration. </summary> /// /// <remarks> Th, 2017/6/13. </remarks> /// /// <param name="serName"> Name of the ser. </param> /// <param name="version"> The version. </param> /// /// <returns> The service configuration. </returns> //////////////////////////////////////////////////////////////////////////////////////////////////// public static ServiceCfg GetServiceCfg(string serName, string version) { if (SerCfg.ContainsKey(serName)) { return(SerCfg[serName]); } else { ServiceCfg entity = BS.Client.Common.CommonHelper.GetServiceEntity(UserName, CurrentHelper.Token.AccessToken, serName.ToString().Replace(".", "/"), version.ToString()); return(entity); } }
public ActionResult Edit(ServiceEntity collection) { ReturnMessage RM = new ReturnMessage(false); try { List <string> inList = new List <string>(); List <string> outList = new List <string>(); string inStr = Request["inAddr"]; if (!string.IsNullOrWhiteSpace(inStr)) { inList = inStr.Split(',').ToList(); } string outStr = Request["outAddr"]; if (!string.IsNullOrWhiteSpace(outStr)) { outList = outStr.Split(',').ToList(); } ServiceCfg cfg = new ServiceCfg(); cfg.InAddr = inList; cfg.OutAddr = outList; cfg.Remarks = collection.Remark; ServiceEntity model = BusinessContext.ServiceList.GetModel(Convert.ToInt32(Request["_id"])); model.ServiceName = collection.ServiceName; model.SecondaryName = collection.SecondaryName; model.Host = collection.Host; model.Version = collection.Version; model.Remark = collection.Remark; model.RegContent = JsonConvert.SerializeObject(cfg); RM.IsSuccess = BusinessContext.ServiceList.Update(model); } catch (Exception ex) { RM.Message = "数据异常,请刷新重试"; LogManager.Error(ex); } return(Json(RM, JsonRequestBehavior.AllowGet)); }
static CurrentHelper() { UserName = "******"; UserPwd = "123456"; Client.Common.CommonHelper.OauthAPI = "http://61.129.57.83:21999"; string path = AppDomain.CurrentDomain.BaseDirectory; FileInfo[] files = new DirectoryInfo(path).GetFiles("*.dto.dll", SearchOption.AllDirectories); foreach (var file in files) { Assembly assembly = Assembly.LoadFrom(file.FullName); List <Type> typeList = assembly.GetTypes().ToList(); Type type = typeList.Where(p => p.Name.Equals("dtoConstants", StringComparison.InvariantCultureIgnoreCase)).FirstOrDefault(); if (type != null) { FieldInfo ServerName = type.GetField("ServerName", BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.IgnoreCase); if (ServerName != null) { object serName = ServerName.GetValue(null); if (serName != null && !SerCfg.ContainsKey(serName.ToString())) { FieldInfo VERSION = type.GetField("VERSION", BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.IgnoreCase); if (VERSION != null) { object version = VERSION.GetValue(null); if (Token != null) { ServiceCfg entity = Client.Common.CommonHelper.GetServiceEntity(UserName, Token.AccessToken, serName.ToString().Replace(".", "/"), version.ToString()); SerCfg.AddOrUpdate(serName.ToString(), entity, (k, v) => entity); } } } } } } }
private void SetRegContent(ServiceEntity model) { var inList = new List <string>(); var outList = new List <string>(); var inPorts = new List <string>(); var outPorts = new List <string>(); var inStr = Request["inAddr"]; if (!string.IsNullOrWhiteSpace(inStr)) { inList = inStr.Split(',').ToList(); } var outStr = Request["outAddr"]; if (!string.IsNullOrWhiteSpace(outStr)) { outList = outStr.Split(',').ToList(); } var inPortStr = Request["inPort"]; if (!string.IsNullOrWhiteSpace(inStr)) { inPorts = inPortStr.Split(',').ToList(); } var outPortStr = Request["outPort"]; if (!string.IsNullOrWhiteSpace(inStr)) { outPorts = outPortStr.Split(',').ToList(); } var cfg = new ServiceCfg { InAddr = inList.Zip(inPorts, (t, p) => !string.IsNullOrEmpty(p) ? t + ":" + p : t).ToList(), OutAddr = outList.Zip(outPorts, (t, p) => !string.IsNullOrEmpty(p) ? t + ":" + p : t).ToList(), Remarks = model.Remark }; model.RegContent = JsonConvert.SerializeObject(cfg); }
public ActionResult Export(string filename) { filename = filename.Split('?')[0]; var rm = new ReturnMessage(false); try { string orderBy = Session["orderBy"] as string ?? "_id"; string desc = Session["desc"] as string ?? "asc"; string id = Session["id"] as string; string keyword = Session["keyword"] as string; string isApproved = Session["isApproved"] as string; string host = Session["host"] as string; var type = Session["type"] as int?; int count; var list = BusinessContext.ServiceList.GetModelList((ServiceTypeEnum?)type, orderBy, desc, 1, int.MaxValue, id, keyword, isApproved, host, out count); if (list == null || !list.Any()) { rm.Message = "没有数据!"; return(Json(rm, JsonRequestBehavior.AllowGet)); } string title = filename; InitializeWorkbook(title); NPOI.SS.UserModel.ISheet sheet1 = _hssfworkbook.GetSheetAt(0); //sheet1.GetRow(1).GetCell(5).SetCellValue(DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss")); //下移 int rows = 2; int num = 1; foreach (var item in list) { sheet1.CreateRow(rows); sheet1.GetRow(rows).CreateCell(0); sheet1.GetRow(rows).GetCell(0).CellStyle = sheet1.GetRow(1).GetCell(5).CellStyle; sheet1.GetRow(rows).GetCell(0).SetCellValue(num); num++; sheet1.GetRow(rows).CreateCell(1); sheet1.GetRow(rows).GetCell(1).CellStyle = sheet1.GetRow(1).GetCell(5).CellStyle; sheet1.GetRow(rows).GetCell(1).SetCellValue(item.PrimaryId); sheet1.GetRow(rows).CreateCell(2); sheet1.GetRow(rows).GetCell(2).CellStyle = sheet1.GetRow(1).GetCell(5).CellStyle; sheet1.GetRow(rows).GetCell(2).SetCellValue(item.SecondaryId); ServiceCfg cfg = new ServiceCfg(); if (!string.IsNullOrWhiteSpace(item.RegContent)) { cfg = JsonConvert.DeserializeObject <ServiceCfg>(item.RegContent); } var inList = cfg.InAddr ?? new List <string>(); var outList = cfg.OutAddr ?? new List <string>(); var inFlag = inList.FirstOrDefault(t => t.Contains(item.Host)) != null; var inAddr = inFlag ? inList.First(t => t.Contains(item.Host)) .Split(new[] { ':' }, StringSplitOptions.RemoveEmptyEntries) : new string[0]; sheet1.GetRow(rows).CreateCell(3); sheet1.GetRow(rows).GetCell(3).CellStyle = sheet1.GetRow(1).GetCell(5).CellStyle; sheet1.GetRow(rows) .GetCell(3) .SetCellValue(item.Host); sheet1.GetRow(rows).CreateCell(4); sheet1.GetRow(rows).GetCell(4).CellStyle = sheet1.GetRow(1).GetCell(5).CellStyle; sheet1.GetRow(rows).GetCell(4).SetCellValue(inFlag ? inAddr.Length > 1 ? inAddr[1] : "" : ""); var outAddr = new List <string>(); var outPort = new List <string>(); if (outList.Any()) { var @out = outList.Select(t => { var arr = t.Split(new[] { ':' }, StringSplitOptions.RemoveEmptyEntries); return(new { Addr = arr[0], Port = arr.Length > 1 ? arr[1] : "" }); }).ToList(); outAddr = @out.Select(t => t.Addr).ToList(); outPort = @out.Select(t => t.Port).ToList(); } sheet1.GetRow(rows).CreateCell(5); sheet1.GetRow(rows).GetCell(5).CellStyle = sheet1.GetRow(1).GetCell(5).CellStyle; sheet1.GetRow(rows).GetCell(5).SetCellValue(string.Join(",", outAddr)); sheet1.GetRow(rows).CreateCell(6); sheet1.GetRow(rows).GetCell(6).CellStyle = sheet1.GetRow(1).GetCell(5).CellStyle; sheet1.GetRow(rows).GetCell(6).SetCellValue(string.Join(",", outPort)); sheet1.GetRow(rows).CreateCell(7); sheet1.GetRow(rows).GetCell(7).CellStyle = sheet1.GetRow(1).GetCell(5).CellStyle; sheet1.GetRow(rows).GetCell(7).SetCellValue(item.ServiceName); sheet1.GetRow(rows).CreateCell(8); sheet1.GetRow(rows).GetCell(8).CellStyle = sheet1.GetRow(1).GetCell(5).CellStyle; sheet1.GetRow(rows).GetCell(8).SetCellValue(item.SecondaryName); sheet1.GetRow(rows).CreateCell(9); sheet1.GetRow(rows).GetCell(9).CellStyle = sheet1.GetRow(1).GetCell(5).CellStyle; sheet1.GetRow(rows).GetCell(9).SetCellValue(item.Version); sheet1.GetRow(rows).CreateCell(10); sheet1.GetRow(rows).GetCell(10).CellStyle = sheet1.GetRow(1).GetCell(5).CellStyle; sheet1.GetRow(rows).GetCell(10).SetCellValue(item.Remark); rows++; } sheet1.ForceFormulaRecalculation = true; var pathLoad = WriteToFile(filename); //弹出下载框 rm.IsSuccess = true; rm.Text = HttpUtility.UrlEncode(pathLoad); } catch (Exception ex) { rm.IsSuccess = false; rm.Message = ex.Message; } return(Json(rm, JsonRequestBehavior.AllowGet)); }