多次添加同一成员以使用添加卡trello聚集,但不起作用
问题
当我输入相同的用户名时,例如
{ "adwin", "adwin", "robert", "dave"}
如果第一个广告赢得循环添加成员是可以的,那么第二个广告赢得时间添加。
代码退出循环并停止工作。
和
当我输入的用户名不在板上,或者用户名是假的。
{ "hghg$*#hgh", "us7s5209hf9", "8shjd76dhj3" }
当添加卡完成并开始添加会员时,它将停止工作并退出程序。
添加另一个用户名是无法完成的。
计划
我认为在添加卡片之前将成员添加到董事会中是可行的,但不会再次生效。
#r"Manatee.Trello.dll"
#r"Manatee.Json.dll"
using System.Net;
using System.ComponentModel;
using System.Drawing;
using System.Windows;
using Manatee.Trello;
using Manatee.Json;
public static async Task<HttpResponseMessage> Run(HttpRequestMessage req, TraceWriter log)
{
string Appkey = "df45ee60b0ff10c19377354490f7054b";
string Token = "6af303020a7a4d24d9cf5a1dd8adf2e5ff95c46888b0371c0b2dba45b2a32d7d";
string BoardID = "5b40363293193091c1ba5013";
string ListID = "5b40363293193091c1ba5015";
string name ="CardAddMember";
string description ="desccccc";
string duedate ="2019-08-04";
string iscomplete =true;
string[] user = {"userinboard","notusername","userinboard"};
try
{
DateTime duedatetime = DateTime.Parse(duedate);//time
bool torf = Boolean.Parse(iscomplete);//finish work check
TrelloAuthorization.Default.AppKey = Appkey;
TrelloAuthorization.Default.UserToken = Token;
ITrelloFactory factory = new TrelloFactory();
var List = factory.List(ListID);
var Board = factory.Board(BoardID);
//var MemberType = factory.Board();
char[] commaSeparator = new char[] { ',' };
string[] authors = username.Split(commaSeparator, StringSplitOptions.None);
var card = await List.Cards.Add(name, description, null, duedatetime, torf, null, null);//add card to trello
foreach (string author in authors){
var Member = factory.Member(author);
await Board.Memberships.Add(Member); // Add member in a board but cant add <<<<<<<<<????????
await card.Members.Add(Member); //add member in card
}
var response = new HttpResponseMessage(HttpStatusCode.OK);
return response;
}
catch //find some err [example not find user]
{
return new HttpResponseMessage(HttpStatusCode.NotFound);
}
}
我该怎么办?Cr.marc_s编辑世界
在添加成员之前,您需要检查这些成员。当您尝试将成员添加到板/卡中,但该成员已存在时,Trello会返回错误。反过来,这将导致海牛.特雷洛抛出一个异常。
此外,一个成员必须属于一个董事会,然后才能被分配到一张卡片上。
首先检查这些成员应该可以解决您的问题。
await Board.Memberships.Refresh(); // this will fetch all of the members of the board
foreach (string author in authors){
var Member = factory.Member(author);
if (!Board.Memberships.Any(m => m.Member == Member))
await Board.Memberships.Add(Member);
if (!Card.Members.Contains(Member))
await card.Members.Add(Member);
}
这应该可以解决您看到的问题。
最后,当您捕捉到异常时,指定异常以及可能的打印或记录结果是很有帮助的。Trello非常擅长返回带有失败响应的错误消息,以及Manatee。Trello将把它们包含在其TrelloInteractionException
s中。