private void button2_Click(object sender, EventArgs e) { string formPath = Config.GetValue("FormPath") + "\\Learun.Application.Web\\"; //来源文件目录 string toPath = Config.GetValue("ToPathWeb"); //目标文件目录 textBox1.Clear(); textBox1.AppendText("开始复制文件\r\n"); string[] filePaths = DirFileHelper.GetFileNames(formPath, "*", true); int num = 0; foreach (string filePath in filePaths) { if (filePath.IndexOf("\\bin\\") == -1 && filePath.IndexOf("\\obj\\") == -1 && filePath.IndexOf("Learun.Application.Web.csproj") == -1) { textBox1.AppendText(num + ":" + filePath + "\r\n"); string path = toPath + filePath.Replace(formPath, ""); if (filePath.IndexOf("\\LR_Content\\") != -1) { string content = File.ReadAllText(filePath, Encoding.UTF8); FileInfo fi = new FileInfo(path); if (fi.Extension == ".js") { if (!string.IsNullOrEmpty(content)) { content = javaScriptCompressor.Compress(content); } DirFileHelper.CreateFileContent(path, content); } else if (fi.Extension == ".css") { if (!string.IsNullOrEmpty(content)) { content = cssCompressor.Compress(content); } DirFileHelper.CreateFileContent(path, content); } else { if (!Directory.Exists(fi.DirectoryName)) { Directory.CreateDirectory(fi.DirectoryName); } System.IO.File.Copy(filePath, path, true); } } else { FileInfo fi = new FileInfo(path); if (!Directory.Exists(fi.DirectoryName)) { Directory.CreateDirectory(fi.DirectoryName); } System.IO.File.Copy(filePath, path, true); } num++; } } textBox1.AppendText("结束复制文件\r\n"); }
/// <summary> /// 同步bin文件 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void button1_Click(object sender, EventArgs e) { string formPath = Config.GetValue("FormPath") + "\\Learun.Framework.Module\\"; //来源文件目录 string toPath = Config.GetValue("ToPath"); //目标文件目录 string[] filePaths = DirFileHelper.GetFileNames(formPath, "*", true); textBox1.Clear(); textBox1.AppendText("开始复制文件\r\n"); int num = 0; foreach (string filePath in filePaths) { if (filePath.IndexOf("\\bin\\Release") != -1) { textBox1.AppendText(num + ":" + filePath + "\r\n"); string path = toPath + filePath.Replace(formPath, ""); FileInfo fi = new FileInfo(path); if (!Directory.Exists(fi.DirectoryName)) { Directory.CreateDirectory(fi.DirectoryName); } System.IO.File.Copy(filePath, path, true); num++; } } textBox1.AppendText("结束复制文件\r\n"); }
public static bool BuildDirectoryMd5(string dirPath, out string dirMD5) { dirMD5 = string.Empty; if (string.IsNullOrEmpty(dirPath)) { return(false); } string[] fileList = null; if (!DirFileHelper.GetFileNames(dirPath, "*", true, out fileList)) { return(false); } StringBuilder builder = new StringBuilder(); if (fileList == null) { return(false); } for (int i = 0; i < fileList.Length; i++) { string str = string.Empty; if (BuildFileMd5(fileList[i], out str)) { builder.Append(str); } } byte[] data = CreateMD5(Encoding.Default.GetBytes(builder.ToString())); dirMD5 = FormatMD5(data); return(true); }
public void Execute(IJobExecutionContext context) { // string path = System.Environment.CurrentDirectory; // MapPath("/App_Data/selfsetting.xml"); HttpContext http = HttpContext.Current; string path = System.IO.Path.Combine(HttpRuntime.AppDomainAppPath, "App_Data/selfsetting.xml"); XmlDocument xmldoc = new XmlDocument(); // string path = System.AppDomain.CurrentDomain.BaseDirectory.ToString()+ "App_Data/selfsetting.xml"; xmldoc.Load(path); string time = xmldoc.SelectSingleNode("root").SelectSingleNode("daorutime").Attributes[0].Value; string daorupath = xmldoc.SelectSingleNode("root").SelectSingleNode("daorudir").Attributes[0].Value; string daorunowdate = xmldoc.SelectSingleNode("root").SelectSingleNode("daorunowdate").Attributes[0].Value; var files = DirFileHelper.GetFileNames(daorupath); if (files.Length > 0) { DataSet ds = ExportFile.ExcelSqlConnection(files[0], "Info"); //调用自定义方法 DataRow[] dr = ds.Tables[0].Select(); int successcount = 0; int failcount = 0; M_HitchInfoBll M_HitchInfoBll = new M_HitchInfoBll(); for (int i = 0; i < dr.Length; i++) { try { M_HitchInfo model = new M_HitchInfo(); model.AreaName = dr[0][0].ToString(); model.FactorySation = dr[i][1].ToString(); model.Signal = dr[i][2].ToString(); model.HappenTimes = int.Parse(dr[i][3].ToString()); model.SignalType = dr[i][4].ToString(); model.HappenTimes1 = int.Parse(dr[i][5].ToString()); model.MessageType = dr[i][6].ToString(); model.CreateUserId = 1; model.CreateUserName = "******"; model.CreateTime = DateTime.Now.AddDays(int.Parse(daorunowdate)); if (M_HitchInfoBll.M_HitchInfoAdd(model) > 0) { successcount++; } else { failcount++; } } catch (Exception) { failcount++; } } for (int i = 0; i < files.Length; i++) { File.Delete(files[i]); } } }
/// <summary> /// 加载专案文件 /// </summary> /// <param name="pPath"></param> /// <param name="pNode"></param> /// <param name="pNodeDic"></param> public void LoadFile(string pPath, TreeNode pNode, Dictionary <string, TreeNode> pNodeDic) { string[] sFiles = DirFileHelper.GetFileNames(pPath); int k = pPath.Length + 1; if (sFiles != null) { for (int i = 0; i < sFiles.Length; i++) { OpenPlot sPlot = CrawlServer.Open(sFiles[i]); if (sPlot == null) { continue; } TreeNode sNode = new TreeNode(sPlot.Name, 2, 2); sNode.Tag = sPlot; CrawlServer.AddPlot2Pool(sPlot); pNodeDic[sFiles[i]] = sNode; pNode.Nodes.Add(sNode); } } }