Ejemplo n.º 1
0
        public static void AddEntry(
            LogEditor logEditor,
            Exception e)
        {
            var content = new List <string>
            {
                e.GetType().ToString(),
                e.Message,
                string.Empty,
                StackTraceHeader,
            };

            content.AddRange(ExceptionHelpers
                             .TrimmedStackTraceFor(e));

            var ie = e.InnerException;

            if (ie != null)
            {
                content.Add(string.Empty);
                content.Add(string.Empty);
                content.Add(@"Inner exception: " + ie.GetType());
                content.Add(ie.Message);
                content.Add(string.Empty);
                content.Add(StackTraceHeader);
                content.AddRange(ExceptionHelpers
                                 .TrimmedStackTraceFor(ie));
            }

            logEditor?.AddEntry(
                ErrorType,
                content.ToArray());
        }
Ejemplo n.º 2
0
        void LogEditor.AddEntry(
            string type,
            IEnumerable <string> content)
        {
            LogEditor editor = this;

            editor.AddEntry(
                new LogEntry(
                    type,
                    new LinkedListLot <string>(content)));
        }
        /// <summary>
        /// This function is the callback used to execute the command when the menu item is clicked.
        /// </summary>
        /// <param name="Sender">Event sender.</param>
        /// <param name="Args">Event args.</param>
        private void GenerateMacroCallback(object Sender, EventArgs Args)
        {
            ThreadHelper.ThrowIfNotOnUIThread();

            // マクロの種類を取得
            EditorSelecter SelecterDialog = new EditorSelecter();

            SelecterDialog.ShowDialog();

            if (SelecterDialog.DialogResult == DialogResult.OK)
            {
                // エディタを起動
                DialogResult DialogResult = DialogResult.None;
                string       EditResult   = string.Empty;
                switch (XmlFunctionLibrary.GetEditorType(SelecterDialog.MacroType))
                {
                case EditorType.MacroEditor:
                    MacroEditor MacroEditor = new MacroEditor(SelecterDialog.MacroType);
                    MacroEditor.ShowDialog();
                    DialogResult = MacroEditor.DialogResult;
                    EditResult   = MacroEditor.MacroString;
                    break;

                case EditorType.LogEditor:
                    LogEditor LogEditor = new LogEditor(SelecterDialog.MacroType);
                    LogEditor.ShowDialog();
                    DialogResult = LogEditor.DialogResult;
                    EditResult   = LogEditor.MacroString;
                    break;

                case EditorType.DelegateEditor:
                    DelegateEditor DelegateEditor = new DelegateEditor(SelecterDialog.MacroType);
                    DelegateEditor.ShowDialog();
                    DialogResult = DelegateEditor.DialogResult;
                    EditResult   = DelegateEditor.MacroString;
                    break;
                }

                if (DialogResult == DialogResult.OK && !string.IsNullOrEmpty(EditResult))
                {
                    // カーソル位置に結果の文字列を挿入
                    DTE Dte = (DTE)ServiceProvider.GetService(typeof(DTE));
                    Assumes.Present(Dte);
                    var Selection = (TextSelection)Dte.ActiveDocument.Selection;
                    Selection.Text = EditResult;

                    // カーソルの行を更新
                    Selection.SelectLine();
                    Selection.SmartFormat();
                    Selection.EndOfLine();
                }
            }
        }
Ejemplo n.º 4
0
        public static void AddEntry(
            LogEditor logEditor,
            UnhandledExceptionEventArgs e)
        {
            if (e == null)
            {
                logEditor?.AddEntry(
                    ErrorType,
                    new[]
                {
                    @"An unhandled exception occurred, "
                    + @"but the event args object was null."
                });
                return;
            }

            var eo = e.ExceptionObject;

            if (eo == null)
            {
                logEditor?.AddEntry(
                    ErrorType,
                    new[]
                {
                    @"An unhandled exception occurred, "
                    + @"but the exception object was null."
                });
                return;
            }

            var ex = eo as Exception;

            if (ex == null)
            {
                logEditor?.AddEntry(
                    ErrorType,
                    new[]
                {
                    @"An unhandled exception occurred, but the exception "
                    + @"did not derive from System.Exception.",
                    @"Here is the exception's type: "
                    + eo.GetType()
                });
                return;
            }

            AddEntry(logEditor, ex);
        }
Ejemplo n.º 5
0
 private void ClearLogButton_OnClick(object sender, RoutedEventArgs e)
 {
     LogEditor.Clear();
 }
Ejemplo n.º 6
0
 private void OnDestroy()
 {
     scriptingInterface = null;
     instance           = null;
 }
Ejemplo n.º 7
0
 private void Awake()
 {
     instance = this;
 }
Ejemplo n.º 8
0
        /// <summary>
        /// This function is the callback used to execute the command when the menu item is clicked.
        /// </summary>
        /// <param name="Sender">Event sender.</param>
        /// <param name="Args">Event args.</param>
        private void EditMacroCallback(object Sender, EventArgs Args)
        {
            ThreadHelper.ThrowIfNotOnUIThread();

            DTE Dte = (DTE)ServiceProvider.GetService(typeof(DTE));

            Assumes.Present(Dte);
            var ActiveDocument = Dte.ActiveDocument;

            if (ActiveDocument != null)
            {
                // 一旦カーソル位置の行を全て選択
                var Selection = (TextSelection)ActiveDocument.Selection;
                Selection.SelectLine();

                // マクロの名前だけ選択
                string        TargetType = string.Empty;
                List <string> MacroTypes = new List <string>(XmlFunctionLibrary.GetMacroTypes(true, true, false));
                foreach (var MacroType in MacroTypes)
                {
                    if (Selection.Text.Contains(MacroType))
                    {
                        TargetType = MacroType;
                        break;
                    }
                }

                Selection.StartOfLine();
                Selection.LineUp();

                while (true)
                {
                    if (Selection.Text.Contains(TargetType))
                    {
                        break;
                    }
                    Selection.WordRight(true);
                }
                Selection.WordLeft();
                Selection.WordRight(true);

                TargetType = Selection.Text;

                // サポートしてなかったらエラー
                MacroTypes.Clear();
                MacroTypes.AddRange(XmlFunctionLibrary.GetMacroTypes(false, false, true));
                if (!MacroTypes.Contains(TargetType))
                {
                    string SupportedMacros = string.Empty;
                    for (int Index = 0; Index < MacroTypes.Count; Index++)
                    {
                        SupportedMacros += MacroTypes[Index] + "\r\n";
                    }

                    MessageBox.Show(
                        TargetType + " is not a supported macro",
                        "Error",
                        MessageBoxButtons.OK,
                        MessageBoxIcon.Error
                        );
                    return;
                }

                // マクロの中身だけ選択する
                string TargetParameters = string.Empty;
                bool   bIsInString      = false;
                int    Depth            = 0;
                while (true)
                {
                    Selection.CharRight(true);

                    var LastChar = Selection.Text[Selection.Text.Length - 1];

                    // マクロ名以降のみを取得
                    TargetParameters += LastChar;

                    // 文字列中はカウントしない
                    if (LastChar == '\"')
                    {
                        bIsInString = !bIsInString;
                    }

                    // カッコの深さをカウント
                    if (!bIsInString && LastChar == '(')
                    {
                        Depth++;
                    }
                    else if (!bIsInString && LastChar == ')')
                    {
                        Depth--;
                    }

                    // カッコの数が合ったら終了
                    if (Depth <= 0)
                    {
                        break;
                    }

                    // カッコの数が合わなかった時の対策
                    if (Selection.ActivePoint.AtEndOfLine)
                    {
                        break;
                    }
                }

                // 文字列中に"が入っている場合はエラー
                if (StringFunctionLibrary.CountOfChar(TargetParameters, '\"') % 2 != 0)
                {
                    MessageBox.Show(
                        "The string literal contains double quotes\r\n" +
                        "Remove the double quotes inside the string literal to edit the macro",
                        "Error",
                        MessageBoxButtons.OK,
                        MessageBoxIcon.Error
                        );
                    return;
                }

                if (!string.IsNullOrEmpty(TargetParameters))
                {
                    // エディタを起動
                    DialogResult DialogResult = DialogResult.None;
                    string       EditResult   = string.Empty;
                    switch (XmlFunctionLibrary.GetEditorType(TargetType))
                    {
                    case EditorType.MacroEditor:
                        MacroEditor MacroEditor = new MacroEditor(TargetType, TargetParameters);
                        MacroEditor.ShowDialog();
                        DialogResult = MacroEditor.DialogResult;
                        EditResult   = MacroEditor.MacroString;
                        break;

                    case EditorType.LogEditor:
                        LogEditor LogEditor = new LogEditor(TargetType, TargetParameters);
                        LogEditor.ShowDialog();
                        DialogResult = LogEditor.DialogResult;
                        EditResult   = LogEditor.MacroString;
                        break;

                    case EditorType.DelegateEditor:
                        DelegateEditor DelegateEditor = new DelegateEditor(TargetType, TargetParameters);
                        DelegateEditor.ShowDialog();
                        DialogResult = DelegateEditor.DialogResult;
                        EditResult   = DelegateEditor.MacroString;
                        break;
                    }

                    if (ActiveDocument != null && DialogResult == DialogResult.OK && !string.IsNullOrEmpty(EditResult))
                    {
                        // カーソル位置に結果の文字列を挿入
                        Selection.Text = EditResult;

                        // カーソルの行を更新
                        Selection.SelectLine();
                        Selection.SmartFormat();
                        Selection.EndOfLine();
                    }
                }
            }
        }