private DataFieldDescriptor CreateReferenceDataFieldDescriptor(DataTypeDescriptor targetDataTypeDescriptor, out string foreignKeyFieldName, string fieldName = null)
        {
            Type   targetType         = TypeManager.GetType(targetDataTypeDescriptor.TypeManagerTypeName);
            string targetKeyFieldName = targetDataTypeDescriptor.KeyPropertyNames.First();

            DataFieldDescriptor targetKeyDataFieldDescriptor = targetDataTypeDescriptor.Fields[targetKeyFieldName];

            foreignKeyFieldName = fieldName ??
                                  string.Format("{0}{1}ForeignKey", targetDataTypeDescriptor.Name, targetKeyFieldName);

            WidgetFunctionProvider widgetFunctionProvider = StandardWidgetFunctions.GetDataReferenceWidget(targetType);

            return(new DataFieldDescriptor(
                       Guid.NewGuid(),
                       foreignKeyFieldName,
                       targetKeyDataFieldDescriptor.StoreType,
                       targetKeyDataFieldDescriptor.InstanceType
                       )
            {
                IsNullable = targetKeyDataFieldDescriptor.IsNullable,
                DefaultValue = targetKeyDataFieldDescriptor.DefaultValue,
                ValidationFunctionMarkup = targetKeyDataFieldDescriptor.ValidationFunctionMarkup,
                ForeignKeyReferenceTypeName = targetDataTypeDescriptor.TypeManagerTypeName,
                FormRenderingProfile = new DataFieldFormRenderingProfile
                {
                    Label = foreignKeyFieldName,
                    HelpText = foreignKeyFieldName,
                    WidgetFunctionMarkup = widgetFunctionProvider.SerializedWidgetFunction.ToString(SaveOptions.DisableFormatting)
                }
            });
        }
예제 #2
0
        private static object GetDefaultValue(DataFieldDescriptor fieldDescriptor)
        {
            Verify.ArgumentNotNull(fieldDescriptor, "fieldDescriptor");

            if (fieldDescriptor.DefaultValue != null)
            {
                return(fieldDescriptor.DefaultValue.Value);
            }

            switch (fieldDescriptor.StoreType.PhysicalStoreType)
            {
            case PhysicalStoreFieldType.Boolean:
                return(false);

            case PhysicalStoreFieldType.DateTime:
                return(DateTime.Now);

            case PhysicalStoreFieldType.Integer:
            case PhysicalStoreFieldType.Long:
            case PhysicalStoreFieldType.Decimal:
                return(0m);

            case PhysicalStoreFieldType.Guid:
                return(Guid.Empty);

            case PhysicalStoreFieldType.String:
            case PhysicalStoreFieldType.LargeString:
                return(string.Empty);
            }

            throw new NotImplementedException("Supplied StoreFieldType contains an unsupported PhysicalStoreType '{0}'."
                                              .FormatWith(fieldDescriptor.StoreType.PhysicalStoreType));
        }
        internal string GetColumnInfo(string tableName, string columnName, DataFieldDescriptor fieldDescriptor, bool includeDefault, bool forceNullable)
        {
            string defaultInfo = string.Empty;

            if (TranslatesIntoDefaultConstraint(fieldDescriptor.DefaultValue))
            {
                if (includeDefault)
                {
                    defaultInfo = string.Format("CONSTRAINT [{0}] DEFAULT {1}", SqlSafeName("DF", tableName, columnName), GetDefaultValueText(fieldDescriptor.DefaultValue));
                }
            }

            // Enabling case sensitive comparison for the random string fields

            var defaultValue = fieldDescriptor.DefaultValue;

            string collation = string.Empty;

            if (defaultValue != null && defaultValue.ValueType == DefaultValueType.RandomString)
            {
                collation = "COLLATE Latin1_General_CS_AS";
            }

            return(string.Format(
                       "[{0}] {1} {2} {3} {4}",
                       fieldDescriptor.Name,
                       DynamicTypesCommon.MapStoreTypeToSqlDataType(fieldDescriptor.StoreType),
                       collation,
                       fieldDescriptor.IsNullable || forceNullable ? "NULL" : "NOT NULL",
                       defaultInfo));
        }
예제 #4
0
        /// <summary>
        /// This method will remove a foreign key (if any exists) that is no longer possible with the
        /// new meta data system (IPageMetaDataDefinition)
        /// </summary>
        /// <param name="dataTypeDescriptor"></param>
        /// <param name="dataStoreExists"></param>
        private void UpdateWithNewPageFolderForeignKeySystem(DataTypeDescriptor dataTypeDescriptor, bool dataStoreExists)
        {
            if (dataTypeDescriptor.IsPageFolderDataType == false)
            {
                return;
            }

            DataFieldDescriptor dataFieldDescriptor = dataTypeDescriptor.Fields["IAggregationDescriptionIdForeignKey"];

            if (dataFieldDescriptor == null)
            {
                return;
            }

            Log.LogVerbose("GeneratedTypesFacade", string.Format("Removing the property {0} on the type {1}.{2}", dataFieldDescriptor.Name, dataTypeDescriptor.Namespace, dataTypeDescriptor.Name));

            if (!dataStoreExists)
            {
                dataTypeDescriptor.Fields.Remove(dataFieldDescriptor);
                DynamicTypeManager.UpdateDataTypeDescriptor(dataTypeDescriptor, false);
                return;
            }

            DataTypeDescriptor oldDataTypeDescriptor = dataTypeDescriptor.Clone();

            dataTypeDescriptor.Fields.Remove(dataFieldDescriptor);

            var dataTypeChangeDescriptor = new DataTypeChangeDescriptor(oldDataTypeDescriptor, dataTypeDescriptor);

            var updateDataTypeDescriptor = new UpdateDataTypeDescriptor(oldDataTypeDescriptor, dataTypeDescriptor);

            DynamicTypeManager.AlterStore(updateDataTypeDescriptor, false);
        }
        private string GetDefaultWidgetFunctionMarkup(DataFieldDescriptor fieldDescriptor)
        {
            // Auto generating a widget for not code generated data types
            Type fieldType;

            if (!fieldDescriptor.ForeignKeyReferenceTypeName.IsNullOrEmpty())
            {
                string referenceTypeName = fieldDescriptor.ForeignKeyReferenceTypeName;
                Type   foreignKeyType    = TypeManager.GetType(referenceTypeName);
                Verify.IsNotNull(foreignKeyType, "Failed to find type '{0}'".FormatWith(referenceTypeName));

                var referenceTemplateType = fieldDescriptor.IsNullable ? typeof(NullableDataReference <>) : typeof(DataReference <>);

                fieldType = referenceTemplateType.MakeGenericType(foreignKeyType);
            }
            else
            {
                fieldType = fieldDescriptor.InstanceType;
            }

            var widgetFunctionProvider = StandardWidgetFunctions.GetDefaultWidgetFunctionProviderByType(fieldType);

            if (widgetFunctionProvider != null)
            {
                return(widgetFunctionProvider.SerializedWidgetFunction.ToString());
            }

            return(null);
        }
        private void ConfigureColumn(string tableName, string columnName, DataFieldDescriptor fieldDescriptor, DataFieldDescriptor originalFieldDescriptor, bool changes)
        {
            if (columnName != fieldDescriptor.Name)
            {
                RenameColumn(tableName, columnName, fieldDescriptor.Name);
            }

            if (changes)
            {
                bool fieldBecameRequired = !fieldDescriptor.IsNullable && originalFieldDescriptor.IsNullable;

                if (fieldBecameRequired)
                {
                    if (fieldDescriptor.StoreType.ToString() != originalFieldDescriptor.StoreType.ToString())
                    {
                        AlterColumn(tableName, GetColumnInfo(tableName, fieldDescriptor.Name, fieldDescriptor, false, true));
                    }

                    string defaultValue = TranslatesIntoDefaultConstraint(fieldDescriptor.DefaultValue)
                                              ? GetDefaultValueText(fieldDescriptor.DefaultValue)
                                              : GetDefaultValueText(fieldDescriptor.StoreType);

                    ExecuteNonQuery("UPDATE [{0}] SET [{1}] = {2} WHERE [{1}] IS NULL"
                                    .FormatWith(tableName, fieldDescriptor.Name, defaultValue));
                }

                AlterColumn(tableName, GetColumnInfo(tableName, fieldDescriptor.Name, fieldDescriptor, false, false));
            }

            ExecuteNonQuery(SetDefaultValue(tableName, fieldDescriptor.Name, fieldDescriptor.DefaultValue));
        }
예제 #7
0
 /// <exclude />
 public ReferenceFailingPropertyInfo(DataFieldDescriptor dataFieldDescriptor, Type referencedType, IData originLocaleDataValue, bool optionalReferenceWithValue)
 {
     this.DataFieldDescriptor        = dataFieldDescriptor;
     this.ReferencedType             = referencedType;
     this.OriginLocaleDataValue      = originLocaleDataValue;
     this.OptionalReferenceWithValue = optionalReferenceWithValue;
 }
        private void Initialize()
        {
            if (_oldDataTypeDescriptor.DataAssociations.Count > 0)
            {
                var dataTypeAssociationDescriptor = _oldDataTypeDescriptor.DataAssociations.Single();

                _associatedType = dataTypeAssociationDescriptor.AssociatedInterfaceType;
            }

            foreach (var dataFieldDescriptor in _oldDataTypeDescriptor.Fields)
            {
                if (dataFieldDescriptor.ForeignKeyReferenceTypeName != null)
                {
                    if (_associatedType != null)
                    {
                        var associatedTypeTypeName = TypeManager.SerializeType(_associatedType);

                        if (dataFieldDescriptor.ForeignKeyReferenceTypeName == associatedTypeTypeName)
                        {
                            _foreignKeyDataFieldDescriptor = dataFieldDescriptor;
                        }
                    }
                }


                if (dataFieldDescriptor.Name == CompositionDescriptionFieldName)
                {
                    _pageMetaDataDescriptionForeignKeyDataFieldDescriptor = dataFieldDescriptor;
                }
            }

            _publishControlled   = IsPublishControlled;
            _localizedControlled = IsLocalizedControlled;
        }
        /// <summary>
        /// Builds a default "Id" field.
        /// </summary>
        /// <returns></returns>
        public static DataFieldDescriptor BuildIdField()
        {
            var idFieldDescriptor = new DataFieldDescriptor(Guid.NewGuid(), IdFieldName, StoreFieldType.Guid, typeof(Guid));

            idFieldDescriptor.DataUrlProfile = new DataUrlProfile {
                Order = 0
            };
            return(idFieldDescriptor);
        }
예제 #10
0
        private IEnumerable <Element> CreateGroupFolderElements(Type interfaceType, DataFieldDescriptor dataFieldDescriptor, IQueryable queryable, EntityToken parentEntityToken, PropertyInfoValueCollection propertyInfoValueCollection)
        {
            PropertyInfo propertyInfo = interfaceType.GetPropertiesRecursively().Single(f => f.Name == dataFieldDescriptor.Name);

            foreach (object obj in queryable)
            {
                var entityToken = new DataGroupingProviderHelperEntityToken(TypeManager.SerializeType(interfaceType))
                {
                    Payload        = this.OnGetPayload(parentEntityToken),
                    GroupingValues = new Dictionary <string, object>()
                };

                foreach (var kvp in propertyInfoValueCollection.PropertyValues)
                {
                    entityToken.GroupingValues.Add(kvp.Key.Name, kvp.Value);
                }
                entityToken.GroupingValues.Add(propertyInfo.Name, obj);


                var element = new Element(_elementProviderContext.CreateElementHandle(entityToken));


                string label = obj?.ToString() ?? string.Format(_undefinedLabelValue, dataFieldDescriptor.Name);
                if (obj is DateTime dt)
                {
                    label = dt.ToString("yyyy-MM-dd");
                }

                if (obj != null && dataFieldDescriptor.ForeignKeyReferenceTypeName != null)
                {
                    Type refType = TypeManager.GetType(dataFieldDescriptor.ForeignKeyReferenceTypeName);

                    IData data = DataFacade.TryGetDataByUniqueKey(refType, obj); // Could be a newly added null field...

                    if (data != null)
                    {
                        label = data.GetLabel();
                    }
                }


                element.VisualData = new ElementVisualizedData
                {
                    Label       = label,
                    ToolTip     = label,
                    HasChildren = true,
                    Icon        = this.FolderClosedIcon,
                    OpenedIcon  = this.FolderOpenIcon
                };

                PropertyInfoValueCollection propertyInfoValueCollectionCopy = propertyInfoValueCollection.Clone();
                propertyInfoValueCollectionCopy.AddPropertyValue(propertyInfo, obj);

                yield return(this.OnAddActions(element, propertyInfoValueCollectionCopy));
            }
        }
        internal static DataFieldDescriptor BuildFieldDescriptor(PropertyInfo propertyInfo, bool inherited)
        {
            string fieldName = propertyInfo.Name;
            Type   fieldType = propertyInfo.PropertyType;
            Guid   fieldId   = DynamicTypeReflectionFacade.GetImmutableFieldId(propertyInfo);

            StoreFieldType storeFieldType = DynamicTypeReflectionFacade.GetStoreFieldType(propertyInfo);


            var fieldDescriptor = new DataFieldDescriptor(fieldId, fieldName, storeFieldType, fieldType, inherited)
            {
                DefaultValue = DynamicTypeReflectionFacade.GetDefaultValue(propertyInfo),
                IsNullable   = DynamicTypeReflectionFacade.IsNullable(propertyInfo),
                ForeignKeyReferenceTypeName = DynamicTypeReflectionFacade.ForeignKeyReferenceTypeName(propertyInfo),
                GroupByPriority             = DynamicTypeReflectionFacade.GetGroupByPriority(propertyInfo),
                TreeOrderingProfile         = DynamicTypeReflectionFacade.GetTreeOrderingProfile(propertyInfo)
            };

            var formRenderingProfile = DynamicTypeReflectionFacade.GetFormRenderingProfile(propertyInfo);

            if (formRenderingProfile != null)
            {
                fieldDescriptor.FormRenderingProfile = formRenderingProfile;
            }

            // These auto added widget functions does not work on a empty system.
            // This code could have added widgets for data types that does not have any widgets attached to them
            //WidgetFunctionProvider widgetFunctionProvider = GetWidgetFunctionMarkup(propertyInfo.PropertyType);
            //if (widgetFunctionProvider != null)
            //{
            //    LazyDataFieldFormRenderingProfile lazyDataFieldFormRenderingProfile = new LazyDataFieldFormRenderingProfile();
            //    lazyDataFieldFormRenderingProfile.Label = propertyInfo.Name;
            //    lazyDataFieldFormRenderingProfile.HelpText = propertyInfo.Name;
            //    lazyDataFieldFormRenderingProfile.WidgetFunctionMarkupFunc = () => widgetFunctionProvider.SerializedWidgetFunction.ToString();

            //    fieldDescriptor.FormRenderingProfile = lazyDataFieldFormRenderingProfile;
            //}

            int position;

            if (DynamicTypeReflectionFacade.TryGetFieldPosition(propertyInfo, out position))
            {
                fieldDescriptor.Position = position;
            }
            else
            {
                fieldDescriptor.Position = 1000;
            }

            fieldDescriptor.NewInstanceDefaultFieldValue = DynamicTypeReflectionFacade.NewInstanceDefaultFieldValue(propertyInfo);

            fieldDescriptor.IsReadOnly = !propertyInfo.CanWrite;

            return(fieldDescriptor);
        }
        public static Type GetInstanceType(DataFieldDescriptor dataFieldDescriptor)
        {
            Type instanceType = dataFieldDescriptor.InstanceType;

            if (instanceType.IsGenericType && instanceType.GetGenericTypeDefinition() == typeof(Nullable <>))
            {
                instanceType = instanceType.GetGenericArguments().First();
            }

            return(instanceType);
        }
 public static WidgetFunctionProvider GetWidgetFunctionProvider(DataFieldDescriptor dataFieldDescriptor)
 {
     if ((dataFieldDescriptor.FormRenderingProfile != null) && (string.IsNullOrEmpty(dataFieldDescriptor.FormRenderingProfile.WidgetFunctionMarkup) == false))
     {
         WidgetFunctionProvider widgetFunctionProvider = new WidgetFunctionProvider(XElement.Parse(dataFieldDescriptor.FormRenderingProfile.WidgetFunctionMarkup));
         return(widgetFunctionProvider);
     }
     else
     {
         return(StandardWidgetFunctions.GetDefaultWidgetFunctionProviderByType(dataFieldDescriptor.InstanceType));
     }
 }
예제 #14
0
        public static SqlColumnInformation CreateSqlColumnInformation(this DataTypeDescriptor dataTypeDescriptor, string fieldName)
        {
            DataFieldDescriptor dataFieldDescriptor = dataTypeDescriptor.Fields[fieldName];

            return(new SqlColumnInformation(
                       dataFieldDescriptor.Name,
                       dataTypeDescriptor.PhysicalKeyPropertyNames.Contains(dataFieldDescriptor.Name),
                       false,
                       false,
                       dataFieldDescriptor.IsNullable,
                       dataFieldDescriptor.InstanceType,
                       DynamicTypesCommon.GetStoreTypeToSqlDataTypeMapping(dataFieldDescriptor.StoreType)
                       ));
        }
예제 #15
0
        private void InsertStaticFieldRegionMember(List <DataFieldDescriptor> fieldDescs, DefType defType, List <DataFieldDescriptor> staticFields, string staticFieldForm, string staticFieldFormTypePrefix, bool staticDataInObject)
        {
            if (staticFields != null && (staticFields.Count > 0))
            {
                // Generate struct symbol for type describing individual fields of the statics region
                ClassFieldsTypeDescriptor fieldsDescriptor = new ClassFieldsTypeDescriptor
                {
                    Size        = (ulong)0,
                    FieldsCount = staticFields.Count
                };

                ClassTypeDescriptor classTypeDescriptor = new ClassTypeDescriptor
                {
                    IsStruct    = !staticDataInObject ? 1 : 0,
                    Name        = staticFieldFormTypePrefix + _objectWriter.GetMangledName(defType),
                    BaseClassId = 0
                };

                if (staticDataInObject)
                {
                    classTypeDescriptor.BaseClassId = GetTypeIndex(defType.Context.GetWellKnownType(WellKnownType.Object), true);
                }

                uint staticFieldRegionTypeIndex       = _objectWriter.GetCompleteClassTypeIndex(classTypeDescriptor, fieldsDescriptor, staticFields.ToArray());
                uint staticFieldRegionSymbolTypeIndex = staticFieldRegionTypeIndex;

                // This means that access to this static region is done via a double indirection
                if (staticDataInObject)
                {
                    PointerTypeDescriptor pointerTypeDescriptor = new PointerTypeDescriptor();
                    pointerTypeDescriptor.Is64Bit     = Is64Bit ? 1 : 0;
                    pointerTypeDescriptor.IsConst     = 0;
                    pointerTypeDescriptor.IsReference = 0;
                    pointerTypeDescriptor.ElementType = staticFieldRegionTypeIndex;

                    uint intermediatePointerDescriptor = _objectWriter.GetPointerTypeIndex(pointerTypeDescriptor);
                    pointerTypeDescriptor.ElementType = intermediatePointerDescriptor;
                    staticFieldRegionSymbolTypeIndex  = _objectWriter.GetPointerTypeIndex(pointerTypeDescriptor);
                }

                DataFieldDescriptor staticRegionField = new DataFieldDescriptor
                {
                    FieldTypeIndex = staticFieldRegionSymbolTypeIndex,
                    Offset         = 0xFFFFFFFF,
                    Name           = staticFieldForm
                };

                fieldDescs.Add(staticRegionField);
            }
        }
        /// <summary>
        /// This method will remove a foreign key (if any exists) that is no longer possible with the
        /// new meta data system (IPageMetaDataDefinition)
        /// </summary>
        /// <param name="dataTypeDescriptor"></param>
        private void UpdateWithNewMetaDataForeignKeySystem(DataTypeDescriptor dataTypeDescriptor)
        {
            if (dataTypeDescriptor.IsPageMetaDataType)
            {
                DataFieldDescriptor dataFieldDescriptor = dataTypeDescriptor.Fields[PageMetaDataFacade.MetaDataType_MetaDataDefinitionFieldName];
                if ((dataFieldDescriptor != null) && (dataFieldDescriptor.ForeignKeyReferenceTypeName != null)) // This should never fail, but want to be sure
                {
                    dataFieldDescriptor.ForeignKeyReferenceTypeName = null;

                    DynamicTypeManager.UpdateDataTypeDescriptor(dataTypeDescriptor, false);

                    Log.LogVerbose("GeneratedTypesFacade", string.Format("Removing foreign on the property {0} on the type {1}.{2}", dataFieldDescriptor.Name, dataTypeDescriptor.Namespace, dataTypeDescriptor.Name));
                }
            }
        }
        public static BaseValueProvider GetFallbackValueProvider(DataFieldDescriptor dataFieldDescriptor, bool isKeyProperty)
        {
            if (dataFieldDescriptor.DefaultValue != null)
            {
                return(new ConstantValueProvider(dataFieldDescriptor.DefaultValue.Value));
            }

            Type instanceType = GetInstanceType(dataFieldDescriptor);

            if (instanceType == typeof(int))
            {
                return(new ConstantValueProvider(0));
            }
            else if (instanceType == typeof(decimal))
            {
                return(new ConstantValueProvider(0.0));
            }
            else if (instanceType == typeof(bool))
            {
                return(new ConstantValueProvider(false));
            }
            else if (instanceType == typeof(string))
            {
                return(new ConstantValueProvider(""));
            }
            else if (instanceType == typeof(Guid))
            {
                if (isKeyProperty)
                {
                    return(new ConstantValueProvider(Guid.NewGuid()));
                }
                else
                {
                    return(new ConstantValueProvider(Guid.Empty));
                }
            }
            else if (instanceType == typeof(DateTime))
            {
                return(new ConstantValueProvider(DateTime.Now));
            }
            else
            {
                return(new ConstantValueProvider(""));
            }
        }
        private bool IsDataFieldBindable(DataTypeDescriptor dataTypeDescriptor, DataFieldDescriptor dataFieldDescriptor)
        {
            if (dataFieldDescriptor.Inherited)
            {
                Type superInterface = dataTypeDescriptor.SuperInterfaces.FirstOrDefault(type => type.GetProperty(dataFieldDescriptor.Name) != null);

                if (superInterface != null && superInterface.Assembly == typeof(IData).Assembly)
                {
                    return(false);
                }
            }

            if ((dataFieldDescriptor.Name == IdFieldName || dataFieldDescriptor.Name == CompositionDescriptionFieldName) &&
                dataTypeDescriptor.IsPageMetaDataType)
            {
                return(false);
            }

            if (PageFolderFacade.GetAllFolderTypes().Contains(this._oldType) && dataFieldDescriptor.Name == PageReferenceFieldName)
            {
                return(false);
            }

            if (dataFieldDescriptor.ForeignKeyReferenceTypeName != null)
            {
                DataTypeAssociationDescriptor dataTypeAssociationDescriptor = dataTypeDescriptor.DataAssociations.FirstOrDefault();

                if (dataTypeAssociationDescriptor != null)
                {
                    if (!this.AllowForeignKeyEditing &&
                        dataFieldDescriptor.Name == dataTypeAssociationDescriptor.ForeignKeyPropertyName)
                    {
                        return(false);
                    }

                    if (dataFieldDescriptor.Name == CompositionDescriptionFieldName && dataTypeDescriptor.IsPageMetaDataType)
                    {
                        return(false);
                    }
                }
            }

            return(true);
        }
        /// <exclude />
        public void SetForeignKeyReference(DataTypeDescriptor targetDataTypeDescriptor, DataAssociationType dataAssociationType)
        {
            if (dataAssociationType == DataAssociationType.None)
            {
                throw new ArgumentException("dataAssociationType");
            }

            if ((dataAssociationType == DataAssociationType.Aggregation || dataAssociationType == DataAssociationType.Composition) &&
                _pageMetaDataDescriptionForeignKeyDataFieldDescriptor != null)
            {
                throw new InvalidOperationException("The type already has a foreign key reference");
            }


            Type   targetType = TypeManager.GetType(targetDataTypeDescriptor.TypeManagerTypeName);
            string fieldName  = null;

            if (targetType == typeof(IPage))
            {
                fieldName            = PageReferenceFieldName;
                _dataAssociationType = dataAssociationType;
            }

            string foreignKeyFieldName;

            _foreignKeyDataFieldDescriptor = CreateReferenceDataFieldDescriptor(targetDataTypeDescriptor, out foreignKeyFieldName, fieldName);

            if (dataAssociationType != DataAssociationType.None)
            {
                _dataTypeAssociationDescriptor = new DataTypeAssociationDescriptor(
                    targetType,
                    foreignKeyFieldName,
                    dataAssociationType
                    );
            }

            if (dataAssociationType == DataAssociationType.Composition)
            {
                DataTypeDescriptor compositionRuleDataTypeDescriptor = DynamicTypeManager.GetDataTypeDescriptor(typeof(IPageMetaDataDefinition));

                _pageMetaDataDescriptionForeignKeyDataFieldDescriptor = CreateWeakReferenceDataFieldDescriptor(compositionRuleDataTypeDescriptor, compositionRuleDataTypeDescriptor.Fields["Name"], CompositionDescriptionFieldName);
            }
        }
예제 #20
0
        private static CodeStatement AddCommitDataMethodFinalHelper(DataFieldDescriptor dataFieldDescriptor, List <CodeStatement> statements)
        {
            // CODEGEN:
            // if(this._emailNullable != null) {
            //     [statements]
            // }

            string fieldName = CreateNullableFieldName(dataFieldDescriptor);

            return(new CodeConditionStatement(
                       new CodeBinaryOperatorExpression(
                           new CodeFieldReferenceExpression(
                               new CodeThisReferenceExpression(),
                               fieldName
                               ),
                           CodeBinaryOperatorType.IdentityInequality,
                           new CodePrimitiveExpression(null)
                           ),
                       statements.ToArray()
                       ));
        }
예제 #21
0
        private static CodeStatement AddCommitDataMethodFinalHelper(DataFieldDescriptor dataFieldDescriptor, IEnumerable <CodeStatement> statements)
        {
            // CODEGEN:
            // if (this._isSet_email && this._emailNullable != null) {
            //     [statements]
            //     _isSet_email = false;
            // }

            string fieldName = CreateNullableFieldName(dataFieldDescriptor);

            // this._isSet_email
            var fieldIsSetFieldReference =
                new CodeFieldReferenceExpression(
                    new CodeThisReferenceExpression(),
                    IsSetFieldName(dataFieldDescriptor)
                    );

            // this._emailNullable != null
            var expression2 = new CodeBinaryOperatorExpression(
                new CodeFieldReferenceExpression(
                    new CodeThisReferenceExpression(),
                    fieldName
                    ),
                CodeBinaryOperatorType.IdentityInequality,
                new CodePrimitiveExpression(null)
                );

            return(new CodeConditionStatement(
                       new CodeBinaryOperatorExpression(
                           fieldIsSetFieldReference, CodeBinaryOperatorType.BooleanAnd, expression2),
                       statements.Concat(new [] {
                // CODEGEN:
                // this._isSetEmail = false;
                new CodeAssignStatement(
                    fieldIsSetFieldReference,
                    new CodePrimitiveExpression(false)
                    )
            }).ToArray()
                       ));
        }
        private void CreateColumn(string tableName, DataFieldDescriptor fieldDescriptor, object defaultValue = null)
        {
            if (defaultValue == null && !fieldDescriptor.IsNullable && fieldDescriptor.DefaultValue != null)
            {
                ExecuteNonQuery("ALTER TABLE [{0}] ADD {1};"
                                .FormatWith(tableName, GetColumnInfo(tableName, fieldDescriptor.Name, fieldDescriptor, true, false)));
                return;
            }

            // Creating a column, making it nullable
            ExecuteNonQuery("ALTER TABLE [{0}] ADD {1};"
                            .FormatWith(tableName, GetColumnInfo(tableName, fieldDescriptor.Name, fieldDescriptor, true, true)));

            // Setting default value with "UPDATE" statement
            if (defaultValue != null || (!fieldDescriptor.IsNullable && fieldDescriptor.DefaultValue == null))
            {
                string defaultValueStr;

                if (defaultValue != null)
                {
                    Type typeOfDefaultValue = defaultValue.GetType();
                    defaultValueStr = (typeOfDefaultValue == typeof(string) || typeOfDefaultValue == typeof(Guid))
                                    ? ("'" + defaultValue + "'")
                                    : defaultValue.ToString();
                }
                else
                {
                    defaultValueStr = GetDefaultValueText(fieldDescriptor.StoreType);
                }

                ExecuteNonQuery("UPDATE [{0}] SET [{1}] = {2};"
                                .FormatWith(tableName, fieldDescriptor.Name, defaultValueStr));
            }

            // Making column not nullable if necessary
            if (!fieldDescriptor.IsNullable)
            {
                AlterColumn(tableName, GetColumnInfo(tableName, fieldDescriptor.Name, fieldDescriptor, false, false));
            }
        }
예제 #23
0
        public static GeneratedTypesHelper.KeyFieldType GetKeyFieldType(DataFieldDescriptor field)
        {
            if (field.InstanceType == typeof(Guid))
            {
                return(GeneratedTypesHelper.KeyFieldType.Guid);
            }

            if (field.InstanceType == typeof(string) && field.DefaultValue != null)
            {
                if (field.DefaultValue.Equals(DefaultValue.RandomString(4, true)))
                {
                    return(GeneratedTypesHelper.KeyFieldType.RandomString4);
                }

                if (field.DefaultValue.Equals(DefaultValue.RandomString(8, false)))
                {
                    return(GeneratedTypesHelper.KeyFieldType.RandomString8);
                }
            }

            return(GeneratedTypesHelper.KeyFieldType.Undefined);
        }
예제 #24
0
        public static void UpdateKeyType(DataFieldDescriptor idField, GeneratedTypesHelper.KeyFieldType selectedFieldType)
        {
            switch (selectedFieldType)
            {
            case GeneratedTypesHelper.KeyFieldType.Guid:
                idField.StoreType    = StoreFieldType.Guid;
                idField.InstanceType = typeof(Guid);
                idField.DefaultValue = null;
                break;

            case GeneratedTypesHelper.KeyFieldType.RandomString4:
                idField.StoreType    = StoreFieldType.String(22);
                idField.InstanceType = typeof(string);
                idField.DefaultValue = DefaultValue.RandomString(4, true);
                break;

            case GeneratedTypesHelper.KeyFieldType.RandomString8:
                idField.StoreType    = StoreFieldType.String(22);
                idField.InstanceType = typeof(string);
                idField.DefaultValue = DefaultValue.RandomString(8, false);
                break;
            }
        }
        internal static DataFieldDescriptor BuildFieldDescriptor(PropertyInfo propertyInfo, bool inherited)
        {
            string fieldName = propertyInfo.Name;
            Type fieldType = propertyInfo.PropertyType;
            Guid fieldId = DynamicTypeReflectionFacade.GetImmutableFieldId(propertyInfo);

            StoreFieldType storeFieldType = DynamicTypeReflectionFacade.GetStoreFieldType(propertyInfo);


            var fieldDescriptor = new DataFieldDescriptor(fieldId, fieldName, storeFieldType, fieldType, inherited)
            {
                DefaultValue = DynamicTypeReflectionFacade.GetDefaultValue(propertyInfo),
                IsNullable = DynamicTypeReflectionFacade.IsNullable(propertyInfo),
                ForeignKeyReferenceTypeName = DynamicTypeReflectionFacade.ForeignKeyReferenceTypeName(propertyInfo),
                GroupByPriority = DynamicTypeReflectionFacade.GetGroupByPriority(propertyInfo),
                TreeOrderingProfile = DynamicTypeReflectionFacade.GetTreeOrderingProfile(propertyInfo),
                NewInstanceDefaultFieldValue = DynamicTypeReflectionFacade.NewInstanceDefaultFieldValue(propertyInfo),
                IsReadOnly = !propertyInfo.CanWrite
            };

            var formRenderingProfile = DynamicTypeReflectionFacade.GetFormRenderingProfile(propertyInfo);
            if (formRenderingProfile != null)
            {
                fieldDescriptor.FormRenderingProfile = formRenderingProfile;
            }

            // These auto added widget functions does not work on a empty system.
            // This code could have added widgets for data types that does not have any widgets attached to them
            //WidgetFunctionProvider widgetFunctionProvider = GetWidgetFunctionMarkup(propertyInfo.PropertyType);            
            //if (widgetFunctionProvider != null)
            //{
            //    LazyDataFieldFormRenderingProfile lazyDataFieldFormRenderingProfile = new LazyDataFieldFormRenderingProfile();
            //    lazyDataFieldFormRenderingProfile.Label = propertyInfo.Name;
            //    lazyDataFieldFormRenderingProfile.HelpText = propertyInfo.Name;
            //    lazyDataFieldFormRenderingProfile.WidgetFunctionMarkupFunc = () => widgetFunctionProvider.SerializedWidgetFunction.ToString();

            //    fieldDescriptor.FormRenderingProfile = lazyDataFieldFormRenderingProfile;
            //}

            int position;
            fieldDescriptor.Position = DynamicTypeReflectionFacade.TryGetFieldPosition(propertyInfo, out position) 
                ? position : 1000;

            return fieldDescriptor;
        }
        private IEnumerable <Element> GetGroupChildrenFolders(DataGroupingProviderHelperEntityToken groupEntityToken, Type interfaceType, Func <IData, bool> filter, DataFieldDescriptor groupingDataFieldDescriptor, PropertyInfoValueCollection propertyInfoValueCollection)
        {
            IQueryable        queryable          = GetFilteredData(interfaceType, filter);
            ExpressionBuilder expressionBuilder  = new ExpressionBuilder(interfaceType, queryable);
            PropertyInfo      selectPropertyInfo = interfaceType.GetPropertiesRecursively(f => f.Name == groupingDataFieldDescriptor.Name).Single();

            IQueryable resultQueryable = expressionBuilder.
                                         Where(propertyInfoValueCollection, true).
                                         OrderBy(selectPropertyInfo, true, groupingDataFieldDescriptor.TreeOrderingProfile.OrderDescending).
                                         Select(selectPropertyInfo, true).
                                         Distinct().
                                         CreateQuery();

            return(CreateGroupFolderElements(interfaceType, groupingDataFieldDescriptor, resultQueryable, groupEntityToken, propertyInfoValueCollection));
        }
        public IEnumerable <Element> GetGroupChildren(DataGroupingProviderHelperEntityToken groupEntityToken, bool includeForeignFolders)
        {
            Type interfaceType = TypeManager.GetType(groupEntityToken.Type);

            var propertyInfoValueCollection = new PropertyInfoValueCollection();

            foreach (var kvp in groupEntityToken.GroupingValues)
            {
                PropertyInfo propertyInfo = interfaceType.GetPropertiesRecursively().Single(f => f.Name == kvp.Key);
                propertyInfoValueCollection.AddPropertyValue(propertyInfo, kvp.Value);
            }

            var dataTypeDescriptor = DynamicTypeManager.GetDataTypeDescriptor(interfaceType);

            DataFieldDescriptor groupingDataFieldDescriptor =
                (from dfd in dataTypeDescriptor.Fields
                 where dfd.GroupByPriority == groupEntityToken.GroupingValues.Count + 1
                 select dfd).SingleOrDefault();

            if (groupingDataFieldDescriptor != null &&
                propertyInfoValueCollection.PropertyValues.Any(f => f.Key.Name == groupingDataFieldDescriptor.Name))
            {
                // Grouping ordering has ben changed, at the moment the best thing we can do its to return no elements
                // TODO: This class and the whole attach element provider stuff should be redone
                return(new Element[] { });
            }

            Func <IData, bool> filter = null;

            if (this.OnGetLeafsFilter != null)
            {
                filter = this.OnGetLeafsFilter(groupEntityToken);
            }

            using (new DataScope(this.OnGetDataScopeIdentifier(interfaceType)))
            {
                if (groupingDataFieldDescriptor != null)
                {
                    PropertyInfoValueCollection propertyInfoValueCol = propertyInfoValueCollection.Clone();
                    List <Element> elements = GetGroupChildrenFolders(groupEntityToken, interfaceType, filter, groupingDataFieldDescriptor, propertyInfoValueCol).ToList();

                    if (groupingDataFieldDescriptor.ForeignKeyReferenceTypeName != null)
                    {
                        elements = (groupingDataFieldDescriptor.TreeOrderingProfile.OrderDescending ?
                                    elements.OrderByDescending(f => f.VisualData.Label) :
                                    elements.OrderBy(f => f.VisualData.Label)).ToList();
                    }

                    if (includeForeignFolders)
                    {
                        using (new DataScope(UserSettings.ForeignLocaleCultureInfo))
                        {
                            PropertyInfoValueCollection foreignPropertyInfoValueCol = propertyInfoValueCollection.Clone();
                            elements.AddRange(GetGroupChildrenFolders(groupEntityToken, interfaceType, filter, groupingDataFieldDescriptor, foreignPropertyInfoValueCol));
                        }
                    }

                    return(elements.Distinct());
                }
                else
                {
                    PropertyInfoValueCollection propertyInfoValueCol = propertyInfoValueCollection.Clone();
                    List <Element> elements = GetGroupChildrenLeafs(interfaceType, filter, propertyInfoValueCol, false).ToList();

                    if (!dataTypeDescriptor.Fields.Any(f => f.TreeOrderingProfile.OrderPriority.HasValue && f.ForeignKeyReferenceTypeName == null))
                    {
                        var labelFieldDescriptor = dataTypeDescriptor.Fields.FirstOrDefault(f => f.Name == dataTypeDescriptor.LabelFieldName);
                        if (labelFieldDescriptor != null && labelFieldDescriptor.ForeignKeyReferenceTypeName != null)
                        {
                            elements = (labelFieldDescriptor.TreeOrderingProfile.OrderDescending ?
                                        elements.OrderByDescending(f => f.VisualData.Label) :
                                        elements.OrderBy(f => f.VisualData.Label)).ToList();
                        }
                    }

                    if (includeForeignFolders)
                    {
                        using (new DataScope(UserSettings.ForeignLocaleCultureInfo))
                        {
                            PropertyInfoValueCollection foreignPropertyInfoValueCol = propertyInfoValueCollection.Clone();
                            elements.AddRange(GetGroupChildrenLeafs(interfaceType, filter, foreignPropertyInfoValueCol, true));
                        }
                    }

                    return(elements.Distinct());
                }
            }
        }
        private IEnumerable <Element> GetRootGroupFolders(Type interfaceType, EntityToken parentEntityToken, DataFieldDescriptor firstDataFieldDescriptor, PropertyInfo propertyInfo)
        {
            Func <IData, bool> filter = (this.OnGetLeafsFilter != null) ? this.OnGetLeafsFilter(parentEntityToken) : null;

            IQueryable queryable = GetFilteredData(interfaceType, filter);

            var expressionBuilder = new ExpressionBuilder(interfaceType, queryable);

            IQueryable resultQueryable = expressionBuilder.
                                         OrderBy(propertyInfo, true, firstDataFieldDescriptor.TreeOrderingProfile.OrderDescending).
                                         Select(propertyInfo, true).
                                         Distinct().
                                         CreateQuery();

            var propertyInfoValueCollection = new PropertyInfoValueCollection();

            return(CreateGroupFolderElements(interfaceType, firstDataFieldDescriptor, resultQueryable, parentEntityToken, propertyInfoValueCollection));
        }
        public IEnumerable <Element> GetRootGroupFolders(Type interfaceType, EntityToken parentEntityToken, bool includeForeignFolders)
        {
            DataTypeDescriptor dataTypeDescriptor = DynamicTypeManager.GetDataTypeDescriptor(interfaceType);

            IEnumerable <DataFieldDescriptor> groupingDataFieldDescriptors =
                from dfd in dataTypeDescriptor.Fields
                where dfd.GroupByPriority != 0
                orderby dfd.GroupByPriority
                select dfd;

            using (new DataScope(this.OnGetDataScopeIdentifier(interfaceType)))
            {
                if (groupingDataFieldDescriptors.Count() != 0)
                {
                    ValidateGroupByPriorities(interfaceType, groupingDataFieldDescriptors);

                    DataFieldDescriptor firstDataFieldDescriptor = groupingDataFieldDescriptors.First();
                    PropertyInfo        propertyInfo             = interfaceType.GetPropertiesRecursively().Single(f => f.Name == firstDataFieldDescriptor.Name);

                    List <Element> elements = GetRootGroupFolders(interfaceType, parentEntityToken, firstDataFieldDescriptor, propertyInfo).ToList();

                    if (firstDataFieldDescriptor.ForeignKeyReferenceTypeName != null)
                    {
                        elements = (firstDataFieldDescriptor.TreeOrderingProfile.OrderDescending ?
                                    elements.OrderByDescending(f => f.VisualData.Label) :
                                    elements.OrderBy(f => f.VisualData.Label)).ToList();
                    }

                    if (includeForeignFolders)
                    {
                        using (new DataScope(UserSettings.ForeignLocaleCultureInfo))
                        {
                            elements.AddRange(GetRootGroupFolders(interfaceType, parentEntityToken, firstDataFieldDescriptor, propertyInfo));
                        }
                    }

                    return(elements.Distinct());
                }
                else
                {
                    Func <IData, bool> filter = null;

                    if (this.OnGetLeafsFilter != null)
                    {
                        filter = this.OnGetLeafsFilter(parentEntityToken);
                    }

                    List <Element> elements = GetRootGroupFoldersFoldersLeafs(interfaceType, filter, false).ToList();

                    bool listingLimitReached = elements.Count == MaxElementsToShow;

                    var labelFieldDescriptor = dataTypeDescriptor.Fields.FirstOrDefault(f => f.Name == dataTypeDescriptor.LabelFieldName);
                    if (labelFieldDescriptor != null && labelFieldDescriptor.ForeignKeyReferenceTypeName != null && labelFieldDescriptor.TreeOrderingProfile.OrderPriority.HasValue)
                    {
                        elements = (labelFieldDescriptor.TreeOrderingProfile.OrderDescending ?
                                    elements.OrderByDescending(f => f.VisualData.Label) :
                                    elements.OrderBy(f => f.VisualData.Label)).ToList();
                    }

                    if (!listingLimitReached && includeForeignFolders)
                    {
                        using (new DataScope(UserSettings.ForeignLocaleCultureInfo))
                        {
                            elements.AddRange(GetRootGroupFoldersFoldersLeafs(interfaceType, filter, true));
                        }

                        elements = elements.Distinct().Take(MaxElementsToShow).ToList();
                    }

                    if (elements.Count == MaxElementsToShow)
                    {
                        elements.Add(GetElipsisElement(parentEntityToken, MaxElementsToShow));
                    }

                    return(elements);
                }
            }
        }
예제 #30
0
 internal static string GenerateListTableName(DataTypeDescriptor typeDescriptor, DataFieldDescriptor fieldDescriptor)
 {
     return(string.Format("{0}_{1}", GenerateTableName(typeDescriptor), fieldDescriptor.Name));
 }
예제 #31
0
 internal static bool AreSame(DataFieldDescriptor a, DataFieldDescriptor b)
 {
     return(a.ToXml().ToString() == b.ToXml().ToString());
 }