private static void ImportQuery(WorkItemQueryInfo query, QueryHierarchy queryHierarchy)
        {
            var currentFolder = queryHierarchy.OfType <QueryFolder>().FirstOrDefault(i => !i.IsPersonal);

            if (currentFolder == null)
            {
                throw new InvalidOperationException("The query hierarchy does not contain a shared (non-personal) root folder.");
            }
            var currentFolderNameIndex = 0;
            var pathComponents         = (query.Path ?? string.Empty).Split('/');

            while (currentFolderNameIndex < pathComponents.Length)
            {
                var childFolderName = pathComponents[currentFolderNameIndex];
                if (currentFolder.Contains(childFolderName))
                {
                    var itemWithName = currentFolder[childFolderName];
                    if (itemWithName is QueryDefinition)
                    {
                        throw new ArgumentException("A query folder was requested but a query file with the same name exists at the same location: " + childFolderName);
                    }
                    else
                    {
                        currentFolder = (QueryFolder)itemWithName;
                    }
                }
                else
                {
                    if (!string.IsNullOrEmpty(childFolderName))
                    {
                        // If childFolderName is empty then we import into the root, otherwise create the folder.
                        var newFolder = new QueryFolder(childFolderName);
                        currentFolder.Add(newFolder);
                        currentFolder = newFolder;
                    }
                }
                currentFolderNameIndex++;
            }

            if (currentFolder.Contains(query.Name))
            {
                var itemWithName = currentFolder[query.Name];
                if (itemWithName is QueryFolder)
                {
                    throw new ArgumentException("A query file was requested but a query folder with the same name exists at the same location: " + query.Name);
                }
                else
                {
                    var existingQuery = (QueryDefinition)itemWithName;
                    existingQuery.QueryText = query.Text;
                }
            }
            else
            {
                var newQuery = new QueryDefinition(query.Name, query.Text);
                currentFolder.Add(newQuery);
            }
        }
 public WorkItemQueryExport(WorkItemQueryInfo query, string saveAsFileName)
 {
     this.Query          = query;
     this.SaveAsFileName = saveAsFileName;
 }