public static void ShowContentWindow(string description, InstanceValue inst, WndType wndType) { lock (_lock) { var list = _unlockledWindows[(int)wndType]; if (list.Count > 0) { var node = list.First; list.RemoveFirst(); list.AddLast(node); node.Value.UpdateInstanceValue(inst, description); return; } int id = Utils.GetNewID(); IValueWindow wnd = null; switch (wndType) { case WndType.Content: wnd = new ContentDisplay(id, description != null ? description : inst.GetDescription(), inst) { Owner = GuiUtils.MainWindowInstance }; break; case WndType.Tree: wnd = new ClassStructDisplay(id, inst.GetDescription(), inst) { Owner = GuiUtils.MainWindowInstance }; break; case WndType.List: wnd = new CollectionDisplay(id, inst.GetDescription(), inst) { Owner = GuiUtils.MainWindowInstance }; break; case WndType.KeyValues: wnd = new KeyValueCollectionDisplay(id, inst.GetDescription(), inst) { Owner = GuiUtils.MainWindowInstance }; break; } if (wnd == null) { throw new MdrDeskException("[ValueWindows.ShowContentWindow] Creating content window failed."); } _wndDct.Add(id, wnd); if (!wnd.Locked) { list.AddFirst(wnd); } ((Window)wnd).Show(); } }
private async void GetInstanceValue(TreeViewItem selTreeItem, InstanceValue selInstValue, bool rawValue = false) { if (TypeExtractor.IsString(selInstValue.Kind)) { if (selInstValue.Value.IsLong()) { ValueWindows.ShowContentWindow(selInstValue.GetDescription(), selInstValue, ValueWindows.WndType.Content); } return; } if (selInstValue.HaveFields()) { return; // already has values } ulong addr = _mainWindow.GetAddressFromEntry(selInstValue.Value.FullContent); if (selInstValue.Address != Constants.InvalidAddress && addr != Constants.InvalidAddress && addr == selInstValue.Address) { if (!rawValue) // if known collection show it in a collection window { if (TypeExtractor.IsKnownType(selInstValue.TypeName)) { var msg = "Getting object value at: " + Utils.RealAddressString(selInstValue.Address); _mainWindow.ExecuteInstanceValueQuery(msg, selInstValue.Address); return; } } var index = MainWindow.CurrentIndex; StatusText.Text = "Getting value at address: " + selInstValue.Address + ", please wait..."; Mouse.OverrideCursor = Cursors.Wait; (string error, InstanceValue[] fields) = await Task.Factory.StartNew(() => { return(index.GetInstanceValueFields(selInstValue.Address, selInstValue.Parent)); }, _mainWindow.DumpSTAScheduler); if (Utils.IsInformation(error)) { StatusText.Text = error; } else { StatusText.Text = "Getting fields at address: " + selInstValue.Address + (fields != null ? ", done." : ", failed."); } Mouse.OverrideCursor = null; if (error != null && !Utils.IsInformation(error)) { GuiUtils.ShowError(error, this); return; } if (fields.Length < 1) { return; } if (fields.Length == 1 && fields[0].IsArray()) { ValueWindows.ShowContentWindow(fields[0].GetDescription(), fields[0], ValueWindows.WndType.List); return; } if (fields.Length > 0) { selInstValue.SetFields(fields); for (int i = 0, icount = fields.Length; i < icount; ++i) { var fld = fields[i]; var tvNode = new TreeViewItem { Header = GuiUtils.GetInstanceValueStackPanel(fld), Tag = fld }; selTreeItem.Items.Add(tvNode); } } selTreeItem.ExpandSubtree(); } else { StatusText.Text = "Value for " + selInstValue.TypeName + " cannot be expanded."; return; } }