public static ValidDatabaseIdenitifer ( string name ) : bool | ||
name | string | |
리턴 | bool |
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.ErrorTextInvalidIdentifierFuncField, this.Name, this.Function.Name), string.Empty, this); } else if (!ValidationHelper.ValidCodeIdentifier(this.PascalName)) { context.LogError(string.Format(ValidationHelper.ErrorTextInvalidIdentifierFuncField, this.Name, this.Function.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.Function.Name + "." + this.Name, validatedLength, this.DataType.ToString()), string.Empty, this); } #endregion } catch (Exception ex) { throw; } finally { nHydrate.Dsl.Custom.DebugHelper.StopTimer(timer, "Stored Procedure Parameter Validate - Main"); } }
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) { 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 { #region Validate some global settings if (!ValidationHelper.ValidDatabaseIdenitifer(this.CompanyName) || !ValidationHelper.ValidCodeIdentifier(this.CompanyName)) { context.LogError(ValidationHelper.ErrorTextInvalidCompany, string.Empty, this); } if (!ValidationHelper.ValidDatabaseIdenitifer(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 var auditFieldList = new List <string>(); 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.TimestampColumnName)) { auditFieldList.Add(this.TimestampColumnName); } if (auditFieldList.Count != 5) { context.LogError(ValidationHelper.ErrorTextAuditFieldsNotUnique, string.Empty, this); } else { auditFieldList = new List <string>(); 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.TimestampPascalName)) { auditFieldList.Add(this.TimestampPascalName); } 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.Where(x => x.IsGenerated)) { { 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 Select Commands //foreach (var command in entity.SelectCommands) //{ // var check = command.PascalName.ToLower(); // if (nameList.Contains(check)) // context.LogError(string.Format(ValidationHelper.ErrorTextDuplicateName, command.PascalName), string.Empty, command); // else // nameList.Add(check); //} //Check Composites foreach (var composite in entity.Composites) { var check = composite.PascalName.ToLower(); if (nameList.Contains(check)) { context.LogError(string.Format(ValidationHelper.ErrorTextDuplicateName, composite.PascalName), string.Empty, composite); } else { nameList.Add(check); } } } //Check Views foreach (var view in this.Views.Where(x => x.IsGenerated)) { var check = view.PascalName.ToLower(); if (nameList.Contains(check)) { context.LogError(string.Format(ValidationHelper.ErrorTextDuplicateName, view.PascalName), string.Empty, view); } else { nameList.Add(check); } } //Check Stored Procedures foreach (var sp in this.StoredProcedures.Where(x => x.IsGenerated)) { var check = sp.PascalName.ToLower(); if (nameList.Contains(check)) { context.LogError(string.Format(ValidationHelper.ErrorTextDuplicateName, sp.PascalName), string.Empty, sp); } 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 (!ValidationHelper.ValidCodeIdentifier(this.TenantColumnName)) { context.LogError(string.Format(ValidationHelper.ErrorTextInvalidIdentifier, this.TenantColumnName), string.Empty, this); } if (!ValidationHelper.ValidCodeIdentifier(this.TenantPrefix)) { context.LogError(string.Format(ValidationHelper.ErrorTextInvalidIdentifier, this.TenantPrefix), string.Empty, this); } } #endregion #region Version if (Convert.ToInt32(this.Version.Split('.').FirstOrDefault()) < 0) { context.LogError(ValidationHelper.ErrorTextVersionNegative, string.Empty, this); } #endregion #region CRUD if (this.UseGeneratedCRUD) { context.LogWarning(ValidationHelper.ErrorTextGeneratedCRUD_EF4, string.Empty, this); } #endregion if (string.IsNullOrEmpty(this.StoredProcedurePrefix)) { context.LogError(ValidationHelper.ErrorTextInvalidStoredProcPrefix, string.Empty, this); } } catch (Exception ex) { throw; } finally { nHydrate.Dsl.Custom.DebugHelper.StopTimer(timer, "Model Validate - Main"); } }
public void Validate(ValidationContext context) { if (!this.IsGenerated) { return; } System.Windows.Forms.Application.DoEvents(); var timer = nHydrate.Dsl.Custom.DebugHelper.StartTimer(); try { //if (!this.IsDirty) return; 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); } #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(x => x.IsGenerated) == 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 && x.IsGenerated) == 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 } catch (Exception ex) { throw; } finally { nHydrate.Dsl.Custom.DebugHelper.StopTimer(timer, "View Validate - Main"); } }
public void Validate(ValidationContext context) { var timer = nHydrate.Dsl.Custom.DebugHelper.StartTimer(); try { if (!this.IsGenerated) { return; } #region Check valid name if (!ValidationHelper.ValidDatabaseIdenitifer(this.DatabaseName)) { context.LogError(string.Format(ValidationHelper.ErrorTextInvalidIdentifierComposite, this.Name, this.Entity.Name), string.Empty, this); } else if (!ValidationHelper.ValidCodeIdentifier(this.PascalName)) { context.LogError(string.Format(ValidationHelper.ErrorTextInvalidIdentifierComposite, this.Name, this.Entity.Name), string.Empty, this); } #endregion #region Table Component must have PK for parent table var pkCount = 0; foreach (var field in this.GetFields()) { if (this.Entity.PrimaryKeyFields.Contains(field)) { pkCount++; } } if (pkCount != this.Entity.PrimaryKeyFields.Count) { context.LogError(String.Format(ValidationHelper.ErrorTextComponentMustHaveTablePK, this.Name), string.Empty, this); } #endregion #region Check valid name if (!ValidationHelper.ValidCodeIdentifier(this.PascalName)) { context.LogError(string.Format(ValidationHelper.ErrorTextInvalidIdentifierComposite, this.Name, this.Entity.Name), string.Empty, this); } #endregion #region Check that object does not have same name as project if (this.PascalName == this.Entity.nHydrateModel.ProjectName) { context.LogError(string.Format(ValidationHelper.ErrorTextComponentProjectSameName, this.Name), string.Empty, this); } #endregion #region Check for classes that will confict with generated classes var classExtensions = new List <string>(); classExtensions.Add("collection"); classExtensions.Add("enumerator"); classExtensions.Add("query"); //classExtensions.Add("search"); classExtensions.Add("pagingfielditem"); classExtensions.Add("paging"); classExtensions.Add("primarykey"); classExtensions.Add("selectall"); classExtensions.Add("pagedselect"); classExtensions.Add("selectbypks"); classExtensions.Add("selectbycreateddaterange"); classExtensions.Add("selectbymodifieddaterange"); classExtensions.Add("selectbysearch"); classExtensions.Add("beforechangeeventargs"); classExtensions.Add("afterchangeeventargs"); foreach (var ending in classExtensions) { if (this.PascalName.ToLower().EndsWith(ending)) { context.LogError(string.Format(ValidationHelper.ErrorTextNameConfictsWithGeneratedCode, this.Name), string.Empty, this); } } #endregion } catch (Exception ex) { throw; } finally { nHydrate.Dsl.Custom.DebugHelper.StopTimer(timer, "Composite Validate - Main"); } }