-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathConfig.cs
130 lines (110 loc) · 4.03 KB
/
Config.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
using System;
using System.Linq;
using System.Net;
using Contentstack.Core.Internals;
namespace Contentstack.Core.Configuration
{
internal class Config
{
#region Private Variable
private string _Protocol;
private string _Host;
private string _Port;
private string _Version;
private string _Environment;
private string _Branch="main";
private int _Timeout;
private WebProxy _proxy;
#endregion
#region Public Properties
public string ApiKey { get; set; }
public string AppUid { get; set; }
public string AuthToken { get; set; }
public string Port {
get { return this._Port ?? "443"; }
set { this._Port = value; }
}
public string Protocol {
get { return this._Protocol ?? "https"; }
set { this._Protocol = value; }
}
public string Host {
get { return _Host ?? HostURL; }
set { this._Host = value; }
}
public ContentstackRegion Region { get; set; } = ContentstackRegion.US;
public string Version
{
get { return this._Version ?? "v3"; }
set { this._Version = value; }
}
public string Environment
{
get { return this._Environment ?? null; }
set { this._Environment = value; }
}
public string Branch
{
get { return this._Branch ?? null; }
set { this._Branch = value; }
}
public int Timeout
{
get { return this._Timeout; }
set { this._Timeout = value; }
}
public WebProxy Proxy
{
get { return this._proxy; }
set { this._proxy = value; }
}
public string BaseUrl
{
get
{
string BaseURL = string.Format("{0}://{1}{2}/{3}",
this.Protocol.Trim('/').Trim('\\'),
regionCode(),
this.Host.Trim('/').Trim('\\'),
this.Version.Trim('/').Trim('\\'));
return BaseURL;
}
}
#endregion
#region Internal
internal string getLivePreviewUrl(LivePreviewConfig livePreviewConfig)
{
return string.Format("{0}://{1}/{2}",
this.Protocol.Trim('/').Trim('\\'),
livePreviewConfig.Host.Trim('/').Trim('\\'),
this.Version.Trim('/').Trim('\\'));
}
internal string getBaseUrl (LivePreviewConfig livePreviewConfig, string contentTypeUID)
{
if (livePreviewConfig != null
&& livePreviewConfig.Enable
&& livePreviewConfig.LivePreview != "init"
&& livePreviewConfig.ContentTypeUID == contentTypeUID)
{
return getLivePreviewUrl(livePreviewConfig);
}
return BaseUrl;
}
internal string regionCode()
{
if (Region == ContentstackRegion.US) return "";
ContentstackRegionCode[] regionCodes = Enum.GetValues(typeof(ContentstackRegionCode)).Cast<ContentstackRegionCode>().ToArray();
return string.Format("{0}-", regionCodes[(int)Region].ToString().Replace("_", "-"));
}
internal string HostURL
{
get
{
if (Region == ContentstackRegion.EU || Region == ContentstackRegion.AZURE_EU || Region == ContentstackRegion.AZURE_NA || Region == ContentstackRegion.GCP_NA)
return "cdn.contentstack.com";
return "cdn.contentstack.io";
}
}
#endregion
}
}