Beispiel #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(Environment.NewLine, "</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;
        }
Beispiel #2
0
        /// <summary>
        /// Load file, compile it and create/load the indicators into the CustomIndicatorsList.
        /// </summary>
        /// <param name="filePath">Path to the source file</param>
        /// <param name="errorMessages">Resulting error messages, if any.</param>
        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;
            string    indicatorFileName = Path.GetFileNameWithoutExtension(filePath);
            Indicator newIndicator      = GetIndicatorInstanceFromAssembly(assembly, indicatorFileName, 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 _customIndicatorsList)
            {
                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
            _customIndicatorsList.Add(newIndicator);

            errorMessages = string.Empty;
            return;
        }