private LogNullError ( string nullObjectName, [ previousMethodName = null ) : void | ||
nullObjectName | string | |
previousMethodName | [ | |
Результат | void |
private void MainTab_Deselecting(object sender, TabControlCancelEventArgs args) { if ((sender == null) || (args == null)) { Logging.LogNullError(nameof(sender) + " || " + nameof(args)); return; } OldTab = args.TabPage; }
private static void UnobservedTaskExceptionHandler(object sender, UnobservedTaskExceptionEventArgs args) { if (args?.Exception == null) { Logging.LogNullError(nameof(args) + " || " + nameof(args.Exception)); return; } Logging.LogGenericException(args.Exception); }
private void MainForm_Shown(object sender, EventArgs args) { if ((sender == null) || (args == null)) { Logging.LogNullError(nameof(sender) + " || " + nameof(args)); return; } Tutorial.OnAction(Tutorial.EPhase.Shown); }
private static void UnhandledExceptionHandler(object sender, UnhandledExceptionEventArgs args) { if (args?.ExceptionObject == null) { Logging.LogNullError(nameof(args) + " || " + nameof(args.ExceptionObject)); return; } Logging.LogGenericException((Exception)args.ExceptionObject); }
private void MainForm_HelpButtonClicked(object sender, CancelEventArgs args) { if ((sender == null) || (args == null)) { Logging.LogNullError(nameof(sender) + " || " + nameof(args)); return; } args.Cancel = true; Process.Start(GitHubWikiConfigurationURL); }
protected override void OnGotFocus(EventArgs args) { if (args == null) { Logging.LogNullError(nameof(args)); return; } base.OnGotFocus(args); ASFConfig.Save(); }
internal static DialogResult InputBox(string title, string promptText, out string value) { if (string.IsNullOrEmpty(title) || string.IsNullOrEmpty(promptText)) { Logging.LogNullError(nameof(title) + " || " + nameof(promptText)); value = null; return(DialogResult.Abort); } TextBox textBox = new TextBox { Anchor = AnchorStyles.Right, Bounds = new Rectangle(12, 36, 372, 20), Width = 1000 }; Button buttonOk = new Button { Anchor = AnchorStyles.Bottom | AnchorStyles.Right, Bounds = new Rectangle(228, 72, 75, 23), DialogResult = DialogResult.OK, Text = Resources.OK }; Button buttonCancel = new Button { Anchor = AnchorStyles.Bottom | AnchorStyles.Right, Bounds = new Rectangle(309, 72, 75, 23), DialogResult = DialogResult.Cancel, Text = Resources.Cancel }; Label label = new Label { AutoSize = true, Bounds = new Rectangle(9, 20, 372, 13), Text = promptText }; Form form = new Form { AcceptButton = buttonOk, CancelButton = buttonCancel, ClientSize = new Size(Math.Max(300, label.Right + 10), 107), Controls = { label, textBox, buttonOk, buttonCancel }, FormBorderStyle = FormBorderStyle.FixedDialog, MinimizeBox = false, MaximizeBox = false, StartPosition = FormStartPosition.CenterScreen, Text = title }; DialogResult dialogResult = form.ShowDialog(); value = textBox.Text; return(dialogResult); }
private void MainForm_HelpButtonClicked(object sender, CancelEventArgs args) { if ((sender == null) || (args == null)) { Logging.LogNullError(nameof(sender) + " || " + nameof(args)); return; } args.Cancel = true; Tutorial.OnAction(Tutorial.EPhase.Help); Process.Start("https://github.com/" + SharedInfo.GithubRepo + "/wiki/Configuration"); Tutorial.OnAction(Tutorial.EPhase.HelpFinished); }
internal static DialogResult YesNoBox(string title, string promptText) { if (string.IsNullOrEmpty(title) || string.IsNullOrEmpty(promptText)) { Logging.LogNullError(nameof(title) + " || " + nameof(promptText)); return(DialogResult.Abort); } Button buttonYes = new Button { Anchor = AnchorStyles.Bottom | AnchorStyles.Right, Bounds = new Rectangle(228, 72, 75, 23), DialogResult = DialogResult.Yes, Text = Resources.Yes }; Button buttonNo = new Button { Anchor = AnchorStyles.Bottom | AnchorStyles.Right, Bounds = new Rectangle(309, 72, 75, 23), DialogResult = DialogResult.No, Text = Resources.No }; Label label = new Label { AutoSize = true, Bounds = new Rectangle(9, 20, 372, 13), Text = promptText }; Form form = new Form { AcceptButton = buttonYes, CancelButton = buttonNo, ClientSize = new Size(Math.Max(300, label.Right + 10), 107), Controls = { label, buttonYes, buttonNo }, FormBorderStyle = FormBorderStyle.FixedDialog, MinimizeBox = false, MaximizeBox = false, StartPosition = FormStartPosition.CenterScreen, Text = title }; DialogResult dialogResult = form.ShowDialog(); return(dialogResult); }
private void MainForm_Load(object sender, EventArgs args) { if ((sender == null) || (args == null)) { Logging.LogNullError(nameof(sender) + " || " + nameof(args)); return; } GlobalConfig globalConfig = GlobalConfig.Load(Path.Combine(SharedInfo.ConfigDirectory, SharedInfo.GlobalConfigFileName)); if (!string.IsNullOrEmpty(globalConfig.CurrentCulture)) { try { // GetCultureInfo() would be better but we can't use it for specifying neutral cultures such as "en" CultureInfo culture = CultureInfo.CreateSpecificCulture(globalConfig.CurrentCulture); CultureInfo.DefaultThreadCurrentCulture = CultureInfo.DefaultThreadCurrentUICulture = culture; } catch (CultureNotFoundException) { Logging.LogGenericErrorWithoutStacktrace(CGStrings.ErrorInvalidCurrentCulture); } } ASFTab = new ConfigPage(globalConfig); MainTab.TabPages.Add(ASFTab); foreach (string configFile in Directory.EnumerateFiles(SharedInfo.ConfigDirectory, "*.json")) { string botName = Path.GetFileNameWithoutExtension(configFile); switch (botName) { case SharedInfo.ASF: case "example": case "minimal": continue; } MainTab.TabPages.Add(new ConfigPage(BotConfig.Load(configFile))); Tutorial.Enabled = false; } MainTab.TabPages.AddRange(new[] { RemoveTab, RenameTab, NewTab }); Tutorial.OnAction(Tutorial.EPhase.Start); }
protected override void OnPropertyValueChanged(PropertyValueChangedEventArgs args) { if (args == null) { Logging.LogNullError(nameof(args)); return; } base.OnPropertyValueChanged(args); ASFConfig.Save(); BotConfig botConfig = ASFConfig as BotConfig; if (botConfig != null) { if (!botConfig.Enabled) { return; } Tutorial.OnAction(Tutorial.EPhase.BotEnabled); if (!string.IsNullOrEmpty(botConfig.SteamLogin) && !string.IsNullOrEmpty(botConfig.SteamPassword)) { Tutorial.OnAction(Tutorial.EPhase.BotReady); } return; } GlobalConfig globalConfig = ASFConfig as GlobalConfig; if (globalConfig == null) { return; } if (globalConfig.SteamOwnerID != 0) { Tutorial.OnAction(Tutorial.EPhase.GlobalConfigReady); } }
internal void Rename(string botName) { if (string.IsNullOrEmpty(botName)) { Logging.LogNullError(nameof(botName)); return; } string queryPath = Path.GetFileNameWithoutExtension(FilePath); lock (FileLock) { foreach (string botFile in Directory.EnumerateFiles(SharedInfo.ConfigDirectory, queryPath + ".*")) { try { File.Move(botFile, Path.Combine(SharedInfo.ConfigDirectory, botName + Path.GetExtension(botFile))); } catch (Exception e) { Logging.LogGenericException(e); } } FilePath = Path.Combine(SharedInfo.ConfigDirectory, botName + ".json"); } }
private void MainTab_Selected(object sender, TabControlEventArgs args) { if ((sender == null) || (args == null)) { Logging.LogNullError(nameof(sender) + " || " + nameof(args)); return; } if (args.TabPage == RemoveTab) { ConfigPage configPage = OldTab as ConfigPage; if (configPage == null) { MainTab.SelectedIndex = -1; return; } if (configPage == ASFTab) { MainTab.SelectedTab = ASFTab; Logging.LogGenericErrorWithoutStacktrace(CGStrings.ErrorCantRemoveGlobalConfig); return; } MainTab.SelectedTab = configPage; if (DialogBox.YesNoBox(CGStrings.Removal, CGStrings.ConfirmRemoval) != DialogResult.Yes) { return; } MainTab.SelectedIndex = 0; configPage.ASFConfig.Remove(); MainTab.TabPages.Remove(configPage); } else if (args.TabPage == RenameTab) { ConfigPage configPage = OldTab as ConfigPage; if (configPage == null) { MainTab.SelectedIndex = -1; return; } if (configPage == ASFTab) { MainTab.SelectedTab = ASFTab; Logging.LogGenericErrorWithoutStacktrace(CGStrings.ErrorCantRenameGlobalConfig); return; } MainTab.SelectedTab = configPage; string input; if (DialogBox.InputBox(CGStrings.Rename, CGStrings.UserInputBotName, out input) != DialogResult.OK) { return; } if (string.IsNullOrEmpty(input)) { Logging.LogGenericErrorWithoutStacktrace(CGStrings.ErrorBotNameEmpty); return; } // Get rid of any potential whitespaces in bot name input = Regex.Replace(input, @"\s+", ""); configPage.ASFConfig.Rename(input); configPage.RefreshText(); } else if (args.TabPage == NewTab) { ConfigPage configPage = OldTab as ConfigPage; if (configPage == null) { MainTab.SelectedIndex = -1; return; } MainTab.SelectedTab = configPage; Tutorial.OnAction(Tutorial.EPhase.BotNickname); string input; if (DialogBox.InputBox(CGStrings.New, CGStrings.UserInputBotName, out input) != DialogResult.OK) { return; } if (string.IsNullOrEmpty(input)) { Logging.LogGenericErrorWithoutStacktrace(CGStrings.ErrorBotNameEmpty); return; } // Get rid of any potential whitespaces in bot name input = Regex.Replace(input, @"\s+", ""); if (string.IsNullOrEmpty(input)) { Logging.LogGenericErrorWithoutStacktrace(CGStrings.ErrorBotNameEmpty); return; } switch (input) { case SharedInfo.ASF: case "example": case "minimal": Logging.LogGenericErrorWithoutStacktrace(CGStrings.ErrorNameReserved); return; } if (ASFConfig.ASFConfigs.Select(config => Path.GetFileNameWithoutExtension(config.FilePath)).Any(fileNameWithoutExtension => (fileNameWithoutExtension == null) || fileNameWithoutExtension.Equals(input))) { Logging.LogGenericErrorWithoutStacktrace(CGStrings.ErrorNameAlreadyUsed); return; } input = Path.Combine(SharedInfo.ConfigDirectory, input + ".json"); ConfigPage newConfigPage = new ConfigPage(BotConfig.Load(input)); MainTab.TabPages.Insert(MainTab.TabPages.Count - ReservedTabs, newConfigPage); MainTab.SelectedTab = newConfigPage; Tutorial.OnAction(Tutorial.EPhase.BotNicknameFinished); } }
private void MainTab_Selected(object sender, TabControlEventArgs args) { if ((sender == null) || (args == null)) { Logging.LogNullError(nameof(sender) + " || " + nameof(args)); return; } if (args.TabPage == RemoveTab) { ConfigPage configPage = OldTab as ConfigPage; if (configPage == null) { MainTab.SelectedIndex = -1; return; } if (configPage == ASFTab) { MainTab.SelectedTab = ASFTab; Logging.LogGenericErrorWithoutStacktrace("You can't remove global config!"); return; } MainTab.SelectedTab = configPage; if (DialogBox.YesNoBox("Removal", "Do you really want to remove this config?") != DialogResult.Yes) { return; } MainTab.SelectedIndex = 0; configPage.ASFConfig.Remove(); MainTab.TabPages.Remove(configPage); } else if (args.TabPage == RenameTab) { ConfigPage configPage = OldTab as ConfigPage; if (configPage == null) { MainTab.SelectedIndex = -1; return; } if (configPage == ASFTab) { MainTab.SelectedTab = ASFTab; Logging.LogGenericErrorWithoutStacktrace("You can't rename global config!"); return; } MainTab.SelectedTab = configPage; string input; if (DialogBox.InputBox("Rename", "Your new bot name:", out input) != DialogResult.OK) { return; } if (string.IsNullOrEmpty(input)) { Logging.LogGenericErrorWithoutStacktrace("Your bot name is empty!"); return; } // Get rid of any potential whitespaces in bot name input = Regex.Replace(input, @"\s+", ""); configPage.ASFConfig.Rename(input); configPage.RefreshText(); } else if (args.TabPage == NewTab) { ConfigPage configPage = OldTab as ConfigPage; if (configPage == null) { MainTab.SelectedIndex = -1; return; } MainTab.SelectedTab = configPage; Tutorial.OnAction(Tutorial.EPhase.BotNickname); string input; if (DialogBox.InputBox("New", "Your new bot name:", out input) != DialogResult.OK) { return; } if (string.IsNullOrEmpty(input)) { Logging.LogGenericErrorWithoutStacktrace("Your bot name is empty!"); return; } // Get rid of any potential whitespaces in bot name input = Regex.Replace(input, @"\s+", ""); if (string.IsNullOrEmpty(input)) { Logging.LogGenericErrorWithoutStacktrace("Your bot name is empty!"); return; } switch (input) { case SharedInfo.ASF: case "example": case "minimal": Logging.LogGenericErrorWithoutStacktrace("This name is reserved!"); return; } if (ASFConfig.ASFConfigs.Select(config => Path.GetFileNameWithoutExtension(config.FilePath)).Any(fileNameWithoutExtension => (fileNameWithoutExtension == null) || fileNameWithoutExtension.Equals(input))) { Logging.LogGenericErrorWithoutStacktrace("Bot with such name exists already!"); return; } input = Path.Combine(SharedInfo.ConfigDirectory, input + ".json"); ConfigPage newConfigPage = new ConfigPage(BotConfig.Load(input)); MainTab.TabPages.Insert(MainTab.TabPages.Count - ReservedTabs, newConfigPage); MainTab.SelectedTab = newConfigPage; Tutorial.OnAction(Tutorial.EPhase.BotNicknameFinished); } else if (args.TabPage == ASFTab) { Tutorial.OnAction(Tutorial.EPhase.GlobalConfigOpened); } }
internal static GlobalConfig Load(string filePath) { if (string.IsNullOrEmpty(filePath)) { Logging.LogNullError(nameof(filePath)); return(null); } if (!File.Exists(filePath)) { return(new GlobalConfig(filePath)); } GlobalConfig globalConfig; try { globalConfig = JsonConvert.DeserializeObject <GlobalConfig>(File.ReadAllText(filePath)); } catch (Exception e) { Logging.LogGenericException(e); return(new GlobalConfig(filePath)); } if (globalConfig == null) { return(new GlobalConfig(filePath)); } globalConfig.FilePath = filePath; // SK2 supports only TCP and UDP steam protocols // Ensure that user can't screw this up switch (globalConfig.SteamProtocol) { case ProtocolType.Tcp: case ProtocolType.Udp: break; default: Logging.LogGenericWarning("Configured SteamProtocol is invalid: " + globalConfig.SteamProtocol + ". Value of " + DefaultSteamProtocol + " will be used instead"); globalConfig.SteamProtocol = DefaultSteamProtocol; break; } // User might not know what he's doing // Ensure that he can't screw core ASF variables if (globalConfig.MaxFarmingTime == 0) { Logging.LogGenericWarning("Configured MaxFarmingTime is invalid: " + globalConfig.MaxFarmingTime + ". Value of " + DefaultMaxFarmingTime + " will be used instead"); globalConfig.MaxFarmingTime = DefaultMaxFarmingTime; } if (globalConfig.FarmingDelay == 0) { Logging.LogGenericWarning("Configured FarmingDelay is invalid: " + globalConfig.FarmingDelay + ". Value of " + DefaultFarmingDelay + " will be used instead"); globalConfig.FarmingDelay = DefaultFarmingDelay; } if (globalConfig.HttpTimeout == 0) { Logging.LogGenericWarning("Configured HttpTimeout is invalid: " + globalConfig.HttpTimeout + ". Value of " + DefaultHttpTimeout + " will be used instead"); globalConfig.HttpTimeout = DefaultHttpTimeout; } if (globalConfig.WCFPort != 0) { return(globalConfig); } Logging.LogGenericWarning("Configured WCFPort is invalid: " + globalConfig.WCFPort + ". Value of " + DefaultWCFPort + " will be used instead"); globalConfig.WCFPort = DefaultWCFPort; return(globalConfig); }