private static TSettings deserialize <TSettings>(string filename, SettingsSerializer serializer) where TSettings : SettingsBase, new() { return(Ut.WaitSharingVio(maximum: TimeSpan.FromSeconds(5), func: () => { switch (serializer) { case SettingsSerializer.ClassifyXml: return ClassifyXml.DeserializeFile <TSettings>(filename); case SettingsSerializer.ClassifyJson: return ClassifyJson.DeserializeFile <TSettings>(filename); case SettingsSerializer.ClassifyBinary: return ClassifyBinary.DeserializeFile <TSettings>(filename); case SettingsSerializer.DotNetBinary: var bf = new BinaryFormatter(); using (var fs = File.Open(filename, FileMode.Open, FileAccess.Read, FileShare.Read)) return (TSettings)bf.Deserialize(fs); default: throw new InternalErrorException("6843184"); } })); }
/// <summary>See base.</summary> protected override bool getUser(ref string username, out string passwordHash, out bool canCreateUsers) { passwordHash = null; canCreateUsers = false; if (File.Exists(_usersPath)) { AuthUsers users; lock (_lock) users = ClassifyXml.DeserializeFile <AuthUsers>(_usersPath); var un = username; // ref parameter can’t be used in a lambda :( var user = users.Users.FirstOrDefault(u => u.Username == un); if (user == null) { return(false); } username = user.Username; passwordHash = user.PasswordHash; canCreateUsers = user.CanCreateUsers; return(true); } else { lock (_lock) ClassifyXml.SerializeToFile <AuthUsers>(new AuthUsers(), _usersPath); } return(false); }
public static GncFileWrapper LoadFromFile(string filename) { var wrapper = ClassifyXml.DeserializeFile <GncFileWrapper>(filename); wrapper.LoadedFromFile = filename; return(wrapper); }
/// <summary>Loads and returns the translation for the specified module and language. The translation must exist in the application /// executable directory under a subdirectory called "Translations". If the translation cannot be loaded successfully, an exception is thrown.</summary> /// <param name="translationType">The type of the translation class to load the translation into.</param> /// <param name="module">The name of the module whose translation to load.</param> /// <param name="language">The language code of the language to load.</param> /// <returns>The loaded translation.</returns> public static TranslationBase LoadTranslation(Type translationType, string module, Language language) { string path = Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), "Translations", module + "." + language.GetIsoLanguageCode() + ".xml"); var trans = (TranslationBase)ClassifyXml.DeserializeFile(translationType, path); trans.Language = language; return(trans); }
static int Main(string[] args) { if (args.Length == 2 && args[0] == "--post-build-check") { return(Ut.RunPostBuildChecks(args[1], Assembly.GetExecutingAssembly())); } var settingsFile = PathUtil.AppPathCombine("MySrvMon.xml"); if (!File.Exists(settingsFile)) { var sample = new Settings(); sample.Modules.Add(new SmartModule()); ClassifyXml.SerializeToFile(sample, settingsFile + ".sample"); Console.WriteLine("Sample settings file saved: " + settingsFile + ".sample"); Console.WriteLine("Edit and rename to " + settingsFile); return(1); } var settings = ClassifyXml.DeserializeFile <Settings>(settingsFile); ClassifyXml.SerializeToFile(settings, settingsFile + ".rewrite"); // for SMTP password encryption foreach (var module in settings.Modules) { module.Execute(); } foreach (var module in settings.Modules.OrderByDescending(m => m.Status)) { ConsoleColoredString report = "===========================\r\n" + "=== " + module.Name + "\r\n" + "===========================\r\n\r\n"; report = report.Color(module.Status.GetConsoleColor()); report += module.ConsoleReport + "\r\n"; ConsoleUtil.Write(report); } var worstStatus = settings.Modules.Max(v => v.Status); return((int)worstStatus); }
static void Main(string[] args) { Console.WriteLine($"Loading settings from {args[0]}..."); var settings = ClassifyXml.DeserializeFile <Settings>(args[0]); ClassifyXml.SerializeToFile(settings, args[0]); Console.Write("Loading static data..."); LeagueStaticData.Load(Path.Combine(settings.DataPath, "Static")); Console.WriteLine(" done"); Console.Write("Initialising global data..."); DataStore.Initialise(settings.DataPath, "", autoRewrites: false); Console.WriteLine(" done"); if (settings.ItemsOutputPath != null) { ItemSheet.Generate(settings.ItemsOutputPath); } if (settings.ItemSetsSettings != null && settings.LeagueInstallPath != null) { ItemSets.Generate(settings.DataPath, settings.LeagueInstallPath, settings.ItemSetsSettings); } if (settings.PersonalOutputPathTemplate != null) { PersonalStats.Generate(settings.DataPath, settings.PersonalOutputPathTemplate, settings.Humans); } if (settings.EventStatsSettings != null && settings.EventStatsSettings.OutputPath != null) { new EventStats(settings.EventStatsSettings).Generate(); } if (settings.SummonerRift5v5StatsSettings != null) { new SummonerRift5v5Stats(settings.SummonerRift5v5StatsSettings).Generate(); } }
/// <summary>See base.</summary> protected override bool changePassword(string username, string newPasswordHash, Func <string, bool> verifyOldPasswordHash) { lock (_lock) { AuthUsers users; try { users = ClassifyXml.DeserializeFile <AuthUsers>(_usersPath); } catch { users = null; } if (users == null) { users = new AuthUsers(); } var user = users.Users.FirstOrDefault(u => u.Username == username); if (user == null || (verifyOldPasswordHash != null && !verifyOldPasswordHash(user.PasswordHash))) { return(false); } user.PasswordHash = newPasswordHash; ClassifyXml.SerializeToFile <AuthUsers>(users, _usersPath); return(true); } }
/// <summary>See base.</summary> protected override bool createUser(string username, string passwordHash, bool canCreateUsers) { lock (_lock) { AuthUsers users; try { users = ClassifyXml.DeserializeFile <AuthUsers>(_usersPath); } catch { users = null; } if (users == null) { users = new AuthUsers(); } if (users.Users.Any(u => u.Username == username)) { return(false); } users.Users.Add(new AuthUser { Username = username, PasswordHash = passwordHash, CanCreateUsers = canCreateUsers }); ClassifyXml.SerializeToFile <AuthUsers>(users, _usersPath); return(true); } }