-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
219 additions
and
186 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
using System; | ||
|
||
namespace Berrysoft.Tsinghua.Net | ||
{ | ||
/// <summary> | ||
/// A simple class represents the current user online. | ||
/// </summary> | ||
public class FluxUser | ||
{ | ||
/// <summary> | ||
/// Initializes a new instance of the <see cref="FluxUser"/> class. | ||
/// </summary> | ||
/// <param name="username">Username of the user.</param> | ||
/// <param name="flux">Flux used by the user this month.</param> | ||
/// <param name="onlineTime">Online time used this time of the user.</param> | ||
/// <param name="balance">The network balance of the user.</param> | ||
public FluxUser(string username, long flux, TimeSpan onlineTime, decimal balance) | ||
{ | ||
Username = username; | ||
Flux = flux; | ||
OnlineTime = onlineTime; | ||
Balance = balance; | ||
} | ||
/// <summary> | ||
/// Username of the user. | ||
/// </summary> | ||
public string Username { get; } | ||
/// <summary> | ||
/// Flux used by the user this month. | ||
/// </summary> | ||
public long Flux { get; } | ||
/// <summary> | ||
/// Online time used this time of the user. | ||
/// </summary> | ||
public TimeSpan OnlineTime { get; } | ||
/// <summary> | ||
/// The network balance of the user. | ||
/// </summary> | ||
public decimal Balance { get; } | ||
|
||
internal static FluxUser Parse(string fluxstr) | ||
{ | ||
string[] r = fluxstr.Split(','); | ||
if (string.IsNullOrWhiteSpace(r[0])) | ||
{ | ||
return null; | ||
} | ||
else | ||
{ | ||
return new FluxUser( | ||
r[0], | ||
long.Parse(r[6]), | ||
TimeSpan.FromSeconds(long.Parse(r[2]) - long.Parse(r[1])), | ||
decimal.Parse(r[11])); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
using System; | ||
using System.Json; | ||
|
||
namespace Berrysoft.Tsinghua.Net | ||
{ | ||
/// <summary> | ||
/// The response of Login or Logout. | ||
/// </summary> | ||
public class LogResponse | ||
{ | ||
/// <summary> | ||
/// Shows whether the command is succeed. | ||
/// </summary> | ||
public bool Succeed { get; } | ||
/// <summary> | ||
/// The formatted response message. | ||
/// </summary> | ||
public string Message { get; } | ||
|
||
/// <summary> | ||
/// Initialize a new instance of <see cref="LogResponse"/> class. | ||
/// </summary> | ||
/// <param name="succeed">Whether the command is succeed.</param> | ||
/// <param name="message">The formatted response message.</param> | ||
public LogResponse(bool succeed, string message) | ||
{ | ||
Succeed = succeed; | ||
Message = message; | ||
} | ||
|
||
internal static LogResponse ParseFromNet(string response) | ||
{ | ||
return new LogResponse(response == "Login is successful.", response); | ||
} | ||
|
||
internal static LogResponse ParseFromAuth(string response) | ||
{ | ||
try | ||
{ | ||
string jsonstr = response.Substring(9, response.Length - 10); | ||
JsonValue json = JsonValue.Parse(jsonstr); | ||
return new LogResponse(json["error"] == "ok", $"error: {json["error"]}\nerror_msg: {json["error_msg"]}"); | ||
} | ||
catch (Exception) | ||
{ | ||
return new LogResponse(false, response); | ||
} | ||
} | ||
|
||
internal static LogResponse ParseFromUsereg(string response) | ||
{ | ||
return new LogResponse(response == "ok", response); | ||
} | ||
} | ||
} |
Oops, something went wrong.