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 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 sIndicatorName in Indicator_Store.OriginalIndicatorNames)
if (sIndicatorName == newIndicator.IndicatorName)
{
errorMessages = "The name '" + sIndicatorName + "' 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;
}