示例#1
0
        /// <summary>
        /// set fields to config from xml
        /// </summary>
        void ConfigLoad(string path, string file)
        {
            // load config from xml
            ConfigXml22 xml = new ConfigXml22(path, file);

            xml.Load();

            // set fields to xml values
            configBearContValue = xml.BearContValue;
            configBearInitType  = xml.BearInitType;
            configBearInitValue = xml.BearInitValue;
            configBearRangeMax  = xml.BearRangeMax;
            configBearRangeMin  = xml.BearRangeMin;
            configBullContValue = xml.BullContValue;
            configBullInitType  = xml.BullInitType;
            configBullInitValue = xml.BullInitValue;
            configBullRangeMax  = xml.BullRangeMax;
            configBullRangeMin  = xml.BullRangeMin;
            configCloseOption   = (EmCloses)Enum.Parse(typeof(EmCloses), xml.CloseOption);
            configOpenOption    = (EmOpens)Enum.Parse(typeof(EmOpens), xml.OpenOption);

            // calculate bear/bull min/max
            RangeInit();

            // update configLoaded
            configLoaded = true;
        }
示例#2
0
        /// <summary>
        /// get config from xml
        /// </summary>
        void XmlLoad()
        {
            // initialize objects
            XmlSerializer xs;
            FileStream    fs = null;

            // load from file
            try
            {
                // set namespace
                XmlSerializerNamespaces ns = new XmlSerializerNamespaces();
                ns.Add(configPrefix, configNamespace);

                // set root attribute
                XmlRootAttribute ra = new XmlRootAttribute(configRoot);
                XmlAttributes    xa = new XmlAttributes();
                xa.XmlRoot = ra;

                // add overrides
                XmlAttributeOverrides xo = new XmlAttributeOverrides();
                xo.Add(typeof(ConfigXml22), xa);

                // open serializer
                xs = new XmlSerializer(typeof(ConfigXml22), xo);

                // file info object
                FileInfo fi = new FileInfo(configPath + configFile);

                // if the config file exists, open it.
                if (fi.Exists)
                {
                    fs = fi.OpenRead();
                    ConfigXml22 xml = (ConfigXml22)xs.Deserialize(fs);

                    // update properties
                    BearContValue = xml.BearContValue;
                    BearInitType  = xml.BearInitType;
                    BearInitValue = xml.BearInitValue;
                    BearRangeMax  = xml.BearRangeMax;
                    BearRangeMin  = xml.BearRangeMin;
                    BullContValue = xml.BullContValue;
                    BullInitType  = xml.BullInitType;
                    BullInitValue = xml.BullInitValue;
                    BullRangeMax  = xml.BullRangeMax;
                    BullRangeMin  = xml.BullRangeMin;
                    CloseOption   = xml.CloseOption;
                    OpenOption    = xml.OpenOption;
                }
            }
            finally
            {
                // ensure object is released
                if (fs != null)
                {
                    fs.Close();
                }
            }
        }
示例#3
0
        /// <summary>
        /// save config to specified xml file
        /// </summary>
        void XmlSave(ref ConfigXml22 xml)
        {
            // do not fire while loading
            if (isLoading)
            {
                return;
            }

            // save xml
            xml.Save();

            // flag save button
            OnSaveNeeded(false);
        }
示例#4
0
        /// <summary>
        /// loads config from file, apply to form, sync chart, reload chart
        /// </summary>
        void OnConfigLoad()
        {
            // update status message
            StatusMessage("Loading ...", Color.DarkRed);

            // set initial directory
            dialogOpen.InitialDirectory = configPath;

            // return if no file selected
            if (dialogOpen.ShowDialog() != DialogResult.OK)
            {
                // reset status message
                StatusMessageReady();

                // return
                return;
            }

            try
            {
                // get file from dialog
                string filename = dialogOpen.FileName;
                string path     = Path.GetDirectoryName(filename) + @"\";
                string file     = Path.GetFileName(filename);

                // get new xml object
                ConfigXml22 xml = new ConfigXml22(path, file);

                // load config from xml
                xml.Load();

                // set form values from xml
                FormApplyXml(xml);

                // update status message
                StatusMessage(string.Concat("Loaded ", file), Color.DarkRed);

                // flag apply button
                OnApplyNeeded(true);

                // flag save button
                OnSaveNeeded(true);
            }
            catch (Exception)
            {
                // error handling
                StatusMessage("Error! Please click [apply].", Color.DarkRed);
            }
        }
示例#5
0
 /// <summary>
 /// set xml values from form
 /// </summary>
 void XmlApplyForm(ref ConfigXml22 xml)
 {
     // set xml values from form
     xml.BearContValue = (int)bearContValue.Value;
     xml.BearInitType  = bearInitMax.Checked ? 1 : bearInitPrev.Checked ? 0 : -1;
     xml.BearInitValue = (int)bearInitValue.Value;
     xml.BearRangeMax  = (int)bearRangeMax.Value;
     xml.BearRangeMin  = (int)bearRangeMin.Value;
     xml.BullContValue = (int)bullContValue.Value;
     xml.BullInitType  = bullInitMax.Checked ? 1 : bullInitPrev.Checked ? 0 : -1;
     xml.BullInitValue = (int)bullInitValue.Value;
     xml.BullRangeMax  = (int)bullRangeMax.Value;
     xml.BullRangeMin  = (int)bullRangeMin.Value;
     xml.CloseOption   = cboCloseOption.SelectedItem.ToString();
     xml.OpenOption    = cboOpenOption.SelectedItem.ToString();
 }
示例#6
0
        /// methods
        /// <summary>
        /// sets data-box values
        /// </summary>
        void DataBoxInit()
        {
            // only fire for EmBars
            dataBox = (Bars.BarsType.DisplayName.Contains("EmBars")) ? true : false;

            if (dataBox)
            {
                // local variables
                int    configId = BarsPeriod.Value;
                string file     = string.Format(@"EmBars-Config-{0}.xml", configId);
                string path     = NinjaTrader.Cbi.Core.UserDataDir + @"bin\Custom\";
                Font   font     = new Font("Courier New", dataBoxFontSize, dataBoxFontStyle);

                // load config from xml
                ConfigXml22 xml = new ConfigXml22(path, file);
                xml.Load();

                // set fields to xml values
                int    emBearContValue = xml.BearContValue;
                int    emBearInitType  = xml.BearInitType;
                int    emBearInitValue = xml.BearInitValue;
                int    emBearRangeMax  = xml.BearRangeMax;
                int    emBearRangeMin  = xml.BearRangeMin;
                int    emBullContValue = xml.BullContValue;
                int    emBullInitType  = xml.BullInitType;
                int    emBullInitValue = xml.BullInitValue;
                int    emBullRangeMax  = xml.BullRangeMax;
                int    emBullRangeMin  = xml.BullRangeMin;
                string emCloseOption   = xml.CloseOption;
                string emOpenOption    = xml.OpenOption;

                // build rows
                string dbmMin  = string.Format("Min     {0}{1} |  {2}{3}", emBullRangeMin, (emBullInitType == -1) ? "*" : " ", emBearRangeMin, (emBearInitType == -1) ? "*" : "");
                string dbmMax  = string.Format("Max     {0}{1} |  {2}{3}", emBullRangeMax, (emBullInitType == 1) ? "*" : " ", emBearRangeMax, (emBearInitType == 1) ? "*" : "");
                string dbmInit = string.Format("Init   {0}{1}{2} | {3}{4}{5}", (emBullInitValue >= 0) ? " " : "", emBullInitValue, (emBullInitType == 0) ? "*" : " ", (emBearInitValue >= 0) ? " " : "", emBearInitValue, (emBearInitType == 0) ? "*" : "");
                string dbmCont = string.Format("Cont   {0}{1}  | {2}{3}", (emBullContValue >= 0) ? " " : "", emBullContValue, (emBearContValue >= 0) ? " " : "", emBearContValue);

                // build message box string
                dataBoxMsg = string.Format("EmBars {0}\r\nConfig  #{1}\r\n{2}\r\n{3}\r\n{4}\r\n{5}\r\nOpen    {6}\r\nClose   {7}", Bars.Instrument.FullName, configId.ToString(), dbmMin, dbmMax, dbmInit, dbmCont, emOpenOption, emCloseOption);

                // draw text-box
                DrawTextFixed("EmBarsDataBox", dataBoxMsg, dataBoxPosition, dataBoxFontColor, font, dataBoxBorderColor, dataBoxBackColor, dataBoxOpacity);

                // flag data-box loaded
                dataBoxLoaded = true;
            }
        }
示例#7
0
        /// <summary>
        /// save config to xml in specified path/file
        /// </summary>
        void OnConfigSaveAs()
        {
            // update status message
            StatusMessage("Saving ...", Color.DarkRed);

            // return if user cancels
            if (ctlSaveFileDialog.ShowDialog() != DialogResult.OK)
            {
                // reset status message
                StatusMessageReady();

                // return
                return;
            }

            // ensure file specified
            if (ctlSaveFileDialog.FileName != string.Empty)
            {
                try
                {
                    // get file from dialog
                    string filename = ctlSaveFileDialog.FileName;
                    string file     = Path.GetFileName(filename);
                    string path     = Path.GetDirectoryName(filename) + @"\";

                    // get new xml object
                    ConfigXml22 xml = new ConfigXml22(path, file);

                    // set xml values from form
                    XmlApplyForm(ref xml);

                    // save config to specified xml file
                    XmlSave(ref xml);

                    // update status message
                    StatusMessage(string.Concat("Saved as ", file), Color.DarkGreen);
                }
                catch (Exception)
                {
                    // error handling
                    StatusMessage("Error! Please click [apply].", Color.DarkRed);
                }
            }
        }
示例#8
0
        /// <summary>
        /// default constructor
        /// </summary>
        public ConfigForm(int id)
        {
            // update fields
            configId = id;

            // create config object
            config = new ConfigXml22(configPath, configFile);

            // load components
            InitializeComponent();
            ComboBoxBind();

            // set modal name to version
            this.Text                 = BuildInfo.WindowTitle;
            this.helpBuild.Text       = BuildInfo.Version;
            this.lblBuildMessage.Text = BuildInfo.Copyright;

            // reset form to config
            OnConfigReset();

            // set messages
            SetMessages();
        }
示例#9
0
        /// <summary>
        /// set form values from xml
        /// </summary>
        void FormApplyXml(ConfigXml22 xml)
        {
            // flag isLoading
            isLoading = true;

            // set form values from config
            bearContValue.Value = (decimal)EmMath.RangeValidate(xml.BearContValue, 100, -100);
            bearInitValue.Value = (decimal)EmMath.RangeValidate(xml.BearInitValue, 100, -100);
            bearRangeMax.Value  = Math.Max(1, (int)xml.BearRangeMax);
            bearRangeMin.Value  = Math.Max(1, (int)xml.BearRangeMin);
            switch (xml.BearInitType)
            {
            case 1:

                // range max
                bearInitMax.Checked = true;
                bearInitMin.Checked = bearInitPrev.Checked = false;
                break;

            case -1:

                // range min
                bearInitMin.Checked = true;
                bearInitMax.Checked = bearInitPrev.Checked = false;
                break;

            case 0:
            default:

                // prev range
                bearInitPrev.Checked = true;
                bearInitMin.Checked  = bearInitMax.Checked = false;
                break;
            }
            bullContValue.Value = (decimal)EmMath.RangeValidate(xml.BullContValue, 100, -100);
            bullInitValue.Value = (decimal)EmMath.RangeValidate(xml.BullInitValue, 100, -100);
            bullRangeMax.Value  = Math.Max(1, (int)xml.BullRangeMax);
            bullRangeMin.Value  = Math.Max(1, (int)xml.BullRangeMin);
            switch (xml.BullInitType)
            {
            case 1:

                // range max
                bullInitMax.Checked = true;
                bullInitMin.Checked = bullInitPrev.Checked = false;
                break;

            case -1:

                // range min
                bullInitMin.Checked = true;
                bullInitMax.Checked = bullInitPrev.Checked = false;
                break;

            case 0:
            default:

                // prev range
                bullInitPrev.Checked = true;
                bullInitMin.Checked  = bullInitMax.Checked = false;
                break;
            }
            cboCloseOption.SelectedItem = (EmCloses)cboCloseOption.FindString(xml.CloseOption);
            cboOpenOption.SelectedItem  = (EmOpens)cboOpenOption.FindString(xml.OpenOption);

            // reset isLoading
            isLoading = false;
        }