Example #1
0
        /// <summary>
        /// Does the job
        /// </summary>
        static void DoWorkTestCustomIndicators(object sender, DoWorkEventArgs e)
        {
            bool isErrors = false;

            StringBuilder errorReport = new StringBuilder();

            errorReport.AppendLine("<h1>" + Language.T("Custom Indicators") + "</h1>");

            StringBuilder okReport = new StringBuilder();

            okReport.AppendLine("<h1>" + Language.T("Custom Indicators") + "</h1>");
            okReport.AppendLine("<p>");

            foreach (string indicatorName in Indicator_Store.CustomIndicatorNames)
            {
                string errorList;
                if (!Indicator_Tester.CustomIndicatorThoroughTest(indicatorName, out errorList))
                {
                    isErrors = true;
                    errorReport.AppendLine("<h2>" + indicatorName + "</h2>");
                    string error = errorList.Replace("\r\n", "</br>");
                    error = error.Replace("\t", "&nbsp; &nbsp; &nbsp;");
                    errorReport.AppendLine("<p>" + error + "</p>");
                }
                else
                {
                    okReport.AppendLine(indicatorName + " - OK" + "<br />");
                }
            }

            okReport.AppendLine("</p>");

            CustomIndicatorsTestResult result = new CustomIndicatorsTestResult();

            result.IsErrors    = isErrors;
            result.ErrorReport = errorReport.ToString();
            result.OKReport    = okReport.ToString();

            e.Result = (object)result;

            return;
        }
        /// <summary>
        /// Load file, compile it and create/load the indicators into the CustomIndicatorsList.
        /// </summary>
        public void LoadCompileSourceFile(string filePath, out string errorMessages)
        {
            string errorLoadSourceFile;
            string source = LoadSourceFile(filePath, out errorLoadSourceFile);

            if (string.IsNullOrEmpty(source))
            {   // Source file loading failed.
                errorMessages = errorLoadSourceFile;
                return;
            }

            Dictionary <string, int> dictCompilationErrors;
            Assembly assembly = compiler.CompileSource(source, out dictCompilationErrors);

            if (assembly == null)
            {   // Assembly compilation failed.
                StringBuilder sbCompilationError = new StringBuilder();
                sbCompilationError.AppendLine("ERROR: Indicator compilation failed in file [" + Path.GetFileName(filePath) + "]");

                foreach (string error in dictCompilationErrors.Keys)
                {
                    sbCompilationError.AppendLine('\t' + error);
                }

                errorMessages = sbCompilationError.ToString();
                return;
            }

            string    errorGetIndicator;
            Indicator newIndicator = GetIndicatorInstanceFromAssembly(assembly, out errorGetIndicator);

            if (newIndicator == null)
            {   // Getting an indicator instance failed.
                errorMessages = errorGetIndicator;
                return;
            }

            // Check for a repeated indicator name among the custom indicators
            foreach (Indicator indicator in listCustomIndicators)
            {
                if (indicator.IndicatorName == newIndicator.IndicatorName)
                {
                    errorMessages = "The name '" + newIndicator.IndicatorName + "' found out in [" + Path.GetFileName(filePath) + "] is already in use.";
                    return;
                }
            }

            // Check for a repeated indicator name among the original indicators
            foreach (string indicatorName in Indicator_Store.OriginalIndicatorNames)
            {
                if (indicatorName == newIndicator.IndicatorName)
                {
                    errorMessages = "The name '" + indicatorName + "' found out in [" + Path.GetFileName(filePath) + "] is already in use.";
                    return;
                }
            }

            // Test the new custom indicator
            string errorTestIndicator;

            if (!Indicator_Tester.CustomIndicatorFastTest(newIndicator, out errorTestIndicator))
            {   // Testing the indicator failed.
                errorMessages = errorTestIndicator;
                return;
            }

            // Adds the custom indicator to the list
            listCustomIndicators.Add(newIndicator);

            errorMessages = string.Empty;
            return;
        }