private async void Session_Load(object sender, RoutedEventArgs e)
        {
            SwagDataSet sdsSession = null;

            SwagWindow.GlobalIsBusy = true;
            await Task.Run(() =>
            {
                sdsSession = SwagWPFContainer.SwagDataService.SwagDataSets.Where(sds => sds.Display == SessionName).FirstOrDefault();
            });

            if (sdsSession != null)
            {
                SwagWPFContainer.SwagDataService.Init(sdsSession);
                SwagDataSet = sdsSession;
                SwagItemPreOrderIterator <SwagData> itrSwagData = SwagDataSet.CreateIterator();
                for (SwagData sd = itrSwagData.First(); !itrSwagData.IsDone; sd = itrSwagData.Next())
                {
                    if (sd is SwagDataTable sdt)
                    {
                        if (!sdt.IsInitialized)
                        {
                            SwagDataGrid.InitSwagDataTable(sdt);
                        }
                        sdt.FilterCommand.Execute(null);
                    }
                }
            }
            SwagWindow.GlobalIsBusy = false;
        }
        private async void Session_Save(object sender, RoutedEventArgs e)
        {
            SwagDataSet.Display = SessionName;
            SwagItemPreOrderIterator <SwagData> itrSwagData = SwagDataSet.CreateIterator();

            SwagWindow.GlobalIsBusy = true;

            await Task.Run(() =>
            {
                for (SwagData sd = itrSwagData.First(); !itrSwagData.IsDone; sd = itrSwagData.Next())
                {
                    if (sd is SwagDataTable sdt && !sdt.IsInitialized)
                    {
                        SwagDataGrid.InitSwagDataTable(sdt);
                    }
                }
            });

            SwagDataSet sdsSession = SwagWPFContainer.SwagDataService.SwagDataSets.Where(sds => sds.Display == SessionName).FirstOrDefault();

            if (sdsSession == SwagDataSet)
            {
                SwagWPFContainer.SwagDataService.SwagDataSets.Update(SwagDataSet);
            }
            else
            {
                SwagWPFContainer.SwagDataService.SwagDataSets.Add(SwagDataSet);
            }
            SwagWindow.GlobalIsBusy = false;
            SwagWPFContainer.SwagDataService.Save();
        }
        private async void Search_OnSearch(object sender, RoutedEventArgs e)
        {
            SearchTextBox searchTextBox = (SearchTextBox)sender;
            SwagData      swagData      = (SwagData)((SwagTabItem)searchTextBox.DataContext).ViewModel;
            SwagItemPreOrderIterator <SwagData> itrSwagData = SwagDataSet.CreateIterator();

            SwagWindow.GlobalIsBusy = true;
            await Task.Run(() =>
            {
                for (SwagData sd = itrSwagData.First(); !itrSwagData.IsDone; sd = itrSwagData.Next())
                {
                    if (sd is SwagDataTable sdg && !sdg.IsInitialized)
                    {
                        SwagDataGrid.InitSwagDataTable(sdg);
                    }
                }
            });

            SwagWindow.GlobalIsBusy = false;

            SwagDataResult swagDataResult = SwagDataSet.Search(searchTextBox.Text, searchTextBox.FilterMode,
                                                               (sdc, sdr, searchValue, filterMode) =>
            {
                String compareTarget = sdr.DataRow[sdc.ColumnName].ToString();
                String compareValue  = searchValue;
                return(SearchHelper.Evaluate(compareTarget, compareValue, false, filterMode, false));
            });

            swagData.SwagDataResult = swagDataResult;
        }
        private void SwagDataSetHeader_Export(object sender, RoutedEventArgs e)
        {
            FrameworkElement fe            = (FrameworkElement)sender;
            SwagDataSet      swagDataSet   = (SwagDataSet)fe.DataContext;
            ParseStrategy    parseStrategy = (ParseStrategy)fe.Tag;

            switch (parseStrategy)
            {
            case ParseStrategy.Sqlite:
                SaveFileDialog sfdSqlite = new SaveFileDialog();
                sfdSqlite.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
                sfdSqlite.FileName         = Path.ChangeExtension(swagDataSet.Display, null);
                sfdSqlite.Filter           = "SQLite files (*.db;*.sqlite)|*.db;*.sqlite";
                System.Windows.Application.Current.Dispatcher.Invoke(new Action(() =>
                {
                    if (sfdSqlite.ShowDialog() ?? false)
                    {
                        DataSetSqliteFileConverter dsConverter = new DataSetSqliteFileConverter();
                        dsConverter.FromDataSet(null, swagDataSet.GetDataSet(), sfdSqlite.FileName);
                    }
                }));
                break;

            case ParseStrategy.Csv:
                System.Windows.Forms.FolderBrowserDialog fbdCsv = new System.Windows.Forms.FolderBrowserDialog();
                fbdCsv.SelectedPath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
                System.Windows.Application.Current.Dispatcher.Invoke(new Action(() =>
                {
                    if (fbdCsv.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                    {
                        DataSetCsvFileConverter dsConverter = new DataSetCsvFileConverter();

                        SwagItemPreOrderIterator <SwagData> itrSwagData = swagDataSet.CreateIterator();
                        swagDataSet.Display = swagDataSet.Display ?? "DataSet";
                        for (SwagData sd = itrSwagData.First(); !itrSwagData.IsDone; sd = itrSwagData.Next())
                        {
                            if (sd is SwagDataSet sds)
                            {
                                String destFolder = "";

                                //If exporting root and root has blank display, use DataSet
                                if (swagDataSet == SwagDataSet && string.IsNullOrEmpty(swagDataSet.Display))
                                {
                                    destFolder = Path.Combine(fbdCsv.SelectedPath, "DataSet", sds.Path);
                                }
                                else
                                {
                                    destFolder = Path.Combine(fbdCsv.SelectedPath, sds.Path);
                                }

                                //limit to depth of 1 when exporting DataSet
                                dsConverter.FromDataSet(null, sds.GetDataSet(1), destFolder);
                            }
                        }
                    }
                }));
                break;
            }
        }
        public static void InitSwagDataSet(SwagDataSet swagDataSet)
        {
            #region FilterTabsCommand
            SwagItemPreOrderIterator <SwagData> itrSwagData = swagDataSet.CreateIterator();
            for (SwagData swagData = itrSwagData.First(); !itrSwagData.IsDone; swagData = itrSwagData.Next())
            {
                if (swagData is SwagDataSet sds)
                {
                    sds.FilterTabsCommand =
                        new RelayCommand(() =>
                    {
                        String filter         = sds.Settings["Tabs"]["Search"]["Text"].GetValue <String>();
                        FilterMode filterMode = sds.Settings["Tabs"]["Search"]["FilterMode"].GetValue <FilterMode>();
                        UIHelper.GetCollectionView(sds.Children).Filter = (item) =>
                        {
                            SwagData swagData         = (SwagData)item;
                            Boolean itemMatch         = SearchHelper.Evaluate(swagData.Display, filter, false, filterMode, false);
                            Boolean childDataSetMatch = false;

                            if (swagData is SwagDataSet subDataSet)
                            {
                                subDataSet.Settings["Tabs"]["Search"]["Text"].SetValue(filter);
                                subDataSet.Settings["Tabs"]["Search"]["FilterMode"].SetValue(filterMode);
                                subDataSet.FilterTabsCommand.Execute(null);
                                ICollectionView subchildren = UIHelper.GetCollectionView(subDataSet.Children);
                                childDataSetMatch           = !subchildren.IsEmpty;
                            }

                            return(itemMatch || childDataSetMatch);
                        };
                    });
                }
            }
            #endregion FilterTabsCommand

            #region InitSettings
            swagDataSet.Settings.TryAddChildSetting("Tabs", new SwagSettingGroup()
            {
                Icon = PackIconMaterialKind.TableSearch
            });
            swagDataSet.Settings["Tabs"].TryAddChildSetting("Search", new SwagSettingGroup()
            {
                Icon = PackIconMaterialKind.Magnify
            });
            swagDataSet.Settings["Tabs"]["Search"].TryAddChildSetting("Text", new SwagSettingString()
            {
                Icon = PackIconBoxIconsKind.RegularText
            });
            swagDataSet.Settings["Tabs"]["Search"].TryAddChildSetting("FilterMode", new SwagSetting <FilterMode>()
            {
                SettingType = SettingType.DropDown, Value = FilterMode.CONTAINS, Icon = PackIconUniconsKind.Filter, ItemsSource = (FilterMode[])Enum.GetValues(typeof(FilterMode))
            });
            swagDataSet.Settings.TryAddChildSetting("Search", new SwagSettingGroup()
            {
                Icon = PackIconMaterialKind.TextSearch
            });
            swagDataSet.Settings["Search"].TryAddChildSetting("Text", new SwagSettingString {
                Icon = PackIconBoxIconsKind.RegularText
            });
            swagDataSet.Settings["Search"].TryAddChildSetting("FilterMode", new SwagSetting <FilterMode>()
            {
                SettingType = SettingType.DropDown, Value = FilterMode.CONTAINS, Icon = PackIconUniconsKind.Filter, ItemsSource = (FilterMode[])Enum.GetValues(typeof(FilterMode))
            });
            #endregion InitSettings

            #region InitTabs
            SwagTabGroup tabs = new SwagTabGroup();
            tabs["Tabs"] = new SwagTabItem()
            {
                Icon = PackIconMaterialKind.TableSearch
            };
            tabs["Parse"] = new SwagTabGroup()
            {
                Icon = PackIconZondiconsKind.DocumentAdd
            };
            tabs["Parse"]["Paste"] = new SwagTabGroup()
            {
                Icon = PackIconZondiconsKind.Paste
            };
            tabs["Parse"]["Paste"]["TSV"] = new SwagTabItem()
            {
                Icon = PackIconMaterialKind.AlphaTBoxOutline
            };
            tabs["Parse"]["Paste"]["JSON"] = new SwagTabItem()
            {
                Icon = PackIconMaterialKind.CodeJson
            };
            tabs["Parse"]["Paste"]["XML"] = new SwagTabItem()
            {
                Icon = PackIconMaterialKind.Xml
            };
            tabs["Search"] = new SwagTabItem()
            {
                Icon = PackIconMaterialKind.TextSearch
            };
            tabs["Session"] = new SwagTabItem()
            {
                Icon = PackIconMaterialKind.WindowRestore
            };
            tabs["Test"] = new SwagTabItem()
            {
                Icon = PackIconOcticonsKind.Beaker
            };
            tabs["Settings"] = new SwagTabItem()
            {
                Icon = PackIconMaterialKind.Cog
            };
            swagDataSet.Tabs = tabs;
            SwagItemPreOrderIterator <SwagTabItem> itrTabs = tabs.CreateIterator();
            for (SwagTabItem tabItem = itrTabs.First(); !itrTabs.IsDone; tabItem = itrTabs.Next())
            {
                tabItem.ViewModel = swagDataSet;
            }
            #endregion InitTabs
        }