Skip to content

Commit ae99688

Browse files
committed
chore: Generate filename param, use MemoryStream rather than FileStream for files
1 parent 48d5b37 commit ae99688

13 files changed

+434
-312
lines changed

Core

Scripts/Services/CompareComply/V1/CompareComplyService.cs

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -133,18 +133,21 @@ public CompareComplyService(string versionDate, Credentials credentials) : base(
133133
/// </summary>
134134
/// <param name="callback">The callback function that is invoked when the operation completes.</param>
135135
/// <param name="file">The file to convert.</param>
136+
/// <param name="filename">The filename for file.</param>
136137
/// <param name="modelId">The analysis model to be used by the service. For the `/v1/element_classification` and
137138
/// `/v1/comparison` methods, the default is `contracts`. For the `/v1/tables` method, the default is `tables`.
138139
/// These defaults apply to the standalone methods as well as to the methods' use in batch-processing requests.
139140
/// (optional)</param>
140141
/// <param name="fileContentType">The content type of file. (optional)</param>
141142
/// <returns><see cref="HTMLReturn" />HTMLReturn</returns>
142-
public bool ConvertToHtml(Callback<HTMLReturn> callback, System.IO.FileStream file, string modelId = null, string fileContentType = null)
143+
public bool ConvertToHtml(Callback<HTMLReturn> callback, System.IO.MemoryStream file, string filename, string modelId = null, string fileContentType = null)
143144
{
144145
if (callback == null)
145146
throw new ArgumentNullException("`callback` is required for `ConvertToHtml`");
146147
if (file == null)
147148
throw new ArgumentNullException("`file` is required for `ConvertToHtml`");
149+
if (string.IsNullOrEmpty(filename))
150+
throw new ArgumentNullException("`filename` is required for `ConvertToHtml`");
148151

149152
RequestObject<HTMLReturn> req = new RequestObject<HTMLReturn>
150153
{
@@ -169,7 +172,7 @@ public bool ConvertToHtml(Callback<HTMLReturn> callback, System.IO.FileStream fi
169172
req.Forms = new Dictionary<string, RESTConnector.Form>();
170173
if (file != null)
171174
{
172-
req.Forms["file"] = new RESTConnector.Form(file, file.Name, fileContentType);
175+
req.Forms["file"] = new RESTConnector.Form(file, filename, fileContentType);
173176
}
174177
if (!string.IsNullOrEmpty(modelId))
175178
{
@@ -218,13 +221,14 @@ private void OnConvertToHtmlResponse(RESTConnector.Request req, RESTConnector.Re
218221
/// </summary>
219222
/// <param name="callback">The callback function that is invoked when the operation completes.</param>
220223
/// <param name="file">The file to classify.</param>
224+
/// <param name="filename">The filename for file. (optional)</param>
221225
/// <param name="modelId">The analysis model to be used by the service. For the `/v1/element_classification` and
222226
/// `/v1/comparison` methods, the default is `contracts`. For the `/v1/tables` method, the default is `tables`.
223227
/// These defaults apply to the standalone methods as well as to the methods' use in batch-processing requests.
224228
/// (optional)</param>
225229
/// <param name="fileContentType">The content type of file. (optional)</param>
226230
/// <returns><see cref="ClassifyReturn" />ClassifyReturn</returns>
227-
public bool ClassifyElements(Callback<ClassifyReturn> callback, System.IO.FileStream file, string modelId = null, string fileContentType = null)
231+
public bool ClassifyElements(Callback<ClassifyReturn> callback, System.IO.MemoryStream file, string filename = null, string modelId = null, string fileContentType = null)
228232
{
229233
if (callback == null)
230234
throw new ArgumentNullException("`callback` is required for `ClassifyElements`");
@@ -254,7 +258,7 @@ public bool ClassifyElements(Callback<ClassifyReturn> callback, System.IO.FileSt
254258
req.Forms = new Dictionary<string, RESTConnector.Form>();
255259
if (file != null)
256260
{
257-
req.Forms["file"] = new RESTConnector.Form(file, file.Name, fileContentType);
261+
req.Forms["file"] = new RESTConnector.Form(file, filename, fileContentType);
258262
}
259263
if (!string.IsNullOrEmpty(modelId))
260264
{
@@ -303,13 +307,14 @@ private void OnClassifyElementsResponse(RESTConnector.Request req, RESTConnector
303307
/// </summary>
304308
/// <param name="callback">The callback function that is invoked when the operation completes.</param>
305309
/// <param name="file">The file on which to run table extraction.</param>
310+
/// <param name="filename">The filename for file. (optional)</param>
306311
/// <param name="modelId">The analysis model to be used by the service. For the `/v1/element_classification` and
307312
/// `/v1/comparison` methods, the default is `contracts`. For the `/v1/tables` method, the default is `tables`.
308313
/// These defaults apply to the standalone methods as well as to the methods' use in batch-processing requests.
309314
/// (optional)</param>
310315
/// <param name="fileContentType">The content type of file. (optional)</param>
311316
/// <returns><see cref="TableReturn" />TableReturn</returns>
312-
public bool ExtractTables(Callback<TableReturn> callback, System.IO.FileStream file, string modelId = null, string fileContentType = null)
317+
public bool ExtractTables(Callback<TableReturn> callback, System.IO.MemoryStream file, string filename = null, string modelId = null, string fileContentType = null)
313318
{
314319
if (callback == null)
315320
throw new ArgumentNullException("`callback` is required for `ExtractTables`");
@@ -339,7 +344,7 @@ public bool ExtractTables(Callback<TableReturn> callback, System.IO.FileStream f
339344
req.Forms = new Dictionary<string, RESTConnector.Form>();
340345
if (file != null)
341346
{
342-
req.Forms["file"] = new RESTConnector.Form(file, file.Name, fileContentType);
347+
req.Forms["file"] = new RESTConnector.Form(file, filename, fileContentType);
343348
}
344349
if (!string.IsNullOrEmpty(modelId))
345350
{
@@ -388,7 +393,9 @@ private void OnExtractTablesResponse(RESTConnector.Request req, RESTConnector.Re
388393
/// </summary>
389394
/// <param name="callback">The callback function that is invoked when the operation completes.</param>
390395
/// <param name="file1">The first file to compare.</param>
396+
/// <param name="file1Filename">The filename for file1. (optional)</param>
391397
/// <param name="file2">The second file to compare.</param>
398+
/// <param name="file2Filename">The filename for file2. (optional)</param>
392399
/// <param name="file1Label">A text label for the first file. (optional, default to file_1)</param>
393400
/// <param name="file2Label">A text label for the second file. (optional, default to file_2)</param>
394401
/// <param name="modelId">The analysis model to be used by the service. For the `/v1/element_classification` and
@@ -398,7 +405,7 @@ private void OnExtractTablesResponse(RESTConnector.Request req, RESTConnector.Re
398405
/// <param name="file1ContentType">The content type of file1. (optional)</param>
399406
/// <param name="file2ContentType">The content type of file2. (optional)</param>
400407
/// <returns><see cref="CompareReturn" />CompareReturn</returns>
401-
public bool CompareDocuments(Callback<CompareReturn> callback, System.IO.FileStream file1, System.IO.FileStream file2, string file1Label = null, string file2Label = null, string modelId = null, string file1ContentType = null, string file2ContentType = null)
408+
public bool CompareDocuments(Callback<CompareReturn> callback, System.IO.MemoryStream file1, System.IO.MemoryStream file2, string file1Filename = null, string file2Filename = null, string file1Label = null, string file2Label = null, string modelId = null, string file1ContentType = null, string file2ContentType = null)
402409
{
403410
if (callback == null)
404411
throw new ArgumentNullException("`callback` is required for `CompareDocuments`");
@@ -430,11 +437,11 @@ public bool CompareDocuments(Callback<CompareReturn> callback, System.IO.FileStr
430437
req.Forms = new Dictionary<string, RESTConnector.Form>();
431438
if (file1 != null)
432439
{
433-
req.Forms["file_1"] = new RESTConnector.Form(file1, file1.Name, file1ContentType);
440+
req.Forms["file_1"] = new RESTConnector.Form(file1, file1Filename, file1ContentType);
434441
}
435442
if (file2 != null)
436443
{
437-
req.Forms["file_2"] = new RESTConnector.Form(file2, file2.Name, file2ContentType);
444+
req.Forms["file_2"] = new RESTConnector.Form(file2, file2Filename, file2ContentType);
438445
}
439446
if (!string.IsNullOrEmpty(file1Label))
440447
{
@@ -909,13 +916,15 @@ private void OnListFeedbackResponse(RESTConnector.Request req, RESTConnector.Res
909916
/// <param name="inputCredentialsFile">A JSON file containing the input Cloud Object Storage credentials. At a
910917
/// minimum, the credentials must enable `READ` permissions on the bucket defined by the `input_bucket_name`
911918
/// parameter.</param>
919+
/// <param name="inputCredentialsFilename">The filename for inputCredentialsFile. (optional)</param>
912920
/// <param name="inputBucketLocation">The geographical location of the Cloud Object Storage input bucket as
913921
/// listed on the **Endpoint** tab of your Cloud Object Storage instance; for example, `us-geo`, `eu-geo`, or
914922
/// `ap-geo`.</param>
915923
/// <param name="inputBucketName">The name of the Cloud Object Storage input bucket.</param>
916924
/// <param name="outputCredentialsFile">A JSON file that lists the Cloud Object Storage output credentials. At a
917925
/// minimum, the credentials must enable `READ` and `WRITE` permissions on the bucket defined by the
918926
/// `output_bucket_name` parameter.</param>
927+
/// <param name="outputCredentialsFilename">The filename for outputCredentialsFile. (optional)</param>
919928
/// <param name="outputBucketLocation">The geographical location of the Cloud Object Storage output bucket as
920929
/// listed on the **Endpoint** tab of your Cloud Object Storage instance; for example, `us-geo`, `eu-geo`, or
921930
/// `ap-geo`.</param>
@@ -925,7 +934,7 @@ private void OnListFeedbackResponse(RESTConnector.Request req, RESTConnector.Res
925934
/// These defaults apply to the standalone methods as well as to the methods' use in batch-processing requests.
926935
/// (optional)</param>
927936
/// <returns><see cref="BatchStatus" />BatchStatus</returns>
928-
public bool CreateBatch(Callback<BatchStatus> callback, string function, System.IO.FileStream inputCredentialsFile, string inputBucketLocation, string inputBucketName, System.IO.FileStream outputCredentialsFile, string outputBucketLocation, string outputBucketName, string modelId = null)
937+
public bool CreateBatch(Callback<BatchStatus> callback, string function, System.IO.MemoryStream inputCredentialsFile, string inputBucketLocation, string inputBucketName, System.IO.MemoryStream outputCredentialsFile, string outputBucketLocation, string outputBucketName, string inputCredentialsFilename = null, string outputCredentialsFilename = null, string modelId = null)
929938
{
930939
if (callback == null)
931940
throw new ArgumentNullException("`callback` is required for `CreateBatch`");
@@ -967,7 +976,7 @@ public bool CreateBatch(Callback<BatchStatus> callback, string function, System.
967976
req.Forms = new Dictionary<string, RESTConnector.Form>();
968977
if (inputCredentialsFile != null)
969978
{
970-
req.Forms["input_credentials_file"] = new RESTConnector.Form(inputCredentialsFile, inputCredentialsFile.Name, "application/json");
979+
req.Forms["input_credentials_file"] = new RESTConnector.Form(inputCredentialsFile, inputCredentialsFilename, "application/json");
971980
}
972981
if (!string.IsNullOrEmpty(inputBucketLocation))
973982
{
@@ -979,7 +988,7 @@ public bool CreateBatch(Callback<BatchStatus> callback, string function, System.
979988
}
980989
if (outputCredentialsFile != null)
981990
{
982-
req.Forms["output_credentials_file"] = new RESTConnector.Form(outputCredentialsFile, outputCredentialsFile.Name, "application/json");
991+
req.Forms["output_credentials_file"] = new RESTConnector.Form(outputCredentialsFile, outputCredentialsFilename, "application/json");
983992
}
984993
if (!string.IsNullOrEmpty(outputBucketLocation))
985994
{

0 commit comments

Comments
 (0)