Ejemplo n.º 1
0
        /*[TestMethod]
        [Ignore]
        public void Test_Convert_Data_To_Xml() {
            using (var db = new DoverEntities(ConnectionString)) {
                foreach (var rf in db.Cell
                    .Include("Field.FieldDataType")
                    .Include("Field.Metadata")
                    .Include("Field.Module")) {
                    Type dataType = Type.GetType(rf.Field.FieldDataType.Name);
                    if (dataType == null) {
                        dataType = Type.GetType(rf.Field.FieldDataType.Name + ", Com.Dover., Version=1.0.0.0, Culture=neutral, PublicKeyToken=null");
                    }
                    var converter = FieldValueConversion.GetConverter(dataType);
                    var cc = new ConversionContext {
                        Repository = new ModuleRepository(new EntityConnection(ConnectionString)),
                        Field = rf.Field,
                        Module = rf.Field.Module
                    };
                    DefaultFieldValueConverter.SerializationMethod = FieldSerializationMethod.Binary;
                    object obj = converter.Deserialize(rf, cc);
                    DefaultFieldValueConverter.SerializationMethod = FieldSerializationMethod.Xml;
                    rf.Data = converter.Serialize(new DynamicModuleField() {
                        Data = obj,
                        DataType = dataType
                    }, cc);
                }
                db.SaveChanges();
            }
        }

        [TestMethod]
        [Ignore]
        public void Test_Migrate_ModuleReference() {
            var dataType = Type.GetType("Com.Dover.Models.DataTypes.ModuleReference, Com.Dover., Version=1.0.0.0, Culture=neutral, PublicKeyToken=null");
            var converter = FieldValueConversion.GetConverter(dataType);

            using (var db = new DoverEntities(ConnectionString)) {
                foreach (var rf in db.Cell
                    .Include("Field.FieldDataType")
                    .Include("Field.Metadata")
                    .Include("Field.Module")) {

                    if (rf.Field.FieldDataType.Name == "Com.Dover.Models.DataTypes.ModuleReference") {
                        var cc = new ConversionContext {
                            Repository = new ModuleRepository(new EntityConnection(ConnectionString)),
                            Field = rf.Field,
                            Module = rf.Field.Module
                        };
                        if (rf.Data != null) {
                            var modRef = converter.Deserialize(rf, cc) as ModuleReference;

                            Assert.IsNotNull(modRef);

                            var row = db.Row.FirstOrDefault(r => r.Cells.Any(rf1 => rf1.ID == modRef.Id));

                            Assert.IsNotNull(row);

                            modRef.Id = row.ID;

                            rf.Data = converter.Serialize(new DynamicModuleField { Data = modRef }, cc);
                        }
                    }
                }
                db.SaveChanges();
            }
        }

        [TestMethod]
        [Ignore]
        public void Migrate_Binary_To_String() {

            using (var db = new DoverEntities(ConnectionString)) {
                foreach (var record in db.GetRowFieldBytes()) {
                    var bytes = record.Data;
                    if (bytes == null || bytes.Length == 0) {
                        continue;
                    }

                    var id = record.ID;
                    string data = null;
                    if ((int)bytes[bytes.Length - 1] == 0) {
                        var newArray = bytes.TakeWhile((b, i) => i < bytes.Length - 1);
                        data = Encoding.UTF8.GetString(newArray.ToArray());
                    }
                    else {
                        data = Encoding.UTF8.GetString(bytes);
                    }

                    var rowField = db.Cell.FirstOrDefault(rf => rf.ID == id);

                    Assert.IsNotNull(rowField);

                    rowField.Data = data;
                }
                db.SaveChanges();
            }
        }*/
        private static object SerializeAndDeserialize(object data)
        {
            var converter = FieldValueConversion.GetConverter(data.GetType());
            var field = new DynamicModuleField { Data = data };
            var rf = new Cell() { Data = converter.Serialize(field) };

            return converter.Deserialize(rf);
        }
Ejemplo n.º 2
0
        public void Test_Password_Should_Keep_Current_Value()
        {
            var samplePassord = "some secret data";
            var data = new Password { Value = Password.BogusText };
            var converter = FieldValueConversion.GetConverter(data.GetType());
            var field = new DynamicModuleField { Data = data };
            var rf = new Cell() { Data = converter.Serialize(field, new ConversionContext { Cell = new Cell { Data = "<Password>" + samplePassord + "</Password>" } }) };
            var retData = converter.Deserialize(rf);

            Assert.IsNotNull(retData);
            Assert.IsInstanceOfType(retData, typeof(Password));

            var pwdResult = retData as Password;

            Assert.AreEqual(pwdResult.Value, samplePassord);
        }
Ejemplo n.º 3
0
        public void Test_Password_Should_Set_Value()
        {
            var samplePassord = "some secret data";
            var data = new Password { Value = samplePassord };
            var converter = FieldValueConversion.GetConverter(data.GetType());
            var field = new DynamicModuleField { Data = data };
            var rf = new Cell() { Data = converter.Serialize(field, new ConversionContext { Cell = new Cell() }) };
            var retData = converter.Deserialize(rf);

            Assert.IsNotNull(retData);
            Assert.IsInstanceOfType(retData, typeof(Password));

            var pwdResult = retData as Password;

            Assert.AreNotEqual(pwdResult.Value, samplePassord);

            var hash = new Hash(Hash.Provider.SHA1);
            var hashData = hash.Calculate(new Data(samplePassord), new Data("|)0ver3ncrypt10n_k3y")).Base64;

            Assert.AreEqual(pwdResult.Value, hashData);
        }
Ejemplo n.º 4
0
        public void Test_Deserialize_ModuleReference()
        {
            // Arrange
            var fakeRepo = new FakeModuleRepository();
            var rowField = fakeRepo.GetRandomCell();

            rowField.Field.Metadata.Add(new FieldMetadata {
                Key = ModuleRepository.ModuleReferenceMetadataKey,
                Value = "\"" + rowField.Field.Module.Id + "\"" });

            var value = new ModuleReference() { Id = rowField.ID };
            var converter = FieldValueConversion.GetConverter(value.GetType());
            var field = new DynamicModuleField { Data = value };
            var rf = new Cell() { Data = converter.Serialize(field) };

            var retData = converter.Deserialize(rf, new ConversionContext {
                Repository = fakeRepo,
                Field = rowField.Field,
                Module = rowField.Field.Module
            });

            // Assert
            Assert.IsNotNull(retData);
            Assert.IsInstanceOfType(retData, typeof(ModuleReference));

            ModuleReference result = (ModuleReference)retData;

            Assert.AreEqual(rowField.Row.ID, result.Id);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Filters a field that was not found in the Fom keys collection
        ///	This allows us to update/add only the fields that were sent via API, i.e., 
        ///	the developer does not need to always send all the row fields.
        /// </summary>
        /// <param name="_model">A DynamicModuleViewModel bound to an Action method</param>
        /// <returns>A DynamicModuleFieldList with only the fields found in the request vars</returns>
        private bool CheckFieldExistency(DynamicModuleField _field)
        {
            string[] array = new string[1000];

            var a = Request;
            var b = a.Form;
            array = b.AllKeys;

            return (_field.Data != null) ||
                array.Any(k => CheckFormKey(k, _field.PropertyName));
        }
Ejemplo n.º 6
0
        private ActionResult ViewModule(Module _module, int? id, bool creating = false)
        {
            if (id != null &&
                _module.Rows.FirstOrDefault(row => row.ID == id) == null) {
                TempData["Message"] = "Registro não encontrado.";
                return this.RedirectToAction("List");
            }

            DynamicModuleViewModel modelRow = new DynamicModuleViewModel() {
                ID = id ?? -1,
                ModuleName = _module.ModuleName,
                DisplayName = _module.DisplayName
            };

            foreach (Field field in _module.Fields) {
                Cell rowField = null;

                if (!creating) {
                    rowField = (id != null)
                        ? field.Cells.FirstOrDefault(rf => rf.Row.ID == id)
                        : field.Cells.FirstOrDefault();
                }

                var fieldDataTpe = Type.GetType(field.FieldDataType.Name);
                var converter = FieldValueConversion.GetConverter(fieldDataTpe);
                var modelField = new DynamicModuleField() {
                    DisplayName = field.DisplayName,
                    PropertyName = field.FieldName,
                    IsReadOnly = field.IsReadOnly,
                    IsRequired = field.IsRequired,
                    DataType = fieldDataTpe
                };

                modelField.Data = converter.Deserialize(
                    rowField,
                    new ConversionContext {
                        Field = field,
                        Module = _module,
                        Repository = ModRepository
                    });

                modelRow.Fields.Add(modelField);
            }

            return View(modelRow);
        }
Ejemplo n.º 7
0
        public ActionResult List(object module)
        {
            var modToList = module as Module;

            ViewData["ModuleName"] = modToList.ModuleName;
            ViewData["DisplayName"] = modToList.DisplayName;
            ViewData["Fields"] = modToList.Fields.Where(f => f.ShowInListMode).Select(f => f.DisplayName);

            List<DynamicModuleViewModel> viewModel = new List<DynamicModuleViewModel>();

            foreach(Row _row in modToList.Rows.OrderBy(r => r.SortIndex)) {
                DynamicModuleViewModel modelRow = new DynamicModuleViewModel() { ID = _row.ID };

                foreach (Field field in modToList.Fields.Where(f => f.ShowInListMode)) {
                    var rowField = field.Cells.FirstOrDefault(rf => rf.Row.ID == _row.ID);
                    var fieldDataTpe = Type.GetType(field.FieldDataType.Name);
                    var converter = FieldValueConversion.GetConverter(fieldDataTpe);

                    var modelField = new DynamicModuleField() {
                        DisplayName = field.DisplayName,
                        PropertyName = field.FieldName,
                        IsReadOnly = field.IsReadOnly,
                        IsRequired = field.IsRequired,
                        DataType = fieldDataTpe
                    };

                    modelField.Data = converter.Deserialize(
                        rowField,
                        new ConversionContext {
                            Field = field,
                            Module = modToList,
                            Repository = ModRepository
                        });

                    modelRow.Fields.Add(modelField);
                }

                viewModel.Add(modelRow);
            }

            return View(viewModel);
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Returns module records based on the provided module module
        /// and filtering parameters.
        /// </summary>
        /// <param name="module">The module to be queried</param>
        /// <param name="id">Optional row id for filtering</param>
        /// <returns>The matching rows in the specified module</returns>
        public DynamicModuleApiResult GetModuleData(IModule module, int? id, NameValueCollection _filters)
        {
            if (module == null) {
                return null;
            }

            var moduleData = new DynamicModuleApiResult() {
                ModuleName = module.ModuleName,
                ModuleType = module.ModuleType,
                ModuleId = module.Id
            };

            var rows = module.Rows;
            var filteredRows = (id != null) ? rows.Where(r => r.ID == id) : rows.AsEnumerable();

            // Search filter
            string reqFilter = _filters["_Filter"];

            if (!String.IsNullOrWhiteSpace(reqFilter)) {
                filteredRows = filteredRows.Where(r => r.Cells.Any(rf => rf.Data != null && rf.Data.IndexOf(reqFilter, StringComparison.CurrentCultureIgnoreCase) != -1));
            }

            // Random entry filter
            string randomEntry = _filters["_Random"];
            int randomTotal;
            if (!String.IsNullOrWhiteSpace(randomEntry) && Int32.TryParse(randomEntry, out randomTotal)) {
                filteredRows = filteredRows.OrderBy(r => Guid.NewGuid()).Take(randomTotal);
            }

            foreach (var key in _filters.AllKeys.Except(new string[] { "_Filter", "_Random" })) {
                var fieldName = key;
                var value = _filters[fieldName];
                filteredRows = filteredRows.Where(r => r.Cells.Any(rf => rf.Field.FieldName == fieldName && rf.Data != null && rf.Data.IndexOf(value, StringComparison.CurrentCultureIgnoreCase) != -1));
            }

            foreach (var row in filteredRows.OrderBy(r => r.SortIndex)) {
                DynamicModuleViewModel modelRow = new DynamicModuleViewModel() { ID = row.ID };

                foreach (Cell rowField in row.Cells) {
                    var field = rowField.Field;
                    var sFieldDataType = field.FieldDataType.Name;
                    var fieldDataTpe = Type.GetType(sFieldDataType);

                    var modelField = new DynamicModuleField() {
                        DisplayName = field.DisplayName,
                        PropertyName = field.FieldName,
                        IsReadOnly = field.IsReadOnly,
                        IsRequired = field.IsRequired,
                        DataType = fieldDataTpe
                    };

                    var converter = FieldValueConversion.GetConverter(fieldDataTpe);
                    modelField.Data = converter.Deserialize(
                        rowField,
                        new ConversionContext {
                            Field = field,
                            Module = module,
                            Repository = ModRepository
                        });

                    modelRow.Fields.Add(modelField);
                }

                moduleData.Rows.Add(modelRow);
            }

            return moduleData;
        }