コード例 #1
0
        private PropertySerializeInfo GetPropertySerializationInfo(DotvvmProperty property)
        {
            var binding = GetBinding(property);

            if (binding == null && !typeof(ITemplate).IsAssignableFrom(property.PropertyType))
            {
                JsonSerializerSettings settings = DefaultViewModelSerializer.CreateDefaultSettings();
                settings.StringEscapeHandling = StringEscapeHandling.EscapeHtml;
                return(new PropertySerializeInfo
                {
                    Property = property,
                    Js = JsonConvert.SerializeObject(GetValue(property), Formatting.None, settings),
                    IsSerializable = true
                });
            }
            else if (binding is IValueBinding)
            {
                return(new PropertySerializeInfo
                {
                    Property = property,
                    Js = (binding as IValueBinding).GetKnockoutBindingExpression(this),
                    IsSerializable = true
                });
            }
            else
            {
                return(new PropertySerializeInfo {
                    Property = property
                });
            }
        }
コード例 #2
0
ファイル: DotvvmMarkupControl.cs プロジェクト: wushian/dotvvm
        private PropertySerializeInfo GetPropertySerializationInfo(DotvvmProperty property)
        {
            if (ContainsPropertyStaticValue(property))
            {
                JsonSerializerSettings settings = DefaultViewModelSerializer.CreateDefaultSettings();
                settings.StringEscapeHandling = StringEscapeHandling.EscapeHtml;

                return(new PropertySerializeInfo {
                    Property = property,
                    Js = JsonConvert.SerializeObject(GetValue(property), Formatting.None, settings),
                    IsSerializable = true
                });
            }
            else if (GetBinding(property) is IValueBinding valueBinding)
            {
                return(new PropertySerializeInfo {
                    Property = property,
                    Js = valueBinding.GetKnockoutBindingExpression(this),
                    IsSerializable = true
                });
            }
            else
            {
                return(new PropertySerializeInfo {
                    Property = property
                });
            }
        }
コード例 #3
0
        static T Populate <T>(string json, JObject encryptedValues = null)
        {
            var serializer = JsonSerializer.Create(DefaultViewModelSerializer.CreateDefaultSettings());

            serializer.Converters.Add(CreateConverter(true, encryptedValues));

            //serializer.Populate(new StringReader(json), viewModel);
            return(serializer.Deserialize <T>(new JsonTextReader(new StringReader(json))));
        }
コード例 #4
0
        /// <summary>
        /// Returns Javascript expression that represents the property value (even if the property contains hardcoded value)
        /// </summary>
        public static string GetKnockoutBindingExpression(this DotvvmBindableObject obj, DotvvmProperty property)
        {
            var binding = obj.GetValueBinding(property);

            if (binding != null)
            {
                return(binding.GetKnockoutBindingExpression(obj));
            }
            return(JsonConvert.SerializeObject(obj.GetValue(property), DefaultViewModelSerializer.CreateDefaultSettings()));
        }
コード例 #5
0
        static string Serialize <T>(T viewModel, out JObject encryptedValues, bool isPostback = false)
        {
            encryptedValues = new JObject();
            var serializer = JsonSerializer.Create(DefaultViewModelSerializer.CreateDefaultSettings());

            serializer.Converters.Add(CreateConverter(isPostback, encryptedValues));

            var output = new StringWriter();

            serializer.Serialize(output, viewModel);
            return(output.ToString());
        }
コード例 #6
0
        protected internal string TranslateValueOrBinding(DotvvmProperty property)
        {
            var binding = GetValueBinding(property);

            if (binding == null)
            {
                return(JsonConvert.SerializeObject(GetValue(property), DefaultViewModelSerializer.CreateDefaultSettings()));
            }
            else
            {
                return("ko.unwrap(" + binding.GetKnockoutBindingExpression(this) + ")");
            }
        }
コード例 #7
0
        private static string TranslateRouteParameter(DotvvmBindableObject control, KeyValuePair <string, object> param, bool caseSensitive = false)
        {
            string expression = "";

            if (param.Value is IBinding)
            {
                EnsureValidBindingType(param.Value as IBinding);

                expression = (param.Value as IValueBinding)?.GetKnockoutBindingExpression(control)
                             ?? JsonConvert.SerializeObject((param.Value as IStaticValueBinding)?.Evaluate(control), DefaultViewModelSerializer.CreateDefaultSettings());
            }
            else
            {
                expression = JsonConvert.SerializeObject(param.Value, DefaultViewModelSerializer.CreateDefaultSettings());
            }
            return(JsonConvert.SerializeObject(caseSensitive ? param.Key : param.Key.ToLower()) + ": " + expression);
        }
コード例 #8
0
ファイル: DotvvmMarkupControl.cs プロジェクト: llenroc/dotvvm
        private PropertySerializeInfo GetPropertySerializationInfo(DotvvmProperty property)
        {
            var binding = GetBinding(property);

            if (binding == null)
            {
                return(new PropertySerializeInfo
                {
                    Property = property,
                    Js = JsonConvert.SerializeObject(GetValue(property), Formatting.None, DefaultViewModelSerializer.CreateDefaultSettings()),
                    IsSerializable = true
                });
            }
            else if (binding is IValueBinding)
            {
                return(new PropertySerializeInfo
                {
                    Property = property,
                    Js = (binding as IValueBinding).GetKnockoutBindingExpression(this),
                    IsSerializable = true
                });
            }
            else
            {
                return(new PropertySerializeInfo {
                    Property = property
                });
            }
        }
コード例 #9
0
        private static void AddValidatedValue(IHtmlWriter writer, IDotvvmRequestContext context, DotvvmProperty prop, DotvvmControl control)
        {
            writer.AddKnockoutDataBind("dotvvmValidation", control, ValueProperty, renderEvenInServerRenderingMode: true);

            // render options
            var bindingGroup = new KnockoutBindingGroup();

            foreach (var property in ValidationOptionProperties)
            {
                var javascriptName = KnockoutHelper.ConvertToCamelCase(property.Name);
                var optionValue    = control.GetValue(property);
                if (!object.Equals(optionValue, property.DefaultValue))
                {
                    bindingGroup.Add(javascriptName, JsonConvert.SerializeObject(optionValue, DefaultViewModelSerializer.CreateDefaultSettings()));
                }
            }
            writer.AddKnockoutDataBind("dotvvmValidationOptions", bindingGroup);
        }
コード例 #10
0
        public virtual void Add(string name, DotvvmControl control, DotvvmProperty property, Action nullBindingAction = null)
        {
            var binding = control.GetValueBinding(property);

            if (binding == null)
            {
                if (nullBindingAction != null)
                {
                    nullBindingAction();
                }
                else
                {
                    Add(name, JsonConvert.SerializeObject(control.GetValue(property), DefaultViewModelSerializer.CreateDefaultSettings()));
                }
            }
            else
            {
                entries.Add(new KnockoutBindingInfo()
                {
                    Name = name, Expression = GetKnockoutBindingExpression(control, control.GetValueBinding(property))
                });
            }
        }