/// <summary> /// 重新创建绝对文件路径 /// </summary> public void ReCreateAbsFilePath() { string rel_directory = GetPathFolder(); string rel_filename = GetFileName(); this.AbsFilePath = PathHelp.CreateUseFilePath(rel_directory, rel_filename); }
public CaseModel Func_ToString() { return(new CaseModel() { NameSign = @"转为字符串", ExeEvent = () => { StackTrace st_def = new StackTrace(); StackTrace st_true = new StackTrace(true); string[] strs = new string[] { string.Format("默认: {0}", st_def.FrameCount), st_def.ToString(), "\n", string.Format("开启文件名、行号、列号:", st_true.FrameCount), st_true.ToString(), }; string path = PathHelp.CreateUseFilePath(directory, @"Func_ToString.txt"); this.ClearAndWriteFile(path, ConvertTool.ToString(strs, "\n")); return true; }, SonCases = new CaseModel[] { Func_StackFrame(), }, }); }
/// <summary> /// 构造函数: 初始化 ini 配置文件对象, /// </summary> public AbsShineUponIni() { string rel_folder = GetPathFolder(); string rel_filename = GetFileName(); string abs_file_path = PathHelp.CreateUseFilePath(rel_folder, rel_filename); this.ini = new IniFile(abs_file_path); }
public string Get_AbsFilePath() { TestModel defmodel = new TestModel(); string rel_directory = defmodel.GetPathFolder(); string rel_filename = string.Format("{0}.ytsdb", defmodel.GetFileName()); string abs_file_path = PathHelp.CreateUseFilePath(rel_directory, rel_filename); return(abs_file_path); }
/// <summary> /// 获取模型数据-文件路径-目标 /// </summary> /// <returns>文件绝对路径</returns> public string GetFilePath_Target(Model.URLReWriter model) { if (CheckData.IsObjectNull(model)) { return(string.Empty); } // 需要指定生成路径文件夹目录 Model.URLReWriterConfig curl = GlobalSystemService.GetInstance().Config.Get <Model.URLReWriterConfig>(); string directory = this.SelfDAL.GetSiteNamePathFolder(curl.RootPage); string path = PathHelp.CreateUseFilePath(directory, model.Target); return(path); }
public void Calc(DirectoryInfo olddir, FileInfo file) { string oldpath = PathHelp.CreateUseFilePath(olddir.FullName, file.Name); int rate = 60; byte[] imgcontent = CanUseImg(file, out rate); string newpath = PathHelp.CreateUseFilePath(olddir.FullName.Replace("imgs", "imgs_c"), file.Name); if (File.Exists(newpath)) { File.Delete(newpath); } SaveImg(imgcontent, newpath); PrintInfo(new FileInfo(oldpath), new FileInfo(newpath), rate); }
public ToRangeList() { this.NameSign = @"获取列表范围"; this.ExeEvent = () => { int sumcount = ToRangeListItem.DataSumCount; string[] source = new string[sumcount]; for (int i = 0; i < source.Length; i++) { source[i] = string.Format("第{0}项", i); } // auto 规则测试 VerifyIList <string, string> verify = new VerifyIList <string, string>(CalcWayEnum.DoubleCycle); foreach (ToRangeListItem item in ToRangeListItem.ResultAnswer()) { verify.Answer = item.result; verify.Source = ConvertTool.ToRangePage(source, item.index, item.count); if (!verify.Calc()) { Console.WriteLine("Error: sum: {0} index: {1} count: {2} result: {3}", source.Length, item.index, item.count, JSON.Serializer(item.result)); } } Console.WriteLine("自动化程序测试结果成功!"); // old 生成结果数据 string absfile = PathHelp.CreateUseFilePath(@"/auto/tools/Test_ConvertTool", @"Func_ToRangeList.txt"); File.Delete(absfile); using (FileStream fileshream = new FileStream(absfile, FileMode.OpenOrCreate)) { using (StreamWriter writer = new StreamWriter(fileshream, YTS.Tools.Const.Format.FILE_ENCODING)) { for (int count = 9; count <= 11; count++) { for (int index = -1; index < 11; index++) { string[] result = ConvertTool.ToRangePage(source, index, count); writer.WriteLine("sum: {0} index: {1} count: {2} result: {3}", source.Length, index, count, JSON.Serializer(result)); } writer.WriteLine(); } writer.Flush(); } } Console.WriteLine("生成结果数据: {0}", absfile); return(true); }; }
public CaseModel Func_ASCII_Special() { return(new CaseModel() { NameSign = @"特别字符", ExeEvent = () => { StringBuilder str = new StringBuilder(); foreach (char c in CommonData.ASCII_Special()) { str.AppendFormat("{{ @\"{0}\", @\"{1}\" }},\n", c, RandomData.GetString(CommonData.ASCII_UpperEnglish(), 5)); } string path = PathHelp.CreateUseFilePath(@"/auto/Tools/Test_CommonData", @"Func_ASCII_Special.txt"); this.ClearAndWriteFile(path, str.ToString()); Dictionary <string, string> dic = FileNameFormat_Dictionary(); return true; }, }); }
public CaseModel Func_XmlSerializer() { return(new CaseModel() { NameSign = @"序列化", ExeEvent = () => { Person[] list = new Person[99]; for (int i = 0; i < list.Length; i++) { list[i] = new Person() { Bill = new Customer() { Surname = RandomData.GetString(43), Title = RandomData.GetString(31), }, }; } string absfile = PathHelp.CreateUseFilePath("/auto/XML/XmlSerializer", "testmodel.xml"); XmlWriterSettings settings = new XmlWriterSettings() { CheckCharacters = true, CloseOutput = true, ConformanceLevel = ConformanceLevel.Document, Encoding = YTS.Tools.Const.Format.FILE_ENCODING, Indent = true, IndentChars = @" ", NamespaceHandling = NamespaceHandling.Default, NewLineOnAttributes = false, NewLineHandling = NewLineHandling.Replace, OmitXmlDeclaration = false, }; using (XmlWriter writer = XmlWriter.Create(absfile, settings)) { XmlSerializer xmlser = new XmlSerializer(typeof(Person[])); xmlser.Serialize(writer, list); } return true; }, }); }
public CaseModel Func_Compression() { return(new CaseModel() { NameSign = @"压缩计算", ExeEvent = () => { const string oldpath = @"D:\ZRQDownloads\imgs"; if (!Directory.Exists(oldpath)) { Console.WriteLine("停止执行, 路径不存在: {0}", oldpath); return true; } ImageHandler handler = new ImageHandler(); const int maxwidth = 1200; const int maxheight = 1200; handler.SetMaxSize(maxwidth, maxheight); const long maxbytelength = 2 * 1024 * 1024; handler.SetMaxByteLength(maxbytelength); DirectoryInfo[] sondirs = PathHelp.AllSonDirectorys(new DirectoryInfo(oldpath)); foreach (DirectoryInfo dirinfo in sondirs) { FileInfo[] fis = PathHelp.PatternFileInfo(dirinfo, @".*\.(jpg|png|gif)"); foreach (FileInfo file in fis) { byte[] imgvalues = handler.Calc(file); if (CheckData.IsSizeEmpty(imgvalues)) { Console.WriteLine("压缩图片失败, 结果为空!"); Console.WriteLine("FileInfo.FullName: {0}", file.FullName); return false; } string newdirpath = file.DirectoryName.Replace("imgs", "imgs_c"); string newfilepath = PathHelp.CreateUseFilePath(newdirpath, file.Name); handler.SaveImg(imgvalues, newfilepath); } } return true; }, }); }
/// <summary> /// 获取模型数据-文件路径-模板 /// </summary> /// <returns>文件绝对路径</returns> public string GetFilePath_Templet(Model.URLReWriter model) { if (CheckData.IsObjectNull(model)) { return(string.Empty); } model.Templet = ConvertTool.ToString(model.Templet); string directory = null; if (Regex.IsMatch(model.Templet, @"^/.*")) { // 留有从根目录来的绝对路径值 directory = this.SelfDAL.GetRootTemplatePathFolder(); } else { // 与 URL 重写的配置文件在同一文件夹下 directory = this.SelfDAL.GetPathFolder(); } string path = PathHelp.CreateUseFilePath(directory, model.Templet); return(path); }
public CaseModel Func_StackFrame() { return(new CaseModel() { NameSign = @"一个堆栈的帧", ExeEvent = () => { StackTrace stack = new StackTrace(true); StackFrame frame = stack.GetFrame(0); string[] strs = new string[] { @"frame.GetFileColumnNumber():", frame.GetFileColumnNumber().ToString(), "\n", @"frame.GetFileLineNumber():", frame.GetFileLineNumber().ToString(), "\n", @"frame.GetFileName():", frame.GetFileName().ToString(), "\n", @"frame.GetILOffset():", frame.GetILOffset().ToString(), "\n", @"frame.GetMethod().Name:", frame.GetMethod().Name.ToString(), "\n", @"frame.GetNativeOffset():", frame.GetNativeOffset().ToString(), "\n", @"frame.ToString():", frame.ToString().ToString(), }; string path = PathHelp.CreateUseFilePath(directory, @"Func_StackFrame.txt"); this.ClearAndWriteFile(path, ConvertTool.ToString(strs, "\n")); return true; }, }); }
public string GetFilePath() { return(PathHelp.CreateUseFilePath("/auto/ini", "first.ini")); }
public CaseModel Func_ToRangeIndex() { return(new CaseModel() { NameSign = @"指定范围索引长度", ExeEvent = () => { StringBuilder str = new StringBuilder(); int[] list = new int[] { 0, 1, 2, 3, 4, 5 }; str.AppendFormat("list: {0}\n\n", JSON.Serializer(list)); for (int index = -2; index < list.Length + 2; index++) { for (int length = -2; length < list.Length + 2; length++) { int[] result = ConvertTool.ToRangeIndex(list, index, length); str.AppendFormat("index: {0} length: {1} result: {2}\n", index, length, JSON.Serializer(result)); } } string path = PathHelp.CreateUseFilePath(@"/auto/tools/Test_ConvertTool", @"Func_ToRangeIndex.txt"); this.ClearAndWriteFile(path, str.ToString()); VerifyIList <int, int> verify = new VerifyIList <int, int>(CalcWayEnum.DoubleCycle); Action <int, int, int[]> method = (index, length, source) => { verify.Answer = source; verify.Source = ConvertTool.ToRangeIndex(list, index, length); if (!verify.Calc()) { Console.WriteLine("Error! index: {0} length: {1} result: {2}", index, length, JSON.Serializer(verify.Source)); throw new Exception("错误!"); } }; method(-2, -2, new int[] { }); method(-2, -1, new int[] { }); method(-2, 0, new int[] { }); method(-2, 1, new int[] { 0 }); method(-2, 2, new int[] { 0, 1 }); method(-2, 3, new int[] { 0, 1, 2 }); method(-2, 4, new int[] { 0, 1, 2, 3 }); method(-2, 5, new int[] { 0, 1, 2, 3, 4 }); method(-2, 6, new int[] { 0, 1, 2, 3, 4, 5 }); method(-2, 7, new int[] { 0, 1, 2, 3, 4, 5 }); method(-1, -2, new int[] { }); method(-1, -1, new int[] { }); method(-1, 0, new int[] { }); method(-1, 1, new int[] { 0 }); method(-1, 2, new int[] { 0, 1 }); method(-1, 3, new int[] { 0, 1, 2 }); method(-1, 4, new int[] { 0, 1, 2, 3 }); method(-1, 5, new int[] { 0, 1, 2, 3, 4 }); method(-1, 6, new int[] { 0, 1, 2, 3, 4, 5 }); method(-1, 7, new int[] { 0, 1, 2, 3, 4, 5 }); method(0, -2, new int[] { }); method(0, -1, new int[] { }); method(0, 0, new int[] { }); method(0, 1, new int[] { 0 }); method(0, 2, new int[] { 0, 1 }); method(0, 3, new int[] { 0, 1, 2 }); method(0, 4, new int[] { 0, 1, 2, 3 }); method(0, 5, new int[] { 0, 1, 2, 3, 4 }); method(0, 6, new int[] { 0, 1, 2, 3, 4, 5 }); method(0, 7, new int[] { 0, 1, 2, 3, 4, 5 }); method(1, -2, new int[] { }); method(1, -1, new int[] { }); method(1, 0, new int[] { }); method(1, 1, new int[] { 1 }); method(1, 2, new int[] { 1, 2 }); method(1, 3, new int[] { 1, 2, 3 }); method(1, 4, new int[] { 1, 2, 3, 4 }); method(1, 5, new int[] { 1, 2, 3, 4, 5 }); method(1, 6, new int[] { 1, 2, 3, 4, 5 }); method(1, 7, new int[] { 1, 2, 3, 4, 5 }); method(2, -2, new int[] { }); method(2, -1, new int[] { }); method(2, 0, new int[] { }); method(2, 1, new int[] { 2 }); method(2, 2, new int[] { 2, 3 }); method(2, 3, new int[] { 2, 3, 4 }); method(2, 4, new int[] { 2, 3, 4, 5 }); method(2, 5, new int[] { 2, 3, 4, 5 }); method(2, 6, new int[] { 2, 3, 4, 5 }); method(2, 7, new int[] { 2, 3, 4, 5 }); method(3, -2, new int[] { }); method(3, -1, new int[] { }); method(3, 0, new int[] { }); method(3, 1, new int[] { 3 }); method(3, 2, new int[] { 3, 4 }); method(3, 3, new int[] { 3, 4, 5 }); method(3, 4, new int[] { 3, 4, 5 }); method(3, 5, new int[] { 3, 4, 5 }); method(3, 6, new int[] { 3, 4, 5 }); method(3, 7, new int[] { 3, 4, 5 }); method(4, -2, new int[] { }); method(4, -1, new int[] { }); method(4, 0, new int[] { }); method(4, 1, new int[] { 4 }); method(4, 2, new int[] { 4, 5 }); method(4, 3, new int[] { 4, 5 }); method(4, 4, new int[] { 4, 5 }); method(4, 5, new int[] { 4, 5 }); method(4, 6, new int[] { 4, 5 }); method(4, 7, new int[] { 4, 5 }); method(5, -2, new int[] { }); method(5, -1, new int[] { }); method(5, 0, new int[] { }); method(5, 1, new int[] { 5 }); method(5, 2, new int[] { 5 }); method(5, 3, new int[] { 5 }); method(5, 4, new int[] { 5 }); method(5, 5, new int[] { 5 }); method(5, 6, new int[] { 5 }); method(5, 7, new int[] { 5 }); method(6, -2, new int[] { }); method(6, -1, new int[] { }); method(6, 0, new int[] { }); method(6, 1, new int[] { }); method(6, 2, new int[] { }); method(6, 3, new int[] { }); method(6, 4, new int[] { }); method(6, 5, new int[] { }); method(6, 6, new int[] { }); method(6, 7, new int[] { }); method(7, -2, new int[] { }); method(7, -1, new int[] { }); method(7, 0, new int[] { }); method(7, 1, new int[] { }); method(7, 2, new int[] { }); method(7, 3, new int[] { }); method(7, 4, new int[] { }); method(7, 5, new int[] { }); method(7, 6, new int[] { }); method(7, 7, new int[] { }); return true; }, }); }
public CaseModel Func_ViewAttributes() { return(new CaseModel() { NameSign = @"查看 Uri 属性", ExeEvent = () => { string[] urls = new string[] { @"", @"C:\A\B\C\D\E\F\G\H\", @"C:\A\B\C\D\X\Y\Z\test.txt", @"..\..\D\X\Y", @"..\..\D\X\Y\Z\test.txt", @"http://127.0.0.1/error_url", @"https://blog.csdn.net/tigerzx/article/details/60335505", @"https://blog.csdn.net:8512/tigerzx/article/details/60335505", @"https://blog.csdn.net:aadwwd/tigerzx/article/details/60335505", @"https://cn.bing.com/search?q=C%23+%E8%A7%A3%E6%9E%90+url+%E7%B1%BB&qs=n&form=QBLH&sp=-1&pq=c%23+%E8%A7%A3%E6%9E%90+url+%E7%B1%BB&sc=0-11&sk=&cvid=162FAA1FDF8347078C9AD231E3966A5E", @"http://yellowtulipshow.site/aspx/YTSTemp/Main_Arena.aspx", @"https://github.com/YellowTulipShow/gitalias", @"http://192.168.1.161:5236/index.html", @"http://192.168.1.161:5236", @"http://127.0.0.1:2684/", @"ftp://*****:*****@yg45.dydytt.net:3122/的士速递5.BD.720p.法语中字.mkv", @"ftp://yellowtulipshow.site/aspx/YTSTemp/Main_Arena.aspx", @"ftp://github.com/YellowTulipShow/gitalias", @"ftp://192.168.1.161:5236/index.html", @"ftp://192.168.1.161:5236", @"ftp://127.0.0.1:2684/", @"file:///D:/ZRQWork/JianGuoYunFolder/WorkFolder/StaticPage/SpreadPage_20180807Dev_RedTheme/index.html", @"file://yellowtulipshow.site/aspx/YTSTemp/Main_Arena.aspx", @"file://github.com/YellowTulipShow/gitalias", @"file://192.168.1.161:5236/index.html", @"file://192.168.1.161:5236", @"file://127.0.0.1:2684/", }; /* * 文档信息正则: * * /?/? * // 摘要: * // (.*) * // * // 返回结果: * // (.*)( * // * // 异常: * // (.*) * // (.*))? * public (.+) (\w+) { get; } */ StringBuilder str = new StringBuilder(); foreach (string url in urls) { Uri uri; try { uri = new Uri(url); } catch (Exception ex) { str.AppendFormat("url: {0} 无法解析! 原因: {1} \n\n\n", url, ex.Message); continue; } str.Append(ConvertTool.ToString(new string[] { string.Format("url: {0}", url), string.Format("AbsolutePath: {0}", uri.AbsolutePath), string.Format("AbsoluteUri: {0}", uri.AbsoluteUri), string.Format("Authority: {0}", uri.Authority), string.Format("DnsSafeHost: {0}", uri.DnsSafeHost), string.Format("Fragment: {0}", uri.Fragment), string.Format("Host: {0}", uri.Host), string.Format("HostNameType: {0}", uri.HostNameType), string.Format("IsAbsoluteUri: {0}", uri.IsAbsoluteUri), string.Format("IsDefaultPort: {0}", uri.IsDefaultPort), string.Format("IsFile: {0}", uri.IsFile), string.Format("IsLoopback: {0}", uri.IsLoopback), string.Format("IsUnc: {0}", uri.IsUnc), string.Format("LocalPath: {0}", uri.LocalPath), string.Format("OriginalString: {0}", uri.OriginalString), string.Format("PathAndQuery: {0}", uri.PathAndQuery), string.Format("Port: {0}", uri.Port), string.Format("Query: {0}", uri.Query), string.Format("Scheme: {0}", uri.Scheme), string.Format("Segments: {0}", uri.Segments), string.Format("UserEscaped: {0}", uri.UserEscaped), string.Format("UserInfo: {0}", uri.UserInfo), }, "\n\t").Trim()); str.Append("\n\n\n\n"); } string abs_file_path = PathHelp.CreateUseFilePath(@"/auto/Learn/Test_URL_or_URI", @"Func_ViewAttributes.txt"); ClearAndWriteFile(abs_file_path, str.ToString()); return true; }, }); }
public CaseModel Func_UseFilePath() { return(new CaseModel() { NameSign = @"准备使用文件路径", ExeEvent = () => { KeyString[] paths = new KeyString[] { new KeyString() { Key = null, Value = string.Empty, // 为空, 默认跳过 }, new KeyString() { Key = string.Empty, // 目录为空, 默认为 "/" Value = "name.yts", }, new KeyString() { Key = "qqqq/sss/", Value = string.Empty, // 为空, 默认跳过 }, new KeyString() { Key = "ttt/rrr/", Value = "name.yts", }, new KeyString() { Key = "uuu/iii/", Value = "/eee/name.yts", // 过滤非法字符为: eeename.yts }, new KeyString() { Key = "/", Value = "fff.yts", }, new KeyString() { Key = "/aaa", Value = "aaa.yts", }, new KeyString() { Key = "/rrr/xxx", Value = "aaa.yts", }, new KeyString() { Key = "/rrr/xxx/", Value = "hhh.yts", }, new KeyString() { Key = "/vvv/yyy", Value = "\\rr/www/aaa.yts", // 过滤非法字符为: rrwwwaaa.yts }, }; foreach (KeyString item in paths) { string absfilepath = PathHelp.CreateUseFilePath("/test_PathHelp/" + item.Key, item.Value); if (CheckData.IsStringNull(absfilepath)) { if (CheckData.IsStringNull(item.Key) || CheckData.IsStringNull(item.Value)) { continue; } else { Console.WriteLine("结果为空, 两个参数都不为空, 不合理", item.Key); Console.WriteLine("directory: {0}", item.Key); Console.WriteLine(" filename: {0}", item.Value); Console.WriteLine(" abs_file: {0}", absfilepath); return false; } } PathHelp.CreateFileExists(absfilepath); if (!File.Exists(absfilepath)) { Console.WriteLine("文件并没有被创建", item.Key); Console.WriteLine("directory: {0}", item.Key); Console.WriteLine(" filename: {0}", item.Value); Console.WriteLine(" abs_file: {0}", absfilepath); return false; } } return true; }, }); }