/// <summary> /// Test is finished /// </summary> private static void WorkerRunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) { var result = (CustomIndicatorsTestResult)e.Result; if (result.IsErrors) { var msgBoxError = new FancyMessageBox(result.ErrorReport, Language.T("Custom Indicators")) { BoxWidth = 550, BoxHeight = 340, TopMost = true }; msgBoxError.Show(); } var msgBoxOk = new FancyMessageBox(result.OkReport, Language.T("Custom Indicators")) { BoxWidth = 350, BoxHeight = 280, TopMost = true }; msgBoxOk.Show(); }
/// <summary> /// Shows the loaded custom indicators. /// </summary> public static void ShowLoadedCustomIndicators() { var loadedIndicators = new StringBuilder(); loadedIndicators.AppendLine("<h1>" + Language.T("Custom Indicators") + "</h1>"); loadedIndicators.AppendLine("<p>Loaded " + IndicatorManager.CustomIndicatorNames.Count + " indicators.</p>"); loadedIndicators.AppendLine("<p>"); foreach (string indicatorName in IndicatorManager.CustomIndicatorNames) { Indicator indicator = IndicatorManager.ConstructIndicator(indicatorName); indicator.Initialize(SlotTypes.NotDefined); string dll = indicator.LoaddedFromDll ? " (dll)" : " (cs)"; loadedIndicators.AppendLine(indicatorName + dll + "</br>"); } loadedIndicators.AppendLine("</p>"); var msgBox = new FancyMessageBox(loadedIndicators.ToString(), Language.T("Custom Indicators")) { BoxWidth = 480, BoxHeight = 260, TopMost = true }; msgBox.Show(); }
/// <summary> /// Calculates an indicator and returns OK status. /// </summary> private bool CalculateIndicator(SlotTypes type, Indicator indicator) { bool okStatus; try { indicator.Calculate(Data.DataSet); okStatus = true; } catch (Exception exception) { string request = "Please report this error in the support forum!"; if (indicator.CustomIndicator) { request = "Please report this error to the author of the indicator!<br />" + "You may remove this indicator from the Custom Indicators folder."; } string text = "<h1>Error: " + exception.Message + "</h1>" + "<p>Slot type: <strong>" + type + "</strong><br />" + "Indicator: <strong>" + indicator + "</strong></p>" + "<p>" + request + "</p>"; const string caption = "Indicator Calculation Error"; var msgBox = new FancyMessageBox(text, caption) { BoxWidth = 450, BoxHeight = 250 }; msgBox.Show(); okStatus = false; } return(okStatus); }
/// <summary> /// Load Source Files /// </summary> public static void LoadCustomIndicators() { var compiledDlls = new List <string>(); var indicatorManager = new IndicatorCompilationManager(); var errorReport = new StringBuilder(); errorReport.AppendLine("<h1>" + Language.T("Custom Indicators") + "</h1>"); bool isError = false; string libSettingsPath = Path.Combine(Data.SystemDir, "Libraries.xml"); Libraries.LoadSettings(libSettingsPath); if (Directory.Exists(Data.SourceFolder)) { string[] pathCsFiles = Directory.GetFiles(Data.SourceFolder, "*.cs"); if (pathCsFiles.Length != 0) { foreach (string sourcePath in pathCsFiles) { string errorMessages; if (Libraries.IsSourceCompiled(sourcePath)) { continue; } LibRecord record = indicatorManager.LoadCompileSourceFile(sourcePath, out errorMessages); if (record != null) { Libraries.AddRecord(record); compiledDlls.Add(Path.GetFileNameWithoutExtension(sourcePath)); } if (string.IsNullOrEmpty(errorMessages)) { continue; } isError = true; errorReport.AppendLine("<h2>File name: " + Path.GetFileName(sourcePath) + "</h2>"); string error = errorMessages.Replace(Environment.NewLine, "</br>"); error = error.Replace("\t", " "); errorReport.AppendLine("<p>" + error + "</p>"); } } } if (Directory.Exists(Data.LibraryDir)) { string[] pathDllFiles = Directory.GetFiles(Data.LibraryDir, "*.dll"); if (pathDllFiles.Length != 0) { foreach (string dllPath in pathDllFiles) { string fileName = Path.GetFileNameWithoutExtension(dllPath); if (compiledDlls.Contains(fileName)) { continue; } string errorMessages; indicatorManager.LoadDllIndicator(dllPath, out errorMessages); if (string.IsNullOrEmpty(errorMessages)) { continue; } isError = true; errorReport.AppendLine("<h2>File name: " + Path.GetFileName(dllPath) + "</h2>"); string error = errorMessages.Replace(Environment.NewLine, "</br>"); error = error.Replace("\t", " "); errorReport.AppendLine("<p>" + error + "</p>"); } } } Libraries.SaveSettings(libSettingsPath); // Adds the custom indicators IndicatorManager.ResetCustomIndicators(indicatorManager.CustomIndicatorsList); IndicatorManager.CombineAllIndicators(); if (isError) { var msgBox = new FancyMessageBox(errorReport.ToString(), Language.T("Custom Indicators")) { BoxWidth = 550, BoxHeight = 340, TopMost = true }; msgBox.Show(); } }
/// <summary> /// Load Source Files /// </summary> public static void LoadCustomIndicators() { var compiledDlls = new List<string>(); var indicatorManager = new IndicatorCompilationManager(); var errorReport = new StringBuilder(); errorReport.AppendLine("<h1>" + Language.T("Custom Indicators") + "</h1>"); bool isError = false; string libSettingsPath = Path.Combine(Data.SystemDir, "Libraries.xml"); Libraries.LoadSettings(libSettingsPath); if (Directory.Exists(Data.SourceFolder)) { string[] pathCsFiles = Directory.GetFiles(Data.SourceFolder, "*.cs"); if (pathCsFiles.Length != 0) { foreach (string sourcePath in pathCsFiles) { string errorMessages; if (Libraries.IsSourceCompiled(sourcePath)) continue; LibRecord record = indicatorManager.LoadCompileSourceFile(sourcePath, out errorMessages); if (record != null) { Libraries.AddRecord(record); compiledDlls.Add(Path.GetFileNameWithoutExtension(sourcePath)); } if (string.IsNullOrEmpty(errorMessages)) continue; isError = true; errorReport.AppendLine("<h2>File name: " + Path.GetFileName(sourcePath) + "</h2>"); string error = errorMessages.Replace(Environment.NewLine, "</br>"); error = error.Replace("\t", " "); errorReport.AppendLine("<p>" + error + "</p>"); } } } if (Directory.Exists(Data.LibraryDir)) { string[] pathDllFiles = Directory.GetFiles(Data.LibraryDir, "*.dll"); if (pathDllFiles.Length != 0) { foreach (string dllPath in pathDllFiles) { string fileName = Path.GetFileNameWithoutExtension(dllPath); if (compiledDlls.Contains(fileName)) continue; string errorMessages; indicatorManager.LoadDllIndicator(dllPath, out errorMessages); if (string.IsNullOrEmpty(errorMessages)) continue; isError = true; errorReport.AppendLine("<h2>File name: " + Path.GetFileName(dllPath) + "</h2>"); string error = errorMessages.Replace(Environment.NewLine, "</br>"); error = error.Replace("\t", " "); errorReport.AppendLine("<p>" + error + "</p>"); } } } Libraries.SaveSettings(libSettingsPath); // Adds the custom indicators IndicatorManager.ResetCustomIndicators(indicatorManager.CustomIndicatorsList); IndicatorManager.CombineAllIndicators(); if (isError) { var msgBox = new FancyMessageBox(errorReport.ToString(), Language.T("Custom Indicators")) {BoxWidth = 550, BoxHeight = 340, TopMost = true}; msgBox.Show(); } }
/// <summary> /// Shows the loaded custom indicators. /// </summary> public static void ShowLoadedCustomIndicators() { var loadedIndicators = new StringBuilder(); loadedIndicators.AppendLine("<h1>" + Language.T("Custom Indicators") + "</h1>"); loadedIndicators.AppendLine("<p>Loaded " + IndicatorManager.CustomIndicatorNames.Count + " indicators.</p>"); loadedIndicators.AppendLine("<p>"); foreach (string indicatorName in IndicatorManager.CustomIndicatorNames) { Indicator indicator = IndicatorManager.ConstructIndicator(indicatorName); indicator.Initialize(SlotTypes.NotDefined); string dll = indicator.LoaddedFromDll ? " (dll)" : " (cs)"; loadedIndicators.AppendLine(indicatorName + dll + "</br>"); } loadedIndicators.AppendLine("</p>"); var msgBox = new FancyMessageBox(loadedIndicators.ToString(), Language.T("Custom Indicators")) {BoxWidth = 480, BoxHeight = 260, TopMost = true}; msgBox.Show(); }
/// <summary> /// Test is finished /// </summary> private static void WorkerRunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) { var result = (CustomIndicatorsTestResult) e.Result; if (result.IsErrors) { var msgBoxError = new FancyMessageBox(result.ErrorReport, Language.T("Custom Indicators")) {BoxWidth = 550, BoxHeight = 340, TopMost = true}; msgBoxError.Show(); } var msgBoxOk = new FancyMessageBox(result.OkReport, Language.T("Custom Indicators")) {BoxWidth = 350, BoxHeight = 280, TopMost = true}; msgBoxOk.Show(); }
/// <summary> /// Calculates an indicator and returns OK status. /// </summary> private bool CalculateIndicator(SlotTypes type, Indicator indicator) { bool okStatus; try { indicator.Calculate(Data.DataSet); okStatus = true; } catch (Exception exception) { string request = "Please report this error in the support forum!"; if (indicator.CustomIndicator) request = "Please report this error to the author of the indicator!<br />" + "You may remove this indicator from the Custom Indicators folder."; string text = "<h1>Error: " + exception.Message + "</h1>" + "<p>Slot type: <strong>" + type + "</strong><br />" + "Indicator: <strong>" + indicator + "</strong></p>" + "<p>" + request + "</p>"; const string caption = "Indicator Calculation Error"; var msgBox = new FancyMessageBox(text, caption) {BoxWidth = 450, BoxHeight = 250}; msgBox.Show(); okStatus = false; } return okStatus; }