示例#1
0
        public static WikiV2 FindOrCreateCodeWiki(VssConnection connection, Guid projectId)
        {
            WikiHttpClient wikiClient = connection.GetClient <WikiHttpClient>();

            List <WikiV2> wikis        = wikiClient.GetAllWikisAsync(projectId).SyncResult();
            WikiV2        wikiToReturn = wikis != null && wikis.Count != 0
                ? wikis.Find(w => w.Type == WikiType.CodeWiki)
                : null;

            if (wikiToReturn == null)
            {
                // No code wiki existing. Create one.
                GitHttpClient        gitClient    = connection.GetClient <GitHttpClient>();
                List <GitRepository> repositories = gitClient.GetRepositoriesAsync(projectId).Result;
                Guid repositoryId = repositories[0].Id;

                var createParameters = new WikiCreateParametersV2()
                {
                    Name         = "sampleCodeWiki",
                    ProjectId    = projectId,
                    RepositoryId = repositoryId,
                    Type         = WikiType.CodeWiki,
                    MappedPath   = "/",    // any folder path in the repository
                    Version      = new GitVersionDescriptor()
                    {
                        Version = "main"
                    }
                };

                wikiToReturn = wikiClient.CreateWikiAsync(createParameters).SyncResult();
            }

            return(wikiToReturn);
        }
示例#2
0
        public static WikiV2 FindOrCreateProjectWiki(ClientSampleContext context)
        {
            VssConnection  connection = context.Connection;
            WikiHttpClient wikiClient = connection.GetClient <WikiHttpClient>();

            Guid projectId = ClientSampleHelpers.FindAnyProject(context).Id;

            List <WikiV2> wikis        = wikiClient.GetAllWikisAsync(projectId).SyncResult();
            WikiV2        wikiToReturn = wikis != null && wikis.Count != 0
                ? wikis.Find(w => w.Type == WikiType.ProjectWiki)
                : null;

            if (wikiToReturn == null)
            {
                // No project wiki existing. Create one.
                var createParameters = new WikiCreateParametersV2()
                {
                    Name      = "sampleProjectWiki",
                    ProjectId = projectId,
                    Type      = WikiType.ProjectWiki
                };

                wikiToReturn = wikiClient.CreateWikiAsync(createParameters).SyncResult();
            }

            return(wikiToReturn);
        }
示例#3
0
        public WikiV2 CreateCodeWiki()
        {
            VssConnection  connection = this.Context.Connection;
            GitHttpClient  gitClient  = connection.GetClient <GitHttpClient>();
            WikiHttpClient wikiClient = connection.GetClient <WikiHttpClient>();

            Guid projectId = ClientSampleHelpers.FindAnyProject(this.Context).Id;
            List <GitRepository> repositories = gitClient.GetRepositoriesAsync(projectId).Result;

            WikiV2 createdWiki  = null;
            Guid   repositoryId = repositories[0].Id;

            var createParameters = new WikiCreateParametersV2()
            {
                Name         = "sampleCodeWiki",
                ProjectId    = projectId,
                RepositoryId = repositoryId,
                Type         = WikiType.CodeWiki,
                MappedPath   = "/",    // any folder path in the repository
                Version      = new GitVersionDescriptor()
                {
                    Version = "master"
                }
            };

            createdWiki = wikiClient.CreateWikiAsync(createParameters).SyncResult();

            Context.Log("Created wiki with name '{0}' in project '{1}'", createdWiki.Name, createdWiki.ProjectId);

            // Cleanup
            ClientSampleHttpLogger.SetSuppressOutput(this.Context, true);
            wikiClient.DeleteWikiAsync(createdWiki.Id).SyncResult();

            return(createdWiki);
        }
示例#4
0
        protected override WikiV2 DoNewItem()
        {
            var(tpc, tp) = GetCollectionAndProject();
            var isProjectWiki = GetParameter <bool>(nameof(NewWiki.ProjectWiki));

            var createParams = new WikiCreateParametersV2()
            {
                Name      = GetParameter <string>(nameof(NewWiki.Wiki)),
                Type      = isProjectWiki ? WikiType.ProjectWiki : WikiType.CodeWiki,
                ProjectId = tp.Id
            };

            if (createParams.Type == WikiType.CodeWiki)
            {
                var repo = GetItem <GitRepository>(new {
                    Repository = GetParameter <object>(nameof(NewWiki.Repository)),
                    Project    = tp
                });

                createParams.RepositoryId = repo.Id;
            }

            var client = GetClient <WikiHttpClient>();

            return(client.CreateWikiAsync(createParams)
                   .GetResult("Error creating Wiki repository"));
        }
示例#5
0
        public static WikiV2 FindOrCreateProjectWiki(VssConnection connection, Guid projectId, string wikiName = "sampleProjectWiki")
        {
            var(wikiToReturn, wikiClient) = FindProjectWiki(connection, projectId);

            if (wikiToReturn == null)
            {
                // No project wiki existing. Create one.
                var createParameters = new WikiCreateParametersV2()
                {
                    Name      = wikiName,
                    ProjectId = projectId,
                    Type      = WikiType.ProjectWiki
                };

                wikiToReturn = wikiClient.CreateWikiAsync(createParameters).SyncResult();
            }

            return(wikiToReturn);
        }
示例#6
0
        public WikiV2 CreateProjectWikiIfNotExisting()
        {
            VssConnection  connection = this.Context.Connection;
            WikiHttpClient wikiClient = connection.GetClient <WikiHttpClient>();

            Guid          projectId = ClientSampleHelpers.FindAnyProject(this.Context).Id;
            List <WikiV2> wikis     = wikiClient.GetAllWikisAsync(projectId).SyncResult();

            WikiV2 createdWiki           = null;
            var    isProjectWikiExisting = false;

            if (wikis != null && wikis.Count > 0)
            {
                isProjectWikiExisting = wikis.Where(wiki => wiki.Type.Equals(WikiType.ProjectWiki)).Any();
            }

            if (isProjectWikiExisting == false)
            {
                // No project wiki existing. Create one.
                var createParameters = new WikiCreateParametersV2()
                {
                    Name      = "sampleProjectWiki",
                    ProjectId = projectId,
                    Type      = WikiType.ProjectWiki
                };

                createdWiki = wikiClient.CreateWikiAsync(createParameters).SyncResult();

                Context.Log("Created wiki with name '{0}' in project '{1}'", createdWiki.Name, createdWiki.ProjectId);
            }
            else
            {
                Context.Log("Project wiki already exists for this project.");
            }

            return(createdWiki);
        }