Code review

This commit is contained in:
JustArchi
2015-10-29 11:09:22 +01:00
parent 18790c57a1
commit 0a13d341b7
2 changed files with 96 additions and 79 deletions

View File

@@ -58,8 +58,6 @@ namespace ArchiSteamFarm {
if (!string.IsNullOrEmpty(apiKey) && !apiKey.Equals("null")) {
ApiKey = apiKey;
} else {
ApiKey = null;
}
}

View File

@@ -48,13 +48,16 @@ namespace ArchiSteamFarm {
return 0;
}
ulong result = ulong.Parse(resultString, CultureInfo.InvariantCulture);
return result;
return ulong.Parse(resultString, CultureInfo.InvariantCulture);
}
internal static async Task<HttpResponseMessage> UrlToHttpResponse(string websiteAddress, Dictionary<string, string> cookieVariables = null) {
if (string.IsNullOrEmpty(websiteAddress)) {
return null;
}
HttpResponseMessage result = null;
if (!string.IsNullOrEmpty(websiteAddress)) {
try {
using (HttpClientHandler clientHandler = new HttpClientHandler { UseCookies = false }) {
using (HttpClient client = new HttpClient(clientHandler)) {
@@ -74,9 +77,10 @@ namespace ArchiSteamFarm {
}
}
}
} catch {
}
} catch (Exception e) {
Logging.LogGenericException("Utilities", e);
}
return result;
}
@@ -85,8 +89,12 @@ namespace ArchiSteamFarm {
}
internal static async Task<HtmlDocument> UrlToHtmlDocument(string websiteAddress, Dictionary<string, string> cookieVariables = null) {
if (string.IsNullOrEmpty(websiteAddress)) {
return null;
}
HtmlDocument result = null;
if (!string.IsNullOrEmpty(websiteAddress)) {
try {
HttpResponseMessage responseMessage = await UrlToHttpResponse(websiteAddress, cookieVariables).ConfigureAwait(false);
if (responseMessage != null) {
@@ -97,15 +105,20 @@ namespace ArchiSteamFarm {
result.LoadHtml(source);
}
}
} catch {
}
} catch (Exception e) {
Logging.LogGenericException("Utilities", e);
}
return result;
}
internal static async Task<bool> UrlPostRequest(string request, Dictionary<string, string> postData, Dictionary<string, string> cookieVariables = null, string referer = null) {
if (string.IsNullOrEmpty(request) || postData == null) {
return false;
}
bool result = false;
if (!string.IsNullOrEmpty(request)) {
try {
using (HttpClientHandler clientHandler = new HttpClientHandler { UseCookies = false }) {
using (HttpClient client = new HttpClient(clientHandler)) {
@@ -128,15 +141,20 @@ namespace ArchiSteamFarm {
}
}
}
} catch {
}
} catch (Exception e) {
Logging.LogGenericException("Utilities", e);
}
return result;
}
internal static async Task<HttpResponseMessage> UrlPostRequestWithResponse(string request, Dictionary<string, string> postData, Dictionary<string, string> cookieVariables = null, string referer = null) {
if (string.IsNullOrEmpty(request) || postData == null) {
return null;
}
HttpResponseMessage result = null;
if (!string.IsNullOrEmpty(request)) {
try {
using (HttpClientHandler clientHandler = new HttpClientHandler { UseCookies = false }) {
using (HttpClient client = new HttpClient(clientHandler)) {
@@ -159,9 +177,10 @@ namespace ArchiSteamFarm {
}
}
}
} catch {
}
} catch (Exception e) {
Logging.LogGenericException("Utilities", e);
}
return result;
}
}