public void Simple_ModelName() { // arrange var expected = "\"test\":{\"name\":\"value\"}"; var obj = new Dictionary <string, object>() { { Serializer.ModelNameKey, "test" }, { "name", "value" } }; var view = new JsonView(); var viewContext = new ViewContext(); viewContext.ViewData = new ViewDataDictionary(obj); viewContext.RouteData = new RouteData(); viewContext.RouteData.Values.Add("action", "test"); viewContext.HttpContext = HttpHelpers.MockHttpContext(); // act var result = new StringWriter(); view.Render(viewContext, result); // assert Assert.IsTrue(result.ToString().Contains(expected), "expected: {0}, but was: {1}", expected, result); }
/// <summary> /// Updates the configuration from a JSON object serialized to a string. /// /// If parsing fails then a DescriptiveFailure exception will be raised /// containing detailed information about the error. /// </summary> /// <param name="json">JSON object.</param> public void UpdateFromJson(JsonView json) { CheckDescriptiveErrorCode((err) => { return(Api.YOGI_ConfigurationUpdateFromJson(Handle, json.Data, err, err.Capacity)); }); }
public JsonViewModel ToModel(JsonView jsonView) { JsonViewModel model = new JsonViewModel(); model.Json = jsonView.GetValueOrDefault("json").ToJsonOrString(); model.Title = jsonView.GetValueOrDefault2("title").ToStringOrDefault(); return(model); }
public void EnableEditMode() { if (SelectedItem != null) { JsonView.ReadOnly = false; JsonView.ColorScheme = Colors.Menu; JsonView.SetFocus(); } }
private void Initialize(JsonView view) { RegistryName = view.RegistryName; Inherits = view.Inherits; var componentsView = view.Components; _components = new List <ComponentSchema>(componentsView.Count); componentsView.ForEach(e => _components.Add(new ComponentSchema(e))); }
public void JsonParameters_GetCorrectNpgsqlType() { Runnable table = new Runnable(); table.Sql(@" DROP TABLE IF EXISTS jerry_json; CREATE TABLE jerry_json( ""Json"" json NOT NULL, ""JsonB"" jsonb NOT NULL );"); Runner.Command(table); TestModel sample = new TestModel() { Json = new JsonModel() { Value1 = 1, Value3 = 2 }, JsonB = new JsonModel() { Value1 = 3, Value3 = 4 }, }; Runnable <TestModel, object> insert = new Runnable <TestModel, object>(sample); insert.Sql("INSERT INTO jerry_json ( "); insert.M(p => p.ColNames()); insert.Sql(" ) VALUES ( "); insert.M(p => p.Pars()); insert.Sql(");"); Runner.Command(insert); Runnable <object, JsonView> select = new Runnable <object, JsonView>(); select.Sql("SELECT "); select.R(p => p.Star()); select.Sql(" FROM jerry_json "); select.R(p => p.Ali()); select.Sql(";"); JsonView fromDb = Runner.Query(select).FirstOrDefault(); fromDb.Json.ShouldNotBeNull(); fromDb.JsonB.ShouldNotBeNull(); fromDb.Json.Value1.ShouldBe(sample.Json.Value1); fromDb.Json.Value3.ShouldBe(sample.Json.Value3); fromDb.JsonB.Value1.ShouldBe(sample.JsonB.Value1); fromDb.JsonB.Value3.ShouldBe(sample.JsonB.Value3); }
public override void Render(System.Web.Mvc.ViewContext viewContext, System.IO.TextWriter writer) { var focus = (IView)null; ResponseType responseType = ResponseType.None; var routeData = viewContext.RouteData.Values; object tempObj; if (routeData.TryGetValue("responseType", out tempObj) && tempObj is ResponseType) responseType = (ResponseType)tempObj; if (responseType == ResponseType.None) responseType = ServiceHelper.GetResponseType(viewContext); switch (responseType) { case ResponseType.JavaScript: focus = new JavaScriptCallbackResult(); break; case ResponseType.Json: focus = new JsonView(); break; case ResponseType.Xml: focus = new XmlView(); break; case ResponseType.Csv: focus = new CsvResult(); break; case ResponseType.Html: default: focus = viewContext.View; break; } if (focus is SerializedView) ServiceHelper.CopyProperties(this, (SerializedView)focus); if (focus != null) focus.Render(viewContext, writer); }
public string View() { BElement time = new BBText(""); if (_viewModel.ShowTime) { time = new BDiv { InnerElements = new List <BElement> { new BBText(DateTime.Now.ToLongTimeString()) } }; } var ui = new JsonView( new BDiv { InnerElements = new List <BElement> { new BBHeader("Test Page"), new BBText(_viewModel.SomeText), new BButton { InnerText = "Click Me!", OnClick = "ChangeSomeText" }, new BButton { InnerText = "Toogle Show Time", OnClick = "ShowTime" }, time } } ); return(JsonConvert.SerializeObject(ui)); }
public void Simple_Json() { // arrange var expected = "\"object\":{\"name\":\"value\"}"; var obj = new Dictionary<string, object>() { { "name", "value" } }; var view = new JsonView(); var viewContext = new ViewContext(); viewContext.ViewData = new ViewDataDictionary(obj); viewContext.RouteData = new RouteData(); viewContext.RouteData.Values.Add("action", "test"); viewContext.HttpContext = HttpHelpers.MockHttpContext(); // act var result = new StringWriter(); view.Render(viewContext, result); // assert Assert.IsTrue(result.ToString().Contains(expected), "expected: {0}, but was: {1}", expected, result); }
/// <summary> /// Constructs a view from JSON data. /// </summary> /// <param name="json">The JSON data.</param> public PayloadView(JsonView json) : this(json.Data, EncodingType.Json) { }
/// <summary> /// Writes JSON for selected DataRow objects for specified JsonView. /// </summary> /// <param name="jsonWriter">The <see cref="JsonWriter"/>.</param> /// <param name="jsonView">The JsonView.</param> /// <param name="dataRows">The selected DataRow objects.</param> /// <returns>This <see cref="JsonWriter"/> for fluent coding.</returns> public static JsonWriter Write(this JsonWriter jsonWriter, JsonView jsonView, IEnumerable <DataRow> dataRows) { return(jsonWriter.InternalWrite(jsonView, dataRows)); }
/// <summary> /// Writes JSON for specified DataRow and JsonView. /// </summary> /// <param name="jsonWriter">The <see cref="JsonWriter"/>.</param> /// <param name="dataRow">The DataRow.</param> /// <param name="jsonView">The JsonView.</param> /// <returns>This <see cref="JsonWriter"/> for fluent coding.</returns> public static JsonWriter Write(this JsonWriter jsonWriter, DataRow dataRow, JsonView jsonView) { return(Write(jsonWriter, jsonView, dataRow)); }
public async Task onclick(UIMouseEventArgs e) { _ui = await client.GetJsonAsync <JsonView>("api/SampleData/View"); StateHasChanged(); }
public String Index(String date, String timezone, double latitude, double longitude, double elevation, String timeformat, String format, String mode) { //if any of the parameters are empty then return a error saying parameters are missing if (date == "") { Console.WriteLine("date is missing, using todays date"); } if (latitude == 0.0) { return("Error: latitude is a required parameter"); } if (longitude == 0.0) { return("Error: longitude is a required parameter"); } //check if the timezone is valid try { ITimeZone timeZone = new WindowsTimeZone(timezone); } catch (Exception ex) { Console.WriteLine("Time zone is invalid returning error " + ex.Message); return("The time zone you have submitted is not valid. Time zones should be formatted like America/New_York"); } //create a general try catch to prevent major errors try { //create a model to pass to the zmanimService ZmanimModel model = new ZmanimModel(); //store the controller params in the model model.latitude = latitude; model.longitude = longitude; model.elevation = elevation; model.mode = mode; model.timeformat = timeformat; model.timezone = timezone; //check if the date is parsable, if its not then set the model date to null DateTime theDate; if (DateTime.TryParse(date, out theDate)) { model.date = theDate; } else { model.date = null; } //now pass the model to the zmanim service ZmanimService service = new ZmanimService(model); //make sure format is instantiated, if its not then instantiate it if (format == null) { format = "json"; } //pass the model to the view and return the view //choose the view based on the format parameter if (format.ToLower() == "xml") { XmlView view = new XmlView(model); return(view.getView()); } else { //use json as the default format JsonView view = new JsonView(model); return(view.getView()); } } catch (Exception ex) { Console.WriteLine("Error:" + ex.Message); //return a error message return("There was a error generating the zmanim, please ensure all of your input parameters are correct and try again later"); } }
/// <summary> /// Updates the configuration from a JSON object serialized to a string. /// /// If parsing fails then a DetailedFailureException with the /// ConfigurationValidationFailed error will be raised containing detailed /// information about the failure. /// </summary> /// <param name="json">JSON object.</param> public void UpdateFromJson(JsonView json) { int res = YogiCore.YOGI_ConfigurationUpdateFromJson(Handle, json.Data); CheckErrorCode(res); }