/// <summary> /// 设置应用程序名称 /// </summary> /// <param name="appInfo"></param> /// <returns></returns> public bool SetApplicationInfo(ApplicationInfo appInfo) { var rootName = string.Empty; if (appInfo != null && !string.IsNullOrEmpty(appInfo.AppPath)) { rootName = appInfo.AppPath.Substring(appInfo.AppPath.LastIndexOf("\\")); } var currentPath = FileProcessingHelper.GetUpLoadFilePath() + appInfo.AppName + rootName; appInfo.AppPath = currentPath; var currentAppEntity = FileProcessingHelper.GetFiles(appInfo.AppPath); if (currentAppEntity != null && currentAppEntity.MDir != null) { currentAppEntity.AppName = appInfo.AppName; currentAppEntity.AppVersion = appInfo.AppVersion; if (AppList == null) { AppList = new List <ApplicationEntity>(); } AppList.Add(currentAppEntity); return(true); } return(false); }
/// <summary> /// 获取项目列表 /// </summary> /// <returns></returns> public List <ApplicationEntity> GetAppList() { var appList = AppList; if (appList != null && appList.Any()) { return(appList); } appList = new List <ApplicationEntity>(); AppList = new List <ApplicationEntity>(); var fileList = FileProcessingHelper.GetFilesFullNameList("*.txt"); if (fileList != null && fileList.Any()) { fileList.ForEach(o => { var getTxtString = File.ReadAllText(o, Encoding.Default); var appEntity = FileProcessingHelper.GetTFromXML <ApplicationEntity>(getTxtString); if (appEntity != null) { AppList.Add(appEntity); } }); appList = AppList; return(appList); } return(new List <ApplicationEntity>()); }
/// <summary> /// 下载文件 /// </summary> /// <param name="dlfile"></param> /// <returns></returns> public DlFileResult DownLoadFile(DlFile dlfile) { string path = FileProcessingHelper.GetUpLoadFilePath() + dlfile.ProjectName + "\\" + dlfile.FileName; if (!File.Exists(path)) { var result = new DlFileResult(); result.Size = 0; result.IsSuccess = false; result.Message = ""; result.FileStream = new MemoryStream(); return(result); } DlFileResult file = new DlFileResult(); file.FileStream = new MemoryStream(); Stream ms = new MemoryStream(); FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read); fs.CopyTo(ms); ms.Position = 0; file.Size = ms.Length; file.FileStream = ms; file.IsSuccess = true; fs.Flush(); fs.Close(); return(file); }
public bool DeleteAppInfo(string appName) { MyLog4NetInfo.LogInfo("调用方法:DeleteAppInfo,准备删除项目:" + appName); if (AppList != null && AppList.Any() && AppList.Any(o => o.AppName == appName)) { using (var transactionScope = new TransactionScope()) { //删除内存中的数据 var effectCount = AppList.RemoveAll(o => o.AppName == appName); MyLog4NetInfo.LogInfo(string.Format("删除内存中项目:{0}的数据,删除{1}!", appName, effectCount > 0?"成功":"失败")); //删除info下的txt File.Delete(FileProcessingHelper.AppInfoXMLPath() + appName + ".txt"); MyLog4NetInfo.LogInfo(string.Format("删除项目:{0} 在AppInfo文件夹下的txt文件", appName)); //删除upload下的文件夹 var deleteResult = FileProcessingHelper.DeleteDir(FileProcessingHelper.GetUpLoadFilePath() + appName); MyLog4NetInfo.LogInfo(string.Format("删除项目:{0} 在UpLoadFile文件夹下的项目文件,删除{1}!", appName, deleteResult?"成功":"失败")); if (effectCount > 0) { transactionScope.Complete(); } MyLog4NetInfo.LogInfo(string.Format("调用方法:DeleteAppInfo,删除项目{0},最终删除结果:{1}", appName, effectCount > 0?"成功":"失败")); } } return(false); }
//public bool SetApplicationInfo(ApplicationInfo appInfo) //{ // var currentAppEntity = FileProcessingHelper.GetFiles(appInfo.AppPath); // writeTxt("apppath:"+appInfo.AppPath+"1111"); // if (currentAppEntity != null && currentAppEntity.MDir != null) // { // currentAppEntity.AppName = appInfo.AppName; // currentAppEntity.AppVersion = appInfo.AppVersion; // if (AppList == null) // AppList = new List<ApplicationEntity>(); // AppList.Add(currentAppEntity); // return true; // } // return false; //} /// <summary> /// 下载文件 /// </summary> /// <param name="dlfile"></param> /// <returns></returns> public DlFileResult DownLoadFile(DlFile dlfile) { string path = FileProcessingHelper.GetUpLoadFilePath() + dlfile.ProjectName + "\\" + dlfile.FileName; DlFileResult file = new DlFileResult(); try { if (!File.Exists(path)) { var result = new DlFileResult(); result.Size = 0; result.IsSuccess = false; result.Message = ""; result.FileStream = new MemoryStream(); return(result); } file.FileStream = new MemoryStream(); Stream ms = new MemoryStream(); FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read); fs.CopyTo(ms); ms.Position = 0; file.Size = ms.Length; file.FileStream = ms; file.IsSuccess = true; fs.Flush(); fs.Close(); } catch (Exception ex) { MyLog4NetInfo.ErrorInfo(string.Format("下载文件报错,文件名称:{0},错误消息:{1},错误堆栈{2},错误实例{3}", dlfile.FileName, ex.Message, ex.StackTrace, ex.InnerException)); throw; } return(file); }
/// <summary> /// 更新应用程序信息到XML中 /// </summary> /// <param name="appName"></param> public bool UpdateAppInfo(string appName) { var isTrue = false; var firstOrDefault = AppList.FirstOrDefault(o => o.AppName == appName); if (firstOrDefault != null) { try { FileProcessingHelper.XMLSerializer(firstOrDefault, AppDomain.CurrentDomain.BaseDirectory + "\\AppInfo\\" + appName + ".txt"); isTrue = true; } catch (Exception ex) { } } return(isTrue); }
/// <summary> /// 从appInfo下读取项目信息列表,更新到IIS内存中 /// </summary> /// <returns></returns> private List <ApplicationEntity> UpdateAppListCommon() { var appList = new List <ApplicationEntity>(); var fileList = FileProcessingHelper.GetAppListFromTxt(); if (fileList != null && fileList.Any()) { if (AppList == null) { AppList = new List <ApplicationEntity>(); } AppList = fileList; appList = fileList; return(appList); } return(AppList ?? (AppList = new List <ApplicationEntity>())); }
/// <summary> /// 获取应用更新列表 /// </summary> /// <param name="applicationName">应用名称</param> /// <returns></returns> public ApplicationEntity GetServerPublishFiles(string applicationName) { if (AppList != null && AppList.Any() && AppList.Any(o => o.AppName == applicationName)) { return(AppList.FirstOrDefault(o => o.AppName == applicationName)); } if (File.Exists(appInfoXMLPath + applicationName + ".txt")) { var getTxtString = File.ReadAllText(appInfoXMLPath + applicationName + ".txt", Encoding.Default); var appEntity = FileProcessingHelper.GetTFromXML <ApplicationEntity>(getTxtString); if (appEntity != null) { AppList = new List <ApplicationEntity>(); AppList.Add(appEntity); return(appEntity); } return(new ApplicationEntity()); } return(new ApplicationEntity()); }
/// <summary> /// 更新应用程序信息到XML中 /// </summary> /// <param name="appName"></param> public bool UpdateAppInfo(string appName) { var isTrue = false; var firstOrDefault = AppList.FirstOrDefault(o => o.AppName == appName); if (firstOrDefault != null) { try { FileProcessingHelper.XMLSerializer(firstOrDefault, AppDomain.CurrentDomain.BaseDirectory + "\\AppInfo\\" + appName + ".txt"); isTrue = true; } catch (Exception ex) { MyLog4NetInfo.ErrorInfo(string.Format("调用方法UpdateAppInfo报错,错误信息:{0},错误堆栈:{1},错误实例:{2}", ex.Message, ex.StackTrace, ex.InnerException)); writeTxt(ex.ToString()); } } return(isTrue); }
/// <summary> /// 获取应用程序名称 /// </summary> /// <param name="applicationName"></param> /// <returns></returns> public string GetVersionByApplicationName(string applicationName) { if (AppList == null || !AppList.Any()) { var appXMLPath = appInfoXMLPath + applicationName + ".txt"; if (File.Exists(appXMLPath)) { var getTxtString = File.ReadAllText(appXMLPath, Encoding.Default); var appEntity = FileProcessingHelper.GetTFromXML <ApplicationEntity>(getTxtString); if (appEntity != null) { AppList = new List <ApplicationEntity>(); AppList.Add(appEntity); return(appEntity.AppVersion); } } return(string.Empty); } if (AppList.Exists(o => o.AppName == applicationName) && !string.IsNullOrEmpty(AppList.FirstOrDefault(o => o.AppName == applicationName).AppVersion)) { return(AppList.FirstOrDefault(o => o.AppName == applicationName).AppVersion); } return(string.Empty); }
/// <summary> /// 删除指定目录下的所有文件和文件夹 /// </summary> /// <param name="projectName"></param> /// <returns></returns> public bool DeleteFile(string projectName) { return(FileProcessingHelper.DeleteDir(path + projectName + "\\")); }
public AutomaticUpdateImplement() { path = FileProcessingHelper.GetUpLoadFilePath(); appInfoXMLPath = FileProcessingHelper.AppInfoXMLPath(); }