using System; using System.Collections.Generic; using TradeIdeas.TIProData; using TradeIdeas.TIProData.Configuration; using TradeIdeas.TIProData.Interfaces; namespace TradeIdeas.TIProGUI { /// /// This is a generic interface for a config window. This will allow us to make pluggable config windows. /// Different people might choose a different window, i.e. beginner, intermediate, advanced. Perhaps /// more important, this allows us to try out new things. /// /// This is also nice because of the number of different inputs to the config window. We had constructor /// with a list of optional arguments that kept getting longer and longer. And a few other ways of adding /// inputs. Now the inputs and outputs are more clear. /// abstract public class ConfigWindowWrapper { /// /// Output. After calling show it, use this to see the result. /// public PrepairedStrategy Strategy { get; protected set; } /// /// Output. /// True if the user hit the cancel button. /// False if is valid. /// public bool Canceled { get { return null == Strategy; } } /// /// Output. /// True if the user hit the cancel button. /// False if is not empty. /// public bool CanceledAIColumnConfig { get { return null == VisibleCustomColumns; } } /// /// Input. Should we display the list of columns or not. /// The compare count window is an example that uses this. /// public bool HideColumns { get; set; } /// /// Input. Should we show other pages. /// The multi-strategy window is an example that uses this. /// public bool OnlyShowColumns { get; set; } private readonly List _extraColumns = new List(); public List ExtraColumns { get { return _extraColumns; } } /// /// Normally we require the user to change something before hitting OK. /// Set this property to true to disable that feature. /// public bool AllowOkayImmediately { get; set; } /// /// Input. /// The caller can suggest that we sort by a specific column. /// This is useful when a user right clicks on a column and asks to sort. /// The default of null means not to do anything special. /// public String SortBy { get; set; } /// /// Input. /// The caller can suggest a certain filter of interest. /// This is useful when a user right clicks on a column. /// The default of null means not to do anything special. /// public String InitialFilter { get; set; } /// /// Input. /// The caller can specify a specific value for a min filter /// be changed. /// public double? SetMinFilter { get; set; } /// /// Input. /// The caller can specify a specific value for a max filter /// be changed. /// /// Input. This is actually set in the constructor because it's not optional and probably shouldn't change. /// public ConfigurationType ConfigurationType { get; private set; } /// /// Input. This is actually set in the constructor because it's not optional and probably shouldn't change. /// public IConnectionMaster ConnectionMaster { get; private set; } /// /// Input. /// This is a collaborate string. /// Start by modifying this configuration. /// If this is null, start from scratch. /// public string InitialConfig { get; set; } /// /// By default the config window might display something like "window name" to the user. /// If you set this property to true, the window will change to something like "strategy name". /// public bool NotAWindow { get; set; } /// /// Are we using TopList data to produce a toplist window, or a "Single Stock Window"? /// public bool IsSingleStock { get; set; } /// /// Are we using the default strategy for the given window? /// Used to customize config window. /// public bool IsDefaultStrategy { get; set; } /// /// Below bool for when using the "column in results" option in oddsmaker, and we're using an abbreviated version of config window /// public bool UsingOddsMaker { get; set; } /// /// This is part of the name sent to the server when the user does anything interesting. /// For example, set this to "Odds", and the server might receive messages like /// "ConfigWindow.Odds.StrategiesTab", when the user clicks on the strategies tab. /// The default value for this property is null. If you leave it null, the code will /// try to pick a good value based on other factors. /// public string UseCaseName { get; set; } public List MultiStrategies { get; set; } public Dictionary StrategyChanges { get; set; } //The below aids the determination the starting point for population of the singleStock window // it is set to either one or zero. In one case, the population begins on the right (right-left-right...etc) //whereas the other begins on the left (left-right-left...etc). How the user arranges his colums will //determine this value public int SingleStockWindowValue { get; set; } /// /// When using Custom Column chooser mode, use AllCustomColumns for all the columns available for choosing. /// public List AllCustomColumns { get; set; } /// /// When using Custom Column chooser mode, use VisibleCustomColumns for the list of columns that are currently visible. /// public List VisibleCustomColumns { get; set; } public int ColumnCount { get; internal set; } /// /// Each config window should create at least one of these. /// This is necessary for . /// But this can also allow us to chain config windows. For example, the development version /// of the config window might bring up a dynamically populated list of choices, each of which /// is one of these. /// /// Alert or Top List /// How to access the server. /// A new ConfigWindowWrapper. public delegate ConfigWindowWrapper Factory(ConfigurationType configurationType, IConnectionMaster connectionMaster); /// /// Set Race Config Mode to true when called from RTSR. /// In this mode, the "Select Base" tab is hidden. /// public bool RaceConfigMode { get; set; } /// /// If you just want to display a config window, you start by calling DefaultFactory(). /// //public static Factory DefaultFactory = TraditionalFactory; public static Factory DefaultFactory = TraditionalConfigWindowWrapper.Factory; abstract public void ShowIt(); /// /// Copy all of the fields that as marked as inputs. /// Leave the outputs in their default state. /// /// The new object is based on this one. protected ConfigWindowWrapper(ConfigWindowWrapper other) { HideColumns = other.HideColumns; OnlyShowColumns = other.OnlyShowColumns; _extraColumns.AddRange(other._extraColumns); AllowOkayImmediately = other.AllowOkayImmediately; SortBy = other.SortBy; InitialFilter = other.InitialFilter; ConfigurationType = other.ConfigurationType; ConnectionMaster = other.ConnectionMaster; InitialConfig = other.InitialConfig; NotAWindow = other.NotAWindow; UseCaseName = other.UseCaseName; IsSingleStock = other.IsSingleStock; UsingOddsMaker = other.UsingOddsMaker; ColumnCount = other.ColumnCount; } /// /// Keep all the defaults. /// The parameters are items with no reasonable default. /// /// Alert or Top List /// How to talk to the server. protected ConfigWindowWrapper(ConfigurationType configurationType, IConnectionMaster connectionMaster) { ConfigurationType = configurationType; ConnectionMaster = connectionMaster; } } /// /// This is a wrapper around the config window that we've had for a while. /// public class TraditionalConfigWindowWrapper : ConfigWindowWrapper { public TraditionalConfigWindowWrapper(ConfigurationType configurationType, IConnectionMaster connectionMaster) : base(configurationType, connectionMaster) { } public TraditionalConfigWindowWrapper(ConfigWindowWrapper other) : base(other) { } public static new ConfigWindowWrapper Factory(ConfigurationType configurationType, IConnectionMaster connectionMaster) { return new TraditionalConfigWindowWrapper(configurationType, connectionMaster); } public override void ShowIt() { using (ConfigWindow configWindow = new ConfigWindow(ConfigurationType, ConnectionMaster, InitialConfig, columnChooserMode: OnlyShowColumns, fromScratch: AllowOkayImmediately, dontShowColumns: HideColumns, extraColumns: ExtraColumns.AsReadOnly(), useCaseName: UseCaseName, notAWindow: NotAWindow, multiStrategies: MultiStrategies, isSingleStock: IsSingleStock, usingOddsMaker: UsingOddsMaker, setMinFilter: SetMinFilter, setMaxFilter: SetMaxFilter, allCustomColumns: AllCustomColumns, allVisibleCustomColumns: VisibleCustomColumns, columnCount:ColumnCount)) { if (null != SortBy) configWindow.serverSortFromOutside(SortBy); if (null != InitialFilter) { configWindow.configFromOutside(InitialFilter, SetMinFilter, SetMaxFilter); } if(ConfigurationType == TIProData.Configuration.ConfigurationType.CustomColumns) { configWindow.ShowDialog(); if (configWindow.DialogResult == System.Windows.Forms.DialogResult.OK) VisibleCustomColumns = configWindow.GetVisibleCustomColumns(); else VisibleCustomColumns = null; } else { configWindow.setListStart(SingleStockWindowValue); configWindow.showWaitPanel(); configWindow.ShowDialog(); if (configWindow.DialogResult == System.Windows.Forms.DialogResult.OK) { Strategy = configWindow.Strategy; StrategyChanges = configWindow.StrategyChanges; SingleStockWindowValue = configWindow.getListStart(); } else { Strategy = null; } } } } } }