/// <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); }
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); }
/// <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 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); }
public AutomaticUpdateImplement() { path = FileProcessingHelper.GetUpLoadFilePath(); appInfoXMLPath = FileProcessingHelper.AppInfoXMLPath(); }