private string LoadEmailClientParameters(Vendor.IVendorEmailClient client, Query.Models.EmailClient savedClient = null) { var html = new StringBuilder("<div class=\"row\">"); foreach (var param in client.Parameters) { html.Append("<div class=\"col six\">"); var value = (savedClient != null && savedClient.config.ContainsKey(param.Key) ? savedClient.config[param.Key] : param.Value.DefaultValue).Replace("\"", """); var idattr = " id=\"" + client.Key + "_" + param.Key + "\""; var placeholder = !string.IsNullOrEmpty(param.Value.Placeholder) ? " placeholder=\"" + param.Value.Placeholder + "\"" : ""; switch (param.Value.DataType) { case Vendor.EmailClientDataType.Boolean: break; default: html.Append("<div class=\"row field\">" + param.Value.Name + "</div>"); break; } switch (param.Value.DataType) { case Vendor.EmailClientDataType.Text: html.Append("<div class=\"row input\"><input type=\"text\"" + idattr + " value=\"" + value + "\"" + placeholder + "/></div>"); break; case Vendor.EmailClientDataType.UserOrEmail: html.Append("<div class=\"row input\"><input type=\"text\"" + idattr + " value=\"" + value + "\"" + placeholder + " autocomplete=\"new-email\"/></div>"); break; case Vendor.EmailClientDataType.Password: html.Append("<div class=\"row input\"><input type=\"password\"" + idattr + " value=\"" + (value != "" ? "********" : "") + "\" autocomplete=\"new-password\"/></div>"); break; case Vendor.EmailClientDataType.Number: html.Append("<div class=\"row input\"><input type=\"number\"" + idattr + " value=\"" + value + "\"" + placeholder + "/></div>"); break; case Vendor.EmailClientDataType.List: html.Append("<div class=\"row input\"><select" + idattr + ">" + string.Join("", param.Value.ListOptions?.Select(a => "<option value=\"" + a + (param.Value.DefaultValue == a ? " selected" : "") + "\">" + a + "</option>") ?? new string[] { "" }) + "</select></div>"); break; case Vendor.EmailClientDataType.Boolean: html.Append("<div class=\"row input\"><input type=\"checkbox\"" + idattr + (value == "1" || value.ToLower() == "true" ? " checked=\"checked\"" : "") + " />" + "<label for=\"" + client.Key + "_" + param.Key + "\">" + param.Value.Name + "</label>" + "</div>"); break; } html.Append("</div>"); } return(html.ToString() + "</div>"); }
private void ValidateEmailClientParameters(Dictionary <string, string> parameters, Vendor.IVendorEmailClient client, Query.Models.EmailClient emailClient = null) { var changes = new List <KeyValuePair <string, string> >(); foreach (var item in parameters) { if (!client.Parameters.ContainsKey(item.Key)) { throw new Exception("Could not find parameter " + item.Key); } var param = client.Parameters[item.Key]; if (param.Required == true && string.IsNullOrEmpty(item.Value) && param.DataType != Vendor.EmailClientDataType.Password) { throw new Exception(param.Name + " is required"); } if (param.DataType == Vendor.EmailClientDataType.Password) { //find password placeholder if (item.Value.Replace("*", "") == "") { if (emailClient != null && emailClient.config.ContainsKey(item.Key)) { //no password change changes.Add(new KeyValuePair <string, string>(item.Key, emailClient.config[item.Key])); } else { //no password changes.Add(new KeyValuePair <string, string>(item.Key, "")); } } } //check boolean parameters for valid values if (param.DataType == Vendor.EmailClientDataType.Boolean) { if (item.Value != "True" && item.Value != "False") { throw new Exception(param.Name + " is not valid"); } } //make chamges to parameters list foreach (var change in changes) { parameters[change.Key] = change.Value; } } }