/// <summary> /// Pastes a strategy from clipboard. /// </summary> protected override void MenuStrategyPaste_OnClick(object sender, EventArgs e) { DialogResult dialogResult = WhetherSaveChangedStrategy(); if (dialogResult == DialogResult.Yes) { SaveStrategy(); } else if (dialogResult == DialogResult.Cancel) { return; } var xmlDoc = new XmlDocument(); var strategyXml = new StrategyXml(); Strategy tempStrategy; try { xmlDoc.InnerXml = Clipboard.GetText(); tempStrategy = strategyXml.ParseXmlStrategy(xmlDoc); Strategy.CheckStrategyCompatibility(tempStrategy); } catch (MissingIndicatorException exception) { string message = string.Format( "{2}{1}{0}{1}Please find this indicator in Repository or in Custom Indicators forum.", exception.Message, Environment.NewLine, "Cannot load the strategy."); MessageBox.Show(message, "Load strategy", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } catch (Exception exception) { MessageBox.Show(exception.Message); return; } OnStrategyChange(); Data.Strategy = tempStrategy; Data.StrategyName = tempStrategy.StrategyName; Data.Strategy.StrategyName = tempStrategy.StrategyName; Data.SetStrategyIndicators(); RebuildStrategyLayout(); SetSrategyOverview(); SetFormText(); Data.IsStrategyChanged = false; Data.LoadedSavedStrategy = Data.StrategyPath; Data.StackStrategy.Clear(); CalculateStrategy(true); AfterStrategyOpening(); }
/// <summary> /// View / edit the strategy description. /// </summary> private void BtnStrategyDescriptionClick(object sender, EventArgs e) { string oldInfo = Data.Strategy.Description; var si = new StrategyDescription(); si.ShowDialog(); if (oldInfo == Data.Strategy.Description) { return; } Data.SetStrategyIndicators(); SetSrategyOverview(); Data.IsStrategyChanged = true; }
/// <summary> /// View / edit the strategy description /// </summary> private void BtnStrategyDescriptionClick(object sender, EventArgs e) { string oldInfo = Data.Strategy.Description; var si = new StrategyDescription(); si.ShowDialog(); if (oldInfo == Data.Strategy.Description) { return; } Data.SetStrategyIndicators(); SetStrategyDescriptionButton(); Text = Path.GetFileNameWithoutExtension(Data.StrategyName) + "* - " + Data.ProgramName; Data.IsStrategyChanged = true; }
/// <summary> /// Reads the strategy from a file. /// </summary> /// <param name="strategyName">The strategy name.</param> /// <returns>0 - success.</returns> private int OpenStrategy(string strategyName) { try { if (File.Exists(strategyName) && Strategy.Load(strategyName)) { // Successfully opened Data.Strategy.StrategyName = Path.GetFileNameWithoutExtension(strategyName); Data.StrategyDir = Path.GetDirectoryName(strategyName); Data.StrategyName = Path.GetFileName(strategyName); } else { Strategy.GenerateNew(); string sMessageText = Language.T("The strategy could not be loaded correctly!") + Environment.NewLine + Language.T("A new strategy has been generated!"); MessageBox.Show(sMessageText, Language.T("Strategy Loading"), MessageBoxButtons.OK, MessageBoxIcon.Exclamation); Data.LoadedSavedStrategy = ""; } Data.SetStrategyIndicators(); RebuildStrategyLayout(); SetSrategyOverview(); SetFormText(); Data.IsStrategyChanged = false; Data.LoadedSavedStrategy = Data.StrategyPath; Data.StackStrategy.Clear(); } catch { Strategy.GenerateNew(); string sMessageText = Language.T("The strategy could not be loaded correctly!") + Environment.NewLine + Language.T("A new strategy has been generated!"); MessageBox.Show(sMessageText, Language.T("Strategy Loading"), MessageBoxButtons.OK, MessageBoxIcon.Exclamation); Data.LoadedSavedStrategy = ""; SetFormText(); RebuildStrategyLayout(); return(1); } return(0); }