我正在尝试使用 Microsoft Graph 创建 Microsoft 团队网站的完整克隆,方法是对团队网站进行基本克隆,然后使用 API 复制和配置所有内容。
我的第一个任务是复制 Planner。我已经足够复制所有可用的计划、桶和任务。
我的问题是我无法弄清楚:
1) 该计划属于旧团队中的哪个选项卡/位置
2) 如何将新计划放入新团队中的所述选项卡/位置
public async Task<IEnumerable<Channel>> GetChannels(string accessToken, string teamId) {
string endpoint = $"{GraphRootUri}/teams/{teamId}/channels";
HttpResponseMessage response =
await ServiceHelper.SendRequest(HttpMethod.Get, endpoint, accessToken); //old functionality of stolen method - ignore these two lines
string destinationTeamID = "Teamid";
//find all plans
endpoint = $"{GraphRootUri}/groups/{teamId}/planner/plans";
HttpResponseMessage responsePlans = await ServiceHelper.SendRequest(HttpMethod.Get, endpoint, accessToken);
var plansIn = await ParseList<Planner>(responsePlans);
//the following two sections are just me seeing if I can find references to the plans
endpoint = $"{GraphRootUri}/teams/{teamId}/channels";
HttpResponseMessage responseChannels = await ServiceHelper.SendRequest(HttpMethod.Get, endpoint, accessToken);
var inChannels = await responseChannels.Content.ReadAsStringAsync();
endpoint = $"{GraphRootUri}/teams/{teamId}/channels/mychannellocation/tabs";
HttpResponseMessage responseTabs = await ServiceHelper.SendRequest(HttpMethod.Get, endpoint, accessToken);
var inTabs = await responseTabs.Content.ReadAsStringAsync();
//the following code copies the plans, buckets and tasks
foreach (Planner plan in plansIn) {
//first we get everything from the previous team plan
//grab tasks from the previous plan
endpoint = $"{GraphRootUri}/planner/plans/{plan.id}/tasks";
HttpResponseMessage responseTasks = await ServiceHelper.SendRequest(HttpMethod.Get, endpoint, accessToken);
var inTasks = await ParseList<plannerTask>(responseTasks);
//get all buckets
endpoint = $"{GraphRootUri}/planner/plans/{plan.id}/buckets";
HttpResponseMessage responseBuckets = await ServiceHelper.SendRequest(HttpMethod.Get, endpoint, accessToken);
var inBuckets = await ParseList<plannerBucket>(responseBuckets);
endpoint = $"{GraphRootUri}/planner/tasks";
//HttpResponseMessage responseTasks = await ServiceHelper.SendRequest(HttpMethod.Get, endpoint, accessToken);
// .content .Deserialize<plannerPlan>(); ;
//then we start to create everything in the new team
//create the plan in the new team
endpoint = $"{GraphRootUri}/planner/plans";
var sendPlanResponse =
await ServiceHelper.SendRequest(HttpMethod.Post, endpoint, accessToken, new plannerStub(plan, destinationTeamID));
var newPlanString = await sendPlanResponse.Content.ReadAsStringAsync();
//get the created plan
var newPlan = JsonConvert.DeserializeObject<Planner>(newPlanString);
//create buckets in the new team
Dictionary<string, string> bucketIdMap = new Dictionary<string, string>();
foreach (plannerBucket bucket in inBuckets) {
endpoint = $"{GraphRootUri}/planner/buckets";
var outBucket = new plannerBucketStub(bucket, newPlan.id);
var sendBucketResponse =
await ServiceHelper.SendRequest(HttpMethod.Post, endpoint, accessToken, new plannerStub(plan, destinationTeamID));
//get the created Bucket
var newBucket = JsonConvert.DeserializeObject<plannerBucket>(await sendPlanResponse.Content.ReadAsStringAsync());
bucketIdMap[bucket.id] = newBucket.id; //so we can send the tasks to our new bucket
}
//create tasks in the new team
foreach (plannerTask task in inTasks) {
endpoint = $"{GraphRootUri}/planner/tasks";
task.bucketId = bucketIdMap[task.bucketId];
task.planId = newPlan.id;
var sendBucketResponse = await ServiceHelper.SendRequest(HttpMethod.Post, endpoint, accessToken, task);
}
//put planner in appropriate tab - stuck at this point
endpoint = $"{GraphRootUri}/teams/{newPlan.id}/channels/";
}
}
之前的代码是我到目前为止所拥有的,有谁知道我如何找到旧计划员住在哪里以及如何将新计划员放在新团队的同一位置?
现在的目标团队是第一支团队的克隆。
我最好的猜测是使用规划器的“上下文”,但我找不到任何相关文档。有谁知道如何解决这个问题?编辑。我尝试使用上下文没有效果,我正式迷失了。
顺便说一句,如果有人找到了一个代码存储库,该代码存储库对 Microsoft Teams 网站进行了完整克隆,但我一直找不到,请告诉我
对于任何给我的问题足够时间阅读本文的人,非常感谢您的帮助,此时任何建议将不胜感激。
最佳答案
查找选项卡位置
您可以通过解析/v1.0/teams/{group-id}/channels/{channel-id}/tabs
返回的结果来检测 channel 选项卡的位置。由此产生teamsTab
array将以相反的顺序包含选项卡(第一个选项卡最后):
{
"@odata.context": "https://graph.microsoft.com/v1.0/$metadata#teams('{{id}}')/channels('{id}')/tabs",
"value": [
{
"id": "{id}",
"displayName": "Tab #2",
"webUrl": "{url}",
"configuration": {
"entityId": null,
"contentUrl": null,
"removeUrl": null,
"websiteUrl": null,
"wikiTabId": 1,
"wikiDefaultTab": true,
"hasContent": false
}
},
{
"id": "{id}",
"displayName": "Tab #1",
"webUrl": "{url}",
"configuration": {
"entityId": "{plan-id}",
"contentUrl": "{url}",
"removeUrl": "{url}",
"websiteUrl": "{url}",
"dateAdded": "2019-02-04T17:38:11.079Z"
}
}
]
}
请记住,“对话”和"file"实际上并不是选项卡,它们的位置是固定的。因此,两者都不会出现在 /tabs
结果中。您的代码应该假设您的 Tab 键顺序实际上从 UI 中的第三个 Tab 位置开始。
设置 Tab 位置
为了复制固定选项卡的顺序,您需要add the tabs按照您想要的顺序。如果您需要对现有选项卡重新排序,则需要首先remove them并按照您想要的顺序重新创建它们。
关于c# - 如何找出计划属于哪个选项卡/位置?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54510392/