Misc improvement

This commit is contained in:
JustArchi 2017-11-17 17:50:14 +01:00
parent bec6cc0419
commit 070e91a6f9
3 changed files with 30 additions and 19 deletions

View file

@ -49,6 +49,7 @@
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=EnforceWhileStatementBraces/@EntryIndexedValue">WARNING</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=FunctionComplexityOverflow/@EntryIndexedValue">SUGGESTION</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=ImplicitlyCapturedClosure/@EntryIndexedValue">SUGGESTION</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=InheritdocConsiderUsage/@EntryIndexedValue">SUGGESTION</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=InvalidTaskElement/@EntryIndexedValue">WARNING</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=InvertCondition_002E1/@EntryIndexedValue">SUGGESTION</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=InvertIf/@EntryIndexedValue">SUGGESTION</s:String>
@ -129,6 +130,8 @@
<s:String x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/INVOCABLE_DECLARATION_BRACES/@EntryValue">END_OF_LINE</s:String>
<s:Int64 x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/KEEP_BLANK_LINES_IN_CODE/@EntryValue">1</s:Int64>
<s:Int64 x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/KEEP_BLANK_LINES_IN_DECLARATIONS/@EntryValue">1</s:Int64>
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/KEEP_EXISTING_EMBEDDED_ARRANGEMENT/@EntryValue">False</s:Boolean>
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/KEEP_EXISTING_INITIALIZER_ARRANGEMENT/@EntryValue">False</s:Boolean>
<s:String x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/OTHER_BRACES/@EntryValue">END_OF_LINE</s:String>
<s:String x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/PLACE_ACCESSOR_ATTRIBUTE_ON_SAME_LINE_EX/@EntryValue">NEVER</s:String>
@ -139,6 +142,7 @@
<s:String x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/PLACE_FIELD_ATTRIBUTE_ON_SAME_LINE_EX/@EntryValue">NEVER</s:String>
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/PLACE_FINALLY_ON_NEW_LINE/@EntryValue">False</s:Boolean>
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/PLACE_SIMPLE_ACCESSOR_ATTRIBUTE_ON_SAME_LINE/@EntryValue">False</s:Boolean>
<s:String x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/PLACE_SIMPLE_EMBEDDED_STATEMENT_ON_SAME_LINE/@EntryValue">NEVER</s:String>
<s:String x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/SIMPLE_CASE_STATEMENT_STYLE/@EntryValue">LINE_BREAK</s:String>
<s:String x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/SIMPLE_EMBEDDED_STATEMENT_STYLE/@EntryValue">LINE_BREAK</s:String>
@ -411,6 +415,8 @@
<s:String x:Key="/Default/Environment/PerformanceGuide/SwitchConflictResolutionMode/=VsBulb/@EntryIndexedValue">NOTIFY</s:String>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ECSharpAttributeForSingleLineMethodUpgrade/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ECSharpPlaceAttributeOnSameLineMigration/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ECSharpPlaceEmbeddedOnSameLineMigration/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ECSharpRenamePlacementToArrangementMigration/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ESettingsUpgrade_002EAddAccessorOwnerDeclarationBracesMigration/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ESettingsUpgrade_002EAlwaysTreatStructAsNotReorderableMigration/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ESettingsUpgrade_002EMigrateBlankLinesAroundFieldToBlankLinesAroundProperty/@EntryIndexedValue">True</s:Boolean>

View file

@ -229,7 +229,7 @@ namespace ArchiSteamFarm {
await Bot.InitializeSteamConfiguration(Program.GlobalConfig.SteamProtocols, Program.GlobalDatabase.CellID, Program.GlobalDatabase.ServerListProvider).ConfigureAwait(false);
foreach (string botName in Directory.EnumerateFiles(SharedInfo.ConfigDirectory, "*.json").Select(Path.GetFileNameWithoutExtension).Where(botName => !string.IsNullOrEmpty(botName) && IsValidBotName(botName)).OrderBy(botName => botName)) {
Bot.RegisterBot(botName);
await Bot.RegisterBot(botName).ConfigureAwait(false);
}
if (Bot.Bots.Count == 0) {
@ -271,7 +271,7 @@ namespace ArchiSteamFarm {
return;
}
Bot.RegisterBot(botName);
await Bot.RegisterBot(botName).ConfigureAwait(false);
}
private static bool IsUnixVersion(string version) {

View file

@ -54,6 +54,7 @@ namespace ArchiSteamFarm {
internal static readonly ConcurrentDictionary<string, Bot> Bots = new ConcurrentDictionary<string, Bot>();
private static readonly SemaphoreSlim BotsSemaphore = new SemaphoreSlim(1, 1);
private static readonly SemaphoreSlim GiftsSemaphore = new SemaphoreSlim(1, 1);
private static readonly SemaphoreSlim LoginSemaphore = new SemaphoreSlim(1, 1);
@ -677,7 +678,7 @@ namespace ArchiSteamFarm {
BotConfig = args.BotConfig;
InitModules();
InitStart().Forget();
InitStart();
} finally {
InitializationSemaphore.Release();
}
@ -711,22 +712,28 @@ namespace ArchiSteamFarm {
return false;
}
internal static void RegisterBot(string botName) {
internal static async Task RegisterBot(string botName) {
if (string.IsNullOrEmpty(botName)) {
ASF.ArchiLogger.LogNullError(nameof(botName));
return;
}
Bot bot;
try {
bot = new Bot(botName);
} catch (ArgumentException e) {
ASF.ArchiLogger.LogGenericException(e);
if (Bots.ContainsKey(botName)) {
return;
}
bot.InitStart().Forget();
await BotsSemaphore.WaitAsync().ConfigureAwait(false);
try {
if (Bots.ContainsKey(botName)) {
return;
}
Bot bot = new Bot(botName);
bot.InitStart();
} finally {
BotsSemaphore.Release();
}
}
internal void RequestPersonaStateUpdate() {
@ -1089,9 +1096,7 @@ namespace ArchiSteamFarm {
return null;
}
var response = new {
Bots = bots
};
var response = new { Bots = bots };
try {
return JsonConvert.SerializeObject(response);
@ -1276,7 +1281,7 @@ namespace ArchiSteamFarm {
}
ConnectionFailureTimer = new Timer(
e => InitPermanentConnectionFailure(),
async e => await InitPermanentConnectionFailure().ConfigureAwait(false),
null,
TimeSpan.FromMinutes(Math.Ceiling(Program.GlobalConfig.ConnectionTimeout / 30.0)), // Delay
Timeout.InfiniteTimeSpan // Period
@ -1345,17 +1350,17 @@ namespace ArchiSteamFarm {
}
}
private void InitPermanentConnectionFailure() {
private async Task InitPermanentConnectionFailure() {
if (!KeepRunning) {
return;
}
ArchiLogger.LogGenericWarning(Strings.BotHeartBeatFailed);
Destroy(true);
RegisterBot(BotName);
await RegisterBot(BotName).ConfigureAwait(false);
}
private async Task InitStart() {
private void InitStart() {
if ((BotConfig == null) || (BotDatabase == null)) {
return;
}
@ -1366,7 +1371,7 @@ namespace ArchiSteamFarm {
}
// Start
await Start().ConfigureAwait(false);
Start().Forget();
}
private static bool IsAllowedToExecuteCommands(ulong steamID) {