ValidCodeIdentifier() public static method

Determines if the specified value is a valid C# token
public static ValidCodeIdentifier ( string name ) : bool
name string
return bool
Esempio n. 1
0
        public void ValidateStoredProcedures(ValidationContext context)
        {
            var timer = nHydrate.Dsl.Custom.DebugHelper.StartTimer();

            try
            {
                #region Verify that the name is valid
                foreach (var item in this.StoredProcedures.Where(x => x.IsGenerated))
                {
                    if (!ValidationHelper.ValidCodeIdentifier(item.PascalName))
                    {
                        context.LogError(string.Format(ValidationHelper.ErrorTextInvalidIdentifierSP, item.Name), string.Empty, this);
                    }

                    foreach (var field in item.Fields)
                    {
                        if (!ValidationHelper.ValidCodeIdentifier(field.PascalName))
                        {
                            context.LogError(string.Format(ValidationHelper.ErrorTextInvalidIdentifierSPField, field.Name, item.Name), string.Empty, this);
                        }
                    }

                    foreach (var parameter in item.Parameters)
                    {
                        if (!ValidationHelper.ValidCodeIdentifier(parameter.PascalName))
                        {
                            context.LogError(string.Format(ValidationHelper.ErrorTextInvalidIdentifierSPParam, parameter.Name, item.Name), string.Empty, this);
                        }
                    }
                }
                #endregion

                #region Check for duplicate names
                var nameList = new Hashtable();
                foreach (var customStoredProcedure in this.StoredProcedures.Where(x => x.IsGenerated))
                {
                    var name = customStoredProcedure.Name.ToLower();
                    if (nameList.ContainsKey(name))
                    {
                        context.LogError(string.Format(ValidationHelper.ErrorTextDuplicateName, name), string.Empty, this);
                    }
                    else
                    {
                        nameList.Add(name, string.Empty);
                    }
                }
                #endregion
            }
            catch (Exception ex)
            {
                throw;
            }
            finally
            {
                nHydrate.Dsl.Custom.DebugHelper.StopTimer(timer, "Model Validate - Stored Procedures");
            }
        }
Esempio n. 2
0
        public void ValidateView(ValidationContext context)
        {
            var timer = nHydrate.Dsl.Custom.DebugHelper.StartTimer();

            try
            {
                #region Verify that the name is valid
                foreach (var item in this.Views)
                {
                    if (!ValidationHelper.ValidCodeIdentifier(item.PascalName))
                    {
                        context.LogError(string.Format(ValidationHelper.ErrorTextInvalidIdentifierView, item.Name), string.Empty, this);
                    }

                    foreach (var field in item.Fields)
                    {
                        if (!ValidationHelper.ValidCodeIdentifier(field.PascalName))
                        {
                            context.LogError(string.Format(ValidationHelper.ErrorTextInvalidFieldIdentifierView, item.Name, field.Name), string.Empty, this);
                        }
                    }
                }
                #endregion

                #region Check for duplicate names
                var nameList = new Hashtable();
                foreach (var customView in this.Views)
                {
                    var name = customView.Name.ToLower();
                    if (nameList.ContainsKey(name))
                    {
                        context.LogError(string.Format(ValidationHelper.ErrorTextDuplicateName, name), string.Empty, this);
                    }
                    else
                    {
                        nameList.Add(name, string.Empty);
                    }
                }
                #endregion
            }
            catch (Exception ex)
            {
                throw;
            }
            finally
            {
                nHydrate.Dsl.Custom.DebugHelper.StopTimer(timer, "Model Validate - Views");
            }
        }
Esempio n. 3
0
        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");
            }
        }
Esempio n. 4
0
        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
        }
Esempio n. 5
0
        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");
            }
        }
Esempio n. 6
0
        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");
            }
        }
Esempio n. 7
0
        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");
            }
        }
Esempio n. 8
0
        public void ValidateEntities(ValidationContext context)
        {
            var timer = nHydrate.Dsl.Custom.DebugHelper.StartTimer();

            try
            {
                #region Check for zero tables
                if (this.Entities.Count(x => x.IsGenerated) == 0)
                {
                    context.LogError(ValidationHelper.ErrorTextNoTables, string.Empty, this);
                    return;
                }
                #endregion

                #region Verify that the name is valid
                foreach (var item in this.Entities.Where(x => x.IsGenerated))
                {
                    if (!ValidationHelper.ValidCodeIdentifier(item.PascalName) || !ValidationHelper.ValidEntityName(item.PascalName))
                    {
                        context.LogError(string.Format(ValidationHelper.ErrorTextInvalidIdentifier, item.Name), string.Empty, this);
                    }

                    foreach (var field in item.Fields)
                    {
                        if (!ValidationHelper.ValidCodeIdentifier(field.PascalName))
                        {
                            context.LogError(string.Format(ValidationHelper.ErrorTextInvalidIdentifier, field.Name), string.Empty, this);
                        }
                    }
                }
                #endregion

                #region Check for duplicate names
                var nameList = new Hashtable();
                foreach (var table in this.Entities.Where(x => x.IsGenerated))
                {
                    var name = table.Name.ToLower();
                    if (nameList.ContainsKey(name))
                    {
                        context.LogError(string.Format(ValidationHelper.ErrorTextDuplicateName, table.Name), string.Empty, this);
                    }
                    else
                    {
                        nameList.Add(name, string.Empty);
                    }
                }
                #endregion

                #region Check for duplication relationship names

                var duplicateList = new Dictionary <string, RelationshipChecker>();
                var relationList  = this.Store.ElementDirectory.AllElements.Where(x => x is EntityHasEntities).ToList().Cast <EntityHasEntities>();
                foreach (var relation in relationList)
                {
                    var childTable     = relation.TargetEntity;
                    var entity         = relation.SourceEntity;
                    var relationFields = this.RelationFields.Where(x => x.RelationID == relation.Id).ToList();

                    if (childTable != null && entity != null && childTable.IsGenerated && entity.IsGenerated)
                    {
                        var key = string.Empty;
                        if (StringHelper.Match(entity.Name, childTable.Name, true))
                        {
                            if (string.Compare(entity.Name, childTable.Name, false) < 0)
                            {
                                key = childTable.Name + "|" + relation.RoleName + "|" + entity.Name;
                            }
                            else
                            {
                                key = entity.Name + "|" + relation.RoleName + "|" + childTable.Name;
                            }
                        }
                        else
                        {
                            if (string.Compare(entity.Name, childTable.Name, false) < 0)
                            {
                                key = entity.Name + "|" + relation.RoleName + "|" + childTable.Name;
                            }
                            else
                            {
                                key = childTable.Name + "|" + relation.RoleName + "|" + entity.Name;
                            }
                        }

                        if (duplicateList.ContainsKey(key))
                        {
                            if (StringHelper.Match(entity.Name, childTable.Name, true))
                            {
                                duplicateList[key].TableList.Add(entity);
                            }
                            else
                            {
                                duplicateList[key].TableList.Add(childTable);
                            }
                        }
                        else
                        {
                            var rc = new RelationshipChecker(relation);
                            if (string.Compare(entity.Name, childTable.Name, true) < 0)
                            {
                                rc.TableList.Add(childTable);
                            }
                            else
                            {
                                rc.TableList.Add(entity);
                            }
                            duplicateList.Add(key, rc);
                        }

                        //Verify that a FK has an index on it
                        foreach (var field in relationFields)
                        {
                            var targetField = field.GetTargetField(relation);
                            if (targetField != null)
                            {
                                if (!childTable.Indexes.SelectMany(x => x.FieldList.Select(z => z.Id)).Any(x => x == targetField.Id))
                                {
                                    context.LogWarning(string.Format(ValidationHelper.ErrorTextFKNeedIndex, childTable.Name + "." + targetField.Name), string.Empty, this);
                                }
                            }
                        }
                    }
                }

                foreach (var key in duplicateList.Keys)
                {
                    if (duplicateList[key].TableList.Count > 1)
                    {
                        var t1 = duplicateList[key].Relationship.SourceEntity.Name;
                        var t2 = duplicateList[key].Relationship.TargetEntity.Name;
                        context.LogError(string.Format(ValidationHelper.ErrorTextConflictingRelationships, "'" + t1 + "' and '" + t2 + "'"), string.Empty, this);
                    }
                }

                #endregion

                #region Check for duplicate codefacades
                if (context.CurrentViolations.Count == 0)
                {
                    nameList = new Hashtable();
                    foreach (var table in this.Entities.Where(x => x.IsGenerated))
                    {
                        var name = table.PascalName.ToLower();
                        if (nameList.ContainsKey(name))
                        {
                            context.LogError(string.Format(ValidationHelper.ErrorTextDuplicateCodeFacade, table.Name), string.Empty, this);
                        }
                        else
                        {
                            nameList.Add(name, string.Empty);
                        }
                    }
                }
                #endregion
            }
            catch (Exception ex)
            {
                throw;
            }
            finally
            {
                nHydrate.Dsl.Custom.DebugHelper.StopTimer(timer, "Model Validate - Entities");
            }
        }
Esempio n. 9
0
        public void ValidateModules(ValidationContext context)
        {
            var timer = nHydrate.Dsl.Custom.DebugHelper.StartTimer();

            try
            {
                //If we are not using modules then nothing to do
                if (!this.UseModules)
                {
                    return;
                }

                #region Verify there are modules
                if (this.Modules.Count == 0)
                {
                    context.LogError(ValidationHelper.ErrorTextNoModules, string.Empty, this);
                    return;
                }
                #endregion

                #region Verify unique modules
                if (this.Modules.Select(x => x.Name.ToLower()).Distinct().Count() != this.Modules.Count)
                {
                    context.LogError(ValidationHelper.ErrorTextModulesNotUnique, string.Empty, this);
                    return;
                }
                #endregion

                #region Verify that the name is valid
                foreach (var item in this.Modules)
                {
                    if (!ValidationHelper.ValidCodeIdentifier(item.Name))
                    {
                        context.LogError(string.Format(ValidationHelper.ErrorTextInvalidIdentifierModule, item.Name), string.Empty, this);
                    }
                }
                #endregion

                #region If a field is in a module then its entity must be as well
                foreach (var entity in this.Entities.Where(x => x.IsGenerated))
                {
                    foreach (var field in entity.Fields.Where(x => x.IsGenerated))
                    {
                        var moduleList = field.Modules.Intersect(entity.Modules);
                        if (moduleList.Count() != field.Modules.Count)
                        {
                            context.LogError(string.Format(ValidationHelper.ErrorTextModuleEntityFieldMismatch, field.Name, moduleList.First().Name), string.Empty, this);
                        }
                    }
                }
                #endregion

                #region Warn that some entities are in NO modules
                foreach (var item in this.Entities.Where(x => x.IsGenerated))
                {
                    if (item.Modules.Count == 0)
                    {
                        context.LogError(string.Format(ValidationHelper.ErrorTextModuleItemNotInModule, item.Name), string.Empty, this);
                    }
                }
                #endregion

                #region Warn that some SP are in NO modules
                foreach (var item in this.StoredProcedures.Where(x => x.IsGenerated))
                {
                    if (item.Modules.Count == 0)
                    {
                        context.LogError(string.Format(ValidationHelper.ErrorTextModuleItemNotInModule, item.Name), string.Empty, this);
                    }
                }
                #endregion

                #region Warn that some views are in NO modules
                foreach (var item in this.Views.Where(x => x.IsGenerated))
                {
                    if (item.Modules.Count == 0)
                    {
                        context.LogError(string.Format(ValidationHelper.ErrorTextModuleItemNotInModule, item.Name), string.Empty, this);
                    }
                }
                #endregion

                #region Warn that some functions are in NO modules
                foreach (var item in this.Functions.Where(x => x.IsGenerated))
                {
                    if (item.Modules.Count == 0)
                    {
                        context.LogError(string.Format(ValidationHelper.ErrorTextModuleItemNotInModule, item.Name), string.Empty, this);
                    }
                }
                #endregion

                #region Verify that if an entity is in a module, at least one PKs is in the module too

                foreach (var item in this.Entities.Where(x => x.IsGenerated))
                {
                    if (item.PrimaryKeyFields.Count > 0)
                    {
                        foreach (var module in item.Modules)
                        {
                            var count = item.PrimaryKeyFields.Count(x => x.Modules.Contains(module));
                            if (count == 0)
                            {
                                context.LogError(string.Format(ValidationHelper.ErrorTextModuleEntityPKMismatch, item.Name, module.Name), string.Empty, this);
                            }
                            else if (item.PrimaryKeyFields.Count != count)
                            {
                                context.LogWarning(string.Format(ValidationHelper.WarningTextModuleEntityPKMismatch, item.Name, module.Name), string.Empty, this);
                            }

                            //foreach (var field in item.PrimaryKeyFields)
                            //{
                            //  if (!field.Modules.Contains(module))
                            //  {
                            //    context.LogError(string.Format(ValidationHelper.ErrorTextModuleEntityPKMismatch, item.Name, module.Name), string.Empty, this);
                            //  }
                            //}
                        }
                    }
                }

                #endregion

                #region Validation Relations that are in NO module

                foreach (var moduleLink in this.AllRelations.Cast <IModuleLink>().Where(x => !x.Modules.Any()))
                {
                    context.LogWarning(ValidationHelper.WarningTextRelationNotInModule, string.Empty, (Microsoft.VisualStudio.Modeling.ModelElement)moduleLink);
                }

                #endregion

                #region Find relations with parent/child in a module, but the relation is not present

                foreach (var moduleLink in this.AllRelations.Cast <IModuleLink>().Where(x => x.Modules.Any()))
                {
                    var relation = (EntityHasEntities)moduleLink;
                    //Find common modules for parent and child table
                    var moduleList = relation.ParentEntity.Modules.Intersect(relation.ChildEntity.Modules).ToList();
                    foreach (var module in moduleList)
                    {
                        //Check if the relation is in the specified module
                        if (!moduleLink.Modules.Contains(module))
                        {
                            context.LogWarning(string.Format(ValidationHelper.WarningTextRelationNotInModuleWithParentChildTables, relation.ParentEntity.Name, relation.ChildEntity.Name, module.Name), string.Empty, relation);
                        }
                    }
                }

                #endregion

                #region Verify Module Rules are setup correctly

                foreach (var module in this.Modules)
                {
                    foreach (var rule in module.ModuleRules)
                    {
                        var dModule = this.Modules.FirstOrDefault(x => x.Id == rule.DependentModule);
                        if (dModule == null)
                        {
                            context.LogError(string.Format(ValidationHelper.WarningErrorModuleRuleInvalid, module.Name), string.Empty, rule);
                        }
                    }
                }

                #endregion

                #region Module Rule apply logic

                foreach (var module in this.Modules)
                {
                    foreach (var rule in module.ModuleRules.Where(x => x.Enforced))
                    {
                        if (rule.GetDependentModuleObject() == null)
                        {
                            context.LogError(string.Format(ValidationHelper.WarningErrorModuleRuleNoDependentModule, module.Name, rule.Status.ToString().ToLower()), string.Empty, rule);
                        }
                        else
                        {
                            var issueList = new List <string>();
                            if (!module.IsValidRule(rule, ref issueList))
                            {
                                var dModule = this.Modules.FirstOrDefault(x => x.Id == rule.DependentModule);
                                if (dModule != null)
                                {
                                    context.LogError(string.Format(ValidationHelper.WarningErrorModuleRuleLogicFail, module.Name, rule.Status.ToString().ToLower(), dModule.Name)
                                                     + string.Join(". ", issueList.ToArray()),
                                                     string.Empty, rule);
                                }
                            }
                        }
                    }
                }

                #endregion

                #region Verify there is at least one entity in a module

                foreach (var module in this.Modules)
                {
                    if (module.Entities.Count(x => x.IsGenerated) == 0)
                    {
                        context.LogError(string.Format(ValidationHelper.ErrorTextModuleIsEmpty, module.Name), string.Empty, module);
                    }
                }

                #endregion
            }
            catch (Exception ex)
            {
                throw;
            }
            finally
            {
                nHydrate.Dsl.Custom.DebugHelper.StopTimer(timer, "Model Validate - Modules");
            }
        }
Esempio n. 10
0
        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
        }
Esempio n. 11
0
        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");
            }
        }
Esempio n. 12
0
        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");
            }
        }
Esempio n. 13
0
        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");
            }
        }
Esempio n. 14
0
        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");
            }
        }