public dynamic GetAllFoldersFromConfig()
        {
            SyncConfiguration config = GetConfiguration();
            var sharePointManager    = config.GetSharePointManager();
            var result = SharePointManager.GetAllFoldersFromConfig(config);

            return(result);
        }
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            TreeViewFolders.Items.Add(new TreeViewItem()
            {
                Header = "Please wait... Loading folders"
            });

            if (_configuration.SelectedFolders != null)
            {
                RadioSelected.IsChecked = true;
            }

            Task.Run(() =>
            {
                try
                {
                    var allFolders = SharePointManager.GetAllFoldersFromConfig(_configuration);

                    Dispatcher.BeginInvoke(new Action(() =>
                    {
                        var rootTreeItem = new FolderViewModel()
                        {
                            Name = _configuration.DocumentLibrary, Folder = "\\"
                        };

                        foreach (var folder in allFolders)
                        {
                            var split = folder.Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries);

                            var treeItem    = new FolderViewModel();
                            treeItem.Name   = split[split.Length - 1];
                            treeItem.Folder = (folder.TrimStart('/').Replace("/", "\\") + "\\").ToLowerInvariant();

                            if (split.Length == 1)
                            {
                                rootTreeItem.AddChildren(treeItem);
                            }
                            else
                            {
                                var splitFolder = string.Empty;
                                for (var i = 0; i < split.Length - 1; i++)
                                {
                                    splitFolder += split[i] + "\\";
                                }

                                FolderViewModel parent = FindTreeViewItemByFolder(rootTreeItem.Children, splitFolder);
                                // should never happen
                                if (parent == null)
                                {
                                    parent = rootTreeItem;
                                }

                                parent.AddChildren(treeItem);
                            }
                        }

                        TreeViewFolders.Items.Clear();
                        TreeViewFolders.Items.Add(rootTreeItem);

                        if (_configuration.SelectedFolders == null)
                        {
                            return;
                        }

                        foreach (var item in _configuration.SelectedFolders)
                        {
                            var fvm = FindTreeViewItemByFolder(rootTreeItem.Children, item);
                            if (fvm == null)
                            {
                                continue;
                            }

                            fvm.IsChecked = true;
                        }
                    }));
                }
                catch (Exception ex)
                {
                    Dispatcher.BeginInvoke(new Action(() =>
                    {
                        var err1TreeItem = new TreeViewItem()
                        {
                            Header = "Error getting list of folders"
                        };
                        var err2TreeItem = new TreeViewItem()
                        {
                            Header = ex.Message
                        };
                        TreeViewFolders.Items.Clear();
                        TreeViewFolders.Items.Add(err1TreeItem);
                        TreeViewFolders.Items.Add(err2TreeItem);

                        Logger.Log("Error getting folder list: {0}{1}{2}", ex.Message, Environment.NewLine, ex.StackTrace);
                    }));
                }
            });
        }