LogGenericException() static private method

static private LogGenericException ( Exception exception, [ previousMethodName = null ) : void
exception System.Exception
previousMethodName [
return void
Example #1
0
        internal static BotConfig Load(string filePath)
        {
            if (string.IsNullOrEmpty(filePath))
            {
                Logging.LogNullError(nameof(filePath));
                return(null);
            }

            if (!File.Exists(filePath))
            {
                return(new BotConfig(filePath));
            }

            BotConfig botConfig;

            try {
                botConfig = JsonConvert.DeserializeObject <BotConfig>(File.ReadAllText(filePath));
            } catch (Exception e) {
                Logging.LogGenericException(e);
                return(new BotConfig(filePath));
            }

            if (botConfig == null)
            {
                return(new BotConfig(filePath));
            }

            botConfig.FilePath = filePath;

            return(botConfig);
        }
Example #2
0
        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;
            globalConfig.ValidateAndFix();
            return(globalConfig);
        }
Example #3
0
        private static void UnobservedTaskExceptionHandler(object sender, UnobservedTaskExceptionEventArgs args)
        {
            if (sender == null || args == null)
            {
                return;
            }

            Logging.LogGenericException(args.Exception);
        }
Example #4
0
        private static void UnhandledExceptionHandler(object sender, UnhandledExceptionEventArgs args)
        {
            if (sender == null || args == null)
            {
                return;
            }

            Logging.LogGenericException((Exception)args.ExceptionObject);
        }
Example #5
0
        private static void UnobservedTaskExceptionHandler(object sender, UnobservedTaskExceptionEventArgs args)
        {
            if ((sender == null) || (args == null) || (args.Exception == null))
            {
                Logging.LogNullError(nameof(sender) + " || " + nameof(args) + " || " + nameof(args.Exception));
                return;
            }

            Logging.LogGenericException(args.Exception);
        }
Example #6
0
        private static void UnhandledExceptionHandler(object sender, UnhandledExceptionEventArgs args)
        {
            if ((sender == null) || (args == null) || (args.ExceptionObject == null))
            {
                Logging.LogNullError(nameof(sender) + " || " + nameof(args) + " || " + nameof(args.ExceptionObject));
                return;
            }

            Logging.LogGenericException((Exception)args.ExceptionObject);
        }
Example #7
0
 internal virtual void Save()
 {
     lock (FilePath) {
         try {
             File.WriteAllText(FilePath, JsonConvert.SerializeObject(this, Formatting.Indented));
         } catch (Exception e) {
             Logging.LogGenericException(e);
         }
     }
 }
Example #8
0
        internal virtual void Remove()
        {
            string queryPath = Path.GetFileNameWithoutExtension(FilePath);

            lock (FilePath) {
                foreach (string botFile in Directory.EnumerateFiles(Program.ConfigDirectory, queryPath + ".*"))
                {
                    try {
                        File.Delete(botFile);
                    } catch (Exception e) {
                        Logging.LogGenericException(e);
                    }
                }
            }
            ASFConfigs.Remove(this);
        }
Example #9
0
        internal virtual void Rename(string botName)
        {
            if (string.IsNullOrEmpty(botName))
            {
                return;
            }

            string queryPath = Path.GetFileNameWithoutExtension(FilePath);

            lock (FilePath) {
                foreach (string botFile in Directory.EnumerateFiles(Program.ConfigDirectory, queryPath + ".*"))
                {
                    try {
                        File.Move(botFile, Path.Combine(Program.ConfigDirectory, botName + Path.GetExtension(botFile)));
                    } catch (Exception e) {
                        Logging.LogGenericException(e);
                    }
                }
                FilePath = Path.Combine(Program.ConfigDirectory, botName + ".json");
            }
        }
Example #10
0
        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);
        }