public void UpdateFile(string folder, string file, byte[] data) { JObject card = cardarray.Children <JObject>() .FirstOrDefault(o => o["name"].ToString() == folder); if (card == null) { throw new Exception("資料夾不存在"); } JArray list = JArray.Parse( TrelloHelper.GetCardAttachmentList(_key, _token, card["id"].Value <string>())); // file list JObject attachment = list.Children <JObject>() .FirstOrDefault(o => o["name"].ToString() == file); // 已存在,刪除檔案 if (attachment != null) { TrelloHelper.DeleteAttachment(_key, _token, card["id"].Value <string>(), attachment["id"].Value <string>()); } TrelloHelper.CreateAttachment(_key, _token, card["id"].Value <string>(), file, data); }
public List <SyncFileInfo> GetFiles(string folder) { List <SyncFileInfo> result = new List <SyncFileInfo>(); JObject obj = cardarray.Children <JObject>() .FirstOrDefault(o => o["name"].ToString() == folder); if (obj != null) { JArray list = JArray.Parse( TrelloHelper.GetCardAttachmentList(_key, _token, obj["id"].Value <string>())); foreach (JObject o in list.Children <JObject>()) { result.Add(new SyncFileInfo() { Name = o["name"].Value <string>(), Path = o["url"].Value <string>(), CreateDate = TrelloHelper.IdToDatetime(o["id"].Value <string>()), UpdateDate = TrelloHelper.IdToDatetime(o["id"].Value <string>()), Size = o["bytes"].Value <int>() } ); } } return(result); }
public void CreateFile(string folder, string name, byte[] file) { JObject obj = cardarray.Children <JObject>() .FirstOrDefault(o => o["name"].ToString() == folder); if (obj == null) { throw new Exception("資料夾不存在"); } JArray list = JArray.Parse( TrelloHelper.GetCardAttachmentList(_key, _token, obj["id"].Value <string>())); // file list JObject attachment = list.Children <JObject>() .FirstOrDefault(o => o["name"].ToString() == name); if (attachment != null) { DeleteFile(folder, name); //已存在,刪除檔案 } TrelloHelper.CreateAttachment(_key, _token, obj["id"].Value <string>(), name, file); }
public void DeleteFile(string folder, string file) { JObject card = cardarray.Children <JObject>() .FirstOrDefault(o => o["name"].ToString() == folder); if (card == null) { throw new Exception("資料夾不存在"); } // fetch file list JArray list = JArray.Parse( TrelloHelper.GetCardAttachmentList(_key, _token, card["id"].Value <string>())); JObject attachment = list.Children <JObject>() .FirstOrDefault(o => o["name"].ToString() == file); if (attachment == null) { throw new Exception("檔案不存在"); } TrelloHelper.DeleteAttachment(_key, _token, card["id"].Value <string>(), attachment["id"].Value <string>()); }