Revert "Resharper cleanup"

This reverts commit 7c8d7b5ada.

Bad cleanup.
This commit is contained in:
JustArchi 2017-04-05 17:01:18 +02:00
parent 7c8d7b5ada
commit fcf9686a79
33 changed files with 223 additions and 332 deletions

View file

@ -106,7 +106,6 @@
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/ALLOW_COMMENT_AFTER_LBRACE/@EntryValue">True</s:Boolean> <s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/ALLOW_COMMENT_AFTER_LBRACE/@EntryValue">True</s:Boolean>
<s:String x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/ANONYMOUS_METHOD_DECLARATION_BRACES/@EntryValue">END_OF_LINE</s:String> <s:String x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/ANONYMOUS_METHOD_DECLARATION_BRACES/@EntryValue">END_OF_LINE</s:String>
<s:Int64 x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/BLANK_LINES_AFTER_CONTROL_TRANSFER_STATEMENTS/@EntryValue">1</s:Int64> <s:Int64 x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/BLANK_LINES_AFTER_CONTROL_TRANSFER_STATEMENTS/@EntryValue">1</s:Int64>
<s:Int64 x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/BLANK_LINES_AROUND_FIELD/@EntryValue">0</s:Int64>
<s:String x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/CASE_BLOCK_BRACES/@EntryValue">END_OF_LINE</s:String> <s:String x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/CASE_BLOCK_BRACES/@EntryValue">END_OF_LINE</s:String>
<s:String x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/EMPTY_BLOCK_STYLE/@EntryValue">TOGETHER_SAME_LINE</s:String> <s:String x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/EMPTY_BLOCK_STYLE/@EntryValue">TOGETHER_SAME_LINE</s:String>
<s:String x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/INITIALIZER_BRACES/@EntryValue">END_OF_LINE</s:String> <s:String x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/INITIALIZER_BRACES/@EntryValue">END_OF_LINE</s:String>

View file

@ -41,9 +41,7 @@ namespace ArchiSteamFarm {
internal DateTime LastPacketReceived { get; private set; } = DateTime.MinValue; internal DateTime LastPacketReceived { get; private set; } = DateTime.MinValue;
internal ArchiHandler(ArchiLogger archiLogger) { internal ArchiHandler(ArchiLogger archiLogger) => ArchiLogger = archiLogger ?? throw new ArgumentNullException(nameof(archiLogger));
ArchiLogger = archiLogger ?? throw new ArgumentNullException(nameof(archiLogger));
}
public override void HandleMsg(IPacketMsg packetMsg) { public override void HandleMsg(IPacketMsg packetMsg) {
if (packetMsg == null) { if (packetMsg == null) {

View file

@ -175,21 +175,20 @@ namespace ArchiSteamFarm {
KeyValue response = null; KeyValue response = null;
for (byte i = 0; (i < WebBrowser.MaxRetries) && (response == null); i++) { for (byte i = 0; (i < WebBrowser.MaxRetries) && (response == null); i++) {
await Task.Run(() => { await Task.Run(() => {
using (dynamic iEconService = WebAPI.GetInterface(IEconService, steamApiKey)) { using (dynamic iEconService = WebAPI.GetInterface(IEconService, steamApiKey)) {
iEconService.Timeout = Timeout; iEconService.Timeout = Timeout;
try { try {
response = iEconService.DeclineTradeOffer( response = iEconService.DeclineTradeOffer(
tradeofferid: tradeID.ToString(), tradeofferid: tradeID.ToString(),
method: WebRequestMethods.Http.Post, method: WebRequestMethods.Http.Post,
secure: true secure: true
); );
} catch (Exception e) { } catch (Exception e) {
Bot.ArchiLogger.LogGenericWarningException(e); Bot.ArchiLogger.LogGenericWarningException(e);
}
} }
}) }
.ConfigureAwait(false); }).ConfigureAwait(false);
} }
if (response == null) { if (response == null) {
@ -229,22 +228,21 @@ namespace ArchiSteamFarm {
KeyValue response = null; KeyValue response = null;
for (byte i = 0; (i < WebBrowser.MaxRetries) && (response == null); i++) { for (byte i = 0; (i < WebBrowser.MaxRetries) && (response == null); i++) {
await Task.Run(() => { await Task.Run(() => {
using (dynamic iEconService = WebAPI.GetInterface(IEconService, steamApiKey)) { using (dynamic iEconService = WebAPI.GetInterface(IEconService, steamApiKey)) {
iEconService.Timeout = Timeout; iEconService.Timeout = Timeout;
try { try {
response = iEconService.GetTradeOffers( response = iEconService.GetTradeOffers(
get_received_offers: 1, get_received_offers: 1,
active_only: 1, active_only: 1,
get_descriptions: 1, get_descriptions: 1,
secure: true secure: true
); );
} catch (Exception e) { } catch (Exception e) {
Bot.ArchiLogger.LogGenericWarningException(e); Bot.ArchiLogger.LogGenericWarningException(e);
}
} }
}) }
.ConfigureAwait(false); }).ConfigureAwait(false);
} }
if (response == null) { if (response == null) {
@ -614,21 +612,20 @@ namespace ArchiSteamFarm {
KeyValue response = null; KeyValue response = null;
for (byte i = 0; (i < WebBrowser.MaxRetries) && (response == null); i++) { for (byte i = 0; (i < WebBrowser.MaxRetries) && (response == null); i++) {
await Task.Run(() => { await Task.Run(() => {
using (dynamic iPlayerService = WebAPI.GetInterface(IPlayerService, steamApiKey)) { using (dynamic iPlayerService = WebAPI.GetInterface(IPlayerService, steamApiKey)) {
iPlayerService.Timeout = Timeout; iPlayerService.Timeout = Timeout;
try { try {
response = iPlayerService.GetOwnedGames( response = iPlayerService.GetOwnedGames(
steamid: steamID, steamid: steamID,
include_appinfo: 1, include_appinfo: 1,
secure: true secure: true
); );
} catch (Exception e) { } catch (Exception e) {
Bot.ArchiLogger.LogGenericWarningException(e); Bot.ArchiLogger.LogGenericWarningException(e);
}
} }
}) }
.ConfigureAwait(false); }).ConfigureAwait(false);
} }
if (response == null) { if (response == null) {
@ -654,20 +651,19 @@ namespace ArchiSteamFarm {
KeyValue response = null; KeyValue response = null;
for (byte i = 0; (i < WebBrowser.MaxRetries) && (response == null); i++) { for (byte i = 0; (i < WebBrowser.MaxRetries) && (response == null); i++) {
await Task.Run(() => { await Task.Run(() => {
using (dynamic iTwoFactorService = WebAPI.GetInterface(ITwoFactorService)) { using (dynamic iTwoFactorService = WebAPI.GetInterface(ITwoFactorService)) {
iTwoFactorService.Timeout = Timeout; iTwoFactorService.Timeout = Timeout;
try { try {
response = iTwoFactorService.QueryTime( response = iTwoFactorService.QueryTime(
method: WebRequestMethods.Http.Post, method: WebRequestMethods.Http.Post,
secure: true secure: true
); );
} catch (Exception e) { } catch (Exception e) {
Bot.ArchiLogger.LogGenericWarningException(e); Bot.ArchiLogger.LogGenericWarningException(e);
}
} }
}) }
.ConfigureAwait(false); }).ConfigureAwait(false);
} }
if (response != null) { if (response != null) {
@ -810,13 +806,9 @@ namespace ArchiSteamFarm {
} }
} }
internal async Task<bool> HasValidApiKey() { internal async Task<bool> HasValidApiKey() => !string.IsNullOrEmpty(await GetApiKey().ConfigureAwait(false));
return !string.IsNullOrEmpty(await GetApiKey().ConfigureAwait(false));
}
internal static void Init() { internal static void Init() => Timeout = Program.GlobalConfig.ConnectionTimeout * 1000;
Timeout = Program.GlobalConfig.ConnectionTimeout * 1000;
}
internal async Task<bool> Init(ulong steamID, EUniverse universe, string webAPIUserNonce, string parentalPin) { internal async Task<bool> Init(ulong steamID, EUniverse universe, string webAPIUserNonce, string parentalPin) {
if ((steamID == 0) || (universe == EUniverse.Invalid) || string.IsNullOrEmpty(webAPIUserNonce) || string.IsNullOrEmpty(parentalPin)) { if ((steamID == 0) || (universe == EUniverse.Invalid) || string.IsNullOrEmpty(webAPIUserNonce) || string.IsNullOrEmpty(parentalPin)) {
@ -847,23 +839,22 @@ namespace ArchiSteamFarm {
KeyValue authResult = null; KeyValue authResult = null;
await Task.Run(() => { await Task.Run(() => {
using (dynamic iSteamUserAuth = WebAPI.GetInterface(ISteamUserAuth)) { using (dynamic iSteamUserAuth = WebAPI.GetInterface(ISteamUserAuth)) {
iSteamUserAuth.Timeout = Timeout; iSteamUserAuth.Timeout = Timeout;
try { try {
authResult = iSteamUserAuth.AuthenticateUser( authResult = iSteamUserAuth.AuthenticateUser(
steamid: steamID, steamid: steamID,
sessionkey: Encoding.ASCII.GetString(WebUtility.UrlEncodeToBytes(cryptedSessionKey, 0, cryptedSessionKey.Length)), sessionkey: Encoding.ASCII.GetString(WebUtility.UrlEncodeToBytes(cryptedSessionKey, 0, cryptedSessionKey.Length)),
encrypted_loginkey: Encoding.ASCII.GetString(WebUtility.UrlEncodeToBytes(cryptedLoginKey, 0, cryptedLoginKey.Length)), encrypted_loginkey: Encoding.ASCII.GetString(WebUtility.UrlEncodeToBytes(cryptedLoginKey, 0, cryptedLoginKey.Length)),
method: WebRequestMethods.Http.Post, method: WebRequestMethods.Http.Post,
secure: true secure: true
); );
} catch (Exception e) { } catch (Exception e) {
Bot.ArchiLogger.LogGenericWarningException(e); Bot.ArchiLogger.LogGenericWarningException(e);
}
} }
}) }
.ConfigureAwait(false); }).ConfigureAwait(false);
if (authResult == null) { if (authResult == null) {
return false; return false;

View file

@ -56,7 +56,6 @@ namespace ArchiSteamFarm {
private static readonly SemaphoreSlim GiftsSemaphore = new SemaphoreSlim(1); private static readonly SemaphoreSlim GiftsSemaphore = new SemaphoreSlim(1);
private static readonly SemaphoreSlim LoginSemaphore = new SemaphoreSlim(1); private static readonly SemaphoreSlim LoginSemaphore = new SemaphoreSlim(1);
internal readonly ArchiLogger ArchiLogger; internal readonly ArchiLogger ArchiLogger;
internal readonly ArchiWebHandler ArchiWebHandler; internal readonly ArchiWebHandler ArchiWebHandler;
internal readonly string BotName; internal readonly string BotName;
@ -81,6 +80,7 @@ namespace ArchiSteamFarm {
private readonly Timer HeartBeatTimer; private readonly Timer HeartBeatTimer;
private readonly SemaphoreSlim InitializationSemaphore = new SemaphoreSlim(1); private readonly SemaphoreSlim InitializationSemaphore = new SemaphoreSlim(1);
private readonly ConcurrentHashSet<uint> OwnedPackageIDs = new ConcurrentHashSet<uint>(); private readonly ConcurrentHashSet<uint> OwnedPackageIDs = new ConcurrentHashSet<uint>();
private readonly Statistics Statistics; private readonly Statistics Statistics;
private readonly SteamApps SteamApps; private readonly SteamApps SteamApps;
private readonly SteamClient SteamClient; private readonly SteamClient SteamClient;
@ -510,9 +510,7 @@ namespace ArchiSteamFarm {
} }
} }
internal void OnFarmingStopped() { internal void OnFarmingStopped() => ResetGamesPlayed();
ResetGamesPlayed();
}
internal async Task OnNewConfigLoaded(ASF.BotConfigEventArgs args) { internal async Task OnNewConfigLoaded(ASF.BotConfigEventArgs args) {
if (args == null) { if (args == null) {
@ -546,9 +544,7 @@ namespace ArchiSteamFarm {
} }
} }
internal void PlayGame(uint gameID, string gameName = null) { internal void PlayGame(uint gameID, string gameName = null) => PlayGames(gameID.ToEnumerable(), gameName);
PlayGames(gameID.ToEnumerable(), gameName);
}
internal void PlayGames(IEnumerable<uint> gameIDs, string gameName = null) { internal void PlayGames(IEnumerable<uint> gameIDs, string gameName = null) {
if (gameIDs == null) { if (gameIDs == null) {
@ -846,7 +842,7 @@ namespace ArchiSteamFarm {
Task.Run(() => Stop()).Forget(); Task.Run(() => Stop()).Forget();
} }
Bots.TryRemove(BotName, out _); Bots.TryRemove(BotName, out Bot _);
} }
private void Disconnect() { private void Disconnect() {
@ -925,9 +921,7 @@ namespace ArchiSteamFarm {
return result; return result;
} }
private ulong GetFirstSteamMasterID() { private ulong GetFirstSteamMasterID() => BotConfig.SteamUserPermissions.Where(kv => (kv.Key != 0) && (kv.Key != SteamID) && (kv.Value == BotConfig.EPermission.Master)).Select(kv => kv.Key).OrderBy(steamID => steamID).FirstOrDefault();
return BotConfig.SteamUserPermissions.Where(kv => (kv.Key != 0) && (kv.Key != SteamID) && (kv.Value == BotConfig.EPermission.Master)).Select(kv => kv.Key).OrderBy(steamID => steamID).FirstOrDefault();
}
private BotConfig.EPermission GetSteamUserPermission(ulong steamID) { private BotConfig.EPermission GetSteamUserPermission(ulong steamID) {
if (steamID != 0) { if (steamID != 0) {
@ -1202,19 +1196,17 @@ namespace ArchiSteamFarm {
private static async Task LimitGiftsRequestsAsync() { private static async Task LimitGiftsRequestsAsync() {
await GiftsSemaphore.WaitAsync().ConfigureAwait(false); await GiftsSemaphore.WaitAsync().ConfigureAwait(false);
Task.Run(async () => { Task.Run(async () => {
await Task.Delay(Program.GlobalConfig.GiftsLimiterDelay * 1000).ConfigureAwait(false); await Task.Delay(Program.GlobalConfig.GiftsLimiterDelay * 1000).ConfigureAwait(false);
GiftsSemaphore.Release(); GiftsSemaphore.Release();
}) }).Forget();
.Forget();
} }
private static async Task LimitLoginRequestsAsync() { private static async Task LimitLoginRequestsAsync() {
await LoginSemaphore.WaitAsync().ConfigureAwait(false); await LoginSemaphore.WaitAsync().ConfigureAwait(false);
Task.Run(async () => { Task.Run(async () => {
await Task.Delay(Program.GlobalConfig.LoginLimiterDelay * 1000).ConfigureAwait(false); await Task.Delay(Program.GlobalConfig.LoginLimiterDelay * 1000).ConfigureAwait(false);
LoginSemaphore.Release(); LoginSemaphore.Release();
}) }).Forget();
.Forget();
} }
private async Task MarkInventoryIfNeeded() { private async Task MarkInventoryIfNeeded() {
@ -1682,10 +1674,9 @@ namespace ArchiSteamFarm {
if (BotConfig.SteamMasterClanID != 0) { if (BotConfig.SteamMasterClanID != 0) {
Task.Run(async () => { Task.Run(async () => {
await ArchiWebHandler.JoinGroup(BotConfig.SteamMasterClanID).ConfigureAwait(false); await ArchiWebHandler.JoinGroup(BotConfig.SteamMasterClanID).ConfigureAwait(false);
JoinMasterChat(); JoinMasterChat();
}) }).Forget();
.Forget();
} }
Statistics?.OnLoggedOn().Forget(); Statistics?.OnLoggedOn().Forget();
@ -2308,10 +2299,9 @@ namespace ArchiSteamFarm {
// Schedule the task after some time so user can receive response // Schedule the task after some time so user can receive response
Task.Run(async () => { Task.Run(async () => {
await Task.Delay(1000).ConfigureAwait(false); await Task.Delay(1000).ConfigureAwait(false);
await Program.Exit().ConfigureAwait(false); await Program.Exit().ConfigureAwait(false);
}) }).Forget();
.Forget();
return FormatStaticResponse(Strings.Done); return FormatStaticResponse(Strings.Done);
} }
@ -3171,10 +3161,9 @@ namespace ArchiSteamFarm {
// Schedule the task after some time so user can receive response // Schedule the task after some time so user can receive response
Task.Run(async () => { Task.Run(async () => {
await Task.Delay(1000).ConfigureAwait(false); await Task.Delay(1000).ConfigureAwait(false);
await Program.Restart().ConfigureAwait(false); await Program.Restart().ConfigureAwait(false);
}) }).Forget();
.Forget();
return FormatStaticResponse(Strings.Done); return FormatStaticResponse(Strings.Done);
} }

View file

@ -95,9 +95,7 @@ namespace ArchiSteamFarm {
} }
} }
internal IEnumerable<ulong> GetBlacklistedFromTradesSteamIDs() { internal IEnumerable<ulong> GetBlacklistedFromTradesSteamIDs() => BlacklistedFromTradesSteamIDs;
return BlacklistedFromTradesSteamIDs;
}
internal bool IsBlacklistedFromTrades(ulong steamID) { internal bool IsBlacklistedFromTrades(ulong steamID) {
if (steamID != 0) { if (steamID != 0) {

View file

@ -42,9 +42,7 @@ namespace ArchiSteamFarm.CMsgs {
AcceptInvite = binaryReader.ReadBoolean(); AcceptInvite = binaryReader.ReadBoolean();
} }
EMsg ISteamSerializableMessage.GetEMsg() { EMsg ISteamSerializableMessage.GetEMsg() => EMsg.ClientAcknowledgeClanInvite;
return EMsg.ClientAcknowledgeClanInvite;
}
void ISteamSerializable.Serialize(Stream stream) { void ISteamSerializable.Serialize(Stream stream) {
if (stream == null) { if (stream == null) {

View file

@ -90,9 +90,7 @@ namespace ArchiSteamFarm {
IdleFarmingTimer?.Dispose(); IdleFarmingTimer?.Dispose();
} }
internal void OnDisconnected() { internal void OnDisconnected() => StopFarming().Forget();
StopFarming().Forget();
}
internal async Task OnNewGameAdded() { internal async Task OnNewGameAdded() {
// If we're not farming yet, obviously it's worth it to make a check // If we're not farming yet, obviously it's worth it to make a check
@ -148,9 +146,7 @@ namespace ArchiSteamFarm {
} }
} }
internal void SetInitialState(bool paused) { internal void SetInitialState(bool paused) => StickyPause = Paused = paused;
StickyPause = Paused = paused;
}
internal async Task StartFarming() { internal async Task StartFarming() {
if (NowFarming || Paused || !Bot.IsPlayingPossible) { if (NowFarming || Paused || !Bot.IsPlayingPossible) {
@ -848,13 +844,9 @@ namespace ArchiSteamFarm {
return (game != null) && Equals(game); return (game != null) && Equals(game);
} }
public override int GetHashCode() { public override int GetHashCode() => (int) AppID;
return (int) AppID;
}
private bool Equals(Game other) { private bool Equals(Game other) => AppID == other.AppID;
return AppID == other.AppID;
}
} }
} }
} }

View file

@ -45,16 +45,8 @@ namespace ArchiSteamFarm {
Enumerator = collection.GetEnumerator(); Enumerator = collection.GetEnumerator();
} }
public void Dispose() { public void Dispose() => Lock.Dispose();
Lock.Dispose(); public bool MoveNext() => Enumerator.MoveNext();
} public void Reset() => Enumerator.Reset();
public bool MoveNext() {
return Enumerator.MoveNext();
}
public void Reset() {
Enumerator.Reset();
}
} }
} }

View file

@ -72,9 +72,7 @@ namespace ArchiSteamFarm {
} }
} }
public IEnumerator<T> GetEnumerator() { public IEnumerator<T> GetEnumerator() => new ConcurrentEnumerator<T>(HashSet, Lock);
return new ConcurrentEnumerator<T>(HashSet, Lock);
}
public void IntersectWith(IEnumerable<T> other) { public void IntersectWith(IEnumerable<T> other) {
using (Lock.WriterLock()) { using (Lock.WriterLock()) {
@ -136,13 +134,9 @@ namespace ArchiSteamFarm {
} }
} }
void ICollection<T>.Add(T item) { void ICollection<T>.Add(T item) => Add(item);
Add(item);
}
IEnumerator IEnumerable.GetEnumerator() { IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
return GetEnumerator();
}
internal bool AddRange(IEnumerable<T> items) { internal bool AddRange(IEnumerable<T> items) {
using (Lock.WriterLock()) { using (Lock.WriterLock()) {

View file

@ -77,9 +77,7 @@ namespace ArchiSteamFarm {
ServerListProvider.ServerListUpdated += OnServerListUpdated; ServerListProvider.ServerListUpdated += OnServerListUpdated;
} }
public void Dispose() { public void Dispose() => ServerListProvider.ServerListUpdated -= OnServerListUpdated;
ServerListProvider.ServerListUpdated -= OnServerListUpdated;
}
internal static GlobalDatabase Load(string filePath) { internal static GlobalDatabase Load(string filePath) {
if (string.IsNullOrEmpty(filePath)) { if (string.IsNullOrEmpty(filePath)) {
@ -109,9 +107,7 @@ namespace ArchiSteamFarm {
return globalDatabase; return globalDatabase;
} }
private void OnServerListUpdated(object sender, EventArgs e) { private void OnServerListUpdated(object sender, EventArgs e) => Save();
Save();
}
private void Save() { private void Save() {
string json = JsonConvert.SerializeObject(this, CustomSerializerSettings); string json = JsonConvert.SerializeObject(this, CustomSerializerSettings);

View file

@ -29,9 +29,7 @@ using Newtonsoft.Json.Linq;
namespace ArchiSteamFarm { namespace ArchiSteamFarm {
internal sealed class IPAddressConverter : JsonConverter { internal sealed class IPAddressConverter : JsonConverter {
public override bool CanConvert(Type objectType) { public override bool CanConvert(Type objectType) => objectType == typeof(IPAddress);
return objectType == typeof(IPAddress);
}
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) { public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) {
JToken token = JToken.Load(reader); JToken token = JToken.Load(reader);

View file

@ -29,9 +29,7 @@ using Newtonsoft.Json.Linq;
namespace ArchiSteamFarm { namespace ArchiSteamFarm {
internal sealed class IPEndPointConverter : JsonConverter { internal sealed class IPEndPointConverter : JsonConverter {
public override bool CanConvert(Type objectType) { public override bool CanConvert(Type objectType) => objectType == typeof(IPEndPoint);
return objectType == typeof(IPEndPoint);
}
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) { public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) {
JObject jo = JObject.Load(reader); JObject jo = JObject.Load(reader);

View file

@ -34,9 +34,7 @@ namespace ArchiSteamFarm {
[JsonProperty(Required = Required.DisallowNull)] [JsonProperty(Required = Required.DisallowNull)]
private readonly ConcurrentHashSet<IPEndPoint> Servers = new ConcurrentHashSet<IPEndPoint>(); private readonly ConcurrentHashSet<IPEndPoint> Servers = new ConcurrentHashSet<IPEndPoint>();
public Task<IEnumerable<IPEndPoint>> FetchServerListAsync() { public Task<IEnumerable<IPEndPoint>> FetchServerListAsync() => Task.FromResult<IEnumerable<IPEndPoint>>(Servers);
return Task.FromResult<IEnumerable<IPEndPoint>>(Servers);
}
public Task UpdateServerListAsync(IEnumerable<IPEndPoint> endPoints) { public Task UpdateServerListAsync(IEnumerable<IPEndPoint> endPoints) {
if (endPoints == null) { if (endPoints == null) {

View file

@ -440,7 +440,7 @@ namespace ArchiSteamFarm.JSON {
internal bool IsFairTypesExchange() { internal bool IsFairTypesExchange() {
Dictionary<uint, Dictionary<Item.EType, uint>> itemsToGivePerGame = new Dictionary<uint, Dictionary<Item.EType, uint>>(); Dictionary<uint, Dictionary<Item.EType, uint>> itemsToGivePerGame = new Dictionary<uint, Dictionary<Item.EType, uint>>();
foreach (Item item in ItemsToGive) { foreach (Item item in ItemsToGive) {
if (!itemsToGivePerGame.TryGetValue(item.RealAppID, out Dictionary<Item.EType, uint> itemsPerType)) { if (!itemsToGivePerGame.TryGetValue(item.RealAppID, out Dictionary<Item.EType, uint> itemsPerType)) {
itemsPerType = new Dictionary<Item.EType, uint> { [item.Type] = item.Amount }; itemsPerType = new Dictionary<Item.EType, uint> { [item.Type] = item.Amount };
itemsToGivePerGame[item.RealAppID] = itemsPerType; itemsToGivePerGame[item.RealAppID] = itemsPerType;
} else { } else {
@ -489,9 +489,7 @@ namespace ArchiSteamFarm.JSON {
return true; return true;
} }
internal bool IsSteamCardsRequest() { internal bool IsSteamCardsRequest() => ItemsToGive.All(item => (item.AppID == Item.SteamAppID) && (item.ContextID == Item.SteamCommunityContextID) && (item.Type == Item.EType.TradingCard));
return ItemsToGive.All(item => (item.AppID == Item.SteamAppID) && (item.ContextID == Item.SteamCommunityContextID) && (item.Type == Item.EType.TradingCard));
}
[SuppressMessage("ReSharper", "UnusedMember.Global")] [SuppressMessage("ReSharper", "UnusedMember.Global")]
internal enum ETradeOfferState : byte { internal enum ETradeOfferState : byte {

View file

@ -68,9 +68,7 @@ namespace ArchiSteamFarm {
private MobileAuthenticator() { } private MobileAuthenticator() { }
public void Dispose() { public void Dispose() => ConfirmationsSemaphore.Dispose();
ConfirmationsSemaphore.Dispose();
}
internal void CorrectDeviceID(string deviceID) { internal void CorrectDeviceID(string deviceID) {
if (string.IsNullOrEmpty(deviceID)) { if (string.IsNullOrEmpty(deviceID)) {
@ -248,9 +246,7 @@ namespace ArchiSteamFarm {
} }
} }
internal void Init(Bot bot) { internal void Init(Bot bot) => Bot = bot ?? throw new ArgumentNullException(nameof(bot));
Bot = bot ?? throw new ArgumentNullException(nameof(bot));
}
internal static async Task OnTimeChanged() { internal static async Task OnTimeChanged() {
await TimeSemaphore.WaitAsync().ConfigureAwait(false); await TimeSemaphore.WaitAsync().ConfigureAwait(false);

View file

@ -77,9 +77,7 @@ namespace ArchiSteamFarm {
} }
} }
private static async void OnTimeChanged(object sender, EventArgs e) { private static async void OnTimeChanged(object sender, EventArgs e) => await MobileAuthenticator.OnTimeChanged().ConfigureAwait(false);
await MobileAuthenticator.OnTimeChanged().ConfigureAwait(false);
}
private static class NativeMethods { private static class NativeMethods {
internal const uint EnableQuickEditMode = 0x0040; internal const uint EnableQuickEditMode = 0x0040;

View file

@ -446,22 +446,18 @@ namespace ArchiSteamFarm {
ServiceName = SharedInfo.ServiceName; ServiceName = SharedInfo.ServiceName;
} }
protected override void OnStart(string[] args) { protected override void OnStart(string[] args) => Task.Run(async () => {
Task.Run(async () => { // Normally it'd make sense to use already provided string[] args parameter above
// Normally it'd make sense to use already provided string[] args parameter above // However, that one doesn't seem to work when ASF is started as a service, it's always null
// However, that one doesn't seem to work when ASF is started as a service, it's always null // Therefore, we will use Environment args in such case
// Therefore, we will use Environment args in such case string[] envArgs = Environment.GetCommandLineArgs();
string[] envArgs = Environment.GetCommandLineArgs(); await Init(envArgs).ConfigureAwait(false);
await Init(envArgs).ConfigureAwait(false);
ShutdownResetEvent.Wait(); ShutdownResetEvent.Wait();
Stop(); Stop();
}); });
}
protected override async void OnStop() { protected override async void OnStop() => await Shutdown().ConfigureAwait(false);
await Shutdown().ConfigureAwait(false);
}
} }
} }
} }

View file

@ -48,13 +48,9 @@ namespace ArchiSteamFarm {
private DateTime LastPersonaStateRequest = DateTime.MinValue; private DateTime LastPersonaStateRequest = DateTime.MinValue;
private bool ShouldSendHeartBeats; private bool ShouldSendHeartBeats;
internal Statistics(Bot bot) { internal Statistics(Bot bot) => Bot = bot ?? throw new ArgumentNullException(nameof(bot));
Bot = bot ?? throw new ArgumentNullException(nameof(bot));
}
public void Dispose() { public void Dispose() => Semaphore.Dispose();
Semaphore.Dispose();
}
internal async Task OnHeartBeat() { internal async Task OnHeartBeat() {
// Request persona update if needed // Request persona update if needed
@ -89,9 +85,7 @@ namespace ArchiSteamFarm {
} }
} }
internal async Task OnLoggedOn() { internal async Task OnLoggedOn() => await Bot.ArchiWebHandler.JoinGroup(SharedInfo.ASFGroupSteamID).ConfigureAwait(false);
await Bot.ArchiWebHandler.JoinGroup(SharedInfo.ASFGroupSteamID).ConfigureAwait(false);
}
internal async Task OnPersonaState(SteamFriends.PersonaStateCallback callback) { internal async Task OnPersonaState(SteamFriends.PersonaStateCallback callback) {
if (callback == null) { if (callback == null) {

View file

@ -43,13 +43,9 @@ namespace ArchiSteamFarm {
private bool ParsingScheduled; private bool ParsingScheduled;
internal Trading(Bot bot) { internal Trading(Bot bot) => Bot = bot ?? throw new ArgumentNullException(nameof(bot));
Bot = bot ?? throw new ArgumentNullException(nameof(bot));
}
public void Dispose() { public void Dispose() => TradesSemaphore.Dispose();
TradesSemaphore.Dispose();
}
internal async Task CheckTrades() { internal async Task CheckTrades() {
// We aim to have a maximum of 2 tasks, one already parsing, and one waiting in the queue // We aim to have a maximum of 2 tasks, one already parsing, and one waiting in the queue
@ -78,15 +74,12 @@ namespace ArchiSteamFarm {
internal static async Task LimitInventoryRequestsAsync() { internal static async Task LimitInventoryRequestsAsync() {
await InventorySemaphore.WaitAsync().ConfigureAwait(false); await InventorySemaphore.WaitAsync().ConfigureAwait(false);
Task.Run(async () => { Task.Run(async () => {
await Task.Delay(Program.GlobalConfig.InventoryLimiterDelay * 1000).ConfigureAwait(false); await Task.Delay(Program.GlobalConfig.InventoryLimiterDelay * 1000).ConfigureAwait(false);
InventorySemaphore.Release(); InventorySemaphore.Release();
}) }).Forget();
.Forget();
} }
internal void OnDisconnected() { internal void OnDisconnected() => IgnoredTrades.ClearAndTrim();
IgnoredTrades.ClearAndTrim();
}
private async Task ParseActiveTrades() { private async Task ParseActiveTrades() {
HashSet<Steam.TradeOffer> tradeOffers = await Bot.ArchiWebHandler.GetActiveTradeOffers().ConfigureAwait(false); HashSet<Steam.TradeOffer> tradeOffers = await Bot.ArchiWebHandler.GetActiveTradeOffers().ConfigureAwait(false);

View file

@ -68,9 +68,7 @@ namespace ArchiSteamFarm {
return cookies.Count != 0 ? (from Cookie cookie in cookies where cookie.Name.Equals(name) select cookie.Value).FirstOrDefault() : null; return cookies.Count != 0 ? (from Cookie cookie in cookies where cookie.Name.Equals(name) select cookie.Value).FirstOrDefault() : null;
} }
internal static uint GetUnixTime() { internal static uint GetUnixTime() => (uint) DateTimeOffset.UtcNow.ToUnixTimeSeconds();
return (uint) DateTimeOffset.UtcNow.ToUnixTimeSeconds();
}
/* /*
internal static int RandomNext(int maxWithout) { internal static int RandomNext(int maxWithout) {
@ -99,7 +97,7 @@ namespace ArchiSteamFarm {
for (byte i = 0; i < text.Length; i += split) { for (byte i = 0; i < text.Length; i += split) {
string textPart = string.Join("", text.Skip(i).Take(split)); string textPart = string.Join("", text.Skip(i).Take(split));
if (!ulong.TryParse(textPart, NumberStyles.HexNumber, null, out _)) { if (!ulong.TryParse(textPart, NumberStyles.HexNumber, null, out ulong _)) {
return false; return false;
} }
} }

View file

@ -50,9 +50,7 @@ namespace ArchiSteamFarm {
StopServer(); StopServer();
} }
public string GetStatus() { public string GetStatus() => Program.GlobalConfig.SteamOwnerID == 0 ? "{}" : Bot.GetAPIStatus(Bot.Bots);
return Program.GlobalConfig.SteamOwnerID == 0 ? "{}" : Bot.GetAPIStatus(Bot.Bots);
}
public string HandleCommand(string input) { public string HandleCommand(string input) {
if (string.IsNullOrEmpty(input)) { if (string.IsNullOrEmpty(input)) {

View file

@ -305,11 +305,7 @@ namespace ArchiSteamFarm {
} }
#if !__MonoCS__ #if !__MonoCS__
private static void InitNonMonoBehaviour() => ServicePointManager.ReusePort = true;
private static void InitNonMonoBehaviour() {
ServicePointManager.ReusePort = true;
}
#endif #endif
private async Task<byte[]> UrlGetToBytes(string request, string referer = null) { private async Task<byte[]> UrlGetToBytes(string request, string referer = null) {

View file

@ -1,24 +1,24 @@
{ {
"AutoRestart": true, "AutoRestart": true,
"AutoUpdates": true, "AutoUpdates": true,
"Blacklist": [], "Blacklist": [],
"ConnectionTimeout": 60, "ConnectionTimeout": 60,
"CurrentCulture": null, "CurrentCulture": null,
"Debug": false, "Debug": false,
"FarmingDelay": 15, "FarmingDelay": 15,
"GiftsLimiterDelay": 1, "GiftsLimiterDelay": 1,
"Headless": false, "Headless": false,
"IdleFarmingPeriod": 3, "IdleFarmingPeriod": 3,
"InventoryLimiterDelay": 3, "InventoryLimiterDelay": 3,
"LoginLimiterDelay": 10, "LoginLimiterDelay": 10,
"MaxFarmingTime": 10, "MaxFarmingTime": 10,
"MaxTradeHoldDuration": 15, "MaxTradeHoldDuration": 15,
"OptimizationMode": 0, "OptimizationMode": 0,
"Statistics": true, "Statistics": true,
"SteamOwnerID": 0, "SteamOwnerID": 0,
"SteamProtocol": 6, "SteamProtocol": 6,
"UpdateChannel": 1, "UpdateChannel": 1,
"WCFBinding": 0, "WCFBinding": 0,
"WCFHost": "127.0.0.1", "WCFHost": "127.0.0.1",
"WCFPort": 1242 "WCFPort": 1242
} }

View file

@ -1,31 +1,31 @@
{ {
"AcceptGifts": false, "AcceptGifts": false,
"CardDropsRestricted": true, "CardDropsRestricted": true,
"CustomGamePlayedWhileFarming": null, "CustomGamePlayedWhileFarming": null,
"CustomGamePlayedWhileIdle": null, "CustomGamePlayedWhileIdle": null,
"DismissInventoryNotifications": false, "DismissInventoryNotifications": false,
"Enabled": false, "Enabled": false,
"FarmingOrder": 0, "FarmingOrder": 0,
"FarmOffline": false, "FarmOffline": false,
"GamesPlayedWhileIdle": [], "GamesPlayedWhileIdle": [],
"HandleOfflineMessages": false, "HandleOfflineMessages": false,
"IsBotAccount": false, "IsBotAccount": false,
"LootableTypes": [ "LootableTypes": [
1, 1,
3, 3,
5 5
], ],
"PasswordFormat": 0, "PasswordFormat": 0,
"Paused": false, "Paused": false,
"RedeemingPreferences": 0, "RedeemingPreferences": 0,
"SendOnFarmingFinished": false, "SendOnFarmingFinished": false,
"SendTradePeriod": 0, "SendTradePeriod": 0,
"ShutdownOnFarmingFinished": false, "ShutdownOnFarmingFinished": false,
"SteamLogin": null, "SteamLogin": null,
"SteamMasterClanID": 0, "SteamMasterClanID": 0,
"SteamParentalPIN": "0", "SteamParentalPIN": "0",
"SteamPassword": null, "SteamPassword": null,
"SteamTradeToken": null, "SteamTradeToken": null,
"SteamUserPermissions": {}, "SteamUserPermissions": {},
"TradingPreferences": 0 "TradingPreferences": 0
} }

View file

@ -1,5 +1,5 @@
{ {
"Enabled": false, "Enabled": false,
"SteamLogin": null, "SteamLogin": null,
"SteamPassword": null "SteamPassword": null
} }

View file

@ -1,16 +1,15 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<packages> <packages>
<package id="Costura.Fody" version="2.0.0-beta0018" targetFramework="net461" developmentDependency="true" /> <package id="Costura.Fody" version="2.0.0-beta0018" targetFramework="net461" developmentDependency="true" />
<package id="Fody" version="1.30.0-beta01" targetFramework="net461" developmentDependency="true" /> <package id="Fody" version="1.30.0-beta01" targetFramework="net461" developmentDependency="true" />
<package id="HtmlAgilityPack" version="1.4.9.5" targetFramework="net461" /> <package id="HtmlAgilityPack" version="1.4.9.5" targetFramework="net461" />
<package id="Microsoft.Bcl" version="1.1.10" targetFramework="net461" /> <package id="Microsoft.Bcl" version="1.1.10" targetFramework="net461" />
<package id="Microsoft.Bcl.Async" version="1.0.168" targetFramework="net461" /> <package id="Microsoft.Bcl.Async" version="1.0.168" targetFramework="net461" />
<package id="Microsoft.Bcl.Build" version="1.0.21" targetFramework="net461" /> <package id="Microsoft.Bcl.Build" version="1.0.21" targetFramework="net461" />
<package id="Newtonsoft.Json" version="10.0.2" targetFramework="net461" /> <package id="Newtonsoft.Json" version="10.0.2" targetFramework="net461" />
<package id="Nito.AsyncEx" version="4.0.1" targetFramework="net461" /> <package id="Nito.AsyncEx" version="4.0.1" targetFramework="net461" />
<package id="NLog" version="5.0.0-beta06" targetFramework="net461" /> <package id="NLog" version="5.0.0-beta06" targetFramework="net461" />
<package id="protobuf-net" version="2.1.0" targetFramework="net461" /> <package id="protobuf-net" version="2.1.0" targetFramework="net461" />
<package id="Resource.Embedder" version="1.2.2" targetFramework="net461" developmentDependency="true" /> <package id="Resource.Embedder" version="1.2.2" targetFramework="net461" developmentDependency="true" />
<package id="SteamKit2" version="2.0.0-Alpha3" targetFramework="net461" /> <package id="SteamKit2" version="2.0.0-Alpha3" targetFramework="net461" />
</packages> </packages>

View file

@ -39,8 +39,6 @@ namespace ConfigGenerator {
Controls.Add(enhancedPropertyGrid); Controls.Add(enhancedPropertyGrid);
} }
internal void RefreshText() { internal void RefreshText() => Text = Path.GetFileNameWithoutExtension(ASFConfig.FilePath);
Text = Path.GetFileNameWithoutExtension(ASFConfig.FilePath);
}
} }
} }

View file

@ -68,9 +68,7 @@ namespace ConfigGenerator {
} }
// Gets the current bit value corresponding to all checked items // Gets the current bit value corresponding to all checked items
private int GetCurrentValue() { private int GetCurrentValue() => (from object t in Items select t as FlagCheckedListBoxItem).Where((item, i) => (item != null) && GetItemChecked(i)).Aggregate(0, (current, item) => current | item.Value);
return (from object t in Items select t as FlagCheckedListBoxItem).Where((item, i) => (item != null) && GetItemChecked(i)).Aggregate(0, (current, item) => current | item.Value);
}
#region Component Designer generated code #region Component Designer generated code
@ -148,9 +146,7 @@ namespace ConfigGenerator {
Caption = c; Caption = c;
} }
public override string ToString() { public override string ToString() => Caption;
return Caption;
}
} }
// UITypeEditor for flag enums // UITypeEditor for flag enums
@ -179,8 +175,6 @@ namespace ConfigGenerator {
return FlagEnumCb.EnumValue; return FlagEnumCb.EnumValue;
} }
public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext context) { public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext context) => UITypeEditorEditStyle.DropDown;
return UITypeEditorEditStyle.DropDown;
}
} }
} }

View file

@ -1,9 +1,8 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<packages> <packages>
<package id="Costura.Fody" version="2.0.0-beta0018" targetFramework="net461" developmentDependency="true" /> <package id="Costura.Fody" version="2.0.0-beta0018" targetFramework="net461" developmentDependency="true" />
<package id="Fody" version="1.30.0-beta01" targetFramework="net461" developmentDependency="true" /> <package id="Fody" version="1.30.0-beta01" targetFramework="net461" developmentDependency="true" />
<package id="GenDictEdit" version="1.1.0" targetFramework="net461" /> <package id="GenDictEdit" version="1.1.0" targetFramework="net461" />
<package id="Newtonsoft.Json" version="10.0.2" targetFramework="net461" /> <package id="Newtonsoft.Json" version="10.0.2" targetFramework="net461" />
<package id="Resource.Embedder" version="1.2.2" targetFramework="net461" developmentDependency="true" /> <package id="Resource.Embedder" version="1.2.2" targetFramework="net461" developmentDependency="true" />
</packages> </packages>

View file

@ -40,8 +40,6 @@ namespace ArchiSteamFarm {
AvatarPictureBox.LoadAsync(); AvatarPictureBox.LoadAsync();
} }
private void AvatarPictureBox_LoadCompleted(object sender, AsyncCompletedEventArgs e) { private void AvatarPictureBox_LoadCompleted(object sender, AsyncCompletedEventArgs e) => MainForm.UpdateBotAvatar(Bot.BotName, AvatarPictureBox.Image);
MainForm.UpdateBotAvatar(Bot.BotName, AvatarPictureBox.Image);
}
} }
} }

View file

@ -57,9 +57,7 @@ namespace ArchiSteamFarm {
BotStatusForm.BotForms[PreviouslySelectedBotName].Visible = true; BotStatusForm.BotForms[PreviouslySelectedBotName].Visible = true;
} }
private async void MainForm_FormClosed(object sender, FormClosedEventArgs e) { private async void MainForm_FormClosed(object sender, FormClosedEventArgs e) => await Program.InitShutdownSequence().ConfigureAwait(false);
await Program.InitShutdownSequence().ConfigureAwait(false);
}
private async void MainForm_Load(object sender, EventArgs e) { private async void MainForm_Load(object sender, EventArgs e) {
BotListView.LargeImageList = BotListView.SmallImageList = AvatarImageList; BotListView.LargeImageList = BotListView.SmallImageList = AvatarImageList;

View file

@ -29,9 +29,7 @@ namespace ArchiSteamFarm {
Application.Exit(); Application.Exit();
} }
internal static string GetUserInput(ASF.EUserInputType userInputType, string botName = SharedInfo.ASF, string extraInformation = null) { internal static string GetUserInput(ASF.EUserInputType userInputType, string botName = SharedInfo.ASF, string extraInformation = null) => null; // TODO
return null;
}
internal static async Task InitASF() { internal static async Task InitASF() {
ASF.ArchiLogger.LogGenericInfo("ASF V" + SharedInfo.Version); ASF.ArchiLogger.LogGenericInfo("ASF V" + SharedInfo.Version);

View file

@ -1,17 +1,16 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<packages> <packages>
<package id="Costura.Fody" version="2.0.0-beta0018" targetFramework="net461" developmentDependency="true" /> <package id="Costura.Fody" version="2.0.0-beta0018" targetFramework="net461" developmentDependency="true" />
<package id="Fody" version="1.30.0-beta01" targetFramework="net461" developmentDependency="true" /> <package id="Fody" version="1.30.0-beta01" targetFramework="net461" developmentDependency="true" />
<package id="HtmlAgilityPack" version="1.4.9.5" targetFramework="net461" /> <package id="HtmlAgilityPack" version="1.4.9.5" targetFramework="net461" />
<package id="Microsoft.Bcl" version="1.1.10" targetFramework="net461" /> <package id="Microsoft.Bcl" version="1.1.10" targetFramework="net461" />
<package id="Microsoft.Bcl.Async" version="1.0.168" targetFramework="net461" /> <package id="Microsoft.Bcl.Async" version="1.0.168" targetFramework="net461" />
<package id="Microsoft.Bcl.Build" version="1.0.21" targetFramework="net461" /> <package id="Microsoft.Bcl.Build" version="1.0.21" targetFramework="net461" />
<package id="Newtonsoft.Json" version="10.0.2" targetFramework="net461" /> <package id="Newtonsoft.Json" version="10.0.2" targetFramework="net461" />
<package id="Nito.AsyncEx" version="4.0.1" targetFramework="net461" /> <package id="Nito.AsyncEx" version="4.0.1" targetFramework="net461" />
<package id="NLog" version="5.0.0-beta06" targetFramework="net461" /> <package id="NLog" version="5.0.0-beta06" targetFramework="net461" />
<package id="NLog.Windows.Forms" version="4.2.3" targetFramework="net461" /> <package id="NLog.Windows.Forms" version="4.2.3" targetFramework="net461" />
<package id="protobuf-net" version="2.1.0" targetFramework="net461" /> <package id="protobuf-net" version="2.1.0" targetFramework="net461" />
<package id="Resource.Embedder" version="1.2.2" targetFramework="net461" developmentDependency="true" /> <package id="Resource.Embedder" version="1.2.2" targetFramework="net461" developmentDependency="true" />
<package id="SteamKit2" version="2.0.0-Alpha3" targetFramework="net461" /> <package id="SteamKit2" version="2.0.0-Alpha3" targetFramework="net461" />
</packages> </packages>