Skip to content

Commit e923d47

Browse files
committed
Revert IAsyncEnumerable.
1 parent a704c5e commit e923d47

3 files changed

Lines changed: 37 additions & 39 deletions

File tree

src/Berrysoft.Tsinghua.Net/AuthHelper.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public abstract class AuthHelper : NetHelperBase, IConnect
1313
private const string LogUriBase = "https://auth{0}.tsinghua.edu.cn/cgi-bin/srun_portal";
1414
private const string FluxUriBase = "https://auth{0}.tsinghua.edu.cn/rad_user_info.php";
1515
private const string ChallengeUriBase = "https://auth{0}.tsinghua.edu.cn/cgi-bin/get_challenge?username={{0}}&double_stack=1&ip&callback=callback";
16-
private static readonly int[] AcIds = new int[] { 1, 25, 33, 35 };
16+
private static readonly int[] AcIds = new int[] { 1, 25, 33, 35, 37 };
1717
private readonly string LogUri;
1818
private readonly string FluxUri;
1919
private readonly string ChallengeUri;

src/Berrysoft.Tsinghua.Net/Berrysoft.Tsinghua.Net.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
<ItemGroup>
1515
<PackageReference Include="HtmlAgilityPack" Version="1.11.3" />
1616
<PackageReference Include="System.Json" Version="4.6.0-preview4.19212.13" />
17-
<PackageReference Include="System.Linq.Async" Version="4.0.0-preview.1.build.745" />
1817
</ItemGroup>
1918

2019
<ItemGroup Condition="'$(TargetFramework)'=='net48'">

src/Berrysoft.Tsinghua.Net/UseregHelper.cs

Lines changed: 36 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Collections;
23
using System.Collections.Generic;
34
using System.Globalization;
45
using System.Linq;
@@ -122,24 +123,36 @@ public UseregHelper(string username, string password, HttpClient client)
122123
/// <returns>The response of the website.</returns>
123124
public async Task<LogResponse> LogoutAsync(IPAddress ip) => LogResponse.ParseFromUsereg(await PostAsync(InfoUri, string.Format(DropData, ip.ToString())));
124125

126+
/// <summary>
127+
/// Get login data with username and password.
128+
/// </summary>
129+
/// <returns>A dictionary contains the data.</returns>
130+
private Dictionary<string, string> GetLoginData()
131+
{
132+
return new Dictionary<string, string>
133+
{
134+
["action"] = "login",
135+
["user_login_name"] = Username,
136+
["user_password"] = CryptographyHelper.GetMD5(Password)
137+
};
138+
}
139+
125140
/// <summary>
126141
/// Get all connections of this user.
127142
/// </summary>
128-
/// <returns><see cref="IAsyncEnumerable{NetUser}"/></returns>
129-
public async IAsyncEnumerable<NetUser> GetUsersAsync()
143+
/// <returns><see cref="IEnumerable{NetUser}"/></returns>
144+
public async Task<IEnumerable<NetUser>> GetUsersAsync()
130145
{
131146
string userhtml = await GetAsync(InfoUri);
132147
var doc = new HtmlDocument();
133148
doc.LoadHtml(userhtml);
134-
foreach (var tr in doc.DocumentNode.Element("html").Element("body").Element("table").Element("tr").Elements("td").Last().Elements("table").ElementAt(1).Elements("tr").Skip(1))
135-
{
136-
var tds = (from td in tr.Elements("td").Skip(1)
137-
select td.FirstChild?.InnerText).ToArray();
138-
yield return new NetUser(
139-
IPAddress.Parse(tds[0]),
140-
DateTime.ParseExact(tds[1], "yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture),
141-
tds[10]);
142-
}
149+
return from tr in doc.DocumentNode.Element("html").Element("body").Element("table").Element("tr").Elements("td").Last().Elements("table").ElementAt(1).Elements("tr").Skip(1)
150+
let tds = (from td in tr.Elements("td").Skip(1)
151+
select td.FirstChild?.InnerText).ToArray()
152+
select new NetUser(
153+
IPAddress.Parse(tds[0]),
154+
DateTime.ParseExact(tds[1], "yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture),
155+
tds[10]);
143156
}
144157

145158
private long ParseFlux(string str)
@@ -164,41 +177,27 @@ private long ParseFlux(string str)
164177
/// <summary>
165178
/// Get all details of this month.
166179
/// </summary>
167-
/// <returns><see cref="IAsyncEnumerable{NetDetail}"/></returns>
168-
public async IAsyncEnumerable<NetDetail> GetDetailsAsync()
180+
/// <returns><see cref="IEnumerable{NetDetail}"/></returns>
181+
public async Task<IEnumerable<NetDetail>> GetDetailsAsync()
169182
{
170183
DateTime now = DateTime.Now;
184+
List<NetDetail> list = new List<NetDetail>();
171185
for (int i = 1; ; i++)
172186
{
173187
string detailhtml = await GetAsync(string.Format(DetailUri, now.Year, now.Month.ToString().PadLeft(2, '0'), now.Day, i));
174188
var doc = new HtmlDocument();
175189
doc.LoadHtml(detailhtml);
176-
bool @continue = false;
177-
foreach (var tr in doc.DocumentNode.Element("html").Element("body").Element("table").Element("tr").Elements("td").Last().Elements("table").Last().Elements("tr").Skip(1))
178-
{
179-
var tds = (from td in tr.Elements("td").Skip(1)
180-
select td.FirstChild?.InnerText).ToArray();
181-
yield return new NetDetail(
190+
int oldsize = list.Count;
191+
list.AddRange(
192+
from tr in doc.DocumentNode.Element("html").Element("body").Element("table").Element("tr").Elements("td").Last().Elements("table").Last().Elements("tr").Skip(1)
193+
let tds = (from td in tr.Elements("td").Skip(1)
194+
select td.FirstChild?.InnerText).ToArray()
195+
select new NetDetail(
182196
DateTime.ParseExact(tds[1], "yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture),
183-
ParseFlux(tds[4]));
184-
@continue = true;
185-
}
186-
if (!@continue) break;
197+
ParseFlux(tds[4])));
198+
if (list.Count <= oldsize) break;
187199
}
188-
}
189-
190-
/// <summary>
191-
/// Get login data with username and password.
192-
/// </summary>
193-
/// <returns>A dictionary contains the data.</returns>
194-
private Dictionary<string, string> GetLoginData()
195-
{
196-
return new Dictionary<string, string>
197-
{
198-
["action"] = "login",
199-
["user_login_name"] = Username,
200-
["user_password"] = CryptographyHelper.GetMD5(Password)
201-
};
200+
return list;
202201
}
203202
}
204203
}

0 commit comments

Comments
 (0)