public static string GenerateJwtToken(SettingLogic setting, string userName, string role, string originalRefreshToken, bool isSuper, out string outRefreshToken) { JwtTokenResponse obj = new JwtTokenResponse(); try { int accessExpire = Convert.ToInt32(setting.GetSettingValueInString("AccessExpire")); int refreshExpire = Convert.ToInt32(setting.GetSettingValueInString("RefreshExpire")); var accessToken = GenerateJwtToken(userName, DateTime.UtcNow.AddMinutes(accessExpire), Utils.Messages.ACCESS_KEY); JwtSecurityToken refreshToken = null; obj.Token = new JwtSecurityTokenHandler().WriteToken(accessToken); if (string.IsNullOrEmpty(originalRefreshToken)) { refreshToken = GenerateJwtToken(userName, DateTime.UtcNow.AddMinutes(refreshExpire), Utils.Messages.REFRESH_KEY); obj.Refresh = new JwtSecurityTokenHandler().WriteToken(refreshToken); } else { obj.Refresh = originalRefreshToken; } obj.UserId = userName; obj.Role = (isSuper ? "SuperAdmin" : role); } catch (Exception ex) { _Logger.Error(ex); } outRefreshToken = obj.Refresh; return(ConvertToJSON(obj)); }
public ActionResult Index() { UserLogic gl = new UserLogic(); RequestLogic rl = new RequestLogic(); ServerLogic sl = new ServerLogic(); //Different models RequestDataViewModel rdvm = rl.GetRequestResponseTimeGraphData(); ServerDataViewModel sdvm = sl.GetServerData(10); SettingLogic s = new SettingLogic(); //events EventViewModel evm = new EventViewModel(); evm.Events = new EventLogic().GetLastEvents(5); evm.NotificationCount = Facade.NotificationDomainController.GetAll().Where(x => x.Seen == false).ToList().Count; //MasterViewModel DashBoardViewModel dbvm = gl.GetUsersGraphData(); dbvm.RequestDataViewModel = rdvm; dbvm.ServerDataViewModel = sdvm; dbvm.SettingsModel = s.GetSettings(); dbvm.EventViewModel = evm; // DashBoardViewModel dbvm = gl.GetGraphDataOneHourInterval(); return(View(dbvm)); }
public SettingsController(SupplyChainContext context, ILogger <SettingsController> logger) : base(context) { _logger = logger; _setting = new SettingLogic(context); }
/// <summary> /// 查询指定服务器组所有负载程序信息 /// </summary> /// <param name="appId">本地程序appid</param> /// <param name="type">类型</param> /// <param name="groupId">服务器组id</param> /// <returns>程序信息集合</returns> public ActionResult QueryRemoteAppInfoList(string appId, string type, string groupId) { List <AppSerView> res = new List <AppSerView>(); try { var serList = SettingLogic.GetRemoteAppList(appId).FirstOrDefault(n => n.SerGroupId == groupId); if (serList != null) { foreach (var appSerListMap in serList.ServiceAdressList) { var remoteAppInfo = new Service().GetRemoteAppInfoById(appSerListMap.AppId, appSerListMap.AppType, appSerListMap.ServiceAdress); res.Add(new AppSerView { AppId = appId, AppType = type, GroupGuid = groupId, RemoteAppView = remoteAppInfo, ServiceAdress = appSerListMap.ServiceAdress, }); } } } catch (Exception e) { TxtLogService.WriteLog(e, "查询指定服务器组上所有负载程序信息异常,信息:" + new { appId, type, groupId }.SerializeObject()); } return(new MyJsonResult { Data = res }); }
/// <summary> /// 批量回退版本 /// </summary> /// <param name="appId">本地程序的appid</param> /// <param name="serGroupId">服务器环境组</param> /// <returns>回退结果</returns> public ActionResult BatchRollBack(string appId, string serGroupId) { Result <List <Result <string> > > res = new Result <List <Result <string> > >(); try { if (string.IsNullOrWhiteSpace(appId)) { res.Message = "请选择要回退的程序"; return(new MyJsonResult { Data = res }); } if (string.IsNullOrWhiteSpace(serGroupId)) { res.Message = "请选择要部署的环境"; return(new MyJsonResult { Data = res }); } var map = SettingLogic.GetRemoteAppList().FirstOrDefault(n => n.AppId == appId && n.SerGroupId == serGroupId); if (map?.ServiceAdressList == null || !map.ServiceAdressList.Any()) { res.Message = "请先配置服务器信息"; return(new MyJsonResult { Data = res }); } Task <Result <string> >[] allTasks = new Task <Result <string> > [map.ServiceAdressList.Count]; for (int i = 0; i < map.ServiceAdressList.Count; i++) { var task = new Service().RollBackAsync(map.ServiceAdressList[i].AppId, map.ServiceAdressList[i].AppType, map.ServiceAdressList[i].ServiceAdress); allTasks[i] = task; } Task.WaitAll(allTasks); List <Result <string> > opRes = new List <Result <string> >(); foreach (var task in allTasks) { opRes.Add(task.Result); } res.IsSucceed = opRes.Exists(n => n.IsSucceed == false); res.Message = !res.IsSucceed ? "部分程序版本回退失败" : ""; res.Data = opRes; } catch (Exception e) { res.IsSucceed = false; res.Message = "批量回退失败"; TxtLogService.WriteLog(e, "批量回退异常,信息:" + new { appId, serGroupId }.SerializeObject()); } return(new MyJsonResult { Data = res }); }
public MenuController(SupplyChainContext context, UserManager <ApplicationUser> userManager, ILogger <MenuController> logger) : base(context) { _userManager = userManager; _setting = new SettingLogic(context); _logger = logger; }
public AuthController(SupplyChainContext context, UserManager <ApplicationUser> userManager, SignInManager <ApplicationUser> signInManager, ILogger <AuthController> logger) : base(context) { _userManager = userManager; _signInManager = signInManager; _logger = logger; _setting = new SettingLogic(_context); }
public UsersController(SupplyChainContext context, UserManager <ApplicationUser> userManager, SignInManager <ApplicationUser> signInManager, RoleManager <ApplicationRole> roleManager, ILogger <UsersController> logger) : base(context) { _userManager = userManager; _signInManager = signInManager; _rolesManager = roleManager; _logger = logger; _setting = new SettingLogic(context); _history = new HistoryLogic(context); }
/// <summary> /// 读取服务器组信息 /// </summary> /// <param name="appId"></param> /// <param name="type"></param> /// <returns></returns> public ActionResult QuerySerGroupByApp(string appId, string type) { var groups = SettingLogic.GetServiceGroups(); List <AppServiceGroupView> res = new List <AppServiceGroupView>(); foreach (var item in groups) { var serList = SettingLogic.GetRemoteAppList(appId).Where(n => n.SerGroupId == item.GroupGuid); res.Add(new AppServiceGroupView { AppId = appId, GroupName = item.GroupName, Guid = item.GroupName, ServiceCount = serList.Count(), }); } return(new MyJsonResult { Data = res }); }
private Result DoIIS(string appId, string fileName, HttpPostedFileBase fileInfo) { string newVersionPath = appId.CopyIISAppToNewDir(); string zipPath = Path.Combine(newVersionPath, fileName); fileInfo.SaveAs(zipPath); // 复制一份压缩包到本网站目录,部署外网的时候就直接从网站目录里面拿取压缩包了。 string zipBackDir = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "ZipFiles"); if (!Directory.Exists(zipBackDir)) { Directory.CreateDirectory(zipBackDir); } string zipBackPath = Path.Combine(zipBackDir, fileName); fileInfo.SaveAs(zipBackPath); SettingLogic.SetAppZipFilePath($"IIS-{appId}", zipBackPath); ZipHelper.UnZip(zipPath, Directory.GetParent(zipPath).FullName); var changeRes = appId.ChangeIISAppVersion(newVersionPath); return(changeRes); }
private Result DoExe(string appId, string fileName, HttpPostedFileBase fileInfo) { Result res = new Result(); try { var allProcesses = Process.GetProcesses(); // 读取进程守护信息 string mgeProcessFileName = SettingLogic.GetMgeProcessFullName(); string processMgeXmlFullName = Path.Combine(Directory.GetParent(mgeProcessFileName).FullName, "ProcessInfo.xml"); XElement element = XElement.Load(processMgeXmlFullName); var appProcessXml = element.Elements().FirstOrDefault(n => n.Attribute("ID")?.Value == appId); if (appProcessXml == null) { throw new Exception("该进程未纳入到守护进程中,无法自动部署"); } var appProcess = allProcesses.FirstOrDefault(n => n.Id.ToString() == appProcessXml.Attribute("PID").Value); if (appProcess == null) { throw new Exception("未找到该进程"); } string appFullPath = appProcess.MainModule.FileName; string appPath = Directory.GetParent(appFullPath).FullName; string newAppPath = appPath.AddVersion(); string zipPath = Path.Combine(newAppPath, fileName); appPath.CopyDirectoryTo(newAppPath); fileInfo.SaveAs(zipPath); // 复制一份压缩包到本网站目录,部署外网的时候就直接从网站目录里面拿取压缩包了。 string zipBackDir = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "ZipFiles"); if (!Directory.Exists(zipBackDir)) { Directory.CreateDirectory(zipBackDir); } string zipBackPath = Path.Combine(zipBackDir, fileName); fileInfo.SaveAs(zipBackPath); SettingLogic.SetAppZipFilePath($"EXE-{appId}", zipBackPath); ZipHelper.UnZip(zipPath, Directory.GetParent(zipPath).FullName); // 关闭进程守护 var mgeProcess = allProcesses.FirstOrDefault(n => String.Equals(n.ProcessName, "ProcessManageApplication", StringComparison.CurrentCultureIgnoreCase)); mgeProcess?.Kill(); // 更新版本号 appProcessXml.Attribute("Path").Value = newAppPath; element.Save(processMgeXmlFullName); // 关闭源程序 appProcess.Kill(); // 启动进程守护 Process.Start(mgeProcessFileName); res.IsSucceed = true; } catch (Exception e) { TxtLogService.WriteLog(e, "切换exe版本异常,信息:" + new { appId, fileName }.SerializeObject()); res.Message = e.Message; } return(res); }
public ActionResult GetSettings() { SettingsModel model = new SettingLogic().GetSettings(); return(PartialView("~/Views/Settings/_SettingsDialog.cshtml", model)); }
public ActionResult BatchDeploy(string appId, string serGroupId) { Result <List <Result <string> > > res = new Result <List <Result <string> > >(); try { if (string.IsNullOrWhiteSpace(appId)) { res.Message = "请选择要部署的程序"; return(new MyJsonResult { Data = res }); } if (string.IsNullOrWhiteSpace(serGroupId)) { res.Message = "请选择要部署的环境"; return(new MyJsonResult { Data = res }); } var map = SettingLogic.GetRemoteAppList().FirstOrDefault(n => n.AppId == appId && n.SerGroupId == serGroupId); if (map?.ServiceAdressList == null || !map.ServiceAdressList.Any()) { res.Message = "请先配置服务器信息"; return(new MyJsonResult { Data = res }); } // 读取压缩文件路径 string key = $"{map.AppType}-{map.AppId}"; var zipFile = SettingLogic.GetAppZipFilePath(key); if (string.IsNullOrWhiteSpace(zipFile)) { var appInfo = new Service().GetAppInfoById(map.AppId, map.AppType); zipFile = appInfo.AppName + ".zip"; ZipHelper.ZipDir(appInfo.AppPhysicalPath, zipFile); } Task <Result <string> >[] allTasks = new Task <Result <string> > [map.ServiceAdressList.Count]; for (int i = 0; i < map.ServiceAdressList.Count; i++) { var task = new Service().DeployAsync(map.ServiceAdressList[i].AppId, map.ServiceAdressList[i].AppType, map.ServiceAdressList[i].ServiceAdress, zipFile); allTasks[i] = task; } Task.WaitAll(allTasks); List <Result <string> > opRes = new List <Result <string> >(); foreach (var task in allTasks) { opRes.Add(task.Result); } res.IsSucceed = opRes.Exists(n => n.IsSucceed == false); res.Message = !res.IsSucceed ? "部分程序版本切换失败" : ""; res.Data = opRes; } catch (Exception e) { res.IsSucceed = false; res.Message = "批量部署失败"; TxtLogService.WriteLog(e, "批量部署异常,信息:" + new { appId, serGroupId }.SerializeObject()); } return(new MyJsonResult { Data = res }); }