IsValidNamespace() public static method

public static IsValidNamespace ( string namespaceValue ) : bool
namespaceValue string
return bool
Beispiel #1
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");
            }
        }
Beispiel #2
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");
            }
        }