public void FileNameTest() { string filename = Path.GetFullPath(myConfigTestFile); bool fileExists = File.Exists(filename); Assert.IsTrue(fileExists); bool loaded = configFile.Load(filename); Assert.IsTrue(loaded); Assert.AreEqual(filename, configFile.FileName); }
public void DoubleLoadMachineConfigTest() { ConfigurationFile machineConfig = new ConfigurationFile(); machineConfig.Load(ConfigurationBuilder.MachineConfigurationFile); ConfigurationFile machineConfig2 = new ConfigurationFile(machineConfig); machineConfig2.Load(ConfigurationBuilder.MachineConfigurationFile); }
private async void Application_Startup(object sender, StartupEventArgs e) { if (e.Args.Length < 1) { return; } var fileName = e.Args[0]; if (File.Exists(fileName)) { try { var config = ConfigurationFile.Load(fileName); await Generator.GenerateAsync(config); Console.WriteLine("出力成功"); Shutdown(); } catch (SerializationException) { Console.WriteLine("指定されたファイルは設定ファイルではないか、壊れています。"); } catch (FileNotFoundException err) { Console.WriteLine(err.Message); } } }
private void OnBeforeArgumentsSet() { if (ConfigurationFile.Load() is Configuration configuration) { configuration.Override(this); } }
static async Task <int> Main(string[] args) { if (Parser.TryParse(args, out CliOptions options)) { try { var configuration = ConfigurationFile.Load(options.ConfigurationFile); ServicesContainer.Configure(x => ServicesConfiguration.Configure(x, options, configuration)); if (string.IsNullOrEmpty(options.CheckNow)) { using (var cancellationSource = ServicesContainer.Provider.GetRequiredService <GlobalCancellationToken>().Source) { var monitor = ServicesContainer.Provider.GetRequiredService <ScheduledMonitoringService>(); monitor.Start(); Console.WriteLine($"Press [CTRL+C] to exit..."); var exitEvent = new ManualResetEventSlim(false); Console.CancelKeyPress += (s, e) => { e.Cancel = true; exitEvent.Set(); }; exitEvent.Wait(cancellationSource.Token); if (!cancellationSource.IsCancellationRequested) { cancellationSource.Cancel(); } monitor.Stop(); } } else { var job = new MonitoringJob(); await job.Execute(options.CheckNow); } return(0); } catch (Exception e) { Parser.DisplayHelp <CliOptions>(); Console.WriteLine(); Console.WriteLine($"[Error: {e.Message}]"); return(e.GetType().GetHashCode()); } } else { return(1); } }
public void MakeSureWhidbeyCofigurationFileCanBeRead() { string machineConfig = Path.GetFullPath("WhidbeyMachine.config"); string fileName = Path.GetFullPath("Whidbey.config"); ConfigurationFile machineFile = new ConfigurationFile(); machineFile.Load(machineConfig); ConfigurationFile file = new ConfigurationFile(machineFile); file.Load(fileName); }
public void OpenConfigFileWithoutPermissions() { FileIOPermission denyPermission = new FileIOPermission(FileIOPermissionAccess.Read, Path.GetFullPath(myConfigTestFile)); PermissionSet permissions = new PermissionSet(PermissionState.None); permissions.AddPermission(denyPermission); permissions.Deny(); ConfigurationFile configFile = new ConfigurationFile(); configFile.Load(Path.GetFullPath(myConfigTestFile)); }
public void ConfigurationFile_Deserialization_Succeeds() { var g = InitializeNameGenerator(); ConfigurationFile.Save(g, "test.txt"); var g2 = ConfigurationFile.Load("test.txt"); Assert.IsNotNull(g2); Assert.IsTrue(g != g2); // Compare the deserialized instance with pre-deserialized instance Assert.IsTrue(g.MaximumRetries == g2.MaximumRetries); Assert.IsTrue(g.MaximumSyllables == g2.MaximumSyllables); Assert.IsTrue(g.MinimumSyllables == g2.MinimumSyllables); Assert.IsTrue(g.MutationProbability == g2.MutationProbability); Assert.AreEqual(g.Mutator.MutationLimit, g2.Mutator.MutationLimit); var p1 = g.Provider; var p2 = g2.Provider; // Components of a syllable Assert.IsTrue(p1.LeadingConsonants.UnorderedListEquals(p2.LeadingConsonants)); Assert.IsTrue(p1.LeadingConsonantSequences.UnorderedListEquals(p2.LeadingConsonantSequences)); Assert.IsTrue(p1.Vowels.UnorderedListEquals(p2.Vowels)); Assert.IsTrue(p1.VowelSequences.UnorderedListEquals(p2.VowelSequences)); Assert.IsTrue(p1.TrailingConsonants.UnorderedListEquals(p2.TrailingConsonants)); Assert.IsTrue(p1.TrailingConsonantSequences.UnorderedListEquals(p2.TrailingConsonantSequences)); // Usage flags Assert.IsTrue(p1.UseLeadingConsonants == p2.UseLeadingConsonants); Assert.IsTrue(p1.UseLeadingConsonantSequences == p2.UseLeadingConsonantSequences); Assert.IsTrue(p1.UseStartingSyllableLeadingVowels == p2.UseStartingSyllableLeadingVowels); Assert.IsTrue(p1.UseVowelSequences == p2.UseVowelSequences); Assert.IsTrue(p1.UseTrailingConsonants == p2.UseTrailingConsonants); Assert.IsTrue(p1.UseTrailingConsonantSequences == p2.UseTrailingConsonantSequences); // Probability of a component showing up in a syllable Assert.IsTrue(p1.ChanceConsonantBeginsSyllable == p2.ChanceConsonantBeginsSyllable); Assert.IsTrue(p1.ChanceConsonantBeginsSyllableAndIsSequence == p2.ChanceConsonantBeginsSyllableAndIsSequence); Assert.IsTrue(p1.ChanceVowelIsSequence == p2.ChanceVowelIsSequence); Assert.IsTrue(p1.ChanceVowelBeginsStartingSyllable == p2.ChanceVowelBeginsStartingSyllable); Assert.IsTrue(p1.ChanceVowelBeginsStartingSyllableAndIsSequence == p2.ChanceVowelBeginsStartingSyllableAndIsSequence); Assert.IsTrue(p1.ChanceConsonantEndsSyllable == p2.ChanceConsonantEndsSyllable); Assert.IsTrue(p1.ChanceConsonantEndsSyllableAndIsSequence == p2.ChanceConsonantEndsSyllableAndIsSequence); // Invalid regular expressions Assert.IsNotNull(g.Validator); Assert.IsNotNull(g.Validator.InvalidPatterns); Assert.IsNotNull(g2.Validator); Assert.IsNotNull(g2.Validator.InvalidPatterns); Assert.IsTrue(g.Validator.InvalidPatterns.UnorderedListEquals(g2.Validator.InvalidPatterns)); }
private void DemoForm_Load(object sender, EventArgs e) { if (File.Exists(Settings.Default.PluginConfigFile)) { AppContext.ConfigurationFile = ConfigurationFile.Load(Settings.Default.PluginConfigFile); LoadPlugins((from x in AppContext.ConfigurationFile.Startup.Plugins select x.AssemblyPath).ToList()); } else { AppContext.ConfigurationFile = new ConfigurationFile(); AppContext.ConfigurationFile.Save(Settings.Default.PluginConfigFile); } }
public void RemoveSectionFromConfigurationFile() { ConfigurationFile file = new ConfigurationFile(); file.Load(Path.GetFullPath(removeConfigTestFile)); file.RemoveSection(ConfigurationSettings.SectionName); XmlDocument doc = new XmlDocument(); doc.Load(file.FileName); XmlNode configSections = doc.DocumentElement.SelectSingleNode("//configuration/configSections"); Assert.IsNotNull(configSections); XmlNode section = configSections.SelectSingleNode(string.Concat("//section[@name='", ConfigurationSettings.SectionName, "']")); Assert.IsNull(section); XmlNode sectionInformationNode = doc.DocumentElement.SelectSingleNode(string.Concat("//entlib:", ConfigurationSettings.SectionName), ConfigurationFile.GetNamespaceManager(doc)); Assert.IsNull(sectionInformationNode); }
private void LoadConfiguration(object obj) { var dialog = new OpenFileDialog() { Filter = "Aceフォント設定ファイル|*.afcfg", }; if (dialog.ShowDialog() == DialogResult.OK) { try { Config = ConfigurationFile.Load(dialog.FileName); } catch (SerializationException) { MessageBox.Show("選択されたファイルは設定ファイルではないか、壊れています。", "ロード中止", MessageBoxButtons.OK); } } }
protected override void OnStart(string[] args) { try { //Instantiate the configuration implementation to be used _configuration = ConfigurationFile.Load(); //Instantiate the repository implementation to be used _repository = MsSqlRepository.Load("MsSql"); //TODO: Implement dependency injection //Instantiate and start the controller _controller = new UsageSyncController(); _controller.Start(_configuration, _repository); } catch (Exception ex) { _log.Fatal("Error starting service.", ex); } }
public static GatewayConfiguration SetupConfig(Environment env) { var configFile = Path.Combine(env.Config, "gateway.yaml"); if (!File.Exists(configFile)) { if (!Directory.Exists("./config")) { Directory.CreateDirectory("./config"); } File.Copy("./Resources/Default.yaml", configFile); } var wellKnown = Path.Combine(env.Data, ".well-known"); if (!Directory.Exists(wellKnown)) { Directory.CreateDirectory(wellKnown); } return(ConfigurationFile.Load(configFile)); }
public void Render() { var tool = asd.Engine.Tool; if (asd.Engine.Tool.BeginFullscreen("FontGenerator", 0)) { var fontType = new[] { selectedFont }; if (tool.BeginCombo("フォントの種類", fontPairs[selectedFont].Name)) { for (int i = 0; i < fontPairs.Count; i++) { if (tool.Selectable(fontPairs[i].Name, i == selectedFont)) { selectedFont = i; viewModel.FontName.Value = fontPairs[i].Name; viewModel.FontIndex.Value = i; tool.SetItemDefaultFocus(); break; } } tool.EndCombo(); } tool.InputText("文字一覧ファイル", viewModel.TextPath); if (tool.Button("ファイルを開く...")) { var defaultPath = File.Exists(viewModel.TextPath.String) ? Path.GetDirectoryName(viewModel.TextPath.String) : Directory.GetCurrentDirectory(); viewModel.TextPath.String = tool.OpenDialog("txt", defaultPath); } tool.InputText("出力先ディレクトリ", viewModel.ExportPath); if (tool.Button("ディレクトリを開く...")) { var defaultPath = Directory.Exists(viewModel.ExportPath.String) ? viewModel.ExportPath.String : Directory.GetCurrentDirectory(); viewModel.ExportPath.String = tool.PickFolder(defaultPath); } tool.InputText("シート名", viewModel.SheetName); tool.InputInt("フォントサイズ", viewModel.FontSize); tool.InputInt("テクスチャサイズ", viewModel.TextureSize); tool.InputInt("輪郭線の太さ", viewModel.OutlineSize); tool.InputColor("フォント色", viewModel.FontColor); tool.InputColor("輪郭線の色", viewModel.OutlineColor); if (preview != null) { tool.Image(preview, preview.Size.To2DF()); } if (tool.Button("設定ロード...")) { var path = tool.OpenDialog("afcfg", Directory.GetCurrentDirectory()); if (!string.IsNullOrWhiteSpace(path)) { converter.LoadFromModel(ConfigurationFile.Load(path), viewModel); selectedFont = fontPairs.IndexOf(fontPairs.Find(x => x.Name == viewModel.FontName.Value)); } } if (tool.Button("設定セーブ...")) { var path = tool.SaveDialog("afcfg", Directory.GetCurrentDirectory()); if (!string.IsNullOrWhiteSpace(path)) { if (path.EndsWith(".afcfg")) { path += ".afcfg"; } ConfigurationFile.Save(converter.ConvertToModel(viewModel), path); } } if (!isGenerating && tool.Button("aff生成")) { isGenerating = true; statusText = "生成中..."; var task = Generator.GenerateAsync(converter.ConvertToModel(viewModel)); task.ContinueWith(x => { isGenerating = false; statusText = "生成完了"; }, TaskContinuationOptions.OnlyOnRanToCompletion); task.ContinueWith(x => { isGenerating = false; if (x.Exception is AggregateException) { statusText = "生成失敗:" + x.Exception.InnerException.Message; } else { statusText = "生成失敗:" + x.Exception.Message; } Console.WriteLine(x.Exception); }, TaskContinuationOptions.OnlyOnFaulted); } tool.Text(statusText); tool.End(); if (isReloadRequired) { var src = asd.Engine.Graphics.CreateEditableTexture2D(previewPath); if (src != null) { var canvas = asd.Engine.Graphics.CreateEmptyTexture2D(320, 100, asd.TextureFormat.R8G8B8A8_UNORM_SRGB); Render(canvas, src); preview = canvas; } else { preview = null; } asd.Engine.Reload(); isReloadRequired = false; } } }
public static void InitializeProgramOptions() => Program.Configuration = ConfigurationFile.Load(Program.EXEPath + Path.DirectorySeparatorChar + "configuration.json");
public static void Main(string[] args) { { // Quickest way to use Syllabore's name generator // without specifying any configuration. This instance // will default to using StandaloneSyllableProvider for // name generator and will not use any NameValidator to // improve output. var g = new NameGenerator(); for (int i = 0; i < 10; i++) { Console.WriteLine(g.Next()); } } { // Normally the constructor takes a SyllableProvider // and NameValidator. There are "Standalone" classes // available for quick and dirty use. It is recommended // you create your own by using ISyllableProvider/INameValidator // or inheriting from ConfigurableSyllableProvider/ConfigurableNameValidator. var provider = new DefaultSyllableProvider(); var validator = new NameValidator() .DoNotAllowPattern(@"[j|p|q|w]$") // Invalidate these awkward endings .DoNotAllowPattern(@"(\w)\1\1") // Invalidate any sequence of 3 or more identical letters .DoNotAllowPattern(@"([^aeiouAEIOU])\1\1\1"); // Invalidate any sequence of 4 or more consonants var g = new NameGenerator(provider, validator); for (int i = 0; i < 10; i++) { Console.WriteLine(g.Next()); } } { // You can choose to build name generators programmatically. var g = new NameGenerator() .UsingProvider(x => x .WithLeadingConsonants("str") .WithVowels("ae")) .LimitSyllableCount(3); for (int i = 0; i < 10; i++) { Console.WriteLine(g.Next()); } Console.WriteLine(); } { // Creating variations of a single name var g = new NameGenerator().UsingMutator(new VowelMutator()); for (int i = 0; i < 3; i++) { var name = g.NextName(); Console.WriteLine(name); for (int j = 0; j < 4; j++) { var variation = g.Mutate(name); Console.WriteLine(variation); } } } { Console.WriteLine(); var g = new NameGenerator() .UsingProvider(p => p .WithVowels("aeoy") .WithLeadingConsonants("vstlr") .WithTrailingConsonants("zrt") .WithVowelSequences("ey", "ay", "oy")) .UsingMutator(m => m .WithMutation(x => x.ReplaceSyllable(0, "Gran")) .WithMutation(x => x.ReplaceSyllable(0, "Bri")) .WithMutation(x => x.InsertSyllable(0, "Deu").AppendSyllable("gard").WithWeight(2)) .WithMutation(x => x.When(-2, "[aeoyAEOY]$").ReplaceSyllable(-1, "opolis")) .WithMutation(x => x.When(-2, "[^aeoyAEOY]$").ReplaceSyllable(-1, "polis")) .WithMutationCount(1)) .UsingValidator(v => v .DoNotAllowPattern( @".{12,}", @"(\w)\1\1", // Prevents any letter from occuring three times in a row @".*([y|Y]).*([y|Y]).*", // Prevents double y @".*([z|Z]).*([z|Z]).*", // Prevents double z @"(zs)", // Prevents "zs" @"(y[v|t])")) // Prevents "yv" and "yt" .LimitMutationChance(0.99) .LimitSyllableCount(2, 4); ConfigurationFile.Save(g, "city-name-generator.txt"); var g2 = ConfigurationFile.Load("city-name-generator.txt"); for (int i = 0; i < 50; i++) { var name = g.NextName(); Console.WriteLine(name); } Console.WriteLine(); } { var provider = new SyllableProvider(); provider.WithVowels("a", "e", "o", "y"); provider.WithLeadingConsonants("v", "s", "t", "l", "r"); provider.WithTrailingConsonants("z", "r", "t"); provider.WithVowelSequences("ey", "ay", "oy"); provider.DisallowLeadingConsonantSequences(); provider.DisallowTrailingConsonantSequences(); var shifter = new VowelMutator("a", "e", "o", "y"); var validator = new NameValidator(); validator.DoNotAllowPattern(@"(\w)\1\1"); validator.DoNotAllowPattern(@"([^aeoyAEOY])\1"); validator.DoNotAllowPattern(@".*([y|Y]).*([y|Y]).*"); validator.DoNotAllowPattern(@".*([z|Z]).*([z|Z]).*"); validator.DoNotAllowPattern(@"(zs)"); validator.DoNotAllowPattern(@"(y[v|t])"); var g = new NameGenerator(provider, shifter, validator); g.LimitSyllableCount(2, 3); } { var name = new Name("syl", "la", "bore"); var mutator = new NameMutator() .Join(new DefaultNameMutator()) .Join(new VowelMutator()); for (int i = 0; i < 20; i++) { Console.WriteLine(mutator.Mutate(name)); } } }
static void Main(string[] args) { try { //Prompt for the type of controller to start ConsoleAction actionToPerform = ConsoleAction.None; do { Console.WriteLine("Select controller to start. Press <Esc> to exit:"); Console.WriteLine(); Console.WriteLine("1) Library Sync Controller"); Console.WriteLine("2) Usage Sync Controller"); Console.WriteLine(); ConsoleKeyInfo userInput = Console.ReadKey(true); switch (userInput.Key) { case ConsoleKey.D1: case ConsoleKey.NumPad1: { actionToPerform = ConsoleAction.StartLibraryController; break; } case ConsoleKey.D2: case ConsoleKey.NumPad2: { actionToPerform = ConsoleAction.StartUsageController; break; } case ConsoleKey.Escape: { actionToPerform = ConsoleAction.Exit; break; } default: { //Clear the console. We'll prompt the user again. Console.Clear(); break; } } }while (actionToPerform == ConsoleAction.None); //Create the configuration implementation to be used for the synchronization. IControllerConfiguration config = ConfigurationFile.Load(); //Create the repository implementation to be used for the synchronization. ILibraryRepository repository = MsSqlRepository.Load("MsSql"); BaseController controller = null; switch (actionToPerform) { case ConsoleAction.Exit: { Console.WriteLine("Exiting application..."); return; } case ConsoleAction.StartLibraryController: { Console.WriteLine("Starting library sync controller..."); controller = new LibrarySyncController <ImageFileRepository>(); break; } case ConsoleAction.StartUsageController: { Console.WriteLine("Starting usage sync controller..."); controller = new UsageSyncController(); break; } } //Start the controller controller.Start(config, repository); //Wait for the user to stop the controller. Console.WriteLine("Controller started. Press any key to stop and exit."); Console.ReadKey(); Console.WriteLine("Stopping controller..."); //Kill it controller.Stop(); } catch (Exception ex) { Console.WriteLine("**ERROR** - {0}", ex); Console.ReadKey(); } }