public void StartCompute() { //计算数据 alpha += (alphaTarget - alpha) * alphaDecay; tick(); //生成结点和链接坐标表 HSSFWorkbook workBook = new HSSFWorkbook(); ISheet nodeSheet = workBook.CreateSheet("结点"); IRow rowHead = nodeSheet.CreateRow(0); rowHead.CreateCell(0).SetCellValue("结点序号"); rowHead.CreateCell(1).SetCellValue("结点名称"); rowHead.CreateCell(2).SetCellValue("结点分组"); rowHead.CreateCell(3).SetCellValue("结点X坐标"); rowHead.CreateCell(4).SetCellValue("结点Y坐标"); for (int i = 0; i < Nodes.Count; i++) { var node = Nodes[i]; var row = nodeSheet.CreateRow(i + 1); row.CreateCell(0).SetCellValue(node.index); row.CreateCell(1).SetCellValue(node.id); row.CreateCell(2).SetCellValue(node.group); row.CreateCell(3).SetCellValue(node.x); row.CreateCell(4).SetCellValue(node.y); } ISheet linkSheet = workBook.CreateSheet("链接"); IRow rowHead2 = linkSheet.CreateRow(0); rowHead2.CreateCell(0).SetCellValue("链接序号"); rowHead2.CreateCell(1).SetCellValue("链接起始点序号"); rowHead2.CreateCell(2).SetCellValue("链接起始点名称"); rowHead2.CreateCell(3).SetCellValue("链接结点点序号"); rowHead2.CreateCell(4).SetCellValue("链接结束点名称"); rowHead2.CreateCell(5).SetCellValue("链接强度"); for (int i = 0; i < Links.Count; i++) { var link = Links[i]; var row = linkSheet.CreateRow(i + 1); row.CreateCell(0).SetCellValue(link.index); row.CreateCell(1).SetCellValue(link.source.index); row.CreateCell(2).SetCellValue(link.source.id); row.CreateCell(3).SetCellValue(link.target.index); row.CreateCell(4).SetCellValue(link.target.id); row.CreateCell(5).SetCellValue(link.value); } var filePath = "result.xls"; using (FileStream fs = new FileStream(filePath, FileMode.Create)) { workBook.Write(fs); CommonTools.Log("生成完毕"); } }
public static void AddPassword(string dirPath, string password) { var fileList = Directory.GetFiles(dirPath, "*.*", SearchOption.TopDirectoryOnly).ToList(); foreach (var filePath in fileList) { string fileName = Path.GetFileNameWithoutExtension(filePath); string extension = Path.GetExtension(filePath); if (extension == ".txt") { continue; } string newfileName = fileName + "[密码:{0}]".FormatStr(password); File.Move(filePath, dirPath + newfileName + extension); } CommonTools.Log("重命名完毕!"); }
/// <summary> /// 监听函数,不断调用计算新位置 /// </summary> public void tick() { //重计算衰减值 while (alpha > alphaMin) { alpha += (alphaTarget - alpha) * alphaDecay; //计算结点位置和速度 forceLink(); forceManyBody(); forceCenter(); for (int i = 0; i < Nodes.Count; i++) { var node = Nodes[i]; node.x += node.vx *= velocityDecay; node.y += node.vy *= velocityDecay; } CommonTools.Log("当前衰减率 - {0}".FormatStr(alpha)); } }
/// <summary> /// 整理本子文件夹路径 /// </summary> /// <param name="path"></param> public static void SortFile(string path) { string errfile = path + @"\error.txt"; string[] files = Directory.GetFiles(path, "*.*", SearchOption.AllDirectories); int i = 1; foreach (var file in files) { var name = Path.GetFileName(file); var newPath = path + name; if (!File.Exists(newPath)) { File.Move(file, newPath); CommonTools.Log("[{0}/{1}] - {2}".FormatStr(i, files.Length, name)); } i++; } CommonTools.Log("处理完毕!"); }
/// <summary> /// 获取网页源代码 /// </summary> /// <param name="url">网页链接</param> /// <returns></returns> public static string GetHtml(string url, string htmlCharset = "utf-8", int type = 0, IDictionary <string, object> parameters = null, CookieCollection cookies = null) { //Http请求 HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url); //设置用户代理,防止网站判定为用户代理 req.UserAgent = "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0; BOIE9;ZHCN)"; //如果方法验证网页来源就加上这一句如果不验证那就可以不写了 //req.Referer = "http://sufei.cnblogs.com"; string html = ""; try { switch (type) { case 0: { //使用GET方法获取链接指向的网页 req.Method = "GET"; //添加Cookie,用来抓取需登陆可见的网页 CookieContainer objcok = new CookieContainer(); Cookie cook1 = new Cookie(); //cook1.Name = "CNZZDATA1257708097"; //cook1.Value = "1167517418-1479817270-%7C1488717892"; //objcok.Add(cook1); objcok.Add(new Cookie("LOGGED_USER", "2Gsu8lGqckigfryi4J%2BxqQ%3D%3D%3AEPYACL1Ic4QgUm9bW2hOXg%3D%3D", "/", ".bcy.net")); req.CookieContainer = objcok; //设置超时 req.Timeout = 5000; //Http响应 HttpWebResponse resp; resp = (HttpWebResponse)req.GetResponse(); Encoding htmlEncoding = Encoding.GetEncoding(htmlCharset); System.IO.StreamReader sr = new System.IO.StreamReader(resp.GetResponseStream(), htmlEncoding); //读取返回的网页 html = sr.ReadToEnd(); resp.Close(); } break; case 1: { HttpWebResponse resp = CreatePostHttpResponse(url, parameters, cookies); Encoding htmlEncoding = Encoding.GetEncoding(htmlCharset); System.IO.StreamReader sr = new System.IO.StreamReader(resp.GetResponseStream(), htmlEncoding); //读取返回的网页 html = sr.ReadToEnd(); resp.Close(); } break; default: break; } return(html); } catch (Exception ex) { CommonTools.Log(ex.Message); return(null); } }
/// <summary> /// 整理本子文件夹路径 /// </summary> /// <param name="path">文件夹路径</param> /// <param name="excludes">要排除的文件夹名称</param> public static void SortDir(string path, List <string> excludes) { string errfile = path + @"\error.txt"; string[] dirs = Directory.GetDirectories(path); int i = 1; foreach (var x in dirs) { bool isEx = false; foreach (var y in excludes) { if (x.Contains(y)) { isEx = true; break; } } if (isEx) { continue; } if (x.Contains("DearSexFriend")) { int df = 324; } var files = Directory.GetFiles(x).ToList(); Regex reg = new Regex(".txt|.url|.torrent"); //Regex reg = new Regex(".rar|.txt|.zip|.url|.torrent"); if (files.Count > 1) { var errorFiles = files.FindAll(s => reg.IsMatch(s)); foreach (var item in errorFiles) { File.Delete(item); } } else { string[] temp = Directory.GetDirectories(x); //if (temp.Length > 1) //{ // string name = Path.GetFileName(x); // File.AppendAllText(errfile, name + System.Environment.NewLine); // i++; // continue; //} if (temp.Length > 0) { int j = 0; string childName = ""; foreach (var childDir in temp) { j++; string name = Path.GetFileName(childDir); if (temp.Length == 1) { childName = name; } string newDir = path + "\\" + name; if (!Directory.Exists(newDir)) { Directory.Move(childDir, newDir); } CommonTools.Log("[{0}/{1}] - [{2}/{3}]{4}".FormatStr(i, dirs.Length, j, temp.Length, name)); } if (string.IsNullOrEmpty(childName)) { Directory.Delete(x, true); } else { string name = Path.GetFileName(x); if (name != childName) { Directory.Delete(x, true); } } } } i++; } CommonTools.Log("处理完毕!"); }