internal static SqlDbType GetStoreTypeToSqlDataTypeMapping(StoreFieldType storeType) { switch (storeType.PhysicalStoreType) { case PhysicalStoreFieldType.Integer: return(SqlDbType.Int); case PhysicalStoreFieldType.Long: return(SqlDbType.BigInt); case PhysicalStoreFieldType.String: return(SqlDbType.NVarChar); case PhysicalStoreFieldType.LargeString: return(SqlDbType.NVarChar); case PhysicalStoreFieldType.DateTime: return(SqlDbType.DateTime); case PhysicalStoreFieldType.Decimal: return(SqlDbType.Decimal); case PhysicalStoreFieldType.Boolean: return(SqlDbType.Bit); case PhysicalStoreFieldType.Guid: return(SqlDbType.UniqueIdentifier); default: throw new ArgumentException("Unknown store type on field"); } }
private string GetDefaultValueText(StoreFieldType storeFieldType) { Verify.ArgumentNotNull(storeFieldType, "storeFieldType"); switch (storeFieldType.PhysicalStoreType) { case PhysicalStoreFieldType.String: case PhysicalStoreFieldType.LargeString: return("N''"); case PhysicalStoreFieldType.Guid: return("'00000000-0000-0000-0000-000000000000'"); case PhysicalStoreFieldType.Integer: case PhysicalStoreFieldType.Long: case PhysicalStoreFieldType.Decimal: return("0"); case PhysicalStoreFieldType.Boolean: return("0"); case PhysicalStoreFieldType.DateTime: return("getdate()"); } throw new NotImplementedException("Supplied StoreFieldType contains an unsupported PhysicalStoreType '{0}'." .FormatWith(storeFieldType.PhysicalStoreType)); }
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); }
/// <summary> /// Specifies what physical store type should be used to store this property. /// This overload is intended for decimal. /// </summary> /// <param name="physicalStoreFieldType">PhysicalStoreFieldType to use - PhysicalStoreFieldType.Decimal expected</param> /// <param name="numericPrecision">Numeric precision for decimal</param> /// <param name="numericScale">Numeric scale for decimal</param> public StoreFieldTypeAttribute(PhysicalStoreFieldType physicalStoreFieldType, int numericPrecision, int numericScale) : this() { switch (physicalStoreFieldType) { case PhysicalStoreFieldType.Decimal: this.StoreFieldType = StoreFieldType.Decimal(numericPrecision, numericScale); return; } throw new ArgumentException(string.Format("[{0}] - field type {1}.{2} does not take two 'int' arguments in the attribute constructor.", this.GetType().Name, typeof(PhysicalStoreFieldType).Name, physicalStoreFieldType)); }
/// <summary> /// Specifies what physical store type should be used to store this property. /// This overload is intended for string. /// </summary> /// <param name="physicalStoreFieldType">PhysicalStoreFieldType to use - PhysicalStoreFieldType.String expected</param> /// <param name="maxLength">Number of characters to reserve in physical store</param> public StoreFieldTypeAttribute(PhysicalStoreFieldType physicalStoreFieldType, int maxLength) : this() { switch (physicalStoreFieldType) { case PhysicalStoreFieldType.String: this.StoreFieldType = StoreFieldType.String(maxLength); return; } throw new ArgumentException(string.Format("[{0}] - field type {1}.{2} does not take an int argument in the attribute constructor.", this.GetType().Name, typeof(PhysicalStoreFieldType).Name, physicalStoreFieldType)); }
internal static string MapStoreTypeToSqlDataType(StoreFieldType storeType) { string result = string.Format(" [{0}]", GetStoreTypeToSqlDataTypeMapping(storeType)); switch (storeType.PhysicalStoreType) { case PhysicalStoreFieldType.String: return(string.Format("{0}({1})", result, storeType.MaximumLength)); case PhysicalStoreFieldType.LargeString: return(string.Format("{0}({1})", result, "max")); case PhysicalStoreFieldType.Decimal: return(string.Format("{0}({1},{2})", result, storeType.NumericPrecision, storeType.NumericScale)); default: return(result); } }
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; } }
private void Initialize() { int counter = 1; while (true) { string typeName = string.Format("{0}{1}", _namePrefix, counter++); if (!DataMetaDataFacade.GeneratedTypeDataTypeDescriptors.Any(d => d.Name == typeName)) { TypeName = TypeTitle = typeName; break; } } _dataFieldDescriptors = new List <DataFieldDescriptor> { new DataFieldDescriptor(Guid.NewGuid(), "MyStringField", StoreFieldType.String(64), typeof(string)) { Position = 10, IsNullable = true, DataUrlProfile = new DataUrlProfile() { Format = DataUrlSegmentFormat.DateTime_Year, Order = 1 }, FormRenderingProfile = new DataFieldFormRenderingProfile { Label = "MyStringField", HelpText = "This is an auto-generated field.", WidgetFunctionMarkup = GetWidgetFunctionMarkup("Composite.Widgets.String.TextBox") }, TreeOrderingProfile = new DataFieldTreeOrderingProfile { OrderPriority = 1, OrderDescending = false, } }, new DataFieldDescriptor(Guid.NewGuid(), "MyIntField", StoreFieldType.Integer, typeof(int)) { Position = 11, FormRenderingProfile = new DataFieldFormRenderingProfile { Label = "MyIntField", HelpText = "This is an auto-generated field.", WidgetFunctionMarkup = GetWidgetFunctionMarkup("Composite.Widgets.String.TextBox") }, TreeOrderingProfile = new DataFieldTreeOrderingProfile { OrderPriority = 2, OrderDescending = true, } }, new DataFieldDescriptor(Guid.NewGuid(), "MyDateTimeField", StoreFieldType.DateTime, typeof(DateTime?)) { IsNullable = true, Position = 12, FormRenderingProfile = new DataFieldFormRenderingProfile { Label = "MyDateTimeField", HelpText = "This is an auto-generated field.", WidgetFunctionMarkup = GetWidgetFunctionMarkup("Composite.Widgets.Date.DateSelector") }, TreeOrderingProfile = new DataFieldTreeOrderingProfile { OrderPriority = null, } } }; }
public static void Validate(IData datum) { Type type = datum.DataSourceId.InterfaceType; ValidationInfo info = _validationInfoCache.Get(type); if (info == null) { lock (_validationInfoCache) { info = _validationInfoCache.Get(type); if (info == null) { info = new ValidationInfo { MaxStringLengthByField = new List <Pair <PropertyInfo, int> >() }; foreach (PropertyInfo propertyInfo in type.GetProperties()) { if (propertyInfo.PropertyType != typeof(string)) { continue; } object[] attributes = propertyInfo.GetCustomAttributes(typeof(StoreFieldTypeAttribute), false); if (attributes.Length > 1) { LoggingService.LogError(typeof(ValidationHelper).Name, "Encoutered more than one '{0}' attrubute".FormatWith(typeof(StoreFieldTypeAttribute).FullName)); continue; } if (attributes.Length == 0) { continue; } var storeFieldTypeAttr = attributes[0] as StoreFieldTypeAttribute; StoreFieldType storeFieldType = storeFieldTypeAttr.StoreFieldType; if (storeFieldType.IsLargeString || !storeFieldType.IsString) { continue; } info.MaxStringLengthByField.Add(new Pair <PropertyInfo, int>(propertyInfo, storeFieldType.MaximumLength)); } _validationInfoCache.Add(type, info); } } } foreach (Pair <PropertyInfo, int> pair in info.MaxStringLengthByField) { string fieldValue = pair.First.GetValue(datum, EmptyParameterList) as string; if (fieldValue != null && fieldValue.Length > pair.Second) { Verify.ThrowInvalidOperationException("Constraint violation. Value for field '{0}' on data type '{1}' is longer than {2} symbols.".FormatWith(pair.First.Name, type.FullName, pair.Second)); } } }