Example #1
0
        /// <summary>
        /// set up predefined test scenarios' buttons
        /// </summary>
        private void SetupPresets()
        {
            var defSets = TradersSettings.ReadSettings();

            SettingsPreset.Presets = new SettingsPreset[]
            {
                new TakerPoolPreset(defSets),
                new MakerTakerEven(defSets),
                new SimpleFadeInPreset(defSets),
                new OneShotPreset(defSets),
                new SinusoidalPreset(defSets),
                new SlowLoadGrowthPreset(defSets),
                new StairsPreset(defSets),
                new StairsDownPreset(defSets)
            };

            presetButtons = new List <Button>
            {
                btnPreset01, btnPreset02, btnPreset03, btnPreset04, btnPreset05, btnPreset06, btnPreset07, btnPreset08
            };

            for (var i = 0; i < presetButtons.Count; i++)
            {
                var preset = SettingsPreset.Presets[i];
                presetButtons[i].Tag        = i;
                presetButtons[i].ImageIndex = preset.ImageIndex;
                toolTip.SetToolTip(presetButtons[i], preset.Description);

                // setup and run the test on the button's click
                presetButtons[i].Click += (sender, args) =>
                {
                    if (pool != null)
                    {
                        return;
                    }
                    var presetIndex = (int)((Button)sender).Tag;
                    var dlg         = new PresetDialog(SettingsPreset.GetPresetByIndex(presetIndex));
                    if (dlg.ShowDialog() != DialogResult.OK)
                    {
                        return;
                    }
                    StartTest();
                };
            }

            toolTip.SetToolTip(btnStop, "Stop the test");
            toolTip.SetToolTip(btnManTest, "Manually set up and start a test");
        }
Example #2
0
        private void OnSavePreset(object sender, RoutedEventArgs e)
        {
            // check methodListBox is empty?
            if (methodListBox.Items.Count == 0)
            {
                MessageBox.Show("Nothing to save. ");
                return;
            }
            // there are something to save

            var presetScreen = new PresetDialog();

            if (presetScreen.ShowDialog() == true)
            {
                string presetName = presetScreen.presetName;


                // any preset file opened before ?
                if (currentPresetFile != "")
                {
                    using (StreamWriter sw = File.AppendText(currentPresetFile)) {
                        sw.WriteLine(presetName);

                        foreach (StringAction action in methodListBox.Items)
                        {
                            string methodTemplate = $"{action.Name}/{action.Args.ParseArgs()}";
                            sw.WriteLine(methodTemplate);
                        }

                        sw.WriteLine("**");
                    }
                    MessageBox.Show($"Saved. Please check preset file in {currentPresetFile}");
                }
                else
                {
                    // default preset path is : C:/BatchRename/preset.txt
                    string presetFolderPath = @"C:\BatchRename";
                    string presetFilePath   = @"C:\BatchRename\preset.txt";

                    if (!Directory.Exists(presetFolderPath))
                    {
                        Directory.CreateDirectory(presetFolderPath);
                    }
                    // if folder exist
                    if (!File.Exists(presetFilePath))
                    {
                        using (StreamWriter sw = File.CreateText(presetFilePath)) {
                            sw.WriteLine(presetName);

                            foreach (StringAction action in methodListBox.Items)
                            {
                                string methodTemplate = $"{action.Name}/{action.Args.ParseArgs()}";
                                sw.WriteLine(methodTemplate);
                            }
                            sw.WriteLine("**");
                        }
                        MessageBox.Show($"Saved. Please check preset file in {presetFilePath}");
                    }
                    else
                    // append file
                    {
                        using (StreamWriter sw = File.AppendText(presetFilePath)) {
                            sw.WriteLine(presetName);

                            foreach (StringAction action in methodListBox.Items)
                            {
                                string methodTemplate = $"{action.Name}/{action.Args.ParseArgs()}";
                                sw.WriteLine(methodTemplate);
                            }

                            sw.WriteLine("**");
                        }
                        MessageBox.Show($"Saved. Please check preset file in {presetFilePath}");
                    }
                }
            }
        }