1
1
// --------------------------------------------------------------------------------------------------------------------
2
2
// <copyright company="Aspose" file="Configuration.cs">
3
- // Copyright (c) 2020 Aspose.PDF Cloud
3
+ // Copyright (c) 2022 Aspose.PDF Cloud
4
4
// </copyright>
5
5
// <summary>
6
6
// Permission is hereby granted, free of charge, to any person obtaining a copy
@@ -50,39 +50,45 @@ public class Configuration
50
50
/// <param name="userAgent">HTTP user agent</param>
51
51
public Configuration ( string apiKey ,
52
52
string appSid ,
53
- String basePath = "https://api.aspose.cloud" ,
54
- Dictionary < String , String > defaultHeader = null ,
53
+ string basePath = "https://api.aspose.cloud" ,
54
+ Dictionary < string , string > defaultHeader = null ,
55
55
string tempFolderPath = null ,
56
56
string dateTimeFormat = null ,
57
57
int timeout = 5 * 60 * 1000 ,
58
58
string userAgent = "aspose pdf cloud sdk"
59
59
)
60
60
{
61
- if ( String . IsNullOrEmpty ( basePath ) )
61
+ if ( string . IsNullOrEmpty ( basePath ) )
62
62
throw new ArgumentException ( "basePath cannot be empty" ) ;
63
+ if ( ! _CheckSidKey ( appSid , apiKey ) )
64
+ throw new ArgumentException ( "appSid and apiKey are messed up or have wrong format" ) ;
63
65
64
66
ApiKey = apiKey ;
65
67
AppSid = appSid ;
66
68
BasePath = basePath ;
67
-
68
69
UserAgent = userAgent ;
69
-
70
70
if ( defaultHeader != null )
71
71
DefaultHeader = defaultHeader ;
72
-
73
72
TempFolderPath = tempFolderPath ;
74
73
DateTimeFormat = dateTimeFormat ;
75
74
Timeout = timeout ;
76
75
}
77
76
77
+ private static bool _CheckSidKey ( string appSid , string apiKey )
78
+ {
79
+ var ssSid = appSid . Split ( '-' ) ;
80
+ var ssKey = apiKey . Split ( '-' ) ;
81
+ return ssSid . Length == 5 && ssKey . Length == 1 ;
82
+ }
83
+
78
84
/// <summary>
79
85
/// Default creation of exceptions for a given method name and response object
80
86
/// </summary>
81
87
public static readonly ExceptionFactory DefaultExceptionFactory = ( methodName , response ) =>
82
88
{
83
89
int status = ( int ) response . StatusCode ;
84
- if ( status >= 400 ) return new ApiException ( status , String . Format ( "Error calling {0}: {1}" , methodName , response . Content ) , response . Content ) ;
85
- if ( status == 0 ) return new ApiException ( status , String . Format ( "Error calling {0}: {1}" , methodName , response . ErrorMessage ) , response . ErrorMessage ) ;
90
+ if ( status >= 400 ) return new ApiException ( status , string . Format ( "Error calling {0}: {1}" , methodName , response . Content ) , response . Content ) ;
91
+ if ( status == 0 ) return new ApiException ( status , string . Format ( "Error calling {0}: {1}" , methodName , response . ErrorMessage ) , response . ErrorMessage ) ;
86
92
return null ;
87
93
} ;
88
94
@@ -107,12 +113,12 @@ public Configuration(string apiKey,
107
113
/// </summary>
108
114
public string AppSid { get ; set ; }
109
115
110
- private Dictionary < String , String > _defaultHeaderMap = new Dictionary < String , String > ( ) ;
116
+ private Dictionary < string , string > _defaultHeaderMap = new Dictionary < string , string > ( ) ;
111
117
112
118
/// <summary>
113
119
/// Gets or sets the default header.
114
120
/// </summary>
115
- public Dictionary < String , String > DefaultHeader
121
+ public Dictionary < string , string > DefaultHeader
116
122
{
117
123
get { return _defaultHeaderMap ; }
118
124
@@ -137,20 +143,20 @@ public void AddDefaultHeader(string key, string value)
137
143
/// Gets or sets the HTTP user agent.
138
144
/// </summary>
139
145
/// <value>Http user agent.</value>
140
- public String UserAgent { get ; set ; }
146
+ public string UserAgent { get ; set ; }
141
147
142
148
private string _tempFolderPath ;
143
149
144
150
/// <summary>
145
151
/// Gets or sets the temporary folder path to store the files downloaded from the server.
146
152
/// </summary>
147
153
/// <value>Folder path.</value>
148
- public String TempFolderPath
154
+ public string TempFolderPath
149
155
{
150
156
get
151
157
{
152
158
// default to Path.GetTempPath() if _tempFolderPath is not set
153
- if ( String . IsNullOrEmpty ( _tempFolderPath ) )
159
+ if ( string . IsNullOrEmpty ( _tempFolderPath ) )
154
160
{
155
161
_tempFolderPath = Path . GetTempPath ( ) ;
156
162
}
@@ -159,7 +165,7 @@ public String TempFolderPath
159
165
160
166
set
161
167
{
162
- if ( String . IsNullOrEmpty ( value ) )
168
+ if ( string . IsNullOrEmpty ( value ) )
163
169
{
164
170
_tempFolderPath = value ;
165
171
return ;
@@ -189,7 +195,7 @@ public String TempFolderPath
189
195
/// No validation is done to ensure that the string you're providing is valid
190
196
/// </summary>
191
197
/// <value>The DateTimeFormat string</value>
192
- public String DateTimeFormat
198
+ public string DateTimeFormat
193
199
{
194
200
get
195
201
{
@@ -213,16 +219,16 @@ public String DateTimeFormat
213
219
/// <summary>
214
220
/// Returns a string with essential information for debugging.
215
221
/// </summary>
216
- public static String ToDebugReport ( )
222
+ public static string ToDebugReport ( )
217
223
{
218
- String report = "C# SDK (Aspose.Pdf.Cloud.Sdk) Debug Report:\n " ;
224
+ string report = "C# SDK (Aspose.Pdf.Cloud.Sdk) Debug Report:\n " ;
219
225
report += " OS: " + Environment . OSVersion + "\n " ;
220
226
report += " .NET Framework Version: " + Assembly
221
227
. GetExecutingAssembly ( )
222
228
. GetReferencedAssemblies ( )
223
229
. Where ( x => x . Name == "System.Core" ) . First ( ) . Version . ToString ( ) + "\n " ;
224
230
report += " Version of the API: 3.0\n " ;
225
- report += " SDK Package Version: 22.3 .0\n " ;
231
+ report += " SDK Package Version: 22.4 .0\n " ;
226
232
227
233
return report ;
228
234
}
0 commit comments