コード例 #1
0
        /// <summary>
        ///     Pastes a strategy from clipboard.
        /// </summary>
        protected override void MenuStrategyPasteOnClick(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);
            }
            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.Error);
                return;
            }
            catch (Exception exception)
            {
                MessageBox.Show(exception.Message);
                return;
            }

            Data.Strategy     = tempStrategy;
            Data.StrategyName = tempStrategy.StrategyName;

            Data.SetStrategyIndicators();
            RebuildStrategyLayout();

            Text = Data.Strategy.StrategyName + " - " + Data.ProgramName;
            Data.IsStrategyChanged   = false;
            Data.LoadedSavedStrategy = Data.StrategyPath;
            Data.StackStrategy.Clear();

            AfterStrategyOpening(false);
            Calculate(false);
        }
コード例 #2
0
        /// <summary>
        ///     Loads the strategy from a file in XML format.
        /// </summary>
        public static bool Load(string filename)
        {
            var xmlDocStrategy = new XmlDocument();

            try
            {
                xmlDocStrategy.Load(filename);
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message, Language.T("Strategy Loading"));

                return(false);
            }

            var strategyXML = new StrategyXML();


            try
            {
                Data.Strategy = strategyXML.ParseXmlStrategy(xmlDocStrategy);
            }
            catch (MissingIndicatorException exception)
            {
                string message = string.Format(
                    "Cannot load \"{2}\" strategy. {1} {0} {1} Please find this indicator in Repository or in Custom Indicators forum.",
                    exception.Message, Environment.NewLine, Path.GetFileNameWithoutExtension(filename));
                MessageBox.Show(message, "Load strategy", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(false);
            }
            catch (Exception exception)
            {
                MessageBox.Show(exception.Message);
                return(false);
            }


            return(true);
        }
コード例 #3
0
        /// <summary>
        ///     Pastes a strategy from clipboard.
        /// </summary>
        protected override void MenuStrategyPasteOnClick(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);
            }
            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.Error);
                return;
            }
            catch (Exception exception)
            {
                MessageBox.Show(exception.Message);
                return;
            }

            Data.Strategy = tempStrategy;
            Data.StrategyName = tempStrategy.StrategyName;

            Data.SetStrategyIndicators();
            RebuildStrategyLayout();

            Text = Data.Strategy.StrategyName + " - " + Data.ProgramName;
            Data.IsStrategyChanged = false;
            Data.LoadedSavedStrategy = Data.StrategyPath;
            Data.StackStrategy.Clear();

            AfterStrategyOpening(false);
            Calculate(false);
        }
コード例 #4
0
        /// <summary>
        ///     Loads the strategy from a file in XML format.
        /// </summary>
        public static bool Load(string filename)
        {
            var xmlDocStrategy = new XmlDocument();

            try
            {
                xmlDocStrategy.Load(filename);
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message, Language.T("Strategy Loading"));

                return false;
            }

            var strategyXML = new StrategyXML();


            try
            {
                Data.Strategy = strategyXML.ParseXmlStrategy(xmlDocStrategy);
            }
            catch (MissingIndicatorException exception)
            {
                string message = string.Format(
                    "Cannot load \"{2}\" strategy. {1} {0} {1} Please find this indicator in Repository or in Custom Indicators forum.",
                    exception.Message, Environment.NewLine, Path.GetFileNameWithoutExtension(filename));
                MessageBox.Show(message, "Load strategy", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return false;
            }
            catch (Exception exception)
            {
                MessageBox.Show(exception.Message);
                return false;
            }


            return true;
        }