public void saveWitAttachments(List<AttachmentDetail> witsAttachments) { if (witsAttachments != null && witsAttachments.Count > 0) { foreach (var witsAtt in witsAttachments) { AttachmentDao attachmentDao = new AttachmentDao(); attachmentDao.saveWitAttachment((AttachmentDetail)witsAtt); } } }
// download all the attachments of a wit to the local folders public void getAttachment(String witId, String fileAssociationId, String fileName, String userProfilepath) { AccessTokenDao accesstokenDao = new AccessTokenDao(); String token = accesstokenDao.getAccessToken(Common.userName); String url = Resource.endpoint + "wittyparrot/api/attachments/associationId/" + fileAssociationId + ""; var client = new RestClient(); client.BaseUrl = new Uri(url); var request = new RestRequest(); request.Method = Method.GET; request.Parameters.Clear(); request.AddParameter("Authorization", "Bearer " + token, ParameterType.HttpHeader); request.RequestFormat = DataFormat.Json; // execute the request IRestResponse response = client.Execute(request); if (response.ErrorException != null) { var statusMessage = RestUtils.getErrorMessage(response.StatusCode); MessageBox.Show(statusMessage == "" ? response.StatusDescription : statusMessage); var myException = new ApplicationException(response.StatusDescription, response.ErrorException); throw myException; } byte[] r = client.DownloadData(request); String fullPath = userProfilepath + "//files//attachments//"; if (!Directory.Exists(fullPath)) { Directory.CreateDirectory(fullPath); } // save the file details to docs table Docs doc = new Docs(); doc.docId = fileName.GetHashCode().ToString(); doc.localPath = fullPath; doc.fileName = fileName; doc.witId = witId; AttachmentDao attachmentDao = new AttachmentDao(); attachmentDao.saveDocs(doc); File.WriteAllBytes(fullPath + fileName, r); }
public void initializeDownloadAttachment() { AttachmentDao attachmentDao = new AttachmentDao(); List<AttachmentDetail> witsAttachments = attachmentDao.getWitAttachments(); attachmentDao.downloadAttachmentThreadGenerator(witsAttachments); }