private static void SetupDictionary <T>(IMvcContext context, object obj, KeyValuePair <string, object> p) { var name = p.Key; var dict = p.Value as IDictionary <string, T>; var stringDefinition = context.Get(name); if (!string.IsNullOrWhiteSpace(stringDefinition)) //try to parse json or tag { stringDefinition = stringDefinition.Trim(); if (stringDefinition.StartsWith("/") && stringDefinition.EndsWith("/")) //is tag notation { var srcdict = TagHelper.Parse(stringDefinition); foreach (var sp in srcdict) { dict[sp.Key] = sp.Value.To <T>(); } } else if ((stringDefinition.StartsWith("{") && stringDefinition.EndsWith("}")) || (stringDefinition.StartsWith("[") && stringDefinition.EndsWith("]"))) //json marker { var uson = stringDefinition.ToUson(); if (uson.UObjMode == UObjMode.Array) { for (var i = 0; i < uson.Array.Count; i++) { dict[i.ToStr()] = uson.Array[i].ToStr().To <T>(); } } else { foreach (var up in uson.Properties) { dict[up.Key] = up.Value.ToStr().To <T>(); } } } } else { //bind with all notation var _prefix = "."; /* RESERVED FOR MAY-BE CUSTOM BIND * var bind = * obj.GetType() * .GetProperty(p.Key) * .GetCustomAttributes(typeof (BindAttribute), true) * .FirstOrDefault() as BindAttribute; */ var parameters = context.GetAll(_prefix); foreach (var valuePair in parameters) { dict[valuePair.Key] = valuePair.Value.To <T>(); } } }
private IChartConfig PrepareChartConfig(IMvcContext context) { if (context.ActionResult is IChartConfig) { return(context.ActionResult as IChartConfig); } if (context.ActionResult is Exception) { return(ChartConfig.Create(context.ActionResult as Exception)); } var result = new ChartConfig { Id = context.Get("id", DateTime.Now.Ticks).ToString(CultureInfo.InvariantCulture), Container = context.Get("container", string.Empty), Width = context.Get("width", "400"), Height = context.Get("height", "300"), Debug = context.Get("debug", "0"), Type = context.Get("type", "Column2D"), Divlines = context.Get("divlines", -1) }; var specAttrs = context.GetAll("fc"); foreach (var attr in specAttrs) { result.Set(attr.Key, attr.Value); } if (context.ActionResult is ChartState) { result.State = context.ActionResult as ChartState; } else { result.NativeResult = context.ActionResult; } return(result); }
private static GraphOptions ExtractOptions(IMvcContext context) { string format = context.Get(FORMATPARAM, GraphOptions.SVGFORMAT); string algorithm = context.Get(ALGORITHMPARAM, GraphOptions.DOTAGORITHM); bool tune = context.Get(TUNEPARAM, true); IEnumerable <KeyValuePair <string, string> > overrides = context.GetAll(OVERRIDEPARAMPREFIX); var options = new GraphOptions { Tune = tune, Algorithm = algorithm, Format = format, Dialect = GraphOptions.DOTDIALECT }; foreach (var o in overrides) { options.OverrideGraphAttributes[o.Key] = o.Value; } options.Context = context; return(options); }
private IChartConfig PrepareChartConfig(IMvcContext context) { if (context.ActionResult is IChartConfig) { return context.ActionResult as IChartConfig; } if (context.ActionResult is Exception) { return ChartConfig.Create(context.ActionResult as Exception); } var result = new ChartConfig { Id = context.Get("id", DateTime.Now.Ticks).ToString(CultureInfo.InvariantCulture), Container = context.Get("container", string.Empty), Width = context.Get("width", "400"), Height = context.Get("height", "300"), Debug = context.Get("debug", "0"), Type = context.Get("type", "Column2D"), Divlines = context.Get("divlines", -1) }; var specAttrs = context.GetAll("fc"); foreach (var attr in specAttrs) { result.Set(attr.Key, attr.Value); } if (context.ActionResult is ChartState) { result.State = context.ActionResult as ChartState; } else { result.NativeResult = context.ActionResult; } return result; }