Example #1
0
        /// <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", "&nbsp; &nbsp; &nbsp;");
                        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", "&nbsp; &nbsp; &nbsp;");
                        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();
            }
        }