-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathStackConfig.cs
More file actions
84 lines (74 loc) · 3.74 KB
/
StackConfig.cs
File metadata and controls
84 lines (74 loc) · 3.74 KB
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
using System;
using System.Configuration;
using Microsoft.Extensions.Options;
using Contentstack.Core.Configuration;
namespace Contentstack.Core.Tests
{
public class StackConfig
{
System.Configuration.Configuration currentConfiguration = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
System.Configuration.Configuration assemblyConfiguration
{
get
{
return ConfigurationManager.OpenExeConfiguration(new Uri(uriString: GetType().Assembly.CodeBase).LocalPath);
}
}
public static ContentstackClient GetStack()
{
StackConfig config = new StackConfig();
if (config.assemblyConfiguration.HasFile && string.Compare(config.assemblyConfiguration.FilePath, config.currentConfiguration.FilePath, true) != 0)
{
config.assemblyConfiguration.SaveAs(config.currentConfiguration.FilePath);
ConfigurationManager.RefreshSection("appSettings");
ConfigurationManager.RefreshSection("connectionStrings");
}
string apiKey = ConfigurationManager.AppSettings["api_key"];
string delivery_token = ConfigurationManager.AppSettings["delivery_token"];
string environment = ConfigurationManager.AppSettings["environment"];
string host = ConfigurationManager.AppSettings["host"];
Configuration.ContentstackOptions contentstackOptions = new Configuration.ContentstackOptions
{
ApiKey = apiKey,
DeliveryToken = delivery_token,
Environment = environment,
Host = host,
Timeout = 4500,
//Proxy = new System.Net.WebProxy("http://example.com:8080")
};
ContentstackClient contentstackClient = new ContentstackClient(new OptionsWrapper<Configuration.ContentstackOptions>(contentstackOptions));
return contentstackClient;
}
public static ContentstackClient GetLPStack()
{
StackConfig config = new StackConfig();
if (config.assemblyConfiguration.HasFile && string.Compare(config.assemblyConfiguration.FilePath, config.currentConfiguration.FilePath, true) != 0)
{
config.assemblyConfiguration.SaveAs(config.currentConfiguration.FilePath);
ConfigurationManager.RefreshSection("appSettings");
ConfigurationManager.RefreshSection("connectionStrings");
}
string apiKey = ConfigurationManager.AppSettings["api_key"];
string delivery_token = ConfigurationManager.AppSettings["delivery_token"];
string environment = ConfigurationManager.AppSettings["environment"];
string host = ConfigurationManager.AppSettings["host"];
Configuration.ContentstackOptions contentstackOptions = new Configuration.ContentstackOptions
{
ApiKey = apiKey,
DeliveryToken = delivery_token,
Environment = environment,
Host = host,
Timeout = 4500,
LivePreview = new LivePreviewConfig
{
Enable = true,
PreviewToken = "preview_token", // Replace with a valid preview token
Host = "test_host" // Replace with a valid preview host (e.g., "rest-preview.contentstack.com")
}
//Proxy = new System.Net.WebProxy("http://example.com:8080")
};
ContentstackClient contentstackClient = new ContentstackClient(new OptionsWrapper<Configuration.ContentstackOptions>(contentstackOptions));
return contentstackClient;
}
}
}