Skip to content

Commit 0f5674e

Browse files
committed
Update Aspose.Cells Apps
1 parent 954026c commit 0f5674e

File tree

217 files changed

+20385
-31746
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

217 files changed

+20385
-31746
lines changed

Demos/.gitignore

Lines changed: 249 additions & 112 deletions
Large diffs are not rendered by default.

Demos/.runsettings

Lines changed: 0 additions & 13 deletions
This file was deleted.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
using System;
2+
3+
namespace Aspose.Cells.API.Api
4+
{
5+
public class ApiException : Exception
6+
{
7+
public int ErrorCode { get; set; }
8+
9+
public ApiException(int errorCode, string message) : base(message)
10+
{
11+
ErrorCode = errorCode;
12+
}
13+
}
14+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
namespace Aspose.Cells.API.Api
2+
{
3+
public class ApiVersion
4+
{
5+
public string Version { get; set; }
6+
7+
private ApiVersion(string version)
8+
{
9+
Version = version;
10+
}
11+
12+
public static ApiVersion V1 = new ApiVersion("1.0");
13+
14+
public override string ToString()
15+
{
16+
return Version;
17+
}
18+
}
19+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
namespace Aspose.Cells.API.Api
2+
{
3+
public enum AuthType
4+
{
5+
OAuth2 = 0,
6+
7+
RequestSignature = 1,
8+
9+
ExternalAuth = 2,
10+
11+
JWT = 3,
12+
}
13+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
namespace Aspose.Cells.API.Api
2+
{
3+
public class Configuration
4+
{
5+
public string ApiBaseUrl { get; set; }
6+
7+
public string ClientSecret { get; set; }
8+
9+
public string ClientId { get; set; }
10+
11+
public string JwtToken { get; set; }
12+
13+
public bool DebugMode { get; set; }
14+
15+
public AuthType AuthType { get; set; }
16+
17+
public ApiVersion ApiVersion { get; set; }
18+
19+
public Configuration()
20+
{
21+
ApiBaseUrl = "https://api.groupdocs.cloud";
22+
DebugMode = false;
23+
ApiVersion = ApiVersion.V1;
24+
AuthType = AuthType.JWT;
25+
}
26+
27+
internal string GetApiRootUrl()
28+
{
29+
var result = ApiBaseUrl + "/v" + ApiVersion + "/translation";
30+
31+
return result.EndsWith("/") ? result.Substring(0, result.Length - 1) : result;
32+
}
33+
34+
public const int MillisecondsTimeout = 300000;
35+
}
36+
}
Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
using System.Collections.Generic;
2+
using System.IO;
3+
using System.Text.RegularExpressions;
4+
using Aspose.Cells.API.Internal;
5+
using Aspose.Cells.API.Internal.RequestHandlers;
6+
using Aspose.Cells.API.Models;
7+
using Aspose.Cells.API.Models.Requests;
8+
9+
namespace Aspose.Cells.API.Api
10+
{
11+
public class FileApi
12+
{
13+
private readonly ApiInvoker _apiInvoker;
14+
private readonly Configuration _configuration;
15+
16+
public FileApi(Configuration configuration)
17+
{
18+
_configuration = configuration;
19+
20+
var requestHandlers = new List<IRequestHandler>();
21+
switch (_configuration.AuthType)
22+
{
23+
case AuthType.RequestSignature:
24+
requestHandlers.Add(new AuthWithSignatureRequestHandler(_configuration));
25+
break;
26+
case AuthType.OAuth2:
27+
requestHandlers.Add(new OAuthRequestHandler(_configuration));
28+
break;
29+
case AuthType.ExternalAuth:
30+
requestHandlers.Add(new ExternalAuthorizationRequestHandler(_configuration));
31+
break;
32+
case AuthType.JWT:
33+
requestHandlers.Add(new JwtRequestHandler(_configuration));
34+
break;
35+
}
36+
37+
requestHandlers.Add(new DebugLogRequestHandler(_configuration));
38+
requestHandlers.Add(new ApiExceptionRequestHandler());
39+
_apiInvoker = new ApiInvoker(requestHandlers);
40+
}
41+
42+
public Stream DownloadFile(DownloadFileRequest request)
43+
{
44+
// verify the required parameter 'path' is set
45+
if (request.Path == null)
46+
{
47+
throw new ApiException(400, "Missing required parameter 'path' when calling DownloadFile");
48+
}
49+
50+
// create path and map variables
51+
var resourcePath = _configuration.GetApiRootUrl() + "/storage/file/{path}";
52+
resourcePath = Regex
53+
.Replace(resourcePath, "\\*", string.Empty)
54+
.Replace("&amp;", "&")
55+
.Replace("/?", "?");
56+
resourcePath = UrlHelper.AddPathParameter(resourcePath, "path", request.Path);
57+
resourcePath = UrlHelper.AddQueryParameterToUrl(resourcePath, "storageName", request.StorageName);
58+
resourcePath = UrlHelper.AddQueryParameterToUrl(resourcePath, "versionId", request.VersionId);
59+
60+
try
61+
{
62+
return _apiInvoker.InvokeBinaryApi(
63+
resourcePath,
64+
"GET",
65+
null,
66+
null,
67+
null);
68+
}
69+
catch (ApiException ex)
70+
{
71+
if (ex.ErrorCode == 404)
72+
{
73+
return null;
74+
}
75+
76+
throw;
77+
}
78+
}
79+
80+
public FilesUploadResult UploadFile(UploadFileRequest request)
81+
{
82+
// verify the required parameter 'path' is set
83+
if (request.Path == null)
84+
{
85+
throw new ApiException(400, "Missing required parameter 'path' when calling UploadFile");
86+
}
87+
88+
// verify the required parameter 'file' is set
89+
if (request.File == null)
90+
{
91+
throw new ApiException(400, "Missing required parameter 'file' when calling UploadFile");
92+
}
93+
94+
// create path and map variables
95+
var resourcePath = _configuration.GetApiRootUrl() + "/storage/file/{path}";
96+
resourcePath = Regex
97+
.Replace(resourcePath, "\\*", string.Empty)
98+
.Replace("&amp;", "&")
99+
.Replace("/?", "?");
100+
var formParams = new Dictionary<string, object>();
101+
resourcePath = UrlHelper.AddPathParameter(resourcePath, "path", request.Path);
102+
resourcePath = UrlHelper.AddQueryParameterToUrl(resourcePath, "storageName", request.StorageName);
103+
104+
if (request.File != null)
105+
{
106+
formParams.Add("file", _apiInvoker.ToFileInfo(request.File, "File"));
107+
}
108+
109+
try
110+
{
111+
var response = _apiInvoker.InvokeApi(
112+
resourcePath,
113+
"PUT",
114+
null,
115+
null,
116+
formParams);
117+
if (response != null)
118+
{
119+
return (FilesUploadResult) SerializationHelper.Deserialize(response, typeof(FilesUploadResult));
120+
}
121+
122+
var errors = new List<Error> {new Error {Code = "500", Message = "response null"}};
123+
return new FilesUploadResult {Errors = errors};
124+
}
125+
catch (ApiException ex)
126+
{
127+
var errors = new List<Error> {new Error {Code = ex.ErrorCode.ToString(), Message = ex.Message, Description = ex.StackTrace}};
128+
return new FilesUploadResult {Errors = errors};
129+
}
130+
}
131+
}
132+
}

0 commit comments

Comments
 (0)