PageRenderTime 46ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/Atlassian.Jira/Attachment.cs

https://bitbucket.org/yyo/atlassian.net-sdk-v2.0
C# | 100 lines | 64 code | 11 blank | 25 comment | 0 complexity | 6e1fbaba57b676c6d59b50a9c6f0f717 MD5 | raw file
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using Atlassian.Jira.Remote;
  6. namespace Atlassian.Jira
  7. {
  8. /// <summary>
  9. /// An attachment associated with an issue
  10. /// </summary>
  11. public class Attachment
  12. {
  13. private readonly string _author;
  14. private readonly DateTime? _created;
  15. private readonly string _fileName;
  16. private readonly string _mimeType;
  17. private readonly long? _fileSize;
  18. private readonly string _id;
  19. private readonly Jira _jira;
  20. private readonly IWebClient _webClient;
  21. internal Attachment(Jira jira, IWebClient webClient, RemoteAttachment remoteAttachment)
  22. {
  23. _jira = jira;
  24. _author = remoteAttachment.author;
  25. _created = remoteAttachment.created;
  26. _fileName = remoteAttachment.filename;
  27. _mimeType = remoteAttachment.mimetype;
  28. _fileSize = remoteAttachment.filesize;
  29. _id = remoteAttachment.id;
  30. _webClient = webClient;
  31. }
  32. /// <summary>
  33. /// Id of attachment
  34. /// </summary>
  35. public string Id
  36. {
  37. get { return _id; }
  38. }
  39. /// <summary>
  40. /// Author of attachment (user that uploaded the file)
  41. /// </summary>
  42. public string Author
  43. {
  44. get { return _author; }
  45. }
  46. /// <summary>
  47. /// Date of creation
  48. /// </summary>
  49. public DateTime? CreatedDate
  50. {
  51. get { return _created; }
  52. }
  53. /// <summary>
  54. /// File name of the attachment
  55. /// </summary>
  56. public string FileName
  57. {
  58. get { return _fileName; }
  59. }
  60. /// <summary>
  61. /// Mime type
  62. /// </summary>
  63. public string MimeType
  64. {
  65. get { return _mimeType; }
  66. }
  67. /// <summary>
  68. /// File size
  69. /// </summary>
  70. public long? FileSize
  71. {
  72. get { return _fileSize; }
  73. }
  74. /// <summary>
  75. /// Downloads attachment to specified file
  76. /// </summary>
  77. /// <param name="fullFileName">Full file name where attachment will be downloaded</param>
  78. public void Download(string fullFileName)
  79. {
  80. _webClient.AddQueryString("os_username", _jira.UserName);
  81. _webClient.AddQueryString("os_password", _jira.Password);
  82. var url = String.Format("{0}secure/attachment/{1}/{2}",
  83. _jira.Url.EndsWith("/") ? _jira.Url : _jira.Url + "/",
  84. this.Id,
  85. this.FileName);
  86. _webClient.Download(url, fullFileName);
  87. }
  88. }
  89. }