public virtual object Deserialize(Cell _data, ConversionContext _context = null)
        {
            if (_data == null ||
                String.IsNullOrWhiteSpace(_data.Data)) {
                return null;
            }

            string strData = _data.Data;

            switch (DataType.Name) {
                case "String":
                    return strData;
                case "Int32":
                    int result;
                    if (Int32.TryParse(strData, out result)) {
                        return result;
                    }
                    return null;
                case "DateTime":
                    DateTime dt;
                    if (DateTime.TryParse(strData, out dt)) {
                        return dt;
                    }
                    return null;
                case "Boolean":
                    bool b;
                    if (Boolean.TryParse(strData, out b)) {
                        return b;
                    }
                    return null;
                default:
                    return ParseXml(strData, DataType);
            }
        }
        public override object Deserialize(Cell _data, ConversionContext _context = null)
        {
            object data = base.Deserialize(_data);
            CheckBoxList chkList;

            if (data == null) {
                chkList = new CheckBoxList();
            }
            else {
                chkList = data as CheckBoxList;
            }

            if (_context == null ||
                _context.Field == null ||
                _context.Field.Metadata == null) {
                return chkList;
            }

            if (!_context.Field.Metadata.IsLoaded) {
                _context.Field.Metadata.Load();
            }

            var metadata = _context.Field.Metadata.FirstOrDefault(m => m.Key == ModuleRepository.CheckBoxListMetadataKey);

            if (metadata != null &&
                !String.IsNullOrWhiteSpace(metadata.Value)) {

                var json = new JavaScriptSerializer();
                var items = json.Deserialize<string[]>(metadata.Value);

                if (items != null) {
                    foreach (var i in items) {
                        // avoid adding empty entries to the dictionary
                        if (!String.IsNullOrWhiteSpace(i)) {
                            var newItem = new CheckBoxItem {
                                Key = i.EscapeName(),
                                Value = i
                            };

                            // checked options will already be present in the list
                            if(!chkList.Any(it => it.Value == i)) {
                                chkList.Add(newItem);
                            }
                        }
                    }
                }
            }

            return chkList;
        }
        public override string Serialize(DynamicModuleField _obj, ConversionContext _context = null)
        {
            if (_context == null) {
                throw new ArgumentNullException("_context");
            }
            if (_obj == null) {
                throw new ArgumentNullException("_obj");
            }

            var data = _obj.Data as HtmlText;

            if (data != null && !String.IsNullOrWhiteSpace(data.Text)) {
                data.Text = HttpUtility.HtmlDecode(data.Text);
                _obj.Data = data;
            }

            return base.Serialize(_obj, _context);
        }
        public override object Deserialize(Cell _data, ConversionContext _context = null)
        {
            object data =  base.Deserialize(_data);
            DropdownButton ddButton;

            if (data == null) {
                ddButton = new DropdownButton();
            }
            else {
                ddButton = data as DropdownButton;
            }

            if (_context == null ||
                _context.Field == null ||
                _context.Field.Metadata == null) {
                return ddButton;
            }

            if (!_context.Field.Metadata.IsLoaded) {
                _context.Field.Metadata.Load();
            }

            var metadata = _context.Field.Metadata.FirstOrDefault(m => m.Key == ModuleRepository.DropdownButtonMetadataKey);

            if (metadata != null &&
                !String.IsNullOrWhiteSpace(metadata.Value)) {

                var json = new JavaScriptSerializer();
                var items = json.Deserialize<string[]>(metadata.Value);

                if (items != null) {
                    foreach (var i in items) {
                        if (!String.IsNullOrWhiteSpace(i)) {
                            // avoid adding empty entries to the dictionary
                            ddButton.ValidValues.Add(i.EscapeName(), i);
                        }
                    }
                }
            }

            return ddButton;
        }
Exemple #5
0
        public override string Serialize(DynamicModuleField _obj, ConversionContext _context = null)
        {
            // For security reasons we cannot send the user's password in plain text to the browser.
            // We send a bogus text. Because of this, we need to check whether the user
            // has changed the password value or not.

            if (_context == null) {
                throw new ArgumentNullException("_context");
            }
            if (_obj == null) {
                throw new ArgumentNullException("_obj");
            }

            var data = _obj.Data as Password;

            // A Password field cannot be set to null or empty string by design
            if (data == null ||
                String.IsNullOrWhiteSpace(data.Value) ||
                data.Value == Password.BogusText) {

                // The user has not changed his password.
                // Let's retrieve the original value from the database and store it again.
                var originalModel = new DynamicModuleField();

                originalModel.Data = Deserialize(_context.Cell, _context);

                _obj.Data = originalModel.Data;
            }
            else {
                // The user is setting a new password. We'll generate a hash for it
                var hash = new Hash(Hash.Provider.SHA1);
                data.Value = hash.Calculate(new Data(data.Value), new Data("|)0ver3ncrypt10n_k3y")).Base64;
            }

            return base.Serialize(_obj, _context);
        }
 public override string Serialize(DynamicModuleField _obj, ConversionContext _context = null)
 {
     return base.Serialize(_obj);
 }
 public override string Serialize(DynamicModuleField _obj, ConversionContext _context = null)
 {
     return(base.Serialize(_obj));
 }
        public virtual string Serialize(DynamicModuleField _obj, ConversionContext _context = null)
        {
            if (_obj == null || _obj.Data == null) {
                return null;
            }

            switch (DataType.Name) {
                case "String":
                case "Int32":
                case "DateTime":
                case "Boolean":
                    return _obj.Data.ToString();
                default:
                    return GenerateXml(_obj.Data);
            }
        }