static void Test() { //使用xpath <B class=ui-page-s-len>2/100</B> Regex reg = new Regex("<B[^>]*>(.+)</B>");//提取符合要求的一段文本 GroupCollection gc = reg.Match("<B class=ui-page-s-len>2/100</B>").Groups; if (gc.Count > 1) {//第一项为匹配的完整串,第二项为标签内的文本 [2/100] Group g = gc[1]; string value = g.Value; } //提取标签内的文本 2/100 string pu = "<B[^>]*>(.*?)</B>"; Regex inner = new Regex(pu); GroupCollection pugc = inner.Match("<B class=ui-page-s-len>2/100</B>").Groups; if (pugc.Count > 0) { Group g = pugc[0]; string value = g.Value; } return; string dir = new AppDirHelper().GetAppDir(AppCategory.WinApp); string zipDir = new DirectoryInfo(dir).Parent.Parent.FullName + "/ZipTemplate"; ZipFileHelper zip = new ZipFileHelper(); zip.Test(); //zip.GenerateZip(zipDir, dir +"/"+ELogType.ZipLog.ToString(), //DateTime.Now.ToString(CommonFormat.DateTimeIntFormat)+ //"000886197005184001_100.zip"); }
static void TestExcel() { DateTime now = DateTime.Now; string time = now.ToString(Common.Data.CommonFormat.DateTimeIntFormat) + "." + CommonHelperEntity.EExcelType.Xlsx; string dir = new AppDirHelper().GetAppDir(AppCategory.WinApp); string fullName = dir + "/" + time; //合并单元格 ExcelHelper.DataFillRowsInSheet <ExcelHeadAttribute, ExcelHeadAttribute>(fullName, EExcelType.Xlsx, now.ToString(Common.Data.CommonFormat.DateIntFormat), DoMergeExcelSheet, DoFillRowToExcelSheet, new List <ExcelHeadAttribute>()); }
void InitLoad() { string exeDir = new AppDirHelper().GetAppDir(AppCategory.WinApp); string dir = exeDir + @"\LogFile\ExcelCompare.xlsx"; firstFile.SetPath(dir); string rightDir = exeDir + @"\LogFile\ExcelCompareCh.xlsx"; secondFile.SetPath(rightDir); }
static void Test() { DataLink dl = new DataLink(); StringBuilder tip = new StringBuilder(); tip.AppendLine("time:\t" + DateTime.Now.ToString(SystemConfig.DateTimeFormat)); tip.AppendLine("App :\t CaptureWebData"); tip.AppendLine("Event:run app"); dl.SendDataToOtherPlatform(string.Format(ConfigurationItems.ErrorSubjetFormat, " Uin" + DateTime.Now.ToString(CommonFormat.DateIntFormat)), tip.ToString());//需要知道当前在进行采集的账户 PickUpTianMaoHtml tm = new PickUpTianMaoHtml(); string dir = new AppDirHelper().GetAppDir(AppCategory.WinApp); tm.DoHtmlFileAnalysis(dir + @"\HttpResponse\list.tmall.com\HttpResponse"); }
public static bool WriteLogProcess(string log) { string logDir = new AppDirHelper().GetAppDir(AppCategory.WebApp); DateTime time = DateTime.Now; string logFormat = Common.Data.CommonFormat.DateToHourIntFormat;//这里会切换使用的日志文件存储大小 //如果不是当天作为文件名,需要在键一个目录 logDir += "/" + time.ToString(Common.Data.CommonFormat.YearMonth); string file = time.ToString(logFormat) + ".log"; LoggerWriter.CreateLogFile(log + time.ToString(Common.Data.CommonFormat.DateTimeMilFormat), logDir, ELogType.HeartBeatLine, file, true); //这里调用日志数据库存储 return(true); }
static void TestMultipleHead() { List <ExcelHeadAttribute> heads = new List <ExcelHeadAttribute>(); heads.Add(new ExcelHeadAttribute() { ColumnName = "姓名", ColumnIndex = 0, ColumnWidth = 200, BeginCellIndex = 0, OccuopationCell = 1, OccupationRow = 2, RowPosition = 0 }); heads.Add(new ExcelHeadAttribute() { ColumnName = "复训带教", ColumnIndex = 1, ColumnWidth = 200, BeginCellIndex = 1, OccuopationCell = 2, OccupationRow = 1, RowPosition = 0 }); heads.Add(new ExcelHeadAttribute() { ColumnName = "复训检查", ColumnIndex = 2, ColumnWidth = 200, BeginCellIndex = 3, OccuopationCell = 2, OccupationRow = 1, RowPosition = 0 }); heads.Add(new ExcelHeadAttribute() { ColumnName = "复训翻译", ColumnIndex = 3, ColumnWidth = 200, BeginCellIndex = 5, OccuopationCell = 2, OccupationRow = 1, RowPosition = 0 }); //子行 heads.Add(new ExcelHeadAttribute() { ColumnName = "小时", ColumnWidth = 200, BeginCellIndex = 1, OccuopationCell = 1, OccupationRow = 1, RowPosition = 1 }); heads.Add(new ExcelHeadAttribute() { ColumnName = "日期", ColumnWidth = 200, BeginCellIndex = 2, OccuopationCell = 1, OccupationRow = 1, RowPosition = 1 }); DateTime now = DateTime.Now; string time = now.ToString(Common.Data.CommonFormat.DateTimeIntFormat) + "." + CommonHelperEntity.EExcelType.Xlsx; string dir = new AppDirHelper().GetAppDir(AppCategory.WinApp); string fullName = dir + "/" + time; ExcelHelper.DataFillSheet(fullName, EExcelType.Xlsx, "1", heads, DoFillRowToExcelSheet, new List <ExcelHeadAttribute>()); }
static bool PackageFolder(string folderName, string zipDir, string zipFileName, bool overrideExisting) { string zipExt = ".zip"; string logDir = new AppDirHelper().GetAppDir(AppCategory.WinApp) + typeof(ELogType).Name; if (folderName.EndsWith(@"\") || folderName.EndsWith("/")) { folderName = folderName.Remove(folderName.Length - 1); } bool result = false; if (!Directory.Exists(folderName)) { return(result); } string compressedFileName = zipDir + "/" + zipFileName; if (!overrideExisting && File.Exists(compressedFileName)) { return(result); } try { string log = DateTime.Now.ToString(CommonFormat.DateIntFormat) + ".log"; if (!Directory.Exists(zipDir)) { Directory.CreateDirectory(zipDir); } using (Package package = Package.Open(compressedFileName, FileMode.Create)) { LoggerWriter.CreateLogFile("Zip Data Source\t" + folderName + "\r\n", logDir, ELogType.DebugData, log, true); var fileList = Directory.EnumerateFiles(folderName, "*", SearchOption.AllDirectories); foreach (string fileName in fileList) { LoggerWriter.CreateLogFile(fileName + "\r\n", logDir, ELogType.DebugData, log, true); string fileFullName = fileName.Replace("\\", "/"); folderName = folderName.Replace("\\", "/"); //The path in the package is all of the subfolders after folderName string pathInPackage = fileFullName.Replace(folderName, string.Empty); //判断开始位置是否含有压缩文件名,存在则从路径中剔除 //压缩包中需要剔除所在的目录【保留相对目录】 string zipReleativeDir = zipFileName.Replace(zipExt, string.Empty); string sign = "/" + zipReleativeDir; if (pathInPackage.IndexOf(sign) == 0) { pathInPackage = pathInPackage.Substring(pathInPackage.IndexOf(sign) + sign.Length); } else if (pathInPackage.IndexOf(zipReleativeDir) == 0) { pathInPackage = pathInPackage.Substring(pathInPackage.IndexOf(zipReleativeDir) + zipReleativeDir.Length); } //Path.GetDirectoryName(fileName).Replace(folderName, string.Empty) + "/" + Path.GetFileName(fileName); //提取到的相对路径 LoggerWriter.CreateLogFile(pathInPackage + "\r\n", logDir, ELogType.DebugData, log, true); Uri partUriDocument = PackUriHelper.CreatePartUri(new Uri(pathInPackage, UriKind.Relative)); PackagePart packagePartDocument = package.CreatePart(partUriDocument, "", CompressionOption.Maximum); using (FileStream fileStream = new FileStream(fileName, FileMode.Open, FileAccess.Read)) { fileStream.CopyTo(packagePartDocument.GetStream()); } } } result = true; } catch (Exception e) { LoggerWriter.CreateLogFile(e.ToString(), logDir, ELogType.ErrorLog); //throw new Exception("Error zipping folder " + folderName, e); } return(result); }
void ChangeCityNode() { AppDirHelper dir = new AppDirHelper(); string path = dir.GetAppDir(AppCategory.WinApp) + @"\Config\CitySubwayCfg.xml"; CitySubway city = new CitySubway(); }