private async Task loadMemberAsync() { TrelloMember tm = await TrelloRepository.GetMemberDataAsync(this.Card); lblFullName.Text = tm.FullName; //imgAvatar.Source = tm.AvatarImg; //HttpClient client = new HttpClient(); //Stream stream = await client.GetStreamAsync(tm.AvatarImg); //imgAvatar.Source = ImageSource.FromStream(() => stream); imgAvatar.Source = new UriImageSource() { Uri = new Uri(tm.gravatarHash), CachingEnabled = false }; lblUsername.Text = tm.UserName; }
public static async Task <TrelloMember> GetMemberDataAsync(TrelloCard card) { TrelloMember list = new TrelloMember(); string url = $"https://api.trello.com/1/members/{card.List.Board.memberId}?key={_APIKEY}&token={_USERTOKEN}"; using (HttpClient client = GetHttpClient()) { try { string json = await client.GetStringAsync(url); list = JsonConvert.DeserializeObject <TrelloMember>(json); } catch (Exception ex) { throw ex; } } return(list); }
static void Main(string[] args) { string startingBoardId = ""; string startingBoardName = ""; //Console.WriteLine("Введите id доски Trello"); //startingBoardId = Console.ReadLine(); //Console.WriteLine("Введите название проекта / команды"); //startingBoardName = Console.ReadLine(); //startingBoardId = "QnqeK3SC"; startingBoardName = "Летний интерсив"; //startingBoardId = "Ni3BxRJ5"; startingBoardName = "KeenSoft"; //startingBoardId = "K0C0i8wF"; startingBoardName = "Beamdog Newewinter Nights"; startingBoardId = "nU6GjV5G"; startingBoardName = "Моя тестовая доска"; //УДАЛЕНИЕ ВСЕХ ДАННЫХ ПО ДОСКЕ //deleteBoard(startingBoardId); return; string scriptPath = "C:/Users/Пользователь/source/repos/PythonJsonDeserializer/PythonJsonDeserializer/ApiCallScripts/"; string scriptFileName; string scriptCallUrl; //url api-запроса для скрипта string callResult; Program program = new Program(); //добавляем доску в бд using (TrelloDbContext db = new TrelloDbContext()) { TrelloBoard board = new TrelloBoard { Id = startingBoardId, Name = startingBoardName }; db.Boards.Add(board); db.SaveChanges(); } //получаем листы доски scriptFileName = "call_board_listsv2.py"; scriptCallUrl = "\"https://api.trello.com/1/boards/" + startingBoardId + "/lists\""; callResult = program.runApiCall(scriptPath + scriptFileName + " " + scriptCallUrl, ""); //Console.WriteLine("Результат " +callResult); List <AbstractModel> tlists = new List <AbstractModel>(); Deserializer <TrelloList> listDeserializer = new Deserializer <TrelloList>(); tlists = listDeserializer.jsonDeserialize(callResult); //перебор полученных листов foreach (TrelloList tlist in tlists) { //отладочный вывод десериализованного содержимого листов Console.WriteLine("Лист. Название: " + decode(tlist.Name) + " / ID: " + tlist.Id + " / Статус: " + tlist.Closed); Console.WriteLine(); //добавляем лист в бд using (TrelloDbContext db = new TrelloDbContext()) { //запиили добавление через обект со всеми полями TrelloList dblist = new TrelloList { Id = tlist.Id, Name = decode(tlist.Name), Closed = tlist.Closed, BoardId = startingBoardId }; db.Lists.Add(dblist); db.SaveChanges(); } //получаем карточки листа scriptFileName = "call_list_cardsv2.py"; scriptCallUrl = "\"https://api.trello.com/1/lists/" + tlist.Id + "/cards\""; //scriptCallUrl = "\"https://api.trello.com/1/lists/59e21320df19579bf6b8e1af/cards\""; callResult = program.runApiCall(scriptPath + scriptFileName + " " + scriptCallUrl, ""); //Console.WriteLine("Результат " + callResult); List <AbstractModel> tcards = new List <AbstractModel>(); Deserializer <TrelloCard> cardDeserializer = new Deserializer <TrelloCard>(); tcards = cardDeserializer.jsonDeserialize(callResult); //Thread.Sleep(5000); //перебор полученных карточек foreach (TrelloCard tcard in tcards) { //отладочный вывод десериализованного содержимого карточек Console.WriteLine("Карточка. Название: " + decode(tcard.Name) + " / ID: " + tcard.Id + " / Статус: " + tcard.Closed + " / Описание: " + decode(tcard.Desc) + " / Последняя активность: " + tcard.DateLastActivity); Console.WriteLine(); //добавляем карточку в бд using (TrelloDbContext db = new TrelloDbContext()) { TrelloCard dbcard = new TrelloCard { Id = tcard.Id, Name = decode(tcard.Name), Desc = decode(tcard.Desc), Closed = tcard.Closed, DateLastActivity = tcard.DateLastActivity, Due = tcard.Due, DueComplete = tcard.DueComplete, ListId = tlist.Id }; db.Cards.Add(dbcard); db.SaveChanges(); } //новый код: получаем разработчиков карточки scriptFileName = "call_card_members.py"; scriptCallUrl = "\"https://api.trello.com/1/cards/" + tcard.Id + "/members\""; callResult = program.runApiCall(scriptPath + scriptFileName + " " + scriptCallUrl, ""); //Отладочный вывод members callResult //Console.WriteLine("\n Результат запроса card members: " + callResult); List <AbstractModel> tmembers = new List <AbstractModel>(); Deserializer <TrelloMember> memberDeserializer = new Deserializer <TrelloMember>(); tmembers = memberDeserializer.jsonDeserialize(callResult); foreach (TrelloMember tmember in tmembers) { try { using (TrelloDbContext db = new TrelloDbContext()) { TrelloMember dbmember = new TrelloMember { Id = tmember.Id, Name = "", FullName = decode(tmember.FullName), Username = tmember.Username }; db.Members.Add(dbmember); db.SaveChanges(); } } catch { } using (TrelloDbContext db = new TrelloDbContext()) { //придумай Id. cardid+memberid слишком длинно? cardid+num? MemberCard dbmembercard = new MemberCard { Id = tmember.Id + tcard.Id, Name = "", CardId = tcard.Id, MemberId = tmember.Id }; db.MembersCards.Add(dbmembercard); db.SaveChanges(); } } } Console.WriteLine(); } Console.WriteLine("Конец скрипта. Нажмите любую клавишу"); Console.Read(); }