public WikiPageMoveResponse ReorderWikiPage()
        {
            VssConnection  connection = this.Context.Connection;
            WikiHttpClient wikiClient = connection.GetClient <WikiHttpClient>();

            WikiV2 wiki = Helpers.FindOrCreateProjectWiki(this.Context);

            var pageCreateParameters = new WikiPageCreateOrUpdateParameters()
            {
                Content = "Wiki page content",
            };

            var randomNumber = new Random().Next(1, 999);
            // First page
            string           firstPagePath     = "SamplePage" + randomNumber;
            WikiPageResponse firstPageResponse = wikiClient.CreateOrUpdatePageAsync(
                pageCreateParameters,
                project: wiki.ProjectId,
                wikiIdentifier: wiki.Name,
                path: firstPagePath,
                Version: null).SyncResult();

            Context.Log("Created page '{0}' in wiki '{1}'", firstPageResponse.Page.Path, wiki.Name);

            // Second page
            string           secondPagePath     = "SamplePage" + (randomNumber + 1);
            WikiPageResponse secondPageResponse = wikiClient.CreateOrUpdatePageAsync(
                pageCreateParameters,
                project: wiki.ProjectId,
                wikiIdentifier: wiki.Name,
                path: secondPagePath,
                Version: null).SyncResult();

            Context.Log("Created page '{0}' in wiki '{1}'", secondPageResponse.Page.Path, wiki.Name);

            var pageMoveParameters = new WikiPageMoveParameters()
            {
                Path     = firstPagePath,
                NewPath  = firstPagePath,
                NewOrder = 0
            };

            WikiPageMoveResponse pageMoveResponse = wikiClient.CreatePageMoveAsync(
                pageMoveParameters: pageMoveParameters,
                project: wiki.ProjectId,
                wikiIdentifier: wiki.Name).SyncResult();

            Context.Log("Page '{0}' moved to order '{1}'", pageMoveResponse.PageMove.Path, pageMoveResponse.PageMove.NewOrder);

            // Cleanup
            ClientSampleHttpLogger.SetSuppressOutput(this.Context, true);
            wikiClient.DeletePageAsync(wiki.ProjectId, wiki.Id, firstPagePath).SyncResult();
            wikiClient.DeletePageAsync(wiki.ProjectId, wiki.Id, secondPagePath).SyncResult();

            return(pageMoveResponse);
        }
Exemple #2
0
        public static int GetAnyWikiPageId(ClientSampleContext context, WikiV2 wiki)
        {
            string         path       = GetAnyWikiPagePath(context, wiki);
            VssConnection  connection = context.Connection;
            WikiHttpClient wikiClient = connection.GetClient <WikiHttpClient>();

            WikiPage anyPage = wikiClient.GetPageAsync(
                project: wiki.ProjectId,
                wikiIdentifier: wiki.Id,
                path: path,
                recursionLevel: VersionControlRecursionType.OneLevel).SyncResult().Page;

            if (!anyPage.Id.HasValue)
            {
                WikiPageCreateOrUpdateParameters parameters = new WikiPageCreateOrUpdateParameters()
                {
                    Content = "Wiki page content"
                };

                WikiPageResponse wikiPageResponse = wikiClient.CreateOrUpdatePageAsync(
                    parameters,
                    project: wiki.ProjectId,
                    wikiIdentifier: wiki.Id,
                    path: "SamplePage" + new Random().Next(1, 999),
                    Version: null).SyncResult();

                context.Log("Create page '{0}' in wiki '{1}'", wikiPageResponse.Page.Path, wiki.Name);

                anyPage = wikiPageResponse.Page;
            }

            return(anyPage.Id.Value);
        }
Exemple #3
0
        public async Task Run(string input, ILogger log)
#endif
        {
            string sb = await GenerateReleaseNotesMarkdown();

            string iterationName = await GetCurrentIterationName();

            using (WikiHttpClient wikiHttpClient = new WikiHttpClient(_uri, credentials))
            {
                try
                {
                    WikiPageResponse wikiPage = await wikiHttpClient.GetPageAsync(_project, _wikiName, $"/{iterationName}");

                    await wikiHttpClient.CreateOrUpdatePageAsync(new WikiPageCreateOrUpdateParameters()
                    {
                        Content = sb.ToString()
                    }, _project, _wikiName, $"/{iterationName}", wikiPage.ETag.First().ToString(), $"Updated on release notes on {DateTime.UtcNow}(UTC)");
                }
                catch (VssServiceException ex)
                {
                    /*
                     * What an ugly pattern to code with!
                     * Had to do this since the GetPageAsync call throws exception if page is not found.
                     * Hopefully, I fix this in the future.
                     */
                    log.LogInformation("Service exception raised. Assumed that the wiki page does not exist. Trying to create one.");
                    await wikiHttpClient.CreateOrUpdatePageAsync(new WikiPageCreateOrUpdateParameters()
                    {
                        Content = sb.ToString()
                    }, _project, _wikiName, $"/{iterationName}", null, $"Added release notes for {iterationName}");
                }
                catch
                {
                    throw;
                }
            }
            log.LogInformation("Completed execution. Please check your wiki for your release notes.");
        }
Exemple #4
0
        public static WikiPageResponse CreatePage(ClientSampleContext context, WikiV2 wiki, string path)
        {
            VssConnection  connection = context.Connection;
            WikiHttpClient wikiClient = connection.GetClient <WikiHttpClient>();

            WikiPageCreateOrUpdateParameters parameters = new WikiPageCreateOrUpdateParameters()
            {
                Content = "Wiki page content"
            };

            WikiPageResponse wikiPageResponse = wikiClient.CreateOrUpdatePageAsync(
                parameters,
                project: wiki.ProjectId,
                wikiIdentifier: wiki.Id,
                path: path,
                Version: null).SyncResult();

            return(wikiPageResponse);
        }
Exemple #5
0
        public WikiPageResponse EditWikiPage()
        {
            VssConnection  connection = this.Context.Connection;
            WikiHttpClient wikiClient = connection.GetClient <WikiHttpClient>();

            WikiV2 wiki         = Helpers.FindOrCreateProjectWiki(this.Context);
            string somePagePath = Helpers.GetAnyWikiPagePath(this.Context, wiki);

            WikiPageResponse pageResponse = wikiClient.GetPageAsync(
                project: wiki.ProjectId,
                wikiIdentifier: wiki.Name,
                path: somePagePath,
                includeContent: true).SyncResult();

            WikiPage somePage = pageResponse.Page;

            Context.Log("Retrieved page '{0}' as JSON in wiki '{1}' with content '{2}'", somePage.Path, wiki.Name, somePage.Content);

            var originalContent = somePage.Content;
            var originalVersion = pageResponse.ETag.ToList()[0];

            WikiPageCreateOrUpdateParameters parameters = new WikiPageCreateOrUpdateParameters()
            {
                Content = "New content for page"
            };

            WikiPageResponse editedPageResponse = wikiClient.CreateOrUpdatePageAsync(
                parameters: parameters,
                project: wiki.ProjectId,
                wikiIdentifier: wiki.Name,
                path: somePagePath,
                Version: originalVersion).SyncResult();

            var updatedContent = editedPageResponse.Page.Content;
            var updatedVersion = editedPageResponse.ETag.ToList()[0];

            Context.Log("Before editing --> Page path: {0}, version: {1}, content: {2}", somePage.Path, originalVersion, originalContent);
            Context.Log("After editing --> Page path: {0}, version: {1}, content: {2}", somePage.Path, updatedVersion, updatedContent);

            return(editedPageResponse);
        }
Exemple #6
0
        public WikiPageResponse CreateWikiPage()
        {
            VssConnection  connection = this.Context.Connection;
            WikiHttpClient wikiClient = connection.GetClient <WikiHttpClient>();

            WikiV2 wiki = Helpers.FindOrCreateProjectWiki(this.Context);
            WikiPageCreateOrUpdateParameters parameters = new WikiPageCreateOrUpdateParameters()
            {
                Content = "Wiki page content"
            };

            WikiPageResponse wikiPageResponse = wikiClient.CreateOrUpdatePageAsync(
                parameters,
                project: wiki.ProjectId,
                wikiIdentifier: wiki.Id,
                path: "SamplePage" + new Random().Next(1, 999),
                Version: null).SyncResult();

            Context.Log("Create page '{0}' in wiki '{1}'", wikiPageResponse.Page.Path, wiki.Name);

            return(wikiPageResponse);
        }