/FAFramework/Forms/UtilityForm/PageDebugViewState.xaml.cs
C# | 260 lines | 225 code | 32 blank | 3 comment | 37 complexity | 9860e470d15bc7e08a86de6deee1a221 MD5 | raw file
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Windows;
- using System.Windows.Controls;
- using System.Windows.Data;
- using System.Windows.Documents;
- using System.Windows.Input;
- using System.Windows.Media;
- using System.Windows.Media.Imaging;
- using System.Windows.Navigation;
- using System.Windows.Shapes;
- using System.Xml.Linq;
-
- namespace FAFramework.Forms.UtilityForm
- {
- /// <summary>
- /// PageDebugViewState.xaml에 대한 상호 작용 논리
- /// </summary>
- public partial class PageDebugViewState : Page
- {
- public PageDebugViewState()
- {
- InitializeComponent();
- }
-
- private void buttonLoadState_Click(object sender, RoutedEventArgs e)
- {
- LoadState();
- }
-
- public void LoadState()
- {
- try
- {
- string path = AppDomain.CurrentDomain.BaseDirectory
- + @"ErrorReport\";
-
- Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog();
- dlg.InitialDirectory = path;
- if ((bool)dlg.ShowDialog() == false) return;
- XElement xel = XElement.Load(dlg.FileName);
- TreeViewItem tvItem = new TreeViewItem();
- tvItem.Header = dlg.SafeFileName;
- LoadTreeView(tvItem, xel);
- treeView1.Items.Add(tvItem);
- }
- catch (Exception e)
- {
- Manager.LogManager.Instance.WriteSystemLog(e.ToString());
- }
- }
-
- private void LoadTreeView(TreeViewItem tvItem, XElement xel)
- {
- foreach (XElement item in xel.Elements())
- {
- string type = "";
- if (item.Element("Type") == null)
- continue;
- else
- type = item.Element("Type").Value;
-
- if (type == "TreeViewItem")
- {
- LoadTreeViewItem(tvItem, item);
- }
- else if (type == "Grid")
- {
- LoadGrid(tvItem, item);
- }
- else if (type == "ListView")
- {
- tvItem.Items.Add(LoadListView(item));
- }
- }
- }
-
- private void LoadTreeViewItem(TreeViewItem tvItem, XElement xel)
- {
- if (xel.Element("Value") != null)
- {
- TreeViewItem subItem = new TreeViewItem();
- if (xel.Element("Header") != null)
- subItem.Header = xel.Element("Header").Value;
- LoadTreeView(subItem, xel.Element("Value"));
- tvItem.Items.Add(subItem);
- }
- }
-
- private void LoadGrid(TreeViewItem tvItem, XElement xel)
- {
- Grid grid = new Grid();
- grid.Margin = new System.Windows.Thickness(0);
-
- foreach (XElement item in xel.Element("Value").Elements())
- {
- string type = "";
- if (item.Element("Type") == null)
- continue;
- else
- type = item.Element("Type").Value;
-
- if (type == "TreeViewItem")
- {
- LoadTreeViewItem(tvItem, item);
- }
- else if (type == "Label")
- {
- AddChildrenToGrid(grid, LoadLabel(item));
- }
- else if (type == "CheckBox")
- {
- AddChildrenToGrid(grid, LoadCheckBox(item));
- }
- else if (type == "TextBox")
- {
- AddChildrenToGrid(grid, LoadTextBox(item));
- }
- else if (type == "ListView")
- {
- AddChildrenToGrid(grid, LoadListView(item));
- }
- }
-
- tvItem.Items.Add(grid);
- }
-
- private Label LoadLabel(XElement xel)
- {
- Label label = new Label();
- label.Padding = new System.Windows.Thickness(0);
- label.Margin = new System.Windows.Thickness(0);
-
- try
- {
- label.Content = xel.Element("Value").Value;
- }
- catch
- {
- }
-
- return label;
- }
-
- private CheckBox LoadCheckBox(XElement xel)
- {
- CheckBox checkBox = new CheckBox();
- checkBox.Padding = new System.Windows.Thickness(0);
- checkBox.Margin = new System.Windows.Thickness(0);
- checkBox.VerticalAlignment = System.Windows.VerticalAlignment.Center;
-
- try
- {
- bool result = false;
- if (bool.TryParse(xel.Element("Value").Value, out result) == false)
- checkBox.IsChecked = false;
- checkBox.IsChecked = result;
- }
- catch
- {
- }
-
- return checkBox;
- }
-
- private TextBox LoadTextBox(XElement xel)
- {
- TextBox textBox = new TextBox();
- textBox.Padding = new System.Windows.Thickness(0);
- textBox.Margin = new System.Windows.Thickness(0);
-
- try
- {
- textBox.Text = xel.Element("Value").Value;
- }
- catch
- {
- }
-
- return textBox;
- }
-
- private ListView LoadListView(XElement xel)
- {
- List<object> list = new List<object>();
-
- foreach (XElement item in xel.Element("Value").Elements())
- {
- object obj = LoadListViewItem(item);
- list.Add(obj);
- }
-
- ListView listView = new ListView();
- if (list.Count > 0)
- listView.View = GetGridView((List<dynamic>)list[0]);
- listView.ItemsSource = list;
- return listView;
- }
-
- private List<dynamic> LoadListViewItem(XElement xel)
- {
- List<dynamic> list = new List<dynamic>();
- foreach (XElement item in xel.Elements())
- {
- list.Add(new { Type = item.Element("Type").Value, Name = item.Element("Name").Value, Value = item.Element("Value").Value });
- }
-
- return list;
- }
-
- private GridView GetGridView(List<dynamic> list)
- {
- GridView gridView = new GridView();
-
- int i = 0;
- foreach (dynamic item in list)
- {
- GridViewColumn col = new GridViewColumn();
- col.Header = item.Name;
- if (item.Type == "System.Boolean")
- {
- System.Windows.DataTemplate template = new System.Windows.DataTemplate();
- System.Windows.FrameworkElementFactory checkBox =
- new System.Windows.FrameworkElementFactory(typeof(CheckBox));
- checkBox.SetValue(CheckBox.VerticalAlignmentProperty, System.Windows.VerticalAlignment.Center);
- Binding bd = new Binding("[" + i.ToString() + "].Value");
- bd.Mode = BindingMode.OneTime;
-
- checkBox.SetBinding(CheckBox.IsCheckedProperty, bd);
- template.VisualTree = checkBox;
- col.CellTemplate = template;
- }
- else
- {
- col.DisplayMemberBinding = new System.Windows.Data.Binding("[" + i.ToString() + "].Value");
- }
-
- gridView.Columns.Add(col);
- i++;
- }
-
- return gridView;
- }
-
- private void AddChildrenToGrid(Grid grid, UIElement obj)
- {
- ColumnDefinition col = new ColumnDefinition();
- grid.ColumnDefinitions.Add(col);
- grid.Children.Add(obj);
- Grid.SetColumn(obj, grid.Children.Count - 1);
- }
-
- private void buttonClear_Click(object sender, RoutedEventArgs e)
- {
- treeView1.Items.Clear();
- }
- }
- }