多次添加同一成员以及添加卡 trello 但不起作用
Add same member many time together with add card trello but don't work
多次添加同一个成员以使用添加卡 trello 收集但不起作用
问题
当我输入相同的用户名时,例如
{ "adwin", "adwin", "robert", "dave"}
如果第一次adwin结束循环添加成员没问题,那么第二次adwin时间去添加。
代码退出循环并停止工作。
和
当我输入的用户名不在版块中或用户名是假的。
{ "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 编辑世界
您需要在添加成员之前检查成员。当您尝试将成员添加到 board/card 但该成员已经存在时,Trello returns 出现错误。这反过来会导致 Manatee.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
中。
多次添加同一个成员以使用添加卡 trello 收集但不起作用
问题
当我输入相同的用户名时,例如
{ "adwin", "adwin", "robert", "dave"}
如果第一次adwin结束循环添加成员没问题,那么第二次adwin时间去添加。
代码退出循环并停止工作。
和
当我输入的用户名不在版块中或用户名是假的。
{ "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 编辑世界
您需要在添加成员之前检查成员。当您尝试将成员添加到 board/card 但该成员已经存在时,Trello returns 出现错误。这反过来会导致 Manatee.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
中。