public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) { var pr = JsonSerializerExtensions.CurrentPropertyRoute; if (pr == null || typeof(IRootEntity).IsAssignableFrom(pr.Type)) { pr = PropertyRoute.Root(value.GetType()); } else if (pr.Type.ElementType() == value.GetType()) { pr = pr.Add("Item"); } ModifiableEntity mod = (ModifiableEntity)value; writer.WriteStartObject(); var entity = mod as Entity; if (entity != null) { writer.WritePropertyName("Type"); writer.WriteValue(TypeLogic.TryGetCleanName(mod.GetType())); writer.WritePropertyName("id"); writer.WriteValue(entity.IdOrNull == null ? null : entity.Id.Object); if (entity.IsNew) { writer.WritePropertyName("isNew"); writer.WriteValue(true); } if (Schema.Current.Table(entity.GetType()).Ticks != null) { writer.WritePropertyName("ticks"); writer.WriteValue(entity.Ticks.ToString()); } } else { writer.WritePropertyName("Type"); writer.WriteValue(mod.GetType().Name); } if (!(mod is MixinEntity)) { writer.WritePropertyName("toStr"); writer.WriteValue(mod.ToString()); } writer.WritePropertyName("modified"); writer.WriteValue(mod.Modified == ModifiedState.Modified || mod.Modified == ModifiedState.SelfModified); foreach (var kvp in PropertyConverter.GetPropertyConverters(value.GetType())) { WriteJsonProperty(writer, serializer, mod, kvp.Key, kvp.Value, pr); } if (entity != null && entity.Mixins.Any()) { writer.WritePropertyName("mixins"); writer.WriteStartObject(); foreach (var m in entity.Mixins) { var prm = pr.Add(m.GetType()); using (JsonSerializerExtensions.SetCurrentPropertyRoute(prm)) { writer.WritePropertyName(m.GetType().Name); serializer.Serialize(writer, m); } } writer.WriteEndObject(); } writer.WriteEndObject(); }
public override void WriteJson(JsonWriter writer, object?value, JsonSerializer serializer) { using (HeavyProfiler.LogNoStackTrace("WriteJson", () => value !.GetType().Name)) { PropertyRoute pr = GetCurrentPropertyRoute(value !); ModifiableEntity mod = (ModifiableEntity)value !; writer.WriteStartObject(); if (mod is Entity entity) { writer.WritePropertyName("Type"); writer.WriteValue(TypeLogic.TryGetCleanName(mod.GetType())); writer.WritePropertyName("id"); writer.WriteValue(entity.IdOrNull == null ? null : entity.Id.Object); if (entity.IsNew) { writer.WritePropertyName("isNew"); writer.WriteValue(true); } if (Schema.Current.Table(entity.GetType()).Ticks != null) { writer.WritePropertyName("ticks"); writer.WriteValue(entity.Ticks.ToString()); } } else { writer.WritePropertyName("Type"); writer.WriteValue(mod.GetType().Name); } if (!(mod is MixinEntity)) { writer.WritePropertyName("toStr"); writer.WriteValue(mod.ToString()); } writer.WritePropertyName("modified"); writer.WriteValue(mod.Modified == ModifiedState.Modified || mod.Modified == ModifiedState.SelfModified); foreach (var kvp in PropertyConverter.GetPropertyConverters(value !.GetType())) { WriteJsonProperty(writer, serializer, mod, kvp.Key, kvp.Value, pr); } if (mod.Mixins.Any()) { writer.WritePropertyName("mixins"); writer.WriteStartObject(); foreach (var m in mod.Mixins) { var prm = pr.Add(m.GetType()); using (JsonSerializerExtensions.SetCurrentPropertyRoute(prm)) { writer.WritePropertyName(m.GetType().Name); serializer.Serialize(writer, m); } } writer.WriteEndObject(); } writer.WriteEndObject(); } }
public override void Execute() { #line 4 "..\..\Signum\Views\NormalControl.cshtml" ModifiableEntity modifiable = Model.UntypedValue as ModifiableEntity; string partialViewName = ViewData[ViewDataKeys.PartialViewName].ToString(); var wc = new WidgetContext { TypeContext = Model, PartialViewName = partialViewName, Url = Url }; #line default #line hidden WriteLiteral("\r\n<h3>\r\n"); WriteLiteral(" "); #line 10 "..\..\Signum\Views\NormalControl.cshtml" Write(Html.AntiForgeryToken()); #line default #line hidden WriteLiteral("\r\n"); WriteLiteral(" "); #line 11 "..\..\Signum\Views\NormalControl.cshtml" Write(Html.Hidden(ViewDataKeys.TabId, ViewData[ViewDataKeys.TabId])); #line default #line hidden WriteLiteral("\r\n"); WriteLiteral(" "); #line 12 "..\..\Signum\Views\NormalControl.cshtml" Write(Html.Hidden(ViewDataKeys.PartialViewName, ViewData[ViewDataKeys.PartialViewName])); #line default #line hidden WriteLiteral("\r\n\r\n"); #line 14 "..\..\Signum\Views\NormalControl.cshtml" #line default #line hidden #line 14 "..\..\Signum\Views\NormalControl.cshtml" if (string.IsNullOrEmpty(ViewBag.Title)) { ViewBag.Title = modifiable?.ToString(); } #line default #line hidden WriteLiteral(" <span"); WriteLiteral(" class=\"sf-entity-title\""); WriteLiteral(">"); #line 18 "..\..\Signum\Views\NormalControl.cshtml" Write(ViewBag.Title); #line default #line hidden WriteLiteral("</span>,\r\n <br />\r\n <small"); WriteLiteral(" class=\"sf-type-nice-name\""); WriteLiteral(">"); #line 20 "..\..\Signum\Views\NormalControl.cshtml" Write(Navigator.Manager.GetTypeTitle(modifiable)); #line default #line hidden WriteLiteral("</small>\r\n</h3>\r\n"); #line 22 "..\..\Signum\Views\NormalControl.cshtml" Write(Html.RenderWidgets(wc )); #line default #line hidden WriteLiteral("\r\n<div"); WriteLiteral(" class=\"sf-button-bar\""); WriteLiteral(">\r\n"); WriteLiteral(" "); #line 25 "..\..\Signum\Views\NormalControl.cshtml" Write(ButtonBarEntityHelper.GetForEntity(new EntityButtonContext { Url = Url, ViewMode = ViewMode.Navigate, ShowOperations = (bool)ViewData[ViewDataKeys.ShowOperations], ControllerContext = this.ViewContext, PartialViewName = ViewData[ViewDataKeys.PartialViewName].ToString(), Prefix = Model.Prefix }, (ModifiableEntity)Model.UntypedValue).ToStringButton(Html)); #line default #line hidden WriteLiteral("\r\n</div>\r\n"); #line 35 "..\..\Signum\Views\NormalControl.cshtml" Write(Html.ValidationSummaryAjax()); #line default #line hidden WriteLiteral("\r\n"); #line 36 "..\..\Signum\Views\NormalControl.cshtml" Write(Html.HiddenRuntimeInfo(Model)); #line default #line hidden WriteLiteral("\r\n"); #line 37 "..\..\Signum\Views\NormalControl.cshtml" if (((bool?)ViewData[ViewDataKeys.WriteEntityState]) == true) { #line default #line hidden #line 39 "..\..\Signum\Views\NormalControl.cshtml" Write(Html.Hidden(ViewDataKeys.EntityState, Navigator.Manager.SerializeEntity(modifiable))); #line default #line hidden #line 39 "..\..\Signum\Views\NormalControl.cshtml" } #line default #line hidden #line 41 "..\..\Signum\Views\NormalControl.cshtml" using (Html.RenderEmbeddedWidget(wc)) { #line default #line hidden WriteLiteral(" <div"); WriteLiteral(" id=\"divMainControl\""); WriteLiteral(" class=\"sf-main-control\""); WriteLiteral(" data-prefix=\""); #line 43 "..\..\Signum\Views\NormalControl.cshtml" Write(Model.Prefix); #line default #line hidden WriteLiteral("\""); WriteLiteral(" data-test-ticks=\""); #line 43 "..\..\Signum\Views\NormalControl.cshtml" Write(DateTime.Now.Ticks); #line default #line hidden WriteLiteral("\""); WriteLiteral(">\r\n"); #line 44 "..\..\Signum\Views\NormalControl.cshtml" #line default #line hidden #line 44 "..\..\Signum\Views\NormalControl.cshtml" Html.RenderPartial(partialViewName, Model); #line default #line hidden WriteLiteral("\r\n </div>\r\n"); #line 46 "..\..\Signum\Views\NormalControl.cshtml" } #line default #line hidden }