SelectObjectRequest.cs 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. using System.Text;
  2. using COSXML.Common;
  3. using COSXML.Network;
  4. using COSXML.Model.Tag;
  5. using COSXML.CosException;
  6. namespace COSXML.Model.Object
  7. {
  8. public sealed class SelectObjectRequest : ObjectRequest
  9. {
  10. private SelectObject selectObject;
  11. internal COSXML.Callback.OnProgressCallback progressCallback;
  12. internal string outputFilePath;
  13. public SelectObjectRequest(string bucket, string key)
  14. : base(bucket, key)
  15. {
  16. this.method = CosRequestMethod.POST;
  17. this.queryParameters.Add("select", null);
  18. this.queryParameters.Add("select-type", "2");
  19. this.selectObject = new SelectObject();
  20. selectObject.ExpressionType = "SQL";
  21. }
  22. public SelectObjectRequest OutputToFile(string filePath)
  23. {
  24. outputFilePath = filePath;
  25. return this;
  26. }
  27. public SelectObjectRequest SetExpression(string expression)
  28. {
  29. selectObject.Expression = expression;
  30. return this;
  31. }
  32. public SelectObjectRequest SetExpressionType(string expressionType)
  33. {
  34. selectObject.ExpressionType = expressionType;
  35. return this;
  36. }
  37. public SelectObjectRequest SetInputFormat(ObjectSelectionFormat inputFormat)
  38. {
  39. selectObject.InputFormat = inputFormat;
  40. return this;
  41. }
  42. public SelectObjectRequest SetOutputFormat(ObjectSelectionFormat outputFormat)
  43. {
  44. selectObject.OutputFormat = outputFormat;
  45. return this;
  46. }
  47. public SelectObjectRequest SetCosProgressCallback(COSXML.Callback.OnProgressCallback progressCallback)
  48. {
  49. this.progressCallback = progressCallback;
  50. return this;
  51. }
  52. public override void CheckParameters()
  53. {
  54. base.CheckParameters();
  55. if (selectObject.Expression == null)
  56. {
  57. throw new CosClientException((int)CosClientError.InvalidArgument,
  58. "expression is null");
  59. }
  60. if (selectObject.InputFormat == null)
  61. {
  62. throw new CosClientException((int)CosClientError.InvalidArgument,
  63. "inputFormat is null");
  64. }
  65. if (selectObject.OutputFormat == null)
  66. {
  67. throw new CosClientException((int)CosClientError.InvalidArgument,
  68. "outputFormat is null");
  69. }
  70. }
  71. public override Network.RequestBody GetRequestBody()
  72. {
  73. return GetXmlRequestBody(selectObject);
  74. }
  75. }
  76. }