public static ValidFieldIdentifier ( string name ) : bool | ||
name | string | |
Résultat | bool |
public void Validate(ValidationContext context) { if (!this.IsGenerated) { return; } //if (!this.IsDirty) return; System.Windows.Forms.Application.DoEvents(); var timer = nHydrate.Dsl.Custom.DebugHelper.StartTimer(); try { var columnList = this.Fields.Where(x => x.IsGenerated).ToList(); #region Check valid name if (!ValidationHelper.ValidDatabaseIdenitifer(this.DatabaseName)) { context.LogError(string.Format(ValidationHelper.ErrorTextInvalidIdentifier, this.Name), string.Empty, this); } else if (!ValidationHelper.ValidCodeIdentifier(this.PascalName)) { context.LogError(string.Format(ValidationHelper.ErrorTextInvalidIdentifier, this.Name), string.Empty, this); } else if (!ValidationHelper.ValidFieldIdentifier(this.PascalName)) { context.LogError(string.Format(ValidationHelper.ErrorTextInvalidIdentifier, this.Name), string.Empty, this); } #endregion #region Check for duplicate names var nameList = new Hashtable(); foreach (var column in columnList) { var name = column.Name.ToLower(); if (nameList.ContainsKey(name)) { context.LogError(string.Format(ValidationHelper.ErrorTextDuplicateName, column.Name), string.Empty, this); } else { nameList.Add(name, string.Empty); } } #endregion #region Check valid name based on codefacade if ((!string.IsNullOrEmpty(this.CodeFacade)) && !ValidationHelper.ValidDatabaseIdenitifer(this.CodeFacade)) { context.LogError(ValidationHelper.ErrorTextInvalidCodeFacade, string.Empty, this); } #endregion #region Verify there is a result if (this.Fields.Count(x => x.IsGenerated) == 0) { context.LogError(string.Format(ValidationHelper.ErrorTextFunctionZeroFields, this.Name), string.Empty, this); } if (this.Fields.Count(x => x.IsGenerated) != 1 && !this.IsTable) { context.LogError(string.Format(ValidationHelper.ErrorTextFunctionScalerMultipleFields, this.Name), string.Empty, this); } #endregion #region Verify the return variable if (!string.IsNullOrEmpty(this.ReturnVariable)) { if (!ValidationHelper.ValidDatabaseIdenitifer(this.ReturnVariable)) { context.LogError(string.Format(ValidationHelper.ErrorTextFunctionReturnVarNotValid, this.ReturnVariable, this.Name), string.Empty, this); } if (!this.IsTable) { context.LogError(string.Format(ValidationHelper.ErrorTextFunctionReturnVarForTabelFunc, this.Name), string.Empty, this); } } #endregion #region Check View SQL if (string.IsNullOrEmpty(this.SQL)) { context.LogError(string.Format(ValidationHelper.ErrorTextSQLRequiredFunction, this.Name), string.Empty, this); } #endregion #region Check Parameters Duplicates var paramList = this.Parameters.Select(x => x.Name.ToLower()); if (paramList.Count() != paramList.Distinct().Count()) { context.LogError(string.Format(ValidationHelper.ErrorTextDuplicateParameters, this.Name), string.Empty, this); } #endregion } catch (Exception ex) { throw; } finally { nHydrate.Dsl.Custom.DebugHelper.StopTimer(timer, "Function Validate - Functions"); } }
public void Validate(ValidationContext context) { var timer = nHydrate.Dsl.Custom.DebugHelper.StartTimer(); try { if (!this.IsGenerated) { return; } //if (!this.IsDirty) return; #region Check valid name if (!ValidationHelper.ValidDatabaseIdenitifer(this.DatabaseName)) { context.LogError(string.Format(ValidationHelper.ErrorTextInvalidIdentifier, this.Entity.Name + "." + this.Name), string.Empty, this); } else if (!ValidationHelper.ValidCodeIdentifier(this.PascalName)) { context.LogError(string.Format(ValidationHelper.ErrorTextInvalidIdentifier, this.Entity.Name + "." + this.Name), string.Empty, this); } else if (!ValidationHelper.ValidFieldIdentifier(this.PascalName)) { context.LogError(string.Format(ValidationHelper.ErrorTextInvalidIdentifier, this.Entity.Name + "." + this.Name), string.Empty, this); } #endregion #region Check valid name based on codefacade if ((!string.IsNullOrEmpty(this.CodeFacade)) && !ValidationHelper.ValidDatabaseIdenitifer(this.CodeFacade)) { context.LogError(ValidationHelper.ErrorTextInvalidCodeFacade, string.Empty, this); } if (this.IsNumericType()) { if (!double.IsNaN(this.Min) && (!double.IsNaN(this.Max))) { if (this.Min > this.Max) { context.LogError(ValidationHelper.ErrorTextMinMaxValueMismatch, string.Empty, this); } } } else //Non-numeric { //Neither should be set if (!double.IsNaN(this.Min) || (!double.IsNaN(this.Max))) { context.LogError(ValidationHelper.ErrorTextMinMaxValueInvalidType, string.Empty, this); } } #endregion #region Validate identity field if (this.Identity != IdentityTypeConstants.None && !this.DataType.SupportsIdentity()) { context.LogError(string.Format(ValidationHelper.ErrorTextInvalidIdentityColumn, this.Name), string.Empty, this); } #endregion #region Varchar Max only supported in SQL 2008 //if (((ModelRoot)this.Root).SQLServerType == SQLServerTypeConstants.SQL2005) //{ // if (ModelHelper.SupportsMax(this.DataType) && this.Length == 0) // { // context.LogError(string.Format(ValidationHelper.ErrorTextColumnMaxNotSupported, this.Name), string.Empty, this); // } //} #endregion #region Columns cannot be 0 length if (!this.DataType.SupportsMax() && this.Length == 0) { context.LogError(string.Format(ValidationHelper.ErrorTextColumnLengthNotZero, this.Name), string.Empty, this); } #endregion #region Validate Decimals if (this.DataType == DataTypeConstants.Decimal) { if (this.Length < 1 || this.Length > 38) { context.LogError(string.Format(ValidationHelper.ErrorTextColumnDecimalPrecision, this.Name), string.Empty, this); } if (this.Scale < 0 || this.Scale > this.Length) { context.LogError(string.Format(ValidationHelper.ErrorTextColumnDecimalScale, this.Name), string.Empty, this); } } #endregion #region Validate max lengths var validatedLength = this.DataType.ValidateDataTypeMax(this.Length); if (validatedLength != this.Length) { context.LogError(string.Format(ValidationHelper.ErrorTextColumnMaxLengthViolation, this.Entity.Name + "." + this.Name, validatedLength, this.DataType.ToString()), string.Empty, this); } #endregion #region Verify Datatypes for SQL 2005/2008 if (!this.DataType.IsSupportedType(this.Entity.nHydrateModel.SQLServerType)) { context.LogError(string.Format(ValidationHelper.ErrorTextDataTypeNotSupported, this.Name), string.Empty, this); } #endregion #region Computed Column if (this.IsCalculated) { if (this.Formula.Trim() == "") { context.LogError(string.Format(ValidationHelper.ErrorTextComputeColumnNoFormula, this.Name), string.Empty, this); } if (this.IsPrimaryKey) { context.LogError(string.Format(ValidationHelper.ErrorTextComputeColumnNoPK, this.Name), string.Empty, this); } } if (!this.IsCalculated && !string.IsNullOrEmpty(this.Formula)) { context.LogError(string.Format(ValidationHelper.ErrorTextComputeNonColumnHaveFormula, this.Name), string.Empty, this); } #endregion #region Validate Defaults if (!string.IsNullOrEmpty(this.Default)) { if (!this.CanHaveDefault()) { context.LogError(string.Format(ValidationHelper.ErrorTextColumnCannotHaveDefault, this.Name), string.Empty, this); } else if (!this.IsValidDefault()) { context.LogWarning(string.Format(ValidationHelper.ErrorTextColumnInvalidDefault, this.Name), string.Empty, this); } } #endregion #region Check Decimals for common error if (this.DataType == DataTypeConstants.Decimal) { if (this.Length == 1) { context.LogError(string.Format(ValidationHelper.ErrorTextDecimalColumnTooSmall, this.Name, this.Length.ToString()), string.Empty, this); } } #endregion #region Verify Metadata var metaKeyList = new List <string>(); foreach (var item in this.FieldMetadata) { if (string.IsNullOrEmpty(item.Key) || metaKeyList.Contains(item.Key.ToLower())) { context.LogError(ValidationHelper.ErrorTextMetadataInvalid, string.Empty, this); } else { metaKeyList.Add(item.Key.ToString()); } } #endregion #region Identity Columns cannot have defaults if (this.Identity != IdentityTypeConstants.None && !string.IsNullOrEmpty(this.Default)) { context.LogError(string.Format(ValidationHelper.ErrorTextColumnIdentityHasDefault, this.Entity.Name + "." + this.Name), string.Empty, this); } #endregion #region Non-nullable, ReadOnly propeties must have a default (except identities) if (this.IsReadOnly && !this.Nullable && (this.Identity != IdentityTypeConstants.Database) && string.IsNullOrEmpty(this.Default)) { context.LogError(string.Format(ValidationHelper.ErrorTextColumnReadonlyNeedsDefault, this.Entity.Name + "." + this.Name), string.Empty, this); } #endregion #region Verify Entity is in some module if (this.Entity.nHydrateModel.UseModules && (this.Modules.Count == 0) && this.IsGenerated) { context.LogError(string.Format(ValidationHelper.ErrorTextModuleItemNotInModule, this.Entity.Name + "." + this.Name), string.Empty, this); } #endregion #region Identity cannot have range check if ((!Double.IsNaN(this.Min) || !Double.IsNaN(this.Max)) && this.Identity != IdentityTypeConstants.None) { context.LogError(string.Format(ValidationHelper.ErrorTextColumnNoRange4Identity, this.Entity.Name + "." + this.Name), string.Empty, this); } #endregion } catch (Exception ex) { throw; } finally { nHydrate.Dsl.Custom.DebugHelper.StopTimer(timer, "Field Validate - Fields"); } }
public void Validate(ValidationContext context) { var timer = nHydrate.Dsl.Custom.DebugHelper.StartTimer(); try { //if (!this.IsDirty) return; #region Check valid name if (!ValidationHelper.ValidDatabaseIdentifier(this.DatabaseName)) { context.LogError(string.Format(ValidationHelper.ErrorTextInvalidIdentifier, this.Entity.Name + "." + this.Name), string.Empty, this); } else if (!ValidationHelper.ValidCodeIdentifier(this.PascalName)) { context.LogError(string.Format(ValidationHelper.ErrorTextInvalidIdentifier, this.Entity.Name + "." + this.Name), string.Empty, this); } else if (!ValidationHelper.ValidFieldIdentifier(this.PascalName)) { context.LogError(string.Format(ValidationHelper.ErrorTextInvalidIdentifier, this.Entity.Name + "." + this.Name), string.Empty, this); } #endregion #region Check valid name based on codefacade if ((!string.IsNullOrEmpty(this.CodeFacade)) && !ValidationHelper.ValidDatabaseIdentifier(this.CodeFacade)) { context.LogError(ValidationHelper.ErrorTextInvalidCodeFacade, string.Empty, this); } #endregion #region Validate identity field if (this.Identity != IdentityTypeConstants.None && !this.DataType.SupportsIdentity()) { context.LogError(string.Format(ValidationHelper.ErrorTextInvalidIdentityColumn, this.Name), string.Empty, this); } #endregion #region Columns cannot be 0 length if (!this.DataType.SupportsMax() && this.Length == 0) { context.LogError(string.Format(ValidationHelper.ErrorTextColumnLengthNotZero, this.Name), string.Empty, this); } #endregion #region Validate Decimals if (this.DataType == DataTypeConstants.Decimal) { if (this.Length < 1 || this.Length > 38) { context.LogError(string.Format(ValidationHelper.ErrorTextColumnDecimalPrecision, this.Name), string.Empty, this); } if (this.Scale < 0 || this.Scale > this.Length) { context.LogError(string.Format(ValidationHelper.ErrorTextColumnDecimalScale, this.Name), string.Empty, this); } } #endregion #region Validate max lengths var validatedLength = this.DataType.ValidateDataTypeMax(this.Length); if (validatedLength != this.Length) { context.LogError(string.Format(ValidationHelper.ErrorTextColumnMaxLengthViolation, this.Entity.Name + "." + this.Name, validatedLength, this.DataType.ToString()), string.Empty, this); } #endregion #region Verify Datatypes for SQL 2005/2008 if (!this.DataType.IsSupportedType()) { context.LogError(string.Format(ValidationHelper.ErrorTextDataTypeNotSupported, this.Name), string.Empty, this); } #endregion #region Computed Column if (this.IsCalculated) { if (this.Formula.Trim() == "") { context.LogError(string.Format(ValidationHelper.ErrorTextComputeColumnNoFormula, this.Name), string.Empty, this); } if (this.IsPrimaryKey) { context.LogError(string.Format(ValidationHelper.ErrorTextComputeColumnNoPK, this.Name), string.Empty, this); } } if (!this.IsCalculated && !string.IsNullOrEmpty(this.Formula)) { context.LogError(string.Format(ValidationHelper.ErrorTextComputeNonColumnHaveFormula, this.Name), string.Empty, this); } #endregion #region Validate Defaults if (!string.IsNullOrEmpty(this.Default)) { if (!this.CanHaveDefault()) { context.LogError(string.Format(ValidationHelper.ErrorTextColumnCannotHaveDefault, this.Name), string.Empty, this); } else if (!this.IsValidDefault()) { context.LogWarning(string.Format(ValidationHelper.ErrorTextColumnInvalidDefault, this.Name), string.Empty, this); } } #endregion #region Check Decimals for common error if (this.DataType == DataTypeConstants.Decimal) { if (this.Length == 1) { context.LogError(string.Format(ValidationHelper.ErrorTextDecimalColumnTooSmall, this.Name, this.Length.ToString()), string.Empty, this); } } #endregion #region Identity Columns cannot have defaults if (this.Identity != IdentityTypeConstants.None && !string.IsNullOrEmpty(this.Default)) { context.LogError(string.Format(ValidationHelper.ErrorTextColumnIdentityHasDefault, this.Entity.Name + "." + this.Name), string.Empty, this); } #endregion #region Non-nullable, ReadOnly propeties must have a default (except identities) if (this.IsReadOnly && !this.Nullable && (this.Identity != IdentityTypeConstants.Database) && string.IsNullOrEmpty(this.Default)) { context.LogError(string.Format(ValidationHelper.ErrorTextColumnReadonlyNeedsDefault, this.Entity.Name + "." + this.Name), string.Empty, this); } #endregion } catch (Exception ex) { throw; } finally { nHydrate.Dsl.Custom.DebugHelper.StopTimer(timer, "Field Validate - Fields"); } }