-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathPerplexUmbracoFormsConfig.cs
More file actions
151 lines (126 loc) · 6.51 KB
/
PerplexUmbracoFormsConfig.cs
File metadata and controls
151 lines (126 loc) · 6.51 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
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
using System;
using System.Collections.Generic;
using System.IO;
using System.Web.Hosting;
using System.Xml.Serialization;
using static PerplexUmbraco.Forms.Code.Constants;
namespace PerplexUmbraco.Forms.Code.Configuration
{
/// <summary>
/// Configuration settings read from a config XML file
/// </summary>
[XmlRoot("PerplexUmbracoFormsConfig")]
public class PerplexUmbracoFormsConfig
{
/// <summary>
/// Cached instance of configuration
/// </summary>
private static PerplexUmbracoFormsConfig Config;
private PerplexUmbracoFormsConfig() { }
public static PerplexUmbracoFormsConfig Get
{
get
{
if (Config == null)
{
// If the file is not there => Create with defaults
CreateIfNotExists();
// Create from configuration file
string path = GetFilePath();
XmlSerializer serializer = new XmlSerializer(typeof(PerplexUmbracoFormsConfig));
// Read from file
using (var reader = new StreamReader(GetFilePath()))
{
Config = (PerplexUmbracoFormsConfig)serializer.Deserialize(reader);
}
}
return Config;
}
}
public static void CreateIfNotExists()
{
// Create from configuration file
string path = GetFilePath();
// If it is not there yet, serialize our defaults to file
if (!File.Exists(path))
{
XmlSerializer serializer = new XmlSerializer(typeof(PerplexUmbracoFormsConfig));
using (StreamWriter file = new StreamWriter(path))
{
serializer.Serialize(file, DefaultConfig);
}
}
}
public List<FieldTypeConfig> HideFieldTypes { get; set; }
public PerplexFileUploadConfig PerplexFileUpload { get; set; }
public PerplexImageUploadConfig PerplexImageUpload { get; set; }
public PerplexRecaptchaConfig PerplexRecaptchaConfig { get; set; }
public PerplexCacheConfig PerplexCacheConfig { get; set; }
private static string GetFilePath()
{
return HostingEnvironment.MapPath(Constants.CONFIGURATION_FILE_PATH);
}
private static readonly PerplexUmbracoFormsConfig DefaultConfig = new PerplexUmbracoFormsConfig
{
HideFieldTypes = new List<FieldTypeConfig>
{
// Perplex Fields =>
new FieldTypeConfig { Guid = new Guid(EnmFieldTypeId.PerplexFileUpload.Description()), Name = "Perplex File Upload", Hide = false },
new FieldTypeConfig { Guid = new Guid(EnmFieldTypeId.PerplexImageUpload.Description()), Name = "Perplex Image Upload", Hide = false },
new FieldTypeConfig { Guid = new Guid(EnmFieldTypeId.PerplexTextField.Description()), Name = "Perplex Text field", Hide = false },
new FieldTypeConfig { Guid = new Guid(EnmFieldTypeId.PerplexTextarea.Description()), Name = "Perplex Textarea", Hide = false },
new FieldTypeConfig { Guid = new Guid(EnmFieldTypeId.PerplexRecaptcha.Description()), Name = "Perplex Recaptcha", Hide = false },
// <= Perplex Fields
// Built-in Fields =>
new FieldTypeConfig { Guid = new Guid(EnmFieldTypeId.Checkbox.Description()), Name = "Checkbox", Hide = false },
new FieldTypeConfig { Guid = new Guid(EnmFieldTypeId.Date.Description()), Name = "Date", Hide = false },
new FieldTypeConfig { Guid = new Guid(EnmFieldTypeId.Dropdown.Description()), Name = "Dropdown", Hide = false },
new FieldTypeConfig { Guid = new Guid(EnmFieldTypeId.ShortAnswer.Description()), Name = "Short answer", Hide = true },
new FieldTypeConfig { Guid = new Guid(EnmFieldTypeId.LongAnswer.Description()), Name = "Long answer", Hide = true },
new FieldTypeConfig { Guid = new Guid(EnmFieldTypeId.FileUpload.Description()), Name = "File upload", Hide = true },
new FieldTypeConfig { Guid = new Guid(EnmFieldTypeId.Password.Description()), Name = "Password", Hide = true },
new FieldTypeConfig { Guid = new Guid(EnmFieldTypeId.MultipleChoice.Description()), Name = "Multiple choice", Hide = false },
new FieldTypeConfig { Guid = new Guid(EnmFieldTypeId.SingleChoice.Description()), Name = "Single choice", Hide = false },
new FieldTypeConfig { Guid = new Guid(EnmFieldTypeId.TitleAndDescription.Description()), Name = "Title and description", Hide = false },
new FieldTypeConfig { Guid = new Guid(EnmFieldTypeId.Recaptcha.Description()), Name = "Recaptcha", Hide = true },
new FieldTypeConfig { Guid = new Guid(EnmFieldTypeId.Hidden.Description()), Name = "Hidden", Hide = true },
// <= Built-in Fields
},
PerplexFileUpload = new PerplexFileUploadConfig
{
AllowedExtensions = new List<ExtensionConfig>
{
new ExtensionConfig { Extension = "doc" },
new ExtensionConfig { Extension = "docx" },
new ExtensionConfig { Extension = "pdf" },
new ExtensionConfig { Extension = "xls" },
new ExtensionConfig { Extension = "xlsx" },
new ExtensionConfig { Extension = "zip" },
new ExtensionConfig { Extension = "rar" },
},
MaxFileSizeRaw = ""
},
PerplexImageUpload = new PerplexImageUploadConfig
{
AllowedExtensions = new List<ExtensionConfig>
{
new ExtensionConfig { Extension = "jpg" },
new ExtensionConfig { Extension = "jpeg" },
new ExtensionConfig { Extension = "png" },
new ExtensionConfig { Extension = "gif" },
new ExtensionConfig { Extension = "tif" },
},
MaxFileSizeRaw = ""
},
PerplexRecaptchaConfig = new PerplexRecaptchaConfig
{
ErrorMessage = ""
},
PerplexCacheConfig = new PerplexCacheConfig
{
EnableCache = false,
CacheDurationInMinutes = 10
}
};
}
}