示例#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 IEnumerable <WikiV2> GetAllWikisInACollection()
        {
            VssConnection  connection = this.Context.Connection;
            WikiHttpClient wikiClient = connection.GetClient <WikiHttpClient>();

            List <WikiV2> wikis = wikiClient.GetAllWikisAsync().SyncResult();

            foreach (WikiV2 wiki in wikis)
            {
                Context.Log("Retrieved wiki with name '{0}' in project '{1}'", wiki.Name, wiki.ProjectId);
            }

            return(wikis);
        }
示例#4
0
        public IEnumerable <WikiV2> GetAllWikisInAProject()
        {
            VssConnection  connection = this.Context.Connection;
            WikiHttpClient wikiClient = connection.GetClient <WikiHttpClient>();

            Guid projectId = ClientSampleHelpers.FindAnyProject(this.Context).Id;

            List <WikiV2> wikis = wikiClient.GetAllWikisAsync(projectId).SyncResult();

            foreach (WikiV2 wiki in wikis)
            {
                Context.Log("Retrieved wiki with name '{0}' in project '{1}'", wiki.Name, wiki.ProjectId);
            }

            return(wikis);
        }
示例#5
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);
        }