/// <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;
}