/// <summary> /// Lists the confluence items. /// </summary> /// <param name="cmdArgs">The command-line args.</param> private static int ListConfluenceItems(ConsoleArgs cmdArgs) { var exitCode = 0; var isValid = false; var output = string.Empty; if (string.IsNullOrEmpty(cmdArgs.Source)) { WriteToOutput("Confluence URL not specified", OutputType.Error); exitCode = 2; } else if (string.IsNullOrEmpty(cmdArgs.User)) { WriteToOutput("Username not specified", OutputType.Error); exitCode = 3; } else if (string.IsNullOrEmpty(cmdArgs.Password)) { WriteToOutput("Password not specified", OutputType.Error); exitCode = 4; } else if (string.IsNullOrEmpty(cmdArgs.Destination)) { WriteToOutput("Output path not specified", OutputType.Error); exitCode = 5; } else { isValid = true; output = cmdArgs.Destination; if (!Path.IsPathRooted(output)) { output = Path.Combine(Environment.CurrentDirectory, output); } } if (isValid) { var stopwatch = new Stopwatch(); stopwatch.Start(); WriteToOutput("Retrieving Confluence items from " + cmdArgs.Source, OutputType.Info); var count = 0; try { var binding = new BasicHttpBinding(); binding.MaxReceivedMessageSize = int.MaxValue; var client = new ConfluenceSoapServiceClient( binding, new EndpointAddress(cmdArgs.Source)); try { var session = client.login(cmdArgs.User, cmdArgs.Password); try { var pages = client.getPages(session, "CCNET"); var document = new XDocument(); if (File.Exists(output)) { document = XDocument.Load(output); } // Make sure there is a root element var rootEl = document.Root; if (rootEl == null) { rootEl = new XElement( "confluence", new XAttribute("space", "CCNET")); document.Add(rootEl); } foreach (var page in pages) { // Attempt to find each page var pageId = page.id.ToString(); var pageEl = (from element in rootEl.Elements("page") where element.Attribute("id").Value == pageId select element).SingleOrDefault(); if (pageEl == null) { // If the page does not exist, add it pageEl = new XElement( "page", new XAttribute("title", page.title), new XAttribute("id", pageId), new XAttribute("url", page.url), new XAttribute("parentId", page.parentId.ToString())); rootEl.Add(pageEl); count++; WriteToOutput("New item added: " + page.title, OutputType.Info); } } if (count > 0) { // Order all the elements var newDoc = new XDocument( new XElement("confluence", new XAttribute("space", "CCNET"))); newDoc.Root.Add(from element in document.Root.Elements() orderby element.Attribute("title").Value select element); newDoc.Save(output); WriteToOutput("Document updated", OutputType.Info); } } finally { client.logout(session); } } catch (Exception error) { WriteToOutput("ERROR: " + error.Message, OutputType.Error); exitCode = 10; } } catch (Exception error) { WriteToOutput("ERROR: " + error.Message, OutputType.Error); exitCode = 10; } stopwatch.Stop(); WriteToOutput( count.ToString() + " new confluence items retrieved in " + stopwatch.Elapsed.TotalSeconds.ToString("#,##0.00") + "s", OutputType.Info); } return exitCode; }