in src/VstsDemoBuilder/Services/ProjectService.cs [2573:2653]
public void CreateProjetWiki(string templatesFolder, Project model, Configuration _wikiConfiguration)
{
try
{
ManageWiki manageWiki = new ManageWiki(_wikiConfiguration);
string projectWikiFolderPath = GetJsonFilePath(model.IsPrivatePath, model.PrivateTemplatePath, model.SelectedTemplate, @"\Wiki\ProjectWiki");
//templatesFolder + model.SelectedTemplate + "\\Wiki\\ProjectWiki";
if (Directory.Exists(projectWikiFolderPath))
{
string createWiki = string.Format(templatesFolder + "\\CreateWiki.json"); // check is path
if (File.Exists(createWiki))
{
string jsonString = File.ReadAllText(createWiki);
jsonString = jsonString.Replace("$ProjectID$", model.Environment.ProjectId)
.Replace("$Name$", model.Environment.ProjectName);
ProjectwikiResponse.Projectwiki projectWikiResponse = manageWiki.CreateProjectWiki(jsonString, model.Environment.ProjectId);
string[] subDirectories = Directory.GetDirectories(projectWikiFolderPath);
foreach (var dir in subDirectories)
{
//dirName==parentName//
string[] dirSplit = dir.Split('\\');
string dirName = dirSplit[dirSplit.Length - 1];
string sampleContent = File.ReadAllText(templatesFolder + "\\SampleContent.json");
sampleContent = sampleContent.Replace("$Content$", "Sample wiki content");
bool isPage = manageWiki.CreateUpdatePages(sampleContent, model.Environment.ProjectName, projectWikiResponse.id, dirName);//check is created
if (isPage)
{
string[] getFiles = Directory.GetFiles(dir);
if (getFiles.Length > 0)
{
List<string> childFileNames = new List<string>();
foreach (var file in getFiles)
{
string[] fileNameExtension = file.Split('\\');
string fileName = (fileNameExtension[fileNameExtension.Length - 1].Split('.'))[0];
string fileContent = model.ReadJsonFile(file);
bool isCreated = false;
Dictionary<string, string> dic = new Dictionary<string, string>();
dic.Add("content", fileContent);
string newContent = JsonConvert.SerializeObject(dic);
if (fileName == dirName)
{
manageWiki.DeletePage(model.Environment.ProjectName, projectWikiResponse.id, fileName);
isCreated = manageWiki.CreateUpdatePages(newContent, model.Environment.ProjectName, projectWikiResponse.id, fileName);
}
else
{
isCreated = manageWiki.CreateUpdatePages(newContent, model.Environment.ProjectName, projectWikiResponse.id, fileName);
}
if (isCreated)
{
childFileNames.Add(fileName);
}
}
if (childFileNames.Count > 0)
{
foreach (var child in childFileNames)
{
if (child != dirName)
{
string movePages = File.ReadAllText(templatesFolder + @"\MovePages.json");
if (!string.IsNullOrEmpty(movePages))
{
movePages = movePages.Replace("$ParentFile$", dirName).Replace("$ChildFile$", child);
manageWiki.MovePages(movePages, model.Environment.ProjectId, projectWikiResponse.id);
}
}
}
}
}
}
}
}
}
}
catch (Exception ex)
{
logger.Info(DateTime.UtcNow.ToString("yyyy-MM-dd HH:mm:ss") + "\t" + "\t" + ex.Message + "\t" + "\n" + ex.StackTrace + "\n");
}
}