private bool PortfolioAjaxAction(HttpListenerContext context) { UiFieldAttribute.SetFieldsFromPropNameValue( context.Request.QueryString.AllKeys.ToDictionary(q => q, q => context.Request.QueryString[q]), RobotFarm.Instance.portfolioTradeSettings, true); RobotFarm.Instance.SaveSettings(); const string answer = "{\"status\": \"OK\"}"; WriteJsonResponse(context, answer); return(true); }
public void TestPropertyDic() { var sets = new AutoTradeSettings { MaxLeverage = 6, TradeAuto = true }; var nameVal = UiFieldAttribute.GetAttributeNameValue(sets); Assert.Greater(nameVal.Count, 0); var cat = new AutoTradeSettings(); UiFieldAttribute.SetFieldsFromPropNameValue( nameVal.ToDictionary(p => p.PropName, p => Converter.GetStringFromObject(p.Value)), cat, false); Assert.AreEqual(sets.MaxLeverage, cat.MaxLeverage); Assert.AreEqual(sets.TradeAuto, cat.TradeAuto); }
private void RenderPortfolioSettings(StringBuilder sb) { RenderAjaxSaveQuery(sb); var sets = RobotFarm.Instance.portfolioTradeSettings; var setVals = UiFieldAttribute.GetAttributeNameValue(sets); // сформировать таблицу для редактирования значений атрибутов RenderTableOpenTag(sb); RenderTableRowTag(sb, true); sb.AppendLine(" <td>Параметр</td><td>Значение</td></tr>"); foreach (var setVal in setVals) { sb.AppendLine(""); sb.Append(" <tr><td>" + setVal.DisplayName + "</td><td>"); if (setVal.PropType.IsAssignableFrom(typeof(bool))) { sb.Append("<input type=\"checkbox\" name=\"" + setVal.PropName + "\" "); if (((bool?)setVal.Value) ?? false) { sb.Append("checked=\"checked\""); } sb.Append("/>"); } else { sb.Append("<input type=\"text\" name=\"" + setVal.PropName + "\" value=\"" + Converter.GetStringFromObject(setVal.Value) + "\"/>"); } sb.Append("</td></tr>"); } sb.AppendLine(" </table>"); sb.AppendLine("<br/>"); sb.Append("<a href=\"#\" onclick=\""); sb.Append("postChangesToPortfolio()"); sb.Append("\">Сохранить изменения</a>"); sb.AppendLine(" <a href=\"?\">Отменить</a>"); }