public void ReadExistsApp(string keyword) { var path = Path.Combine(Environment.CurrentDirectory, "查询结果", GetSafeFileName(keyword)); if (!File.Exists(path)) { return; } Workbook workbook = new Workbook(path, new LoadOptions(LoadFormat.Xlsx)); var all = workbook.Worksheets[0].Cells; for (int i = 1; i < all.Rows.Count; i++) { var row = all.Rows[i]; var model = new ExportedModel { PackageName = row[0].StringValue, AppName = row[1].StringValue, PackageId = row[2].IntValue, Official = row[3].StringValue, VersionCode = row[4].IntValue, VersionName = row[5].StringValue, DownloadCount = row[6].StringValue, IsOnline = row[7].StringValue, UserContent = row[8].StringValue, NewStatus = 0 }; this.existsApps.Add(model); } }
private void ProcessPage(WebClient client, string keyword, int pageIndex) { var encodeKeyword = HttpUtility.UrlEncode(keyword); var listUrl = string.Format(LIST_URL, encodeKeyword, pageIndex); client.Encoding = Encoding.UTF8; var json = client.DownloadString(listUrl); var result = JsonConvert.DeserializeObject <SearchResult>(json); if (result.totalCount > 0) { foreach (var app in result.value) { var existApp = this.existsApps.FirstOrDefault(x => x.PackageId == app.id && x.PackageName == app.package_name); if (existApp != null) { existApp.DownloadCount = app.download_count; existApp.VersionCode = app.version_code; existApp.VersionName = app.version_name; } else { existApp = new ExportedModel { AppName = app.title_zh, PackageId = app.id, PackageName = app.package_name, Official = app.official == "0" ? "" : "是", NewStatus = 1, DownloadCount = app.download_count, VersionCode = app.version_code, VersionName = app.version_name }; searchResults.Add(existApp); } } if (result.pageNo < result.maxPage) { pageIndex++; ProcessPage(client, keyword, pageIndex); } } }