private static PropertyInfo VerifyAndGetField(Type dataType, string fieldName)
        {
            if (fieldName == null)
            {
                fieldName = dataType.GetKeyProperties().Single().Name;
            }

            var propertyInfo = dataType.GetPropertiesRecursively().FirstOrDefault(p => p.Name == fieldName);
            Verify.IsNotNull(propertyInfo, "Failed to get property '{0}' on type '{1}'", fieldName, dataType);

            return propertyInfo;
        }
Ejemplo n.º 2
0
        private static IEnumerable<KeyValuePair> GetOptionsForDefault(Type t, string typeManagerName)
        {
            DataTypeDescriptor dtd = GetTypeInfo(typeManagerName).Second;

            Verify.That(dtd.KeyPropertyNames.Count == 1, "Unable to deliver data for selector widget. The selected type '{0}' should have exactly one key property.".FormatWith(typeManagerName));

            string keyFieldName = dtd.KeyPropertyNames[0];

            var allData = DataFacade.GetData(t)
                .ToDataList()
                .Select(data => new { Data = data, Label = data.GetLabel(true) })
                .OrderBy(data => data.Label);

            PropertyInfo keyPi = t.GetPropertiesRecursively(f => f.Name == keyFieldName).FirstOrDefault();
            Verify.That(keyPi != null, "The type '{0}' has invalid meta data. The specified key property '{1}' not found.", typeManagerName, keyFieldName);

            return
                from data in allData
                select new KeyValuePair { Key = (keyPi.GetValue(data.Data, new object[] { }) ?? "").ToString(), Value = data.Label };
        }
Ejemplo n.º 3
0
 private static Dictionary<string, PropertyInfo> GetDataTypeProperties(Type type)
 {
     return type.GetPropertiesRecursively().Where(property => !IsObsoleteProperty(property)).ToDictionary(prop => prop.Name);
 }
Ejemplo n.º 4
0
        private bool ValidateTable(Type interfaceType, string tableName, StringBuilder errors)
        {
            ISqlTableInformation sqlTableInformation = SqlTableInformationStore.GetTableInformation(_connectionString, tableName);

            if (sqlTableInformation == null)
            {
                errors.AppendLine("Table '{0}' does not exist".FormatWith(tableName));
                return false;
            }

            int primaryKeyCount = sqlTableInformation.ColumnInformations.Count(column => column.IsPrimaryKey);

            if (primaryKeyCount == 0)
            {
                errors.AppendLine(string.Format("The table '{0}' is missing a primary key", tableName));
                return false;
            }

            var columns = new List<SqlColumnInformation>(sqlTableInformation.ColumnInformations);
            var properties = interfaceType.GetPropertiesRecursively();

            foreach (PropertyInfo property in properties)
            {
                if (property.Name == "DataSourceId") continue;

                SqlColumnInformation column = columns.Find(col => col.ColumnName == property.Name);
                if (column == null)
                {
                    errors.AppendLine(string.Format("The interface property named '{0}' does not exist in the table '{1}' as a column", property.Name, sqlTableInformation.TableName));
                    return false;
                }

                if (!column.IsNullable || column.Type == typeof(string))
                {
                    if (column.Type != property.PropertyType)
                    {
                        errors.AppendLine(string.Format("Type mismatch. The interface type '{0}' does not match the database type '{1}'", property.PropertyType, column.Type));
                        return false;
                    }
                }
            }

            // Updating schema from C1 4.1, to be removed in future versions.
            //            if (typeof (ILocalizedControlled).IsAssignableFrom(interfaceType)
            //                && !properties.Any(p => p.Name == "CultureName")
            //                && columns.Any(c => c.ColumnName == "CultureName"))
            //            {
            //                Log.LogInformation(LogTitle, "Removing obsolete 'CultureName' column from table '{0}'", tableName);

            //                string selectConstraintName = string.Format(
            //                    @"SELECT df.name 'ConstraintName'
            //                    FROM sys.default_constraints df
            //                    INNER JOIN sys.tables t ON df.parent_object_id = t.object_id
            //                    INNER JOIN sys.columns c ON df.parent_object_id = c.object_id AND df.parent_column_id = c.column_id
            //                    where t.name = '{0}'
            //                    and c.name = 'CultureName'", tableName);

            //                var dt = ExecuteReader(selectConstraintName);
            //                List<string> constraints = (from DataRow dr in dt.Rows select dr["ConstraintName"].ToString()).ToList();

            //                foreach (var constrainName in constraints)
            //                {
            //                    ExecuteSql("ALTER TABLE [{0}] DROP CONSTRAINT [{1}]".FormatWith(tableName, constrainName));
            //                }

            //                string sql = "ALTER TABLE [{0}] DROP COLUMN [CultureName]".FormatWith(tableName);

            //                ExecuteSql(sql);
            //            }

            return true;
        }
Ejemplo n.º 5
0
 /// <exclude />
 public static PropertyInfo GetDefinitionPageReferencePropertyInfo(Type pageFolderType)
 {
     return pageFolderType.GetPropertiesRecursively().Last(f => f.Name == PageFolderType_PageIdFieldName);
 }
Ejemplo n.º 6
0
 /// <exclude />
 public static PropertyInfo GetDefinitionPageReferencePropertyVersionInfo(Type metaDataType)
 {
     return metaDataType.GetPropertiesRecursively().Last(f => f.Name == MetaDataType_PageReferenceFieldVersionName);
 }
Ejemplo n.º 7
0
 /// <exclude />
 public static PropertyInfo GetDefinitionNamePropertyInfo(Type metaDataType)
 {
     return metaDataType.GetPropertiesRecursively().Single(f => f.Name == MetaDataType_MetaDataDefinitionFieldName);
 }
Ejemplo n.º 8
0
        private void AddType(Type typeToAdd, string providerName, bool writeableProvider)
        {
            Verify.That(typeToAdd.IsInterface, "The data provider {0} returned an non-interface ({1})", providerName, typeToAdd);
            Verify.That(typeof(IData).IsAssignableFrom(typeToAdd), "The data provider {0} returned an non IData interface ({1})", providerName, typeToAdd);

            using (TimerProfilerFacade.CreateTimerProfiler())
            {
                List<DataScopeIdentifier> supportedDataScopes = typeToAdd.GetSupportedDataScopes().ToList();

                if (supportedDataScopes.Count == 0)
                {
                    throw new InvalidOperationException(string.Format("The data provider {0} returned an IData interface ({1}) with no data scopes defined. Use the {2} attribute to define scopes.", providerName, typeToAdd, typeof(DataScopeAttribute)));
                }

                foreach (PropertyInfo propertyInfo in typeToAdd.GetPropertiesRecursively())
                {
                    bool containsBadAttribute = propertyInfo.GetCustomAttributesRecursively<Microsoft.Practices.EnterpriseLibrary.Validation.Validators.StringLengthValidatorAttribute>().Any();
                    if (!containsBadAttribute) continue;

#pragma warning disable 0612
                    Log.LogWarning("DataProviderRegistry", string.Format("The property named '{0}' on the type '{1}' has an attribute of type '{2}' wich is not supported, use '{3}'", typeToAdd, propertyInfo.Name, typeof(Microsoft.Practices.EnterpriseLibrary.Validation.Validators.StringLengthValidatorAttribute), typeof(Composite.Data.Validation.Validators.StringLengthValidatorAttribute)));
#pragma warning restore 0612
                }

                var readableList = _interfaceTypeToReadableProviderNames.GetOrAdd(typeToAdd, () => new List<string>());
                if (!readableList.Contains(providerName))
                {
                    readableList.Add(providerName);
                }


                if (writeableProvider)
                {
                    var writableList = _interfaceTypeToWriteableProviderNames.GetOrAdd(typeToAdd, () => new List<string>());
                    if (!writableList.Contains(providerName))
                    {
                        writableList.Add(providerName);
                    }
                }
            }
        }
Ejemplo n.º 9
0
 /// <exclude />
 public static PropertyInfo GetPageReferencePropertyInfo(Type compositionType)
 {
     return compositionType.GetPropertiesRecursively().Single(f => f.Name == PageReferenceFieldName);
 }
Ejemplo n.º 10
0
 /// <exclude />
 public static PropertyInfo GetCompositionDescriptionPropertyInfo(Type compositionType)
 {
     return compositionType.GetPropertiesRecursively().Single(f => f.Name == CompositionDescriptionFieldName);
 }
Ejemplo n.º 11
0
        private static void ResolvePropertyBinding(
            ElementCompileTreeNode element, PropertyCompileTreeNode property, CompileContext compileContext, string bindSourceName, string[] propertyPath,
                out object value, out Type type, out object propertyOwner, out string propertyName, out MethodInfo getMethodInfo, out MethodInfo setMethodInfo
            )
        {
            string typeName = ((BindingsProducer)compileContext.BindingsProducer).GetTypeNameByName(bindSourceName);
            if (typeName == null)
            {
                throw new FormCompileException(string.Format("{1} binds to an undeclared binding name '{0}'. All binding names must be declared in /cms:formdefinition/cms:bindings", bindSourceName, element.XmlSourceNodeInformation.XPath), element, property);
            }

            Type bindType = TypeManager.TryGetType(typeName);
            if (bindType == null)
            {
                throw new FormCompileException(string.Format("The form binding '{0}' is declared as an unknown type '{1}'", bindSourceName, typeName), element, property);
            }

            object bindingObject = compileContext.GetBindingObject(bindSourceName);
            if (bindingObject == null)
            {
                throw new FormCompileException(string.Format("The binding object named '{0}' not found in the input dictionary", bindSourceName), element, property);
            }

            Type bindingObjectType = bindingObject.GetType();
            if (!bindType.IsAssignableFrom(bindingObjectType)) throw new FormCompileException(string.Format("The binding object named '{0}' from the input dictionary is not of expected type '{1}', but '{2}'", bindSourceName, bindType.FullName, bindingObjectType.FullName), element, property);


            propertyName = null;
            getMethodInfo = setMethodInfo = null;
            type = bindType;
            propertyOwner = value = bindingObject;

            for (int i = 0; i < propertyPath.Length; ++i)
            {
                string name = propertyName = propertyPath[i];

                PropertyInfo propertyInfo = type.GetPropertiesRecursively(x => x.Name == name).FirstOrDefault();

                if (propertyInfo == null)
                {
                    throw new FormCompileException(string.Format("The type {0} does not have a property named {1}", type, propertyName), element, property);
                }

                getMethodInfo = propertyInfo.GetGetMethod();
                if (getMethodInfo == null)
                {
                    throw new FormCompileException(string.Format("The type {0} does not have a get property named {1}", type, propertyName), element, property);
                }

                setMethodInfo = propertyInfo.GetSetMethod();

                propertyOwner = value;

                type = getMethodInfo.ReturnType;
                value = getMethodInfo.Invoke(propertyOwner, null);
            }
        }