Пример #1
0
        /// <summary>
        /// Adds a span indicator.
        /// </summary>
        /// <param name="layerKey">The key of the layer that will add the span indicator.</param>
        /// <param name="layerDisplayPriority">The display priority of the layer.</param>
        /// <param name="indicator">The <see cref="SpanIndicator"/> to add.</param>
        /// <param name="textRange">The text range over which to add the indicator.</param>
        private void AddSpanIndicator(
			ActiproSoftware.SyntaxEditor.SyntaxEditor editor,
			string layerKey,
			int layerDisplayPriority,
			ActiproSoftware.SyntaxEditor.SpanIndicator indicator,
			ActiproSoftware.SyntaxEditor.TextRange textRange)
        {
            // Ensure there is a selection
            if (textRange.AbsoluteLength == 0)
            {
                ActiproSoftware.SyntaxEditor.DefaultWordBreakFinder wbf = new ActiproSoftware.SyntaxEditor.DefaultWordBreakFinder();
                int startOffset = wbf.FindNextWordStart(editor.Document, textRange.StartOffset);
                int endOffset = wbf.FindCurrentWordEnd(editor.Document, startOffset);

                if (endOffset <= startOffset)
                    return;

                textRange = new TextRange(startOffset, endOffset);
                //MessageBox.Show("Please make a selection first.");
                //return;
            }
            // Ensure that a syntax error layer is created...
            ActiproSoftware.SyntaxEditor.SpanIndicatorLayer layer = editor.Document.SpanIndicatorLayers[layerKey];
            if (layer == null)
            {
                layer = new ActiproSoftware.SyntaxEditor.SpanIndicatorLayer(layerKey, layerDisplayPriority);
                editor.Document.SpanIndicatorLayers.Add(layer);
            }
            // Don't allow the indicator to overlap another one
            if (layer.OverlapsWith(textRange))
            {
                //MessageBox.Show("Span indicators within the same layer may not overlap.");
                return;
            }
            // Add the indicator
            layer.Add(indicator, textRange);
        }
Пример #2
0
        private void HighlightRuntimeException(int functionId, ArchAngel.Common.Generator.DebugPos debugPos, string errDescription)
        {
            //string funcName = (string)dataGridViewErrors[ColFile.Index, e.RowIndex].Value;
            int line = debugPos.Line;

            treeFiles.SelectedNode = treeFiles.FindNodeByDataKey("File_" + functionId);

            syntaxEditorFilename.Document.SpanIndicatorLayers.Clear();
            syntaxEditor1.Document.SpanIndicatorLayers.Clear();

            ActiproSoftware.SyntaxEditor.SyntaxEditor editor;
            //if (codeFunction == "Filename")
            //{
            //editor = syntaxEditorFilename;
            //highlighter1.SetHighlightColor(syntaxEditorFilename, DevComponents.DotNetBar.Validator.eHighlightColor.Red);
            ////editor.Document.Lines[0].BackColor = Color.Salmon;
            //}
            //else if (codeFunction == "Body")
            //{
            editor = syntaxEditor1;
            highlighter1.SetHighlightColor(syntaxEditorFilename, DevComponents.DotNetBar.Validator.eHighlightColor.None);
            //    //editor.Document.Lines[0].BackColor = Color.White;
            //}
            //else
            //    throw new NotImplementedException("Function type not handled yet: " + codeFunction);

            int startOffset = editor.Document.Lines[line].TextRange.StartOffset;// +column;
            ActiproSoftware.SyntaxEditor.DefaultWordBreakFinder wbf = new ActiproSoftware.SyntaxEditor.DefaultWordBreakFinder();
            int endOffset = editor.Document.Lines[line].TextRange.EndOffset;// wbf.FindCurrentWordEnd(editor.Document, startOffset);

            if (endOffset < startOffset)
            {
                //MessageBox.Show("endOffset < startOffset");
                return;
            }
            ActiproSoftware.SyntaxEditor.HighlightingStyle highlightingStyle = new ActiproSoftware.SyntaxEditor.HighlightingStyle("Test", null, Color.Empty, Color.Red);
            ActiproSoftware.SyntaxEditor.HighlightingStyleSpanIndicator highlightSpan = new ActiproSoftware.SyntaxEditor.HighlightingStyleSpanIndicator("Test", highlightingStyle);
            highlightSpan.Tag = errDescription;

            this.AddSpanIndicator(
                editor,
                ActiproSoftware.SyntaxEditor.SpanIndicatorLayer.SyntaxErrorKey,
                ActiproSoftware.SyntaxEditor.SpanIndicatorLayer.SyntaxErrorDisplayPriority,
                highlightSpan, new ActiproSoftware.SyntaxEditor.TextRange(startOffset, endOffset));

            editor.SelectedView.GoToLine(line);
            editor.Caret.Offset = startOffset;
            editor.SelectedView.ScrollToCaret();

            if (superTabControl1.SelectedTab != superTabItemScript)
                superTabControl1.SelectedTab = superTabItemScript;

            string description = string.Format("{0}\nLine: {1}", errDescription, line);
            MessageBox.Show(this, description, "Runtime error", MessageBoxButtons.OK, MessageBoxIcon.Error);

            //if (superTabControl1.SelectedTab != superTabItemScript)
            //    superTabControl1.SelectedTab = superTabItemScript;
        }
Пример #3
0
        private void QuickCompile(
			bool execute,
			int fileId,
			object param,
			out string genFilename,
			out string genBody,
			out bool genSkipFile)
        {
            genFilename = "";
            genBody = "";
            genSkipFile = false;

            System.Diagnostics.Stopwatch stopwatch = System.Diagnostics.Stopwatch.StartNew();
            ArchAngel.Interfaces.Template.TemplateProject proj = new ArchAngel.Interfaces.Template.TemplateProject();

            if (treeFiles.SelectedNode.Tag is ArchAngel.Interfaces.Template.File)
            {
                ArchAngel.Interfaces.Template.File file = (ArchAngel.Interfaces.Template.File)treeFiles.SelectedNode.Tag;
                file.Name = syntaxEditorFilename.Text;
                file.Script.Syntax = Slyce.Common.SyntaxEditorHelper.LanguageEnumFromName(comboBoxSyntax.Text);
                file.Script.Body = syntaxEditor1.Text;

                if (comboBoxIterator.Text.ToLowerInvariant().Trim() == "one file")
                    file.Iterator = ArchAngel.Interfaces.Template.IteratorTypes.None;
                else
                {
                    string iterator = comboBoxIterator.Text.ToLowerInvariant().Trim();
                    iterator = iterator.Substring(iterator.LastIndexOf(' ') + 1);
                    file.Iterator = (ArchAngel.Interfaces.Template.IteratorTypes)Enum.Parse(typeof(ArchAngel.Interfaces.Template.IteratorTypes), iterator, true);
                }
                proj.OutputFolder.Files.Add(file);
            }
            else if (treeFiles.SelectedNode.Tag is ArchAngel.Interfaces.Template.Folder)
            {
                ArchAngel.Interfaces.Template.Folder folder = (ArchAngel.Interfaces.Template.Folder)treeFiles.SelectedNode.Tag;
                folder.Name = syntaxEditorFilename.Text;

                if (comboBoxIterator.Text.ToLowerInvariant().Trim() == "one folder")
                    folder.Iterator = ArchAngel.Interfaces.Template.IteratorTypes.None;
                else
                {
                    string iterator = comboBoxIterator.Text.ToLowerInvariant().Trim();
                    iterator = iterator.Substring(iterator.LastIndexOf(' ') + 1);
                    folder.Iterator = (ArchAngel.Interfaces.Template.IteratorTypes)Enum.Parse(typeof(ArchAngel.Interfaces.Template.IteratorTypes), iterator, true);
                }
                proj.OutputFolder.Folders.Add(folder);
            }
            string exeDir = Path.GetDirectoryName(Application.ExecutablePath);
            List<string> referencedAssemblies = new List<string>();
            //referencedAssemblies.Add(Path.Combine(exeDir, "ArchAngel.Scripting.dll"));
            referencedAssemblies.Add(Path.Combine(exeDir, "ArchAngel.Interfaces.dll"));
            referencedAssemblies.Add(Path.Combine(exeDir, "ArchAngel.Providers.EntityModel.dll"));
            referencedAssemblies.Add(Path.Combine(exeDir, "ArchAngel.NHibernateHelper.dll"));
            #if DEBUG
            referencedAssemblies.Add(Slyce.Common.RelativePaths.GetFullPath(System.Reflection.Assembly.GetExecutingAssembly().Location, @"..\..\..\..\3rd_Party_Libs\Inflector.Net.dll"));
            #else
            referencedAssemblies.Add(Path.Combine(exeDir, "Inflector.Net.dll"));
            #endif
            //referencedAssemblies.Add(BaseAssemblyPath);

            List<System.CodeDom.Compiler.CompilerError> compileErrors;

            ArchAngel.Common.Generator gen = new ArchAngel.Common.Generator(
                null,
                Controller.Instance.CurrentProject.TemplateLoader);

            //gen.CompileFunctionsAssembly(proj, referencedAssemblies, out compileErrors);
            string temp = Path.Combine(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), Branding.ProductName + Path.DirectorySeparatorChar + "Temp"), "Compile");

            if (!Directory.Exists(temp))
                Directory.CreateDirectory(temp);

            temp = Path.Combine(temp, Path.GetFileNameWithoutExtension(Path.GetTempFileName()) + ".dll");
            gen.CompileCombinedAssembly(proj, referencedAssemblies, null, out compileErrors, execute, temp);

            if (treeFiles.SelectedNode.Tag is ArchAngel.Interfaces.Template.File)
                treeFiles.SelectedNode.ImageIndex = compileErrors.Count == 0 ? IMG_FILE_GREEN : IMG_FILE_ORANGE;
            else if (treeFiles.SelectedNode.Tag is ArchAngel.Interfaces.Template.Folder)
                treeFiles.SelectedNode.ImageIndex = compileErrors.Count == 0 ? IMG_CLOSED_FOLDER : IMG_FOLDER_ORANGE;

            if (execute)
            {
                if (compileErrors.Count == 0)
                {
                    if (treeFiles.SelectedNode.Tag is ArchAngel.Interfaces.Template.File)
                    {
                        ArchAngel.Interfaces.Template.File file = (ArchAngel.Interfaces.Template.File)treeFiles.SelectedNode.Tag;
                        gen.SetProjectInCode(ArchAngel.Interfaces.SharedData.CurrentProject.ScriptProject);
                        genFilename = gen.GetFileName(fileId, param);

                        try
                        {
                            genBody = Utility.StandardizeLineBreaks(gen.GetFileBody(file.Id, param, out genSkipFile), Utility.LineBreaks.Windows);
                        }
                        catch (Exception e)
                        {
                            int errLine;
                            string stackTrace = ArchAngel.Common.Generator.GetCleanStackTrace(e.InnerException.StackTrace, file.Id, out errLine);
                            stackTrace = stackTrace.Substring(stackTrace.IndexOf(":line ") + ":line ".Length);
                            //throw new Exception("TODO: Work out how to handle filename: file vs. static file");
                            ArchAngel.Common.Generator.DebugPos debugPos = ArchAngel.Common.Generator.GetDebugPos(string.Format("File_{0}", file.Id), errLine - 1, 1, string.Format("Error: {0}\nFile: {1}", e.Message, file.Id));
                            debugPos.Line = errLine; // GFH
                            HighlightRuntimeException(file.Id, debugPos, e.InnerException.Message);
                            return;
                        }
                    }
                    else if (treeFiles.SelectedNode.Tag is ArchAngel.Interfaces.Template.Folder)
                    {
                        ArchAngel.Interfaces.Template.Folder folder = (ArchAngel.Interfaces.Template.Folder)treeFiles.SelectedNode.Tag;

                        try
                        {
                            genFilename = gen.GetFolderName(folder.ID, param);
                        }
                        catch (Exception e)
                        {
                            MessageBox.Show(this, e.InnerException.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }
                        genBody = "";
                    }
                    else
                        throw new NotImplementedException("Template type not handled yet: " + treeFiles.SelectedNode.Tag.GetType().ToString());

                    if (superTabControl1.SelectedTab != superTabItemTest)
                        superTabControl1.SelectedTab = superTabItemTest;
                }
                else
                {
                    if (superTabControl1.SelectedTab != superTabItemScript)
                        superTabControl1.SelectedTab = superTabItemScript;

                    MessageBox.Show(this, "See bottom of screen for errors.", "Errors occurred", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            syntaxEditorFilename.Document.SpanIndicatorLayers.Clear();
            syntaxEditor1.Document.SpanIndicatorLayers.Clear();
            BusyPopulatingErrors = true;
            dataGridViewErrors.Rows.Clear();
            highlighter1.SetHighlightColor(syntaxEditorFilename, DevComponents.DotNetBar.Validator.eHighlightColor.None);

            if (compileErrors.Count == 0)
            {
                labelHeader.BackgroundStyle.BackColor = Color.GreenYellow;
                labelHeader.BackgroundStyle.BackColor2 = Color.Green;
                labelHeader.Refresh();
            }
            else
            {
                labelHeader.BackgroundStyle.BackColor = Color.FromArgb(249, 224, 123);
                labelHeader.BackgroundStyle.BackColor2 = Color.FromArgb(224, 113, 21);
                labelHeader.Refresh();

                //Controller.Instance.RaiseCompileErrors(compileErrors);
                //progressHelper.ReportProgress(100, new GenerateFilesProgress(0, new Controller.CompileErrorsDelegate(compileErrors)));

                foreach (var err in compileErrors)
                {
                    //throw new Exception("TODO: Work out how to handle filename: file vs. static file");
                    ArchAngel.Common.Generator.DebugPos debugPos = ArchAngel.Common.Generator.GetDebugPos(err.FileName, err.Line, err.Column, string.Format("Error: {0}\nFile: {1}", err.ErrorText, err.FileName));
                    string functionName = debugPos.FunctionName == "GetFileName" ? "Filename" : "Body";
                    int line = debugPos.Line - 1;
                    int column = err.Column - 10 - 1;
                    string filename = treeFiles.FindNodeByDataKey(err.FileName).Text;
                    string description = err.ErrorText
                        .Replace("Slyce.FunctionRunner.", "");

                    ActiproSoftware.SyntaxEditor.SyntaxEditor editor;

                    if (functionName == "Filename")
                        editor = syntaxEditorFilename;
                    else if (functionName == "Body")
                        editor = syntaxEditor1;
                    else
                        throw new NotImplementedException("Function type not handled yet: " + functionName);

                    int startOffset = editor.Document.Lines[line].TextRange.StartOffset + column;

                    //if (startOffset < 0 && functionName == "Body")
                    //{
                    //    editor = syntaxEditorFilename;
                    //    startOffset = editor.Document.Lines[line].TextRange.StartOffset + column;
                    //}

                    dataGridViewErrors.Rows.Add(err.FileName, "", description, filename, functionName, debugPos.Line, err.Column - 10);

                    // Account for \r\n instead of \n
                    //startOffset -= line;
                    //int endOffset = syntaxEditor1.Document.findc startOffset + 3;
                    ActiproSoftware.SyntaxEditor.DefaultWordBreakFinder wbf = new ActiproSoftware.SyntaxEditor.DefaultWordBreakFinder();

                    if (startOffset < 0)
                        return;

                    int endOffset = wbf.FindCurrentWordEnd(editor.Document, startOffset);

                    if (endOffset < startOffset)
                    {
                        //MessageBox.Show("endOffset < startOffset");
                        return;
                    }
                    ActiproSoftware.SyntaxEditor.WaveLineSpanIndicator errorIndicator = new ActiproSoftware.SyntaxEditor.WaveLineSpanIndicator(Color.Red);
                    errorIndicator.Tag = err.ErrorText;

                    this.AddSpanIndicator(
                        editor,
                        ActiproSoftware.SyntaxEditor.SpanIndicatorLayer.SyntaxErrorKey,
                        ActiproSoftware.SyntaxEditor.SpanIndicatorLayer.SyntaxErrorDisplayPriority,
                        errorIndicator, new ActiproSoftware.SyntaxEditor.TextRange(startOffset, endOffset));
                }
                bar1.SelectedDockContainerItem = dockContainerItemErrors;
                BusyPopulatingErrors = false;
            }
            stopwatch.Stop();
            long duration = stopwatch.ElapsedMilliseconds;
            #if DEBUG
            timer1.Interval = 600;
            #else
            timer1.Interval = Math.Max((int)duration * 3, 600);
            #endif
        }
Пример #4
0
        private void dataGridViewErrors_RowEnter(object sender, DataGridViewCellEventArgs e)
        {
            if (BusyPopulatingErrors)
                return;

            string functionId = (string)dataGridViewErrors[ColFunctionId.Index, e.RowIndex].Value;
            string funcName = (string)dataGridViewErrors[ColFile.Index, e.RowIndex].Value;
            int line = (int)dataGridViewErrors[ColLine.Index, e.RowIndex].Value - 1;
            int column = (int)dataGridViewErrors[ColColumn.Index, e.RowIndex].Value - 1;
            string codeFunction = (string)dataGridViewErrors[ColCodeFunction.Index, e.RowIndex].Value;
            string errDescription = (string)dataGridViewErrors[ColDescription.Index, e.RowIndex].Value;

            if (line < 0)
            {
                MessageBox.Show("Error before beginning");
                return;
            }
            treeFiles.SelectedNode = treeFiles.FindNodeByDataKey(functionId);

            syntaxEditorFilename.Document.SpanIndicatorLayers.Clear();
            syntaxEditor1.Document.SpanIndicatorLayers.Clear();

            ActiproSoftware.SyntaxEditor.SyntaxEditor editor;
            if (codeFunction == "Filename")
            {
                editor = syntaxEditorFilename;
                highlighter1.SetHighlightColor(syntaxEditorFilename, DevComponents.DotNetBar.Validator.eHighlightColor.Red);
                //editor.Document.Lines[0].BackColor = Color.Salmon;
            }
            else if (codeFunction == "Body")
            {
                editor = syntaxEditor1;
                highlighter1.SetHighlightColor(syntaxEditorFilename, DevComponents.DotNetBar.Validator.eHighlightColor.None);
                //editor.Document.Lines[0].BackColor = Color.White;
            }
            else
                throw new NotImplementedException("Function type not handled yet: " + codeFunction);

            int startOffset = editor.Document.Lines[line].TextRange.StartOffset + column;
            // Account for \r\n instead of \n
            //startOffset -= line;
            //int endOffset = syntaxEditor1.Document.findc startOffset + 3;
            ActiproSoftware.SyntaxEditor.DefaultWordBreakFinder wbf = new ActiproSoftware.SyntaxEditor.DefaultWordBreakFinder();
            int endOffset = wbf.FindCurrentWordEnd(editor.Document, startOffset);

            if (endOffset < startOffset)
            {
                MessageBox.Show("endOffset < startOffset");
                return;
            }
            //editor.Document.SpanIndicatorLayers.Clear();

            //this.AddSpanIndicator(
            //    syntaxEditor1,
            //    ActiproSoftware.SyntaxEditor.SpanIndicatorLayer.SyntaxErrorKey,
            //    ActiproSoftware.SyntaxEditor.SpanIndicatorLayer.SyntaxErrorDisplayPriority,
            //    new ActiproSoftware.SyntaxEditor.WaveLineSpanIndicator(Color.Red), new ActiproSoftware.SyntaxEditor.TextRange(startOffset, endOffset));

            ActiproSoftware.SyntaxEditor.HighlightingStyle highlightingStyle = new ActiproSoftware.SyntaxEditor.HighlightingStyle("Test", null, Color.Empty, Color.Red);
            ActiproSoftware.SyntaxEditor.HighlightingStyleSpanIndicator highlightSpan = new ActiproSoftware.SyntaxEditor.HighlightingStyleSpanIndicator("Test", highlightingStyle);
            highlightSpan.Tag = errDescription;

            this.AddSpanIndicator(
                editor,
                ActiproSoftware.SyntaxEditor.SpanIndicatorLayer.SyntaxErrorKey,
                ActiproSoftware.SyntaxEditor.SpanIndicatorLayer.SyntaxErrorDisplayPriority,
                highlightSpan, new ActiproSoftware.SyntaxEditor.TextRange(startOffset, endOffset));

            editor.SelectedView.GoToLine(line);
            editor.Caret.Offset = startOffset;
            editor.SelectedView.ScrollToCaret();
        }