LogGenericException() static private method

static private LogGenericException ( Exception exception, [ previousMethodName = null ) : void
exception System.Exception
previousMethodName [
return void
示例#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);
        }
示例#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);
        }
示例#3
0
        private static void UnobservedTaskExceptionHandler(object sender, UnobservedTaskExceptionEventArgs args)
        {
            if (sender == null || args == null)
            {
                return;
            }

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

            Logging.LogGenericException((Exception)args.ExceptionObject);
        }
示例#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);
        }
示例#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);
        }
示例#7
0
 internal virtual void Save()
 {
     lock (FilePath) {
         try {
             File.WriteAllText(FilePath, JsonConvert.SerializeObject(this, Formatting.Indented));
         } catch (Exception e) {
             Logging.LogGenericException(e);
         }
     }
 }
示例#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);
        }
示例#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");
            }
        }
示例#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);
        }