public void Validate(ValidationContext context) { //if (!this.IsDirty) return; #region Check valid name if (!ValidationHelper.ValidDatabaseIdentifier(this.DatabaseName)) { context.LogError(string.Format(ValidationHelper.ErrorTextInvalidIdentifierViewField, this.Name, this.View.Name), string.Empty, this); } else if (!ValidationHelper.ValidCodeIdentifier(this.PascalName)) { context.LogError(string.Format(ValidationHelper.ErrorTextInvalidIdentifierViewField, this.Name, this.View.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.View.Name + "." + this.Name, validatedLength, this.DataType.ToString()), string.Empty, this); } #endregion }
public void Validate(ValidationContext context) { //if (!this.IsDirty) return; var columnList = this.Fields.ToList(); #region Check valid name if (!ValidationHelper.ValidDatabaseIdentifier(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); } #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 View SQL if (this.SQL == string.Empty) { context.LogError(string.Format(ValidationHelper.ErrorTextSQLRequiredView, this.Name), string.Empty, this); } #endregion #region Check that object has at least one generated column if (this.Fields.Count() == 0) { context.LogError(ValidationHelper.ErrorTextColumnsRequired, string.Empty, this); } #endregion #region Verify that there is at least one PK if (this.Fields.Count(x => x.IsPrimaryKey) == 0) { context.LogError(string.Format(ValidationHelper.ErrorTextNoPrimaryKey, this.Name), string.Empty, this); } #endregion #region Verify that no column has same name as container foreach (var field in this.Fields) { if (string.Compare(field.PascalName, this.PascalName, true) == 0) { context.LogError(string.Format(ValidationHelper.ErrorTextTableColumnNameMatch, field.Name, this.Name), string.Empty, this); } } #endregion }
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"); } }
public void Validate(ValidationContext context) { var timer = nHydrate.Dsl.Custom.DebugHelper.StartTimer(); try { #region Validate some global settings if (!ValidationHelper.ValidDatabaseIdentifier(this.CompanyName) || !ValidationHelper.ValidCodeIdentifier(this.CompanyName)) { context.LogError(ValidationHelper.ErrorTextInvalidCompany, string.Empty, this); } if (!ValidationHelper.ValidDatabaseIdentifier(this.ProjectName) || !ValidationHelper.ValidCodeIdentifier(this.ProjectName)) { context.LogError(ValidationHelper.ErrorTextInvalidProject, string.Empty, this); } if (!string.IsNullOrEmpty(this.DefaultNamespace)) { if (!ValidationHelper.IsValidNamespace(this.DefaultNamespace)) { context.LogError(ValidationHelper.ErrorTextInvalidNamespace, string.Empty, this); } } #endregion #region Validate audit fields //Fields must have a value if (string.IsNullOrEmpty(this.CreatedByColumnName)) { context.LogError(ValidationHelper.ErrorTextAuditFieldsMustExist, this.CreatedByColumnName, this); } if (string.IsNullOrEmpty(this.CreatedDateColumnName)) { context.LogError(ValidationHelper.ErrorTextAuditFieldsMustExist, this.CreatedDateColumnName, this); } if (string.IsNullOrEmpty(this.ModifiedByColumnName)) { context.LogError(ValidationHelper.ErrorTextAuditFieldsMustExist, this.ModifiedByColumnName, this); } if (string.IsNullOrEmpty(this.ModifiedDateColumnName)) { context.LogError(ValidationHelper.ErrorTextAuditFieldsMustExist, this.ModifiedDateColumnName, this); } if (string.IsNullOrEmpty(this.ConcurrencyCheckColumnName)) { context.LogError(ValidationHelper.ErrorTextAuditFieldsMustExist, this.ConcurrencyCheckColumnName, this); } if (string.IsNullOrEmpty(this.TenantColumnName)) { context.LogError(ValidationHelper.ErrorTextAuditFieldsMustExist, this.TenantColumnName, this); } //Fields must be unique var auditFieldList = new List <string>(); if (!auditFieldList.Contains(this.CreatedByColumnName)) { auditFieldList.Add(this.CreatedByColumnName); } if (!auditFieldList.Contains(this.CreatedDateColumnName)) { auditFieldList.Add(this.CreatedDateColumnName); } if (!auditFieldList.Contains(this.ModifiedByColumnName)) { auditFieldList.Add(this.ModifiedByColumnName); } if (!auditFieldList.Contains(this.ModifiedDateColumnName)) { auditFieldList.Add(this.ModifiedDateColumnName); } if (!auditFieldList.Contains(this.ConcurrencyCheckColumnName)) { auditFieldList.Add(this.ConcurrencyCheckColumnName); } if (auditFieldList.Count != 5) { context.LogError(ValidationHelper.ErrorTextAuditFieldsNotUnique, string.Empty, this); } else { auditFieldList = new List <string>(); if (!auditFieldList.Contains(this.CreatedByPascalName)) { auditFieldList.Add(this.CreatedByPascalName); } if (!auditFieldList.Contains(this.CreatedDatePascalName)) { auditFieldList.Add(this.CreatedDatePascalName); } if (!auditFieldList.Contains(this.ModifiedByPascalName)) { auditFieldList.Add(this.ModifiedByPascalName); } if (!auditFieldList.Contains(this.ModifiedDatePascalName)) { auditFieldList.Add(this.ModifiedDatePascalName); } if (!auditFieldList.Contains(this.ConcurrencyCheckPascalName)) { auditFieldList.Add(this.ConcurrencyCheckPascalName); } if (auditFieldList.Count != 5) { context.LogError(ValidationHelper.ErrorTextAuditFieldsNotUnique, string.Empty, this); } } #endregion #region Check for Global Uniqueness var nameList = new HashSet <string>(); //Check all entities foreach (var entity in this.Entities) { { var check = entity.PascalName.ToLower(); if (nameList.Contains(check)) { context.LogError(string.Format(ValidationHelper.ErrorTextDuplicateName, entity.PascalName), string.Empty, entity); } else { nameList.Add(check); } } } //Check Views foreach (var view in this.Views) { var check = view.PascalName.ToLower(); if (nameList.Contains(check)) { context.LogError(string.Format(ValidationHelper.ErrorTextDuplicateName, view.PascalName), string.Empty, view); } else { nameList.Add(check); } } #endregion #region Validate OutputTarget if (!string.IsNullOrEmpty(this.OutputTarget)) { try { var fi = new System.IO.FileInfo(System.IO.Path.Combine(@"c:\", this.OutputTarget)); } catch (Exception) { context.LogError(ValidationHelper.ErrorTextOutputTargetInvalid, string.Empty, this); } } #endregion #region Tenant if (this.Entities.Any(x => x.IsTenant)) { if (!string.IsNullOrEmpty(this.TenantColumnName) && !ValidationHelper.ValidCodeIdentifier(this.TenantColumnName)) { context.LogError(string.Format(ValidationHelper.ErrorTextInvalidIdentifier, this.TenantColumnName), string.Empty, this); } } #endregion #region Version if (Convert.ToInt32(this.Version.Split('.').FirstOrDefault()) < 0) { context.LogError(ValidationHelper.ErrorTextVersionNegative, string.Empty, this); } #endregion } catch (Exception ex) { throw; } finally { nHydrate.Dsl.Custom.DebugHelper.StopTimer(timer, "Model Validate - Main"); } }