Exemple #1
0
 public void OpenFile(int aSectionID, int aLine)
 {
     Debugger.Debug.FileData fileData = Debugger.Debug.SessionData.inst().Files.FirstOrDefault(file => file.SectionID == aSectionID);
     if (fileData != null)
     {
         CodeEditor editor = OpenFile(fileData);
         editor.Editor.TextArea.Caret.Line = aLine;
         editor.Editor.ScrollToLine(aLine);
         editor.InvalidateVisual();
     }
 }
        public CodeEditor(FileData aModelData)
        {
            InitializeComponent();
            aModelData.AttachEditor(editor);
            this.data = aModelData;
            editor.ShowLineNumbers = true;
            editor.Options.ConvertTabsToSpaces = true;
            editor.Options.IndentationSize = 4;
            editor.Foreground = new SolidColorBrush(Colors.White);
            editor.SyntaxHighlighting = AvalonExtensions.LoadHighlightingDefinition("Debugger.Resources.Angelscript.xshd");
            editor.Text = data.Code;
            editor.FontFamily = new FontFamily("Consolas");
            editor.TextArea.TextView.CurrentLineBackground = new SolidColorBrush(Colors.LightGray);
            editor.TextArea.TextView.BackgroundRenderers.Add(new LineHighlighter());
            editor.TextArea.LeftMargins.Insert(0, bpMargin = new BreakpointMargin(aModelData));
            SearchPanel panel = SearchPanel.Install(editor.TextArea);
            aModelData.PropertyChanged += aModelData_PropertyChanged;
            foldingManager = FoldingManager.Install(editor.TextArea);
            codeFolding = new BraceFoldingStrategy();
            UpdateFolding();

            // If using IDE data then give ourselves an IntellisenseSource
            if (Debug.SessionData.inst().Settings.UseIDEData)
                intelSource = IDE.Intellisense.Sources.SourceBuilder.GetSourceForExtension(System.IO.Path.GetExtension(aModelData.SectionName));

            depthScanner = new IDE.Intellisense.DepthScanner();
            depthScanner.Process(editor.Text);

            editor.MouseHover += editor_MouseHover;
            editor.TextArea.MouseWheel += editor_MouseWheel;
            editor.KeyUp += editor_KeyUp;
            editor.TextChanged += editor_TextChanged;

            t = new System.Timers.Timer();
            t.Interval = 175;
            t.Elapsed += t_Elapsed;
            t.Start();
        }
        public CodeEditor OpenFile(FileData aData)
        {
            foreach (TabItem item in tabs.Items) {
                if (item.Tag.Equals(aData.SectionName)) {
                    tabs.SelectedItem = item;
                    ((CodeEditor)((TabItem)tabs.SelectedItem).Content).SetCode(aData.Code);
                    return ((CodeEditor)((TabItem)tabs.SelectedItem).Content);
                }
            }
            Grid grid = new Grid();
            grid.ColumnDefinitions.Add(new ColumnDefinition());
            grid.ColumnDefinitions.Add(new ColumnDefinition());

            TextBlock txt = new TextBlock { Text = aData.SectionName };
            txt.Foreground = FindResource("ButtonText") as Brush;
            txt.Style = FindResource("IDETabHeader") as Style;

            grid.Children.Add(txt);
            Button close = new Button { Content = "X", Padding = new Thickness(0), Foreground = new SolidColorBrush(Colors.LightGray), FontWeight = FontWeights.Bold, VerticalAlignment = System.Windows.VerticalAlignment.Top };
            close.MinHeight = close.MinWidth = 18;
            close.MaxHeight = close.MaxWidth = 18;
            close.Background = close.BorderBrush = null;
            close.Click += onCloseTab;
            Grid.SetColumn(txt, 0);
            Grid.SetColumn(close, 1);
            grid.Children.Add(close);

            tabs.Items.Add(new TabItem {
                 Tag = aData.SectionName,
                 Header = grid,
                 Content = new CodeEditor(aData),
            });
            ((TabItem)tabs.Items[tabs.Items.Count - 1]).MouseUp += EditorTabs_MouseUp;
            tabs.SelectedItem = tabs.Items[tabs.Items.Count - 1];
            return ((CodeEditor)((TabItem)tabs.SelectedItem).Content);
        }
        void _ReceiveMsg(object o, MessageReceivedEventArgs args)
        {
            try {
                string   msg   = args.Message.Substring(0, 4).ToLower();
                string[] parts = args.Message.Split(' '); /*Regex.Matches(msg, @"[\""].+?[\""]|[^ ]+")
                                                           * .Cast<Match>()
                                                           * .Select(m => m.Value)
                                                           * .ToArray();*/

                if (VerboseLog)                           //if vebose logging then send all messages
                {
                    MainWindow.inst().Dispatcher.Invoke(delegate() {
                        session_.Log.Add(new LogMessage {
                            Message = args.Message, MsgType = MessageType.Data
                        });
                    });
                }

                if (msg.Equals("varv"))
                {
                    //TODO
                    MainWindow.inst().Dispatcher.Invoke(delegate() {
                        session_.Log.Add(new LogMessage {
                            Message = args.Message, MsgType = MessageType.Data
                        });
                    });
                }
                else if (msg.Equals("reqv"))
                {
                    string varName  = parts[1];
                    string varValue = parts[2];
                    //TODO
                }
                else if (msg.Equals("locv"))
                {
                    string code  = args.Message.Substring(5);
                    JArray array = JArray.Parse(code);
                    MainWindow.inst().Dispatcher.Invoke(delegate() {
                        SessionData.inst().LocalData = new Json.JWrapper("Stack Level ", array);
                        //Screens.DebugScreen.inst().LocalsTree.DataContext = null;
                        Screens.DebugScreen.inst().LocalsTree.DataContext = SessionData.inst().LocalData;
                    });
                }
                else if (msg.Equals("glov"))
                {
                    string code  = args.Message.Substring(5).Replace("1.#INF", "\"1.#INF\"");
                    JArray array = JArray.Parse(code);
                    MainWindow.inst().Dispatcher.Invoke(delegate() {
                        SessionData.inst().GlobalData = new Json.JWrapper("Globals", array);
                        //Screens.DebugScreen.inst().GlobalsTree.DataContext = null;
                        Screens.DebugScreen.inst().GlobalTree.DataContext = SessionData.inst().GlobalData;
                    });
                }
                else if (msg.Equals("this"))
                {
                    int     stackDepth = int.Parse(parts[1]);
                    string  code       = JoinStringsWith(parts, 2, " ");
                    JObject array      = JObject.Parse(code);
                    MainWindow.inst().Dispatcher.Invoke(delegate() {
                        SessionData.inst().ThisData = new Json.JWrapper("This", array);
                        //Screens.DebugScreen.inst().ThisTree.DataContext = null;
                        Screens.DebugScreen.inst().ThisTree.DataContext = SessionData.inst().ThisData;
                    });
                    //TODO
                }
                else if (msg.Equals("modl"))
                {
                    JArray array = JArray.Parse(args.Message.Substring(5));
                    for (int i = 0; i < array.Count; ++i)
                    {
                        if (array[i].Type == JTokenType.String)
                        {
                            string str = array[i].ToString();
                            MainWindow.inst().Dispatcher.Invoke(delegate() {
                                if (session_.Modules.FirstOrDefault(m => m.Name.Equals(str)) == null)
                                {
                                    session_.Modules.Add(new Module {
                                        Name = str
                                    });
                                }
                            });
                        }
                    }
                }
                else if (msg.Equals("ctxl"))
                {
                }
                else if (msg.Equals("stck"))
                {
                    if (parts[1].StartsWith("["))
                    {
                        //TODO
                        string code  = args.Message.Substring(5);
                        JArray array = JArray.Parse(code);
                        MainWindow.inst().Dispatcher.Invoke(delegate() {
                            SessionData.inst().CallStack.Clear();
                            //STCK [{"l":47,"c":5,"s":18,"f":"UIElement@ SetValue(LineEdit@, const String&in, bool)"},{"l":471,"c":9,"s":18,"f":"void LoadAttributeEditor(UIElement@, const Variant&in, const AttributeInfo&in, bool, bool, const Variant[]&in)"},{"l":444,"c":9,"s":18,"f":"void LoadAttributeEditor(ListView@, Serializable@[]@, const AttributeInfo&in, uint)"},{"l":785,"c":9,"s":18,"f":"void UpdateAttributes(Serializable@[]@, ListView@, bool&inout)"},{"l":226,"c":9,"s":17,"f":"void UpdateAttributeInspector(bool = true)"},{"l":738,"c":5,"s":2,"f":"void HandleHierarchyListSelectionChange()"}]
                            int i = 0;
                            foreach (JObject obj in array.Children <JObject>())
                            {
                                session_.CallStack.Add(new Callstack {
                                    Line          = obj.Property("l").Value.ToObject <int>(),
                                    StackFunction = obj.Property("f").Value.ToString(),
                                    StackLevel    = i,
                                    SectionID     = obj.Property("s").Value.ToObject <int>()
                                });
                                ++i;
                            }
                        });
                    }
                    else
                    {
                        string ctx       = parts[1];
                        int    depth     = int.Parse(parts[2]);
                        int    line      = int.Parse(parts[3]);
                        int    sectionid = int.Parse(parts[4]);
                        MainWindow.inst().Dispatcher.Invoke(delegate() {
                            session_.CallStack.Add(new Callstack {
                                StackLevel    = depth,
                                StackFunction = ctx,
                                SectionID     = sectionid,
                                Line          = line
                            });
                        });
                    }
                }
                else if (msg.Equals("scls"))
                {
                    JArray array = JArray.Parse(args.Message.Substring(5));

                    foreach (JObject obj in array.Children <JObject>())
                    {
                        int    id     = obj.Property("id").Value.ToObject <int>();
                        string module = obj.Property("mod").Value.ToString();
                        string name   = obj.Property("name").Value.ToString();
                        //??if (name.Trim().Length == 0) //ignore that empty one for the immediate mode context
                        //??    return;
                        MainWindow.inst().Dispatcher.Invoke(delegate() {
                            FileData fd = session_.Files.FirstOrDefault(file => file.SectionName.Equals(name));
                            if (fd == null)
                            {
                                session_.Files.Add(new FileData {
                                    SectionName = name,
                                    Module      = module,
                                    SectionID   = id
                                });
                            }
                            else
                            {
                                fd.SectionID = id;
                            }
                        });
                    }
                }
                else if (msg.Equals("file"))
                {
                    int    sectionID = int.Parse(parts[1]);
                    int    len       = sectionID.ToString().Length + 6;
                    string data      = args.Message.Substring(len);

                    Debugger.Debug.FileData file = session_.Files.FirstOrDefault(f => f.SectionID == sectionID);
                    if (file != null)
                    {
                        file.Code = data;
                    }
                    //??is there an else case? should presumably know the section ahead of time
                }
                else if (msg.Equals("bset"))
                {
                    int sectionID = int.Parse(parts[1]);
                    int line      = int.Parse(parts[2]);

                    Debugger.Debug.FileData file = session_.Files.FirstOrDefault(f => f.SectionID == sectionID);
                    if (file != null)
                    {
                        Debugger.Debug.Breakpoint breakpoint = file.BreakPoints.FirstOrDefault(bp => bp.LineNumber == line);
                        if (breakpoint == null)
                        {
                            MainWindow.inst().Dispatcher.Invoke(delegate() {
                                file.BreakPoints.Add(new Breakpoint {
                                    LineNumber = line, Active = true, SectionID = sectionID, File = file.SectionName
                                });
                            });
                        }
                        else
                        {
                            breakpoint.Active = true;
                        }
                    }
                    else
                    {
                        Debugger.Debug.FileData fd = new FileData {
                            SectionID = sectionID
                        };
                    }
                }
                else if (msg.Equals("brem"))
                {
                    int sectionID = int.Parse(parts[1]);
                    int line      = int.Parse(parts[2]);
                    Debugger.Debug.FileData file = session_.Files.FirstOrDefault(f => f.SectionID == sectionID);
                    if (file != null)
                    {
                        Debugger.Debug.Breakpoint breakpoint = file.BreakPoints.FirstOrDefault(bp => bp.LineNumber == line);
                        if (breakpoint != null)
                        {
                            breakpoint.Active = false;
                        }
                    }
                }
                else if (msg.Equals("hitl"))
                {
                    session_.IsDebugging = true;
                    int sectionId = int.Parse(parts[1]);
                    int line      = int.Parse(parts[2]);
                    session_.CurrentSection = sectionId;
                    session_.CurrentLine    = line;
                    MainWindow.inst().Dispatcher.Invoke(delegate() {
                        Screens.DebugScreen.inst().EditorTabs.OpenFile(sectionId, line);
                    });
                }
                else if (msg.Equals("cont"))
                {
                }
                else if (msg.Equals("secm"))     //A file has been changed remotely, send a request for it
                {
                    int sectionid = int.Parse(parts[1]);
                    socket_.Send(string.Format("GETF {0}", sectionid));
                }
                else if (msg.Equals("logw"))
                {
                    string m = args.Message.Substring(5);
                    MainWindow.inst().Dispatcher.Invoke(delegate() {
                        session_.Log.Add(new LogMessage {
                            MsgType = MessageType.Warning,
                            Message = JoinStringsWith(parts, 1, " ")
                        });
                    });
                }
                else if (msg.Equals("loge"))
                {
                    string m = args.Message.Substring(5);
                    MainWindow.inst().Dispatcher.Invoke(delegate() {
                        session_.Log.Add(new LogMessage {
                            MsgType = MessageType.Error,
                            Message = JoinStringsWith(parts, 1, " ")
                        });
                    });
                }
                else if (msg.Equals("logi"))
                {
                    string m = args.Message.Substring(5);
                    MainWindow.inst().Dispatcher.Invoke(delegate() {
                        session_.Log.Add(new LogMessage {
                            MsgType = MessageType.Info,
                            Message = JoinStringsWith(parts, 1, " ")
                        });
                    });
                }
                else if (msg.Equals("rstr"))
                {
                    //TODO
                }
                else
                {
                    //Unknown msg
                    MainWindow.inst().Dispatcher.Invoke(delegate() {
                        session_.Log.Add(new LogMessage {
                            MsgType = MessageType.Data,
                            Message = args.Message
                        });
                    });
                }
            }
            catch (Exception ex) {
                MainWindow.inst().Dispatcher.Invoke(delegate() {
                    session_.Log.Add(new LogMessage {
                        MsgType = MessageType.Error,
                        Message = ex.Message
                    });
                    session_.Log.Add(new LogMessage {
                        MsgType = MessageType.Info,
                        Message = args.Message
                    });
                });
            }
        }
 public void GetFile(FileData aData)
 {
     socket_.Send(string.Format("GETF {0}", aData.SectionID));
 }
        void _ReceiveMsg(object o, MessageReceivedEventArgs args)
        {
            try {
                string msg = args.Message.Substring(0, 4).ToLower();
                string[] parts = args.Message.Split(' ');

                if (VerboseLog) { //if vebose logging then send all messages
                    MainWindow.inst().Dispatcher.Invoke(delegate() {
                        session_.Log.Add(new LogMessage { Message = args.Message, MsgType = MessageType.Data });
                    });
                }

                if (msg.Equals("varv")) { //Variable Value message
                    //TODO
                    MainWindow.inst().Dispatcher.Invoke(delegate() {
                        session_.Log.Add(new LogMessage { Message = args.Message, MsgType = MessageType.Data });
                    });
                } else if (msg.Equals("reqv")) { // Request Variable Message
                    string varName = parts[1];
                    string varValue = parts[2];
                    //TODO
                } else if (msg.Equals("locv")) { // Local Stack Values Message
                    string code = args.Message.Substring(5);
                    JArray array = JArray.Parse(code);
                    MainWindow.inst().Dispatcher.Invoke(delegate() {
                        SessionData.inst().LocalData = new Json.JWrapper("", array);
                        Screens.DebugScreen.inst().LocalsTree.DataContext = SessionData.inst().LocalData;
                    });
                } else if (msg.Equals("glov")) { // Global Variables Message
                    string code = args.Message.Substring(5).Replace("1.#INF","\"1.#INF\"");
                    JArray array = JArray.Parse(code);
                    MainWindow.inst().Dispatcher.Invoke(delegate() {
                        SessionData.inst().GlobalData = new Json.JWrapper("Globals", array);
                        Screens.DebugScreen.inst().GlobalTree.DataContext = SessionData.inst().GlobalData;
                    });
                } else if (msg.Equals("this")) { // "This" Object data
                    int stackDepth = int.Parse(parts[1]);
                    string code = JoinStringsWith(parts, 2, " ");
                    JObject array = JObject.Parse(code);
                    MainWindow.inst().Dispatcher.Invoke(delegate() {
                        SessionData.inst().ThisData = new Json.JWrapper("This", array);
                        SessionData.inst().ThisData.UserData = stackDepth;
                        //Screens.DebugScreen.inst().ThisTree.DataContext = null;
                        Screens.DebugScreen.inst().ThisTree.DataContext = SessionData.inst().ThisData;
                    });
                    //TODO
                } else if (msg.Equals("modl")) { // Script Modules Message
                    JArray array = JArray.Parse(args.Message.Substring(5));
                    for (int i = 0; i < array.Count; ++i) {
                        if (array[i].Type == JTokenType.String) {
                            string str = array[i].ToString();
                            MainWindow.inst().Dispatcher.Invoke(delegate() {
                                if (session_.Modules.FirstOrDefault(m => m.Name.Equals(str)) == null) {
                                    session_.Modules.Add(new Module {
                                        Name = str
                                    });
                                }
                            });
                        }
                    }
                } else if (msg.Equals("ctxl")) { // Script Context messages, irrelevant in simple AS implementations

                } else if (msg.Equals("stck")) { // Call stack Message
                    if (parts[1].StartsWith("[")) {
                        //TODO
                        string code = args.Message.Substring(5);
                        JArray array = JArray.Parse(code);
                        MainWindow.inst().Dispatcher.Invoke(delegate() {
                            SessionData.inst().CallStack.Clear();
                            //STCK [{"l":47,"c":5,"s":18,"f":"UIElement@ SetValue(LineEdit@, const String&in, bool)"},{"l":471,"c":9,"s":18,"f":"void LoadAttributeEditor(UIElement@, const Variant&in, const AttributeInfo&in, bool, bool, const Variant[]&in)"},{"l":444,"c":9,"s":18,"f":"void LoadAttributeEditor(ListView@, Serializable@[]@, const AttributeInfo&in, uint)"},{"l":785,"c":9,"s":18,"f":"void UpdateAttributes(Serializable@[]@, ListView@, bool&inout)"},{"l":226,"c":9,"s":17,"f":"void UpdateAttributeInspector(bool = true)"},{"l":738,"c":5,"s":2,"f":"void HandleHierarchyListSelectionChange()"}]
                            int i = 0;
                            foreach (JObject obj in array.Children<JObject>()) {
                                session_.CallStack.Add(new Callstack {
                                    Line = obj.Property("l").Value.ToObject<int>(),
                                    StackFunction = obj.Property("f").Value.ToString(),
                                    StackLevel = i,
                                    SectionID = obj.Property("s").Value.ToObject<int>()
                                });
                                ++i;
                            }
                        });

                    } else {
                        string ctx = parts[1];
                        int depth = int.Parse(parts[2]);
                        int line = int.Parse(parts[3]);
                        int sectionid = int.Parse(parts[4]);
                        MainWindow.inst().Dispatcher.Invoke(delegate() {
                            session_.CallStack.Add(new Callstack {
                                StackLevel = depth,
                                StackFunction = ctx,
                                SectionID = sectionid,
                                Line = line
                            });
                        });
                    }
                } else if (msg.Equals("scls")) { // List of "Script Sections"/files
                    JArray array = JArray.Parse(args.Message.Substring(5));

                    foreach (JObject obj in array.Children<JObject>()) {
                        int id = obj.Property("id").Value.ToObject<int>();
                        string module = obj.Property("mod").Value.ToString();
                        string name = obj.Property("name").Value.ToString();
                        if (module.Length == 0)
                            continue;
                        MainWindow.inst().Dispatcher.Invoke(delegate() {
                            FileData fd = session_.Files.FirstOrDefault(file => file.SectionName.Equals(name));
                            if (fd == null) {
                                session_.Files.Add(new FileData {
                                    SectionName = name,
                                    Module = module,
                                    SectionID = id
                                });
                            } else {
                                fd.SectionID = id; // Faciliates "lost" connection
                            }
                        });
                    }

                } else if (msg.Equals("file")) { // Script code sent to us
                    int sectionID = int.Parse(parts[1]);
                    int len = sectionID.ToString().Length + 6;
                    string data = args.Message.Substring(len);

                    Debugger.Debug.FileData file = session_.Files.FirstOrDefault(f => f.SectionID == sectionID);
                    if (file != null)
                        file.Code = data;
                    //??is there an else case? should presumably know the section ahead of time

                } else if (msg.Equals("bset")) { // Someone has set a breakpoint
                    int sectionID = int.Parse(parts[1]);
                    int line = int.Parse(parts[2]);

                    Debugger.Debug.FileData file = session_.Files.FirstOrDefault(f => f.SectionID == sectionID);
                    if (file != null) {
                        Debugger.Debug.Breakpoint breakpoint = file.BreakPoints.FirstOrDefault(bp => bp.LineNumber == line);
                        if (breakpoint == null) {
                            MainWindow.inst().Dispatcher.Invoke(delegate() {
                                file.BreakPoints.Add(new Breakpoint { LineNumber = line, Active = true, SectionID = sectionID, File = file.SectionName });
                            });
                        } else {
                            breakpoint.Active = true;
                        }
                    } else {
                        Debugger.Debug.FileData fd = new FileData { SectionID = sectionID };
                    }
                } else if (msg.Equals("brem")) { // Someone has removed a breakpoint
                    int sectionID = int.Parse(parts[1]);
                    int line = int.Parse(parts[2]);
                    Debugger.Debug.FileData file = session_.Files.FirstOrDefault(f => f.SectionID == sectionID);
                    if (file != null) {
                        Debugger.Debug.Breakpoint breakpoint = file.BreakPoints.FirstOrDefault(bp => bp.LineNumber == line);
                        if (breakpoint != null) {
                            breakpoint.Active = false;
                        }
                    }
                } else if (msg.Equals("hitl")) { // "HitLine" current line position
                    // If we had not already halted then play the beep sound if enabled
                    if (!session_.IsDebugging && session_.Settings.PlayBeepSound)
                        SystemSounds.Hand.Play();
                    session_.IsDebugging = true;
                    int sectionId = int.Parse(parts[1]);
                    int line = int.Parse(parts[2]);
                    session_.CurrentSection = sectionId;
                    session_.CurrentLine = line;
                    MainWindow.inst().Dispatcher.Invoke(delegate() {
                        Screens.DebugScreen.inst().EditorTabs.OpenFile(sectionId, line);
                    });

                } else if (msg.Equals("cont")) { // Execution resumed by someone
                } else if (msg.Equals("secm")) { //A file has been changed remotely, send a request for it
                    int sectionid = int.Parse(parts[1]);
                    socket_.Send(string.Format("GETF {0}", sectionid));
                } else if (msg.Equals("logw")) { // Log Warning
                    string m = args.Message.Substring(5);
                    MainWindow.inst().Dispatcher.Invoke(delegate() {
                        session_.Log.Add(new LogMessage {
                            MsgType = MessageType.Warning,
                            Message = JoinStringsWith(parts, 1, " ")
                        });
                    });
                } else if (msg.Equals("loge") || msg.Equals("erro")) { // Log Error
                    string m = args.Message.Substring(5);
                    MainWindow.inst().Dispatcher.Invoke(delegate() {
                        session_.Log.Add(new LogMessage {
                            MsgType = MessageType.Error,
                            Message = JoinStringsWith(parts, 1, " ")
                        });
                    });
                } else if (msg.Equals("logi")) { // Log Info
                    string m = args.Message.Substring(5);
                    MainWindow.inst().Dispatcher.Invoke(delegate() {
                        session_.Log.Add(new LogMessage {
                            MsgType = MessageType.Info,
                            Message = JoinStringsWith(parts, 1, " ")
                        });
                    });
                } else if (msg.Equals("rstr")) { // A restart message
                    //TODO
                } else {
                    //Unknown msg
                    MainWindow.inst().Dispatcher.Invoke(delegate() {
                        session_.Log.Add(new LogMessage {
                            MsgType = MessageType.Data,
                            Message = args.Message
                        });
                    });
                }
            }
            catch (Exception ex) {
                MainWindow.inst().Dispatcher.Invoke(delegate() {
                    session_.Log.Add(new LogMessage {
                        MsgType = MessageType.Error,
                        Message = ex.Message
                    });
                    session_.Log.Add(new LogMessage {
                        MsgType = MessageType.Info,
                        Message = args.Message
                    });
                });
            }
        }
 public void Save(FileData aData)
 {
     socket_.Send(string.Format("SAVE {0} {1}", aData.SectionID, aData.Code));
 }
 public BreakpointMargin(FileData aFileData)
 {
     fileData = aFileData;
 }
Exemple #9
0
        void _ReceiveMsg(object o, MessageReceivedEventArgs args)
        {
            try {
                string   msg   = args.Message.Substring(0, 4).ToLower();
                string[] parts = args.Message.Split(' ');

                if (VerboseLog)   //if vebose logging then send all messages
                {
                    MainWindow.inst().Dispatcher.Invoke(delegate() {
                        session_.Log.Add(new LogMessage {
                            Message = args.Message, MsgType = MessageType.Data
                        });
                    });
                }

                if (msg.Equals("varv"))   //Variable Value message
                //TODO
                {
                    MainWindow.inst().Dispatcher.Invoke(delegate() {
                        session_.Log.Add(new LogMessage {
                            Message = args.Message, MsgType = MessageType.Data
                        });
                    });
                }
                else if (msg.Equals("reqv"))     // Request Variable Message
                {
                    string varName  = parts[1];
                    string varValue = parts[2];
                    //TODO
                }
                else if (msg.Equals("locv"))     // Local Stack Values Message
                {
                    string code  = args.Message.Substring(5);
                    JArray array = JArray.Parse(code);
                    MainWindow.inst().Dispatcher.Invoke(delegate() {
                        SessionData.inst().LocalData = new Json.JWrapper("", array);
                        Screens.DebugScreen.inst().LocalsTree.DataContext = SessionData.inst().LocalData;
                    });
                }
                else if (msg.Equals("glov"))     // Global Variables Message
                {
                    string code  = args.Message.Substring(5).Replace("1.#INF", "\"1.#INF\"");
                    JArray array = JArray.Parse(code);
                    MainWindow.inst().Dispatcher.Invoke(delegate() {
                        SessionData.inst().GlobalData = new Json.JWrapper("Globals", array);
                        Screens.DebugScreen.inst().GlobalTree.DataContext = SessionData.inst().GlobalData;
                    });
                }
                else if (msg.Equals("this"))     // "This" Object data
                {
                    int     stackDepth = int.Parse(parts[1]);
                    string  code       = JoinStringsWith(parts, 2, " ");
                    JObject array      = JObject.Parse(code);
                    MainWindow.inst().Dispatcher.Invoke(delegate() {
                        SessionData.inst().ThisData          = new Json.JWrapper("This", array);
                        SessionData.inst().ThisData.UserData = stackDepth;
                        //Screens.DebugScreen.inst().ThisTree.DataContext = null;
                        Screens.DebugScreen.inst().ThisTree.DataContext = SessionData.inst().ThisData;
                    });
                    //TODO
                }
                else if (msg.Equals("modl"))     // Script Modules Message
                {
                    JArray array = JArray.Parse(args.Message.Substring(5));
                    for (int i = 0; i < array.Count; ++i)
                    {
                        if (array[i].Type == JTokenType.String)
                        {
                            string str = array[i].ToString();
                            MainWindow.inst().Dispatcher.Invoke(delegate() {
                                if (session_.Modules.FirstOrDefault(m => m.Name.Equals(str)) == null)
                                {
                                    session_.Modules.Add(new Module {
                                        Name = str
                                    });
                                }
                            });
                        }
                    }
                }
                else if (msg.Equals("ctxl"))     // Script Context messages, irrelevant in simple AS implementations

                {
                }
                else if (msg.Equals("stck"))     // Call stack Message
                {
                    if (parts[1].StartsWith("["))
                    {
                        //TODO
                        string code  = args.Message.Substring(5);
                        JArray array = JArray.Parse(code);
                        MainWindow.inst().Dispatcher.Invoke(delegate() {
                            SessionData.inst().CallStack.Clear();
                            //STCK [{"l":47,"c":5,"s":18,"f":"UIElement@ SetValue(LineEdit@, const String&in, bool)"},{"l":471,"c":9,"s":18,"f":"void LoadAttributeEditor(UIElement@, const Variant&in, const AttributeInfo&in, bool, bool, const Variant[]&in)"},{"l":444,"c":9,"s":18,"f":"void LoadAttributeEditor(ListView@, Serializable@[]@, const AttributeInfo&in, uint)"},{"l":785,"c":9,"s":18,"f":"void UpdateAttributes(Serializable@[]@, ListView@, bool&inout)"},{"l":226,"c":9,"s":17,"f":"void UpdateAttributeInspector(bool = true)"},{"l":738,"c":5,"s":2,"f":"void HandleHierarchyListSelectionChange()"}]
                            int i = 0;
                            foreach (JObject obj in array.Children <JObject>())
                            {
                                session_.CallStack.Add(new Callstack {
                                    Line          = obj.Property("l").Value.ToObject <int>(),
                                    StackFunction = obj.Property("f").Value.ToString(),
                                    StackLevel    = i,
                                    SectionID     = obj.Property("s").Value.ToObject <int>()
                                });
                                ++i;
                            }
                        });
                    }
                    else
                    {
                        string ctx       = parts[1];
                        int    depth     = int.Parse(parts[2]);
                        int    line      = int.Parse(parts[3]);
                        int    sectionid = int.Parse(parts[4]);
                        MainWindow.inst().Dispatcher.Invoke(delegate() {
                            session_.CallStack.Add(new Callstack {
                                StackLevel    = depth,
                                StackFunction = ctx,
                                SectionID     = sectionid,
                                Line          = line
                            });
                        });
                    }
                }
                else if (msg.Equals("scls"))     // List of "Script Sections"/files
                {
                    JArray array = JArray.Parse(args.Message.Substring(5));

                    foreach (JObject obj in array.Children <JObject>())
                    {
                        int    id     = obj.Property("id").Value.ToObject <int>();
                        string module = obj.Property("mod").Value.ToString();
                        string name   = obj.Property("name").Value.ToString();
                        if (module.Length == 0)
                        {
                            continue;
                        }
                        MainWindow.inst().Dispatcher.Invoke(delegate() {
                            FileData fd = session_.Files.FirstOrDefault(file => file.SectionName.Equals(name));
                            if (fd == null)
                            {
                                session_.Files.Add(new FileData {
                                    SectionName = name,
                                    Module      = module,
                                    SectionID   = id
                                });
                            }
                            else
                            {
                                fd.SectionID = id; // Faciliates "lost" connection
                            }
                        });
                    }
                }
                else if (msg.Equals("file"))     // Script code sent to us
                {
                    int    sectionID = int.Parse(parts[1]);
                    int    len       = sectionID.ToString().Length + 6;
                    string data      = args.Message.Substring(len);

                    Debugger.Debug.FileData file = session_.Files.FirstOrDefault(f => f.SectionID == sectionID);
                    if (file != null)
                    {
                        file.Code = data;
                    }
                    //??is there an else case? should presumably know the section ahead of time
                }
                else if (msg.Equals("bset"))     // Someone has set a breakpoint
                {
                    int sectionID = int.Parse(parts[1]);
                    int line      = int.Parse(parts[2]);

                    Debugger.Debug.FileData file = session_.Files.FirstOrDefault(f => f.SectionID == sectionID);
                    if (file != null)
                    {
                        Debugger.Debug.Breakpoint breakpoint = file.BreakPoints.FirstOrDefault(bp => bp.LineNumber == line);
                        if (breakpoint == null)
                        {
                            MainWindow.inst().Dispatcher.Invoke(delegate() {
                                file.BreakPoints.Add(new Breakpoint {
                                    LineNumber = line, Active = true, SectionID = sectionID, File = file.SectionName
                                });
                            });
                        }
                        else
                        {
                            breakpoint.Active = true;
                        }
                    }
                    else
                    {
                        Debugger.Debug.FileData fd = new FileData {
                            SectionID = sectionID
                        };
                    }
                }
                else if (msg.Equals("brem"))     // Someone has removed a breakpoint
                {
                    int sectionID = int.Parse(parts[1]);
                    int line      = int.Parse(parts[2]);
                    Debugger.Debug.FileData file = session_.Files.FirstOrDefault(f => f.SectionID == sectionID);
                    if (file != null)
                    {
                        Debugger.Debug.Breakpoint breakpoint = file.BreakPoints.FirstOrDefault(bp => bp.LineNumber == line);
                        if (breakpoint != null)
                        {
                            breakpoint.Active = false;
                        }
                    }
                }
                else if (msg.Equals("hitl"))     // "HitLine" current line position
                // If we had not already halted then play the beep sound if enabled
                {
                    if (!session_.IsDebugging && session_.Settings.PlayBeepSound)
                    {
                        SystemSounds.Hand.Play();
                    }
                    session_.IsDebugging = true;
                    int sectionId = int.Parse(parts[1]);
                    int line      = int.Parse(parts[2]);
                    session_.CurrentSection = sectionId;
                    session_.CurrentLine    = line;
                    MainWindow.inst().Dispatcher.Invoke(delegate() {
                        Screens.DebugScreen.inst().EditorTabs.OpenFile(sectionId, line);
                    });
                }
                else if (msg.Equals("cont"))     // Execution resumed by someone
                {
                }
                else if (msg.Equals("secm"))     //A file has been changed remotely, send a request for it
                {
                    int sectionid = int.Parse(parts[1]);
                    socket_.Send(string.Format("GETF {0}", sectionid));
                }
                else if (msg.Equals("logw"))     // Log Warning
                {
                    string m = args.Message.Substring(5);
                    MainWindow.inst().Dispatcher.Invoke(delegate() {
                        session_.Log.Add(new LogMessage {
                            MsgType = MessageType.Warning,
                            Message = JoinStringsWith(parts, 1, " ")
                        });
                    });
                }
                else if (msg.Equals("loge") || msg.Equals("erro"))     // Log Error
                {
                    string m = args.Message.Substring(5);
                    MainWindow.inst().Dispatcher.Invoke(delegate() {
                        session_.Log.Add(new LogMessage {
                            MsgType = MessageType.Error,
                            Message = JoinStringsWith(parts, 1, " ")
                        });
                    });
                }
                else if (msg.Equals("logi"))     // Log Info
                {
                    string m = args.Message.Substring(5);
                    MainWindow.inst().Dispatcher.Invoke(delegate() {
                        session_.Log.Add(new LogMessage {
                            MsgType = MessageType.Info,
                            Message = JoinStringsWith(parts, 1, " ")
                        });
                    });
                }
                else if (msg.Equals("rstr"))     // A restart message
                //TODO
                {
                }
                else
                {
                    //Unknown msg
                    MainWindow.inst().Dispatcher.Invoke(delegate() {
                        session_.Log.Add(new LogMessage {
                            MsgType = MessageType.Data,
                            Message = args.Message
                        });
                    });
                }
            }
            catch (Exception ex) {
                MainWindow.inst().Dispatcher.Invoke(delegate() {
                    session_.Log.Add(new LogMessage {
                        MsgType = MessageType.Error,
                        Message = ex.Message
                    });
                    session_.Log.Add(new LogMessage {
                        MsgType = MessageType.Info,
                        Message = args.Message
                    });
                });
            }
        }