Exemplo n.º 1
0
        private Control GenerateDropdownList(AMLParam param, string id)
        {
            DropDownList drop = new DropDownList();

            drop.ID = id;
            drop.Attributes.Add("Class", "amount form-control");
            foreach (string ele in param.StrEnum)
            {
                ListItem litem = new ListItem();
                litem.Text = ele;
                if (litem.Text.ToLower() == param.DefaultValue.ToLower())
                {
                    litem.Selected = true;
                }
                drop.Items.Add(litem);
            }
            return(drop);
        }
Exemplo n.º 2
0
        private Control GenerateControlDefault(AMLParam param, string id)
        {
            TextBox txt = new TextBox();

            txt.ID   = id;
            txt.Text = param.DefaultValue;
            txt.Attributes.Add("Class", "amount form-control form-control-number");
            if (param.StrEnum != null && param.StrEnum.Count > 0)      // Droplist
            {
                return(GenerateDropdownList(param, id));
            }
            else if (param.Type == "integer")
            {
                txt.TextMode = TextBoxMode.Number;
            }
            else if (param.Format == "script")
            {
                txt.TextMode = TextBoxMode.MultiLine;
            }
            return(txt);
        }
        private List <AMLParam> ParseMLParmeter(string jsonStr, string ParameterXPath)
        {
            List <AMLParam> aMLParams;

            try
            {
                List <AMLParam> aMLParams1 = new List <AMLParam>();
                JToken          jTokens    = JObject.Parse(jsonStr).SelectToken(ParameterXPath);
                JArray          jArrays    = JArray.Parse(jTokens["required"].ToString());
                JObject         jObjects   = JObject.Parse(jTokens["properties"].ToString());
                jArrays.ToList <JToken>();
                foreach (KeyValuePair <string, JToken> keyValuePair in jObjects)
                {
                    AMLParam aMLParam = new AMLParam()
                    {
                        Name         = keyValuePair.Key,
                        Type         = keyValuePair.Value["type"].ToString(),
                        Format       = (keyValuePair.Value["format"] != null ? keyValuePair.Value["format"].ToString() : ""),
                        Description  = (keyValuePair.Value["description"] != null ? keyValuePair.Value["description"].ToString() : ""),
                        DefaultValue = (keyValuePair.Value["default"] != null ? keyValuePair.Value["default"].ToString() : "")
                    };
                    string[] strArrays = aMLParam.Description.Split(new char[] { '|' });
                    if ((int)strArrays.Length == 2)
                    {
                        aMLParam.Alias       = strArrays[0];
                        aMLParam.Description = strArrays[1];
                    }
                    if (aMLParam.Type == "bool")
                    {
                        aMLParam.StrEnum.Add("true");
                        aMLParam.StrEnum.Add("false");
                    }
                    if (keyValuePair.Value["enum"] != null)
                    {
                        JArray jArrays1 = JArray.Parse(keyValuePair.Value["enum"].ToString());
                        aMLParam.StrEnum = jArrays1.ToObject <List <string> >();
                        if (string.IsNullOrEmpty(aMLParam.DefaultValue))
                        {
                            aMLParam.DefaultValue = aMLParam.StrEnum[0];
                        }
                    }
                    else if ((aMLParam.Type == "integer" ? true : aMLParam.Type == "number"))
                    {
                        if (string.IsNullOrEmpty(aMLParam.DefaultValue))
                        {
                            aMLParam.DefaultValue = "0";
                        }
                        else if (aMLParam.Type == "bool" && string.IsNullOrEmpty(aMLParam.DefaultValue))
                        {
                            aMLParam.DefaultValue = "true";
                        }
                    }
                    aMLParams1.Add(aMLParam);
                }
                aMLParams = aMLParams1;
            }
            catch (Exception exception)
            {
                aMLParams = null;
            }
            return(aMLParams);
        }