public override MessageCollection Verify()
        {
            try
            {
                var retval = new MessageCollection();
                retval.AddRange(base.Verify());

                var customViewColumn = (CustomViewColumn)this.Object;

                //Check valid name
                if (!ValidationHelper.ValidDatabaseIdenitifer(customViewColumn.DatabaseName))
                {
                    retval.Add(MessageTypeConstants.Error, string.Format(ValidationHelper.ErrorTextInvalidIdentifier, customViewColumn.Name), customViewColumn.Controller);
                }
                if (!ValidationHelper.ValidCodeIdentifier(customViewColumn.PascalName))
                {
                    retval.Add(MessageTypeConstants.Error, string.Format(ValidationHelper.ErrorTextInvalidIdentifier, customViewColumn.Name), customViewColumn.Controller);
                }
                if (!ValidationHelper.ValidFieldIdentifier(customViewColumn.PascalName))
                {
                    retval.Add(MessageTypeConstants.Error, string.Format(ValidationHelper.ErrorTextInvalidIdentifier, customViewColumn.Name), customViewColumn.Controller);
                }

                //Check valid name
                if ((!string.IsNullOrEmpty(customViewColumn.CodeFacade)) && !ValidationHelper.ValidDatabaseIdenitifer(customViewColumn.CodeFacade))
                {
                    retval.Add(MessageTypeConstants.Error, ValidationHelper.ErrorTextInvalidCodeFacade, customViewColumn.Controller);
                }

                return(retval);
            }
            catch (Exception ex)
            {
                throw;
            }
        }
Пример #2
0
		public override MessageCollection Verify()
		{
			var retval = new MessageCollection();
			retval.AddRange(base.Verify());
			return retval;
		}
		public override MessageCollection Verify()
		{
			try
			{
				var retval = new MessageCollection();
				retval.AddRange(base.Verify());

				var customRetrieveRule = (CustomRetrieveRule)this.Object;

				//Check valid name
				if (!ValidationHelper.ValidDatabaseIdenitifer(customRetrieveRule.DatabaseName))
					retval.Add(MessageTypeConstants.Error, string.Format(ValidationHelper.ErrorTextInvalidIdentifier, customRetrieveRule.Name), this);
				if (!ValidationHelper.ValidCodeIdentifier(customRetrieveRule.PascalName))
					retval.Add(MessageTypeConstants.Error, string.Format(ValidationHelper.ErrorTextInvalidIdentifier, customRetrieveRule.Name), this);

				//Check SQL
				if (string.IsNullOrEmpty(customRetrieveRule.SQL))
					retval.Add(MessageTypeConstants.Error, ValidationHelper.ErrorTextSQLRequired, this);

				return retval;

			}
			catch(Exception ex)
			{
				throw;
			}

		}
Пример #4
0
		public override MessageCollection Verify()
		{
			try
			{
				var retval = new MessageCollection();
				retval.AddRange(base.Verify());

				var database = (Database)this.Object;

				//Check valid name
				//if (!ValidationHelper.ValidDatabaseIdenitifer(database.DatabaseName))
				//  retval.Add(MessageTypeConstants.Error, ValidationHelper.ErrorTextInvalidDatabase, this);

				//Check Relations
				var deleteList = new ArrayList();
				var checkList = new ArrayList();
				foreach (Relation relation in database.Relations)
				{
					var table1 = (Table)relation.ParentTableRef.Object;
					var table2 = (Table)relation.ChildTableRef.Object;
					if ((table1 != null) && (table2 != null))
					{
						var relationName = table1.Name + "." + table1.GetAbsoluteBaseTable().Name + "." + relation.PascalRoleName + "." + table2.Name;
						if (checkList.Contains(relationName))
						{
							INHydrateModelObjectController controller = this;
							var list = database.Relations.Find(relation.Key);
							if (list.Length > 0)
							{
								var key = ((Relation)list.GetValue(0)).Key;
								var nodeList = this.Node.Nodes.Find(key, true);
								if (nodeList.Length > 0)
									controller = ((ModelObjectTreeNode)nodeList[0]).Controller;
							}
							retval.Add(MessageTypeConstants.Error, String.Format(ValidationHelper.ErrorTextDuplicateRoleName, table1.Name, table2.Name), table1.Controller);
						}

						else
						{
							checkList.Add(relationName);
						}
					}
					else
					{
						deleteList.Add(relation);
						//TODO
						//retval.Add(MessageTypeConstants.Error, ValidationHelper.ErrorTextRelationMustHaveParentChild, null);
					}
				}

				//Remove errors
				foreach (Relation relation in deleteList)
					database.Relations.Remove(relation);

				//Validate audit fields
				var auditFieldList = new List<string>();
				auditFieldList.Add(database.CreatedByColumnName);
				if (!auditFieldList.Contains(database.CreatedDateColumnName))
					auditFieldList.Add(database.CreatedDateColumnName);
				if (!auditFieldList.Contains(database.ModifiedByColumnName))
					auditFieldList.Add(database.ModifiedByColumnName);
				if (!auditFieldList.Contains(database.ModifiedDateColumnName))
					auditFieldList.Add(database.ModifiedDateColumnName);
				if (!auditFieldList.Contains(database.TimestampColumnName))
					auditFieldList.Add(database.TimestampColumnName);

				if (auditFieldList.Count != 5)
				{
					retval.Add(MessageTypeConstants.Error, ValidationHelper.ErrorTextAuditFieldsNotUnique, database.Controller);
				}
				else
				{
					auditFieldList = new List<string>();
					auditFieldList.Add(database.CreatedByPascalName);
					if (!auditFieldList.Contains(database.CreatedDatePascalName))
						auditFieldList.Add(database.CreatedDatePascalName);
					if (!auditFieldList.Contains(database.ModifiedByPascalName))
						auditFieldList.Add(database.ModifiedByPascalName);
					if (!auditFieldList.Contains(database.ModifiedDatePascalName))
						auditFieldList.Add(database.ModifiedDatePascalName);
					if (!auditFieldList.Contains(database.TimestampPascalName))
						auditFieldList.Add(database.TimestampPascalName);

					if (auditFieldList.Count != 5)
						retval.Add(MessageTypeConstants.Error, ValidationHelper.ErrorTextAuditFieldsNotUnique, database.Controller);
				}

				return retval;

			}
			catch (Exception ex)
			{
				throw;
			}

		}
		public override MessageCollection Verify()
		{
			try
			{
				var retval = new MessageCollection();
				retval.AddRange(base.Verify());

				var customViewColumn = (CustomViewColumn)this.Object;

				//Check valid name
				if (!ValidationHelper.ValidDatabaseIdenitifer(customViewColumn.DatabaseName))
					retval.Add(MessageTypeConstants.Error, string.Format(ValidationHelper.ErrorTextInvalidIdentifier, customViewColumn.Name), customViewColumn.Controller);
				if (!ValidationHelper.ValidCodeIdentifier(customViewColumn.PascalName))
					retval.Add(MessageTypeConstants.Error, string.Format(ValidationHelper.ErrorTextInvalidIdentifier, customViewColumn.Name), customViewColumn.Controller);
				if (!ValidationHelper.ValidFieldIdentifier(customViewColumn.PascalName))
					retval.Add(MessageTypeConstants.Error, string.Format(ValidationHelper.ErrorTextInvalidIdentifier, customViewColumn.Name), customViewColumn.Controller);

				//Check valid name
				if ((!string.IsNullOrEmpty(customViewColumn.CodeFacade)) && !ValidationHelper.ValidDatabaseIdenitifer(customViewColumn.CodeFacade))
					retval.Add(MessageTypeConstants.Error, ValidationHelper.ErrorTextInvalidCodeFacade, customViewColumn.Controller);

				return retval;

			}
			catch(Exception ex)
			{
				throw;
			}

		}
Пример #6
0
		public override MessageCollection Verify()
		{
			try
			{
				var retval = new MessageCollection();
				retval.AddRange(base.Verify());

				var parameter = (Parameter)this.Object;

				//Check valid name
				if (!ValidationHelper.ValidDatabaseIdenitifer(parameter.DatabaseName))
					retval.Add(MessageTypeConstants.Error, string.Format(ValidationHelper.ErrorTextInvalidIdentifier, parameter.Name), this);
				if (!ValidationHelper.ValidCodeIdentifier(parameter.PascalName))
					retval.Add(MessageTypeConstants.Error, string.Format(ValidationHelper.ErrorTextInvalidIdentifier, parameter.Name), this);

				return retval;

			}
			catch (Exception ex)
			{
				throw;
			}

		}
Пример #7
0
		public override MessageCollection Verify()
		{
			try
			{
				var retval = new MessageCollection();
				retval.AddRange(base.Verify());

				var column = (Column)this.Object;

				#region Check valid name
				if (!ValidationHelper.ValidDatabaseIdenitifer(column.DatabaseName))
					retval.Add(MessageTypeConstants.Error, string.Format(ValidationHelper.ErrorTextInvalidIdentifier, column.Name), column.Controller);
				if (!ValidationHelper.ValidCodeIdentifier(column.PascalName))
					retval.Add(MessageTypeConstants.Error, string.Format(ValidationHelper.ErrorTextInvalidIdentifier, column.Name), column.Controller);
				if (!ValidationHelper.ValidFieldIdentifier(column.PascalName))
					retval.Add(MessageTypeConstants.Error, string.Format(ValidationHelper.ErrorTextInvalidIdentifier, column.Name), column.Controller);

				#endregion

				#region Check valid name based on codefacade
				if ((!string.IsNullOrEmpty(column.CodeFacade)) && !ValidationHelper.ValidDatabaseIdenitifer(column.CodeFacade))
					retval.Add(MessageTypeConstants.Error, ValidationHelper.ErrorTextInvalidCodeFacade, column.Controller);

				if (ModelHelper.IsNumericType(column.DataType))
				{
					if ((column.Min >= double.MinValue) && (column.Max >= double.MinValue))
					{
						if (column.Min > column.Max)
							retval.Add(MessageTypeConstants.Error, ValidationHelper.ErrorTextMinMaxValueMismatch, column.Controller);
					}
				}
				else //Non-numeric
				{
					//Neither should be set
					if ((column.Min >= double.MinValue) || (column.Max >= double.MinValue))
					{
						retval.Add(MessageTypeConstants.Error, ValidationHelper.ErrorTextMinMaxValueInvalidType, column.Controller);
					}
				}
				#endregion

				#region Validate identity field
				if (column.Identity != IdentityTypeConstants.None)
				{
					//If this is an identity then must be of certain datatype
					switch (column.DataType)
					{
						//case System.Data.SqlDbType.TinyInt:
						case System.Data.SqlDbType.SmallInt:
						case System.Data.SqlDbType.Int:
						case System.Data.SqlDbType.BigInt:
						case System.Data.SqlDbType.UniqueIdentifier:
							break;
						default:
							retval.Add(MessageTypeConstants.Error, string.Format(ValidationHelper.ErrorTextInvalidIdentityColumn, column.Name), column.Controller);
							break;
					}
				}
				#endregion

				#region Varchar Max only supported in SQL 2008

				//if (((ModelRoot)column.Root).SQLServerType == SQLServerTypeConstants.SQL2005)
				//{
				//  if (ModelHelper.SupportsMax(column.DataType) && column.Length == 0)
				//  {
				//    retval.Add(MessageTypeConstants.Error, string.Format(ValidationHelper.ErrorTextColumnMaxNotSupported, column.Name), column.Controller);
				//  }
				//}

				#endregion

				#region Columns cannot be 0 length

				if (!ModelHelper.SupportsMax(column.DataType) && column.Length == 0)
				{
					retval.Add(MessageTypeConstants.Error, string.Format(ValidationHelper.ErrorTextColumnLengthNotZero, column.Name), column.Controller);
				}

				#endregion

				#region Validate Decimals

				if (column.DataType == System.Data.SqlDbType.Decimal)
				{
					if (column.Length < 1 || column.Length > 38)
						retval.Add(MessageTypeConstants.Error, string.Format(ValidationHelper.ErrorTextColumnDecimalPrecision, column.Name), column.Controller);
					if (column.Scale < 0 || column.Scale > column.Length)
						retval.Add(MessageTypeConstants.Error, string.Format(ValidationHelper.ErrorTextColumnDecimalScale, column.Name), column.Controller);
				}

				#endregion

				#region Verify Datatypes for SQL 2005/2008

				if (!Column.IsSupportedType(column.DataType, ((ModelRoot)this.Object.Root).SQLServerType))
				{
					retval.Add(MessageTypeConstants.Error, string.Format(ValidationHelper.ErrorTextDataTypeNotSupported, column.Name), column.Controller);
				}

				#endregion

				#region Computed Column

				if (column.ComputedColumn)
				{
					if (column.Formula.Trim() == "")
					{
						retval.Add(MessageTypeConstants.Error, string.Format(ValidationHelper.ErrorTextComputeColumnNoFormula, column.Name), column.Controller);
					}

					if (column.PrimaryKey)
					{
						retval.Add(MessageTypeConstants.Error, string.Format(ValidationHelper.ErrorTextComputeColumnNoPK, column.Name), column.Controller);
					}

				}

				if (!column.ComputedColumn && !string.IsNullOrEmpty(column.Formula))
				{
					retval.Add(MessageTypeConstants.Error, string.Format(ValidationHelper.ErrorTextComputeNonColumnHaveFormula, column.Name), column.Controller);
				}

				#endregion

				#region Validate Defaults

				if (!string.IsNullOrEmpty(column.Default))
				{
					if (!column.CanHaveDefault())
					{
						retval.Add(MessageTypeConstants.Error, string.Format(ValidationHelper.ErrorTextColumnCannotHaveDefault, column.Name), column.Controller);
					}
					else if (!column.IsValidDefault())
					{
						retval.Add(MessageTypeConstants.Warning, string.Format(ValidationHelper.ErrorTextColumnInvalidDefault, column.Name), column.Controller);
					}
				}

				#endregion

				#region Check Decimals for common error

				if (column.DataType == System.Data.SqlDbType.Decimal)
				{
					if (column.Length == 1)
						retval.Add(MessageTypeConstants.Warning, string.Format(ValidationHelper.ErrorTextDecimalColumnTooSmall, column.Name, column.Length.ToString()), column.Controller);
				}

				#endregion

				return retval;

			}
			catch (Exception ex)
			{
				throw;
			}

		}
Пример #8
0
        public override MessageCollection Verify()
        {
            try
            {
                var retval = new MessageCollection();
                retval.AddRange(base.Verify());

                var column = (Column)this.Object;

                #region Check valid name
                if (!ValidationHelper.ValidDatabaseIdenitifer(column.DatabaseName))
                {
                    retval.Add(MessageTypeConstants.Error, string.Format(ValidationHelper.ErrorTextInvalidIdentifier, column.Name), column.Controller);
                }
                if (!ValidationHelper.ValidCodeIdentifier(column.PascalName))
                {
                    retval.Add(MessageTypeConstants.Error, string.Format(ValidationHelper.ErrorTextInvalidIdentifier, column.Name), column.Controller);
                }
                if (!ValidationHelper.ValidFieldIdentifier(column.PascalName))
                {
                    retval.Add(MessageTypeConstants.Error, string.Format(ValidationHelper.ErrorTextInvalidIdentifier, column.Name), column.Controller);
                }

                #endregion

                #region Check valid name based on codefacade
                if ((!string.IsNullOrEmpty(column.CodeFacade)) && !ValidationHelper.ValidDatabaseIdenitifer(column.CodeFacade))
                {
                    retval.Add(MessageTypeConstants.Error, ValidationHelper.ErrorTextInvalidCodeFacade, column.Controller);
                }

                if (ModelHelper.IsNumericType(column.DataType))
                {
                    if ((column.Min >= double.MinValue) && (column.Max >= double.MinValue))
                    {
                        if (column.Min > column.Max)
                        {
                            retval.Add(MessageTypeConstants.Error, ValidationHelper.ErrorTextMinMaxValueMismatch, column.Controller);
                        }
                    }
                }
                else                 //Non-numeric
                {
                    //Neither should be set
                    if ((column.Min >= double.MinValue) || (column.Max >= double.MinValue))
                    {
                        retval.Add(MessageTypeConstants.Error, ValidationHelper.ErrorTextMinMaxValueInvalidType, column.Controller);
                    }
                }
                #endregion

                #region Validate identity field
                if (column.Identity != IdentityTypeConstants.None)
                {
                    //If this is an identity then must be of certain datatype
                    switch (column.DataType)
                    {
                    //case System.Data.SqlDbType.TinyInt:
                    case System.Data.SqlDbType.SmallInt:
                    case System.Data.SqlDbType.Int:
                    case System.Data.SqlDbType.BigInt:
                    case System.Data.SqlDbType.UniqueIdentifier:
                        break;

                    default:
                        retval.Add(MessageTypeConstants.Error, string.Format(ValidationHelper.ErrorTextInvalidIdentityColumn, column.Name), column.Controller);
                        break;
                    }
                }
                #endregion

                #region Varchar Max only supported in SQL 2008

                //if (((ModelRoot)column.Root).SQLServerType == SQLServerTypeConstants.SQL2005)
                //{
                //  if (ModelHelper.SupportsMax(column.DataType) && column.Length == 0)
                //  {
                //    retval.Add(MessageTypeConstants.Error, string.Format(ValidationHelper.ErrorTextColumnMaxNotSupported, column.Name), column.Controller);
                //  }
                //}

                #endregion

                #region Columns cannot be 0 length

                if (!ModelHelper.SupportsMax(column.DataType) && column.Length == 0)
                {
                    retval.Add(MessageTypeConstants.Error, string.Format(ValidationHelper.ErrorTextColumnLengthNotZero, column.Name), column.Controller);
                }

                #endregion

                #region Validate Decimals

                if (column.DataType == System.Data.SqlDbType.Decimal)
                {
                    if (column.Length < 1 || column.Length > 38)
                    {
                        retval.Add(MessageTypeConstants.Error, string.Format(ValidationHelper.ErrorTextColumnDecimalPrecision, column.Name), column.Controller);
                    }
                    if (column.Scale < 0 || column.Scale > column.Length)
                    {
                        retval.Add(MessageTypeConstants.Error, string.Format(ValidationHelper.ErrorTextColumnDecimalScale, column.Name), column.Controller);
                    }
                }

                #endregion

                #region Verify Datatypes for SQL 2005/2008

                if (!Column.IsSupportedType(column.DataType, ((ModelRoot)this.Object.Root).SQLServerType))
                {
                    retval.Add(MessageTypeConstants.Error, string.Format(ValidationHelper.ErrorTextDataTypeNotSupported, column.Name), column.Controller);
                }

                #endregion

                #region Computed Column

                if (column.ComputedColumn)
                {
                    if (column.Formula.Trim() == "")
                    {
                        retval.Add(MessageTypeConstants.Error, string.Format(ValidationHelper.ErrorTextComputeColumnNoFormula, column.Name), column.Controller);
                    }

                    if (column.PrimaryKey)
                    {
                        retval.Add(MessageTypeConstants.Error, string.Format(ValidationHelper.ErrorTextComputeColumnNoPK, column.Name), column.Controller);
                    }
                }

                if (!column.ComputedColumn && !string.IsNullOrEmpty(column.Formula))
                {
                    retval.Add(MessageTypeConstants.Error, string.Format(ValidationHelper.ErrorTextComputeNonColumnHaveFormula, column.Name), column.Controller);
                }

                #endregion

                #region Validate Defaults

                if (!string.IsNullOrEmpty(column.Default))
                {
                    if (!column.CanHaveDefault())
                    {
                        retval.Add(MessageTypeConstants.Error, string.Format(ValidationHelper.ErrorTextColumnCannotHaveDefault, column.Name), column.Controller);
                    }
                    else if (!column.IsValidDefault())
                    {
                        retval.Add(MessageTypeConstants.Warning, string.Format(ValidationHelper.ErrorTextColumnInvalidDefault, column.Name), column.Controller);
                    }
                }

                #endregion

                #region Check Decimals for common error

                if (column.DataType == System.Data.SqlDbType.Decimal)
                {
                    if (column.Length == 1)
                    {
                        retval.Add(MessageTypeConstants.Warning, string.Format(ValidationHelper.ErrorTextDecimalColumnTooSmall, column.Name, column.Length.ToString()), column.Controller);
                    }
                }

                #endregion

                return(retval);
            }
            catch (Exception ex)
            {
                throw;
            }
        }
Пример #9
0
		public override MessageCollection Verify()
		{
			var retval = new MessageCollection();
			retval.AddRange(base.Verify());
			return retval;
		}
Пример #10
0
		public override MessageCollection Verify()
		{
			var retval = new MessageCollection();
			retval.AddRange(base.Verify());

			var relation = (Relation)this.Object;


			return retval;
		}
Пример #11
0
        public override MessageCollection Verify()
        {
            try
            {
                var retval = new MessageCollection();
                retval.AddRange(base.Verify());

                var database = (Database)this.Object;

                //Check valid name
                //if (!ValidationHelper.ValidDatabaseIdenitifer(database.DatabaseName))
                //  retval.Add(MessageTypeConstants.Error, ValidationHelper.ErrorTextInvalidDatabase, this);

                //Check Relations
                var deleteList = new ArrayList();
                var checkList  = new ArrayList();
                foreach (Relation relation in database.Relations)
                {
                    var table1 = (Table)relation.ParentTableRef.Object;
                    var table2 = (Table)relation.ChildTableRef.Object;
                    if ((table1 != null) && (table2 != null))
                    {
                        var relationName = table1.Name + "." + table1.GetAbsoluteBaseTable().Name + "." + relation.PascalRoleName + "." + table2.Name;
                        if (checkList.Contains(relationName))
                        {
                            INHydrateModelObjectController controller = this;
                            var list = database.Relations.Find(relation.Key);
                            if (list.Length > 0)
                            {
                                var key      = ((Relation)list.GetValue(0)).Key;
                                var nodeList = this.Node.Nodes.Find(key, true);
                                if (nodeList.Length > 0)
                                {
                                    controller = ((ModelObjectTreeNode)nodeList[0]).Controller;
                                }
                            }
                            retval.Add(MessageTypeConstants.Error, String.Format(ValidationHelper.ErrorTextDuplicateRoleName, table1.Name, table2.Name), table1.Controller);
                        }

                        else
                        {
                            checkList.Add(relationName);
                        }
                    }
                    else
                    {
                        deleteList.Add(relation);
                        //TODO
                        //retval.Add(MessageTypeConstants.Error, ValidationHelper.ErrorTextRelationMustHaveParentChild, null);
                    }
                }

                //Remove errors
                foreach (Relation relation in deleteList)
                {
                    database.Relations.Remove(relation);
                }

                //Validate audit fields
                var auditFieldList = new List <string>();
                auditFieldList.Add(database.CreatedByColumnName);
                if (!auditFieldList.Contains(database.CreatedDateColumnName))
                {
                    auditFieldList.Add(database.CreatedDateColumnName);
                }
                if (!auditFieldList.Contains(database.ModifiedByColumnName))
                {
                    auditFieldList.Add(database.ModifiedByColumnName);
                }
                if (!auditFieldList.Contains(database.ModifiedDateColumnName))
                {
                    auditFieldList.Add(database.ModifiedDateColumnName);
                }
                if (!auditFieldList.Contains(database.TimestampColumnName))
                {
                    auditFieldList.Add(database.TimestampColumnName);
                }

                if (auditFieldList.Count != 5)
                {
                    retval.Add(MessageTypeConstants.Error, ValidationHelper.ErrorTextAuditFieldsNotUnique, database.Controller);
                }
                else
                {
                    auditFieldList = new List <string>();
                    auditFieldList.Add(database.CreatedByPascalName);
                    if (!auditFieldList.Contains(database.CreatedDatePascalName))
                    {
                        auditFieldList.Add(database.CreatedDatePascalName);
                    }
                    if (!auditFieldList.Contains(database.ModifiedByPascalName))
                    {
                        auditFieldList.Add(database.ModifiedByPascalName);
                    }
                    if (!auditFieldList.Contains(database.ModifiedDatePascalName))
                    {
                        auditFieldList.Add(database.ModifiedDatePascalName);
                    }
                    if (!auditFieldList.Contains(database.TimestampPascalName))
                    {
                        auditFieldList.Add(database.TimestampPascalName);
                    }

                    if (auditFieldList.Count != 5)
                    {
                        retval.Add(MessageTypeConstants.Error, ValidationHelper.ErrorTextAuditFieldsNotUnique, database.Controller);
                    }
                }

                return(retval);
            }
            catch (Exception ex)
            {
                throw;
            }
        }
		public override MessageCollection Verify()
		{
			try
			{
				var retval = new MessageCollection();
				retval.AddRange(base.Verify());

				if (!(((ReferenceCollection)this.Object).Parent is Table))
					return retval;

				var referenceCollection = (ReferenceCollection)this.Object;
				var columnList = new List<Column>();
				foreach (Reference reference in referenceCollection)
				{
					var column = (Column)reference.Object;
					columnList.Add(column);
				}

				//Check for duplicate names
				var nameList = new Hashtable();
				foreach (var column in columnList)
				{
					var name = column.Name.ToLower();
					if (nameList.ContainsKey(name))
						retval.Add(MessageTypeConstants.Error, string.Format(ValidationHelper.ErrorTextDuplicateName, column.Name), column.Controller);
					else
						nameList.Add(name, string.Empty);
				}

				if (retval.Count == 0)
				{
					//Check for duplicate codefacades
					nameList = new Hashtable();
					foreach (var column in columnList)
					{
						var name = column.PascalName.ToLower();
						if (nameList.ContainsKey(name))
							retval.Add(MessageTypeConstants.Error, string.Format(ValidationHelper.ErrorTextDuplicateCodeFacade, column.Name), column.Controller);
						else
							nameList.Add(name, string.Empty);
					}
				}

				//Check for a primary key        
				var isPrimaryNull = false;
				foreach (var column in columnList)
				{
					if (column.PrimaryKey)
					{
						//hasPrimary = true;
						isPrimaryNull |= column.AllowNull;
					}
				}

				//Check for field named created,modfied,timestamp as these are taken
				foreach (var column in columnList)
				{
					var name = column.Name.ToLower().Replace("_", string.Empty);
					var t = (Table)column.ParentTableRef.Object;
					if (t.AllowCreateAudit)
					{
						//If there is a CreateAudit then no fields can be named the predined values
						if (string.Compare(name, ((ModelRoot)column.Root).Database.CreatedByColumnName.Replace("_", ""), true) == 0)
							retval.Add(MessageTypeConstants.Error, string.Format(ValidationHelper.ErrorTextPreDefinedNameField, name), column.Controller);
						else if (string.Compare(name, ((ModelRoot)column.Root).Database.CreatedDateColumnName.Replace("_", ""), true) == 0)
							retval.Add(MessageTypeConstants.Error, string.Format(ValidationHelper.ErrorTextPreDefinedNameField, name), column.Controller);
					}
					if (t.AllowModifiedAudit)
					{
						if (string.Compare(name, ((ModelRoot)column.Root).Database.ModifiedByColumnName.Replace("_", ""), true) == 0)
							retval.Add(MessageTypeConstants.Error, string.Format(ValidationHelper.ErrorTextPreDefinedNameField, name), column.Controller);
						else if (string.Compare(name, ((ModelRoot)column.Root).Database.ModifiedDateColumnName.Replace("_", ""), true) == 0)
							retval.Add(MessageTypeConstants.Error, string.Format(ValidationHelper.ErrorTextPreDefinedNameField, name), column.Controller);
					}
					if (t.AllowTimestamp)
					{
						if (string.Compare(name, ((ModelRoot)column.Root).Database.TimestampColumnName.Replace("_", ""), true) == 0)
							retval.Add(MessageTypeConstants.Error, string.Format(ValidationHelper.ErrorTextPreDefinedNameField, name), column.Controller);
					}
				}

				if (columnList.Count != 0)
				{
					var parentTable = (Table)columnList[0].ParentTableRef.Object;
					if (parentTable.Generated)
					{
						//Make sure all PK are generated
						if (parentTable.PrimaryKeyColumns.Count != columnList.Count(x => x.Generated && x.PrimaryKey == true))
							retval.Add(MessageTypeConstants.Error, ValidationHelper.ErrorTextNoPrimaryKey, parentTable.Controller);
						else if (parentTable.PrimaryKeyColumns.Count == 0)
							retval.Add(MessageTypeConstants.Error, ValidationHelper.ErrorTextNoPrimaryKey, parentTable.Controller);
						else if (isPrimaryNull)
							retval.Add(MessageTypeConstants.Error, ValidationHelper.ErrorTextPrimaryKeyNull, parentTable.Controller);
					}
				}
				return retval;

			}
			catch (Exception ex)
			{
				throw;
			}
			finally
			{
				Application.DoEvents();
			}
		}
Пример #13
0
		public override MessageCollection Verify()
		{
			try
			{
				var retval = new MessageCollection();
				retval.AddRange(base.Verify());

				var table = (Table)this.Object;

				#region Remove invalid columns
				var deleteRelationList = new List<Relation>();
				foreach (var relation in ((ModelRoot)table.Root).Database.Relations.ToList())
				{
					if (relation.ParentTableRef == null)
						deleteRelationList.Add(relation);
					else if (relation.FkColumns.Count() == 0)
						deleteRelationList.Add(relation);
					else if (relation.ChildTableRef == null)
						deleteRelationList.Add(relation);
					else if (relation.FkColumns.Count() == 0)
						deleteRelationList.Add(relation);
					else
					{
						foreach (var tempRelation in ((Table)relation.ChildTableRef.Object).ChildRoleRelations)
						{
							if (tempRelation.ChildTableRef == null)
								deleteRelationList.Add(relation);
							else if (tempRelation.ChildTableRef.Object == null)
								deleteRelationList.Add(relation);
							else if (tempRelation.ParentTableRef == null)
								deleteRelationList.Add(relation);
							else if (tempRelation.ParentTableRef.Object == null)
								deleteRelationList.Add(relation);
						}

						foreach (var column in relation.FkColumns)
						{
							if (column.ParentTableRef == null)
								deleteRelationList.Add(relation);
						}
					}
				}
				#endregion

				if (table.Generated)
				{
					var heirList = table.GetTableHierarchy();

					#region Check valid name
					if (!ValidationHelper.ValidDatabaseIdenitifer(table.DatabaseName))
						retval.Add(MessageTypeConstants.Error, string.Format(ValidationHelper.ErrorTextInvalidIdentifier, table.Name), this);
					if (!ValidationHelper.ValidCodeIdentifier(table.PascalName) && (table.DatabaseName != table.PascalName)) //Not same name
						retval.Add(MessageTypeConstants.Error, string.Format(ValidationHelper.ErrorTextInvalidIdentifier, table.Name), this);
					#endregion

					#region Check that non-key relationships have a unique index on fields
					foreach (var reference in table.Relationships.ToList())
					{
						var relation = (Relation)reference.Object;
						if (!relation.IsPrimaryKeyRelation())
						{
							foreach (ColumnRelationship columnRelationship in relation.ColumnRelationships)
							{
								var parentColumn = (Column)columnRelationship.ParentColumnRef.Object;
								if (!parentColumn.IsUnique)
									retval.Add(MessageTypeConstants.Error, string.Format(ValidationHelper.ErrorTextTableColumnNonPrimaryRelationNotUnique, parentColumn.DatabaseName, table.Name), this);
							}
						}
					}
					#endregion

					#region Unit tests cannot be performed on base tables
					if (table.AllowUnitTest != Table.UnitTestSettingsConstants.StubOnly)
					{
						if (table.Immutable)
						{
							retval.Add(MessageTypeConstants.Error, string.Format(ValidationHelper.ErrorTextTableDoesNotAllowModification, table.PascalName), this);
						}
					}
					#endregion

					#region Check that object has at least one generated column
					if (table.GetColumns().Count(x => x.Generated) == 0)
						retval.Add(MessageTypeConstants.Error, ValidationHelper.ErrorTextColumnsRequired, this);
					#endregion

					#region Clean up bogus references (in case this happened)
					var delReferences = new ArrayList();

					//Verify that no column has same name as table
					foreach (var column in table.GetColumns())
					{
						if (string.Compare(column.PascalName, table.PascalName, true) == 0)
						{
							retval.Add(MessageTypeConstants.Error, ValidationHelper.ErrorTextTableColumnNameMatch + " (" + column.ToString() + ")", this);
						}
					}

					//Verify relationships
					foreach (var reference in table.Relationships.ToList())
					{
						var relation = (Relation)reference.Object;
						if (relation != null)
						{
							foreach (var cRel in relation.ColumnRelationships.ToList())
							{
								var c1 = (Column)cRel.ParentColumnRef.Object;
								var c2 = (Column)cRel.ChildColumnRef.Object;
								if (c1.DataType != c2.DataType)
								{
									retval.Add(MessageTypeConstants.Error, ValidationHelper.ErrorTextRelationshipTypeMismatch + " (" + c1.ToString() + " -> " + c2.ToString() + ")", this);
								}
							}

						}
					}

					//Remove old relations
					foreach (Reference reference in delReferences)
					{
						table.Relationships.Remove(reference);
					}

					//Verify that inheritance is setup correctly
					if (!table.IsValidInheritance)
					{
						retval.Add(MessageTypeConstants.Error, string.Format(ValidationHelper.ErrorTextInvalidInheritance, table.Name), this);
					}

					#endregion

					#region Check that table does not have same name as project

					if (table.PascalName == ((ModelRoot)table.Root).ProjectName)
					{
						retval.Add(MessageTypeConstants.Error, string.Format(ValidationHelper.ErrorTextTableProjectSameName, table.PascalName), 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 (table.PascalName.ToLower().EndsWith(ending))
						{
							retval.Add(MessageTypeConstants.Error, string.Format(ValidationHelper.ErrorTextNameConfictsWithGeneratedCode, table.Name), this);
						}
					}

					#endregion

					#region Verify that child tables have a relation to their parent table

					if (table.ParentTable != null)
					{
						var isValidRelation = true;
						IEnumerable<Relation> relations = table.ParentTable.GetRelations().FindByChildTable(table);
						foreach (var relation in relations)
						{
							if (relation.ColumnRelationships.Count == table.PrimaryKeyColumns.Count)
							{
								foreach (var columnRelationship in relation.ColumnRelationships.ToList())
								{
									var parentColumn = (Column)columnRelationship.ParentColumnRef.Object;
									var childColumn = (Column)columnRelationship.ChildColumnRef.Object;
									isValidRelation |= ((table.ParentTable.PrimaryKeyColumns.Contains(parentColumn)) && (!table.PrimaryKeyColumns.Contains(childColumn)));
								}
							}
							else
							{
								isValidRelation = false;
							}
						}
						if (!isValidRelation || relations.Count() == 0)
						{
							retval.Add(MessageTypeConstants.Error, string.Format(ValidationHelper.ErrorTextParentTableNoRelation, table.ParentTable.Name, table.Name), this);
						}
					}

					#endregion

					#region Check for inherit heirarchy that all tables are modifiable or not modifiable

					//If this table is Mutable then make sure it is NOT derived from an Immutable table
					if (!table.Immutable)
					{
						var immutableCount = 0;
						Table immutableTable = null;
						foreach (var h in heirList)
						{
							if (h.Immutable)
							{
								if (immutableTable == null) immutableTable = h;
								immutableCount++;
							}
						}

						//If the counts are different then show errors
						if (immutableCount > 0)
						{
							retval.Add(MessageTypeConstants.Error, string.Format(ValidationHelper.ErrorTextMutableInherit, table.Name, immutableTable.Name), this);
						}
					}

					#endregion

					#region Check that all tables in inheritance chain are generated

					{
						var nonGenCount = 0;
						Table nonGenTable = null;
						foreach (var h in heirList)
						{
							if (!h.Generated)
							{
								if (nonGenTable == null) nonGenTable = h;
								nonGenCount++;
							}
						}

						//If the counts are different then show errors
						if (nonGenCount > 0)
						{
							retval.Add(MessageTypeConstants.Error, string.Format(ValidationHelper.ErrorTextBaseTableNonGenerated, nonGenTable.Name, table.Name), this);
						}
					}

					#endregion

					#region Type Tables must be immutable

					if (table.IsTypeTable & !table.Immutable)
						retval.Add(MessageTypeConstants.Error, string.Format(ValidationHelper.ErrorTextTypeTableIsMutable, table.Name), this);

					#endregion

					#region Type Tables must have specific columns and data

					if (table.IsTypeTable && (table.PrimaryKeyColumns.Count > 0))
					{
						//Mast have one PK that is integer type
						if ((table.PrimaryKeyColumns.Count > 1) || !((Column)table.PrimaryKeyColumns[0]).IsIntegerType)
						{
							retval.Add(MessageTypeConstants.Error, string.Format(ValidationHelper.ErrorTextTypeTablePrimaryKey, table.Name), this);
						}

						//Must have static data
						if (table.StaticData.Count == 0)
						{
							retval.Add(MessageTypeConstants.Error, string.Format(ValidationHelper.ErrorTextTypeTableNoData, table.CodeFacade), this);
						}

						//Must have a "Name" or "Description" field
						var typeTableTextField = table.GetColumns().FirstOrDefault(x => x.Name.ToLower() == "name");
						if (typeTableTextField == null) typeTableTextField = table.GetColumns().FirstOrDefault(x => x.Name.ToLower() == "description");
						if (typeTableTextField == null)
						{
							retval.Add(MessageTypeConstants.Error, string.Format(ValidationHelper.ErrorTextTypeTableTextField, table.Name), this);
						}
						else
						{
							//Verify that type tables have data
							foreach (RowEntry row in table.StaticData)
							{
								//Primary key must be set
								var cell = row.CellEntries[((Column)table.PrimaryKeyColumns[0]).Name];
								if (cell == null)
								{
									retval.Add(MessageTypeConstants.Error, string.Format(ValidationHelper.ErrorTextTypeTableStaticDataEmpty, table.Name), this);
								}
								else if (string.IsNullOrEmpty(cell.Value))
								{
									retval.Add(MessageTypeConstants.Error, string.Format(ValidationHelper.ErrorTextTypeTableStaticDataEmpty, table.Name), this);
								}

								//Enum name must be set
								cell = row.CellEntries[typeTableTextField.Name];
								if (cell == null)
								{
									retval.Add(MessageTypeConstants.Error, string.Format(ValidationHelper.ErrorTextTypeTableStaticDataEmpty, table.Name), this);
								}
								else if (string.IsNullOrEmpty(cell.Value))
								{
									retval.Add(MessageTypeConstants.Error, string.Format(ValidationHelper.ErrorTextTypeTableStaticDataEmpty, table.Name), this);
								}
							}
						}

						//Verify that the static data is not duplicated
						var staticDataIdentifierList = new List<string>();
						foreach (RowEntry rowEntry in table.StaticData)
						{
							var id = rowEntry.GetCodeIdentifier(table);
							if (!staticDataIdentifierList.Contains(id))
							{
								staticDataIdentifierList.Add(id);
							}
							else
							{
								retval.Add(MessageTypeConstants.Error, string.Format(ValidationHelper.ErrorTextDuplicateStaticData, id, table.Name), this);
							}
						}

					}

					#endregion

					#region Audit Fields must go down to base table

					//Ensure that audit fields are down in 1st base class
					foreach (var t in heirList)
					{
						if (t.AllowCreateAudit != table.AllowCreateAudit) retval.Add(MessageTypeConstants.Error, string.Format(ValidationHelper.ErrorTextAuditFieldMatchBase, table.Name), this);
					}
					foreach (var t in heirList)
					{
						if (t.AllowModifiedAudit != table.AllowModifiedAudit) retval.Add(MessageTypeConstants.Error, string.Format(ValidationHelper.ErrorTextAuditFieldMatchBase, table.Name), this);
					}
					foreach (var t in heirList)
					{
						if (t.AllowTimestamp != table.AllowTimestamp) retval.Add(MessageTypeConstants.Error, string.Format(ValidationHelper.ErrorTextAuditFieldMatchBase, table.Name), this);
					}

					#endregion

					#region Self-ref table MUST have role name

					#endregion

					#region Self-ref table cannot map child column to PK field

					foreach (Reference reference in table.Relationships)
					{
						var relation = (Relation)reference.Object;
						var parentTable = (Table)relation.ParentTableRef.Object;
						var childTable = (Table)relation.ChildTableRef.Object;
						if (parentTable == childTable)
						{
							if (string.IsNullOrEmpty(relation.RoleName))
							{
								retval.Add(MessageTypeConstants.Error, string.Format(ValidationHelper.ErrorTextSelfRefMustHaveRole, table.Name), this);
							}
							else
							{
								foreach (ColumnRelationship columnRelationShip in relation.ColumnRelationships)
								{
									if (table.PrimaryKeyColumns.Contains((Column)columnRelationShip.ChildColumnRef.Object))
									{
										retval.Add(MessageTypeConstants.Error, string.Format(ValidationHelper.ErrorTextSelfRefChildColumnPK, table.Name), this);
									}
								}
							}
						}
					}

					#endregion

					#region There can be only 1 self reference per table

					if (table.AllRelationships.Count(x => x.ChildTableRef == x.ParentTableRef) > 1)
					{
						retval.Add(MessageTypeConstants.Error, string.Format(ValidationHelper.ErrorTextSelfRefOnlyOne, table.Name), this);
					}

					#endregion

					#region Verify Relations

					var relationList = new List<string>();
					foreach (Relation relation in table.GetRelations())
					{
						var key = string.Empty;
						var parentTable = (Table)relation.ParentTableRef.Object;
						var childTable = (Table)relation.ChildTableRef.Object;
						var foreignKeys = new List<Column>();
						foreach (var columnRelationship in relation.ColumnRelationships.ToList())
						{
							var parentColumn = (Column)columnRelationship.ParentColumnRef.Object;
							var childColumn = (Column)columnRelationship.ChildColumnRef.Object;
							if (!string.IsNullOrEmpty(key)) key += ", ";
							key += parentTable.Name + "." + childColumn.Name + " -> " + childTable.Name + "." + parentColumn.Name;
							if ((parentColumn.Identity == IdentityTypeConstants.Database) &&
								(childColumn.Identity == IdentityTypeConstants.Database))
							{
								retval.Add(MessageTypeConstants.Error, string.Format(ValidationHelper.ErrorTextChildTableRelationIdentity, childTable.Name, parentTable.Name), this);
							}

							if (foreignKeys.Contains(childColumn))
							{
								retval.Add(MessageTypeConstants.Error, string.Format(ValidationHelper.ErrorTextMultiFieldRelationsMapDifferentFields, childTable.Name, parentTable.Name), this);
							}
							foreignKeys.Add(childColumn);

							//Verify that field name does not match foreign table name
							if (childColumn.PascalName == parentTable.PascalName)
							{
								retval.Add(MessageTypeConstants.Error, string.Format(ValidationHelper.ErrorTextRelationFieldNotMatchAssociatedTable, parentTable.Name, childTable.Name), this);
							}
						}

						//Role names cannot start with number
						if (relation.PascalRoleName.Length > 0)
						{
							var roleFirstChar = relation.PascalRoleName[0];
							if ("0123456789".Contains(roleFirstChar))
							{
								retval.Add(MessageTypeConstants.Error, string.Format(ValidationHelper.ErrorTextRoleNoStartNumber, key), this);
							}
						}

						//Verify that relations are not duplicated (T1.C1 -> T2.C2)
						if (!relationList.Contains(relation.PascalRoleName + "|" + key))
						{
							relationList.Add(relation.PascalRoleName + "|" + key);
						}
						else
						{
							retval.Add(MessageTypeConstants.Error, string.Format(ValidationHelper.ErrorTextDuplicateRelation, key), this);
						}

					}

					//Look for duplication relations based on child tables too
					//Check the full table hierarchy for relations
					relationList.Clear();
					foreach (var relation in table.GetRelationsFullHierarchy().Where(x => !x.IsInherited && (x.ChildTableRef.Object != table)))
					{
						var key = string.Empty;
						var parentTable = (Table)relation.ParentTableRef.Object;
						var childTable = (Table)relation.ChildTableRef.Object;

						if (!table.IsInheritedFrom(childTable))
						{
							if (relation.IsOneToOne) key = relation.PascalRoleName + childTable.PascalName;
							else key = relation.PascalRoleName + childTable.PascalName + "List";

							//Verify that relations are not duplicated (T1.C1 -> T2.C2)
							if (!relationList.Contains(key))
							{
								relationList.Add(key);
							}
							else
							{
								retval.Add(MessageTypeConstants.Error, string.Format(ValidationHelper.ErrorTextDuplicateRelationFullHierarchy, table.Name, childTable.Name), this);
							}
						}

					}

					//Verify M:N relations have same role name on both sides
					foreach (var relation in table.GetRelations().Where(x => x.IsManyToMany))
					{
						var relation2 = relation.GetAssociativeOtherRelation();
						if (relation2 == null)
						{
							//TODO
						}
						else if (relation.RoleName != relation.GetAssociativeOtherRelation().RoleName)
						{
							retval.Add(MessageTypeConstants.Error, string.Format(ValidationHelper.ErrorTextRelationM_NRoleMismatch, relation.ChildTable.Name), this);
						}
					}

					//Verify M:N relations do not map to same property names
					//This can happen if 2 M:N tables are defined between the same two tables...(why people do this I do not know)
					relationList.Clear();
					foreach (var relation in table.GetRelations().Where(x => x.IsManyToMany))
					{
						var relation2 = relation.GetAssociativeOtherRelation();
						if (relation2 == null)
						{
							//TODO
						}
						else
						{
							var mappedName = relation.RoleName + "|" + relation.GetSecondaryAssociativeTable().Name;
							if (relationList.Contains(mappedName))
							{
								retval.Add(MessageTypeConstants.Error, string.Format(ValidationHelper.ErrorTextRelationM_NNameDuplication, table.Name, relation.GetSecondaryAssociativeTable().Name), this);
							}
							else
							{
								relationList.Add(mappedName);
							}
						}
					}

					{
						//Verify that if related to an associative table I do not also have a direct link
						var relatedTables = new List<string>();
						foreach (var relation in table.GetRelations().ToList())
						{
							if (relation.IsManyToMany)
							{
								relatedTables.Add(relation.GetSecondaryAssociativeTable().PascalName + relation.RoleName);
							}
						}

						//Now verify that I have no relation to them
						var invalid = false;
						foreach (var relation in table.GetRelations().ToList())
						{
							if (!relation.IsManyToMany)
							{
								if (relatedTables.Contains(relation.ChildTable.PascalName + relation.RoleName))
								{
									invalid = true;
								}
							}
						}

						if (invalid)
							retval.Add(MessageTypeConstants.Error, string.Format(ValidationHelper.ErrorTextRelationCausesNameConflict, table.Name, relatedTables.First()), this);

					}

					//Only 1 relation can exist from A->B on the same columns 
					{
						var hashList = new List<string>();
						var rList = table.GetRelations().Where(x => x.ParentTable.Generated && x.ChildTable.Generated).ToList();
						foreach (var r in rList)
						{
							if (!hashList.Contains(r.LinkHash))
								hashList.Add(r.LinkHash);
						}
						if (rList.Count != hashList.Count)
							retval.Add(MessageTypeConstants.Error, string.Format(ValidationHelper.ErrorTextRelationDuplicate, table.Name), this);
					}

					#endregion

					#region Associative Tables

					if (table.AssociativeTable)
					{
						var count = 0;
						foreach (var relation in ((ModelRoot)_object.Root).Database.Relations.ToList())
						{
							if (relation.ChildTableRef.Object == table)
							{
								count++;
							}
						}
						if (count != 2)
						{
							retval.Add(MessageTypeConstants.Error, string.Format(ValidationHelper.ErrorTextAssociativeTableMustHave2Relations, table.Name, count), this);
						}

						//Associative tables cannot be inherited
						if (table.ParentTable != null)
							retval.Add(MessageTypeConstants.Error, string.Format(ValidationHelper.ErrorTextAssociativeTableNotInherited, table.Name), this);
					}

					#endregion

					#region There can be only 1 Identity per table

					var identityCount = table.GetColumns().Count(x => x.Identity == IdentityTypeConstants.Database);
					if (identityCount > 1)
					{
						//If there is an identity column, it can be the only PK
						retval.Add(MessageTypeConstants.Error, string.Format(ValidationHelper.ErrorTextIdentityOnlyOnePerTable, table.Name), this);
					}

					#endregion

					#region Identity PK can be only PK

					var pkIdentityCount = table.PrimaryKeyColumns.Count(x => x.Identity != IdentityTypeConstants.None);
					if ((pkIdentityCount > 0) && (table.PrimaryKeyColumns.Count != pkIdentityCount))
					{
						//If there is an identity column, it can be the only PK
						retval.Add(MessageTypeConstants.Warning, string.Format(ValidationHelper.ErrorTextIdentityPKNotOnlyKey, table.Name), this);
					}

					#endregion

					#region Associative table cannot be immutable

					if (table.AssociativeTable & table.Immutable)
					{
						retval.Add(MessageTypeConstants.Error, ValidationHelper.ErrorTextAssociativeTableNotImmutable, this);
					}

					#endregion

					#region Tables must have a non-identity column

					if (!table.Immutable)
					{
						if (table.GetColumns().Count(x => x.Identity == IdentityTypeConstants.Database) == table.GetColumns().Count(x => x.Generated))
						{
							retval.Add(MessageTypeConstants.Error, string.Format(ValidationHelper.ErrorTextTableNotHave1IdentityOnly, table.Name), this);
						}
					}

					#endregion

					#region AllowAuditTracking

					//if (table.AllowAuditTracking && table.AssociativeTable)
					//{
					//  retval.Add(MessageTypeConstants.Error, string.Format(ValidationHelper.ErrorTextTableAssociativeNoAuditTracking, table.Name), this);
					//}

					#endregion

					#region Associative must have non-overlapping PK column

					if (table.AssociativeTable)
					{
						var rlist = table.GetRelationsWhereChild().ToList();
						if (rlist.Count == 2)
						{
							var r1 = rlist.First();
							var r2 = rlist.Last();
							if (table.PrimaryKeyColumns.Count != r1.ParentTable.PrimaryKeyColumns.Count + r2.ParentTable.PrimaryKeyColumns.Count)
							{
								retval.Add(MessageTypeConstants.Error, string.Format(ValidationHelper.ErrorTextTableAssociativeNeedsNonOverlappingColumns, table.Name), this);
							}
						}
					}

					#endregion

					#region Verify Static Data
					var dataValid = true;
					foreach (var entry in table.StaticData.OfType<RowEntry>())
					{
						foreach (var cell in entry.CellEntries.OfType<CellEntry>())
						{
							if (!cell.IsDataValid())
								dataValid = false;
						}
					}
					if (!dataValid)
						retval.Add(MessageTypeConstants.Error, string.Format(ValidationHelper.ErrorTextTableBadStaticData, table.Name), this);
					#endregion

				}

				return retval;
			}
			catch (Exception ex)
			{
				throw;
			}
			finally
			{
				Application.DoEvents();
			}

		}
Пример #14
0
		public override MessageCollection Verify()
		{
			try
			{
				var retval = new MessageCollection();
				retval.AddRange(base.Verify());

				var root = (ModelRoot)this.Object;

				//Check valid name
				if (!ValidationHelper.ValidDatabaseIdenitifer(root.CompanyName) || !ValidationHelper.ValidCodeIdentifier(root.CompanyName))
					retval.Add(MessageTypeConstants.Error, ValidationHelper.ErrorTextInvalidCompany, this);
				if (!ValidationHelper.ValidDatabaseIdenitifer(root.ProjectName) || !ValidationHelper.ValidCodeIdentifier(root.ProjectName))
					retval.Add(MessageTypeConstants.Error, ValidationHelper.ErrorTextInvalidProject, this);
				if (!ValidationHelper.ValidDatabaseIdenitifer(root.CompanyAbbreviation) || !ValidationHelper.ValidCodeIdentifier(root.CompanyAbbreviation))
					retval.Add(MessageTypeConstants.Error, ValidationHelper.ErrorTextInvalidCompanyAbbreviation, this);

				if (!string.IsNullOrEmpty(root.DefaultNamespace))
				{
					if (!ValidationHelper.IsValidNamespace(root.DefaultNamespace))
						retval.Add(MessageTypeConstants.Error, ValidationHelper.ErrorTextInvalidNamespace, this);
				}

				return retval;

			}
			catch (Exception ex)
			{
				throw;
			}

		}
		public override MessageCollection Verify()
		{
			try
			{
				var retval = new MessageCollection();
				retval.AddRange(base.Verify());

				var customStoredProcedure = (CustomStoredProcedure)this.Object;
				if (customStoredProcedure.Generated)
				{
					//Check valid name
					if (!ValidationHelper.ValidDatabaseIdenitifer(customStoredProcedure.DatabaseName))
						retval.Add(MessageTypeConstants.Error, string.Format(ValidationHelper.ErrorTextInvalidIdentifier, customStoredProcedure.Name), this);
					if (!ValidationHelper.ValidCodeIdentifier(customStoredProcedure.PascalName))
						retval.Add(MessageTypeConstants.Error, string.Format(ValidationHelper.ErrorTextInvalidIdentifier, customStoredProcedure.Name), this);

					//Check StoredProcedure SQL
					if (!customStoredProcedure.IsExisting && string.IsNullOrEmpty(customStoredProcedure.SQL))
					{
						retval.Add(MessageTypeConstants.Error, ValidationHelper.ErrorTextSQLRequired, this);
					}

					if (customStoredProcedure.IsExisting && string.IsNullOrEmpty(customStoredProcedure.DatabaseObjectName))
					{
						retval.Add(MessageTypeConstants.Error, string.Format(ValidationHelper.ErrorTextExistingSPNeedsDBName, customStoredProcedure.Name), this);
					}

					//Check that object has at least one generated column
					//if (customStoredProcedure.GetColumns().Count(x => x.Generated) == 0)
					//	retval.Add(MessageTypeConstants.Error, ValidationHelper.ErrorTextColumnsRequired, this);

				}

				return retval;

			}
			catch (Exception ex)
			{
				throw;
			}

		}
		public override MessageCollection Verify()
		{
			try
			{
				var retval = new MessageCollection();
				retval.AddRange(base.Verify());

				var tableCompositeCollection = (TableCompositeCollection)this.Object;

				//Check for duplicate names
				var nameList = new Hashtable();
				foreach (TableComposite composite in tableCompositeCollection)
				{
					var name = composite.Name.ToLower();
					if (nameList.ContainsKey(name))
						retval.Add(MessageTypeConstants.Error, string.Format(ValidationHelper.ErrorTextDuplicateName, composite.Name), composite.Controller);
					else
						nameList.Add(name, string.Empty);
				}

				foreach (TableComposite composite in tableCompositeCollection)
				{
					if (composite.Columns.Count == 0)
					{
						retval.Add(MessageTypeConstants.Error, string.Format(ValidationHelper.ErrorTextTableCompositeNoColumns, composite.Name), composite.Controller);
					}
				}

				return retval;

			}
			catch (Exception ex)
			{
				throw;
			}

		}
Пример #17
0
        public override MessageCollection Verify()
        {
            try
            {
                var retval = new MessageCollection();
                retval.AddRange(base.Verify());

                var tableComponent = (TableComponent)this.Object;

                if (tableComponent.Generated)
                {
                    #region Table Component must have PK for parent table
                    var pkCount = 0;
                    foreach (Reference reference in tableComponent.Columns)
                    {
                        var column = (Column)reference.Object;
                        if (tableComponent.Parent.PrimaryKeyColumns.Contains(column))
                        {
                            pkCount++;
                        }
                    }

                    if (pkCount != tableComponent.Parent.PrimaryKeyColumns.Count)
                    {
                        retval.Add(MessageTypeConstants.Error, String.Format(ValidationHelper.ErrorTextComponentMustHaveTablePK, tableComponent.Name), this);
                    }
                    #endregion

                    #region Check valid name
                    if (!ValidationHelper.ValidCodeIdentifier(tableComponent.PascalName))
                    {
                        retval.Add(MessageTypeConstants.Error, string.Format(ValidationHelper.ErrorTextInvalidIdentifier, tableComponent.Parent.Name), this);
                    }
                    #endregion

                    #region Check that object does not have same name as project

                    if (tableComponent.PascalName == ((ModelRoot)tableComponent.Parent.Root).ProjectName)
                    {
                        retval.Add(MessageTypeConstants.Error, string.Format(ValidationHelper.ErrorTextComponentProjectSameName, tableComponent.Parent.PascalName), 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 (tableComponent.PascalName.ToLower().EndsWith(ending))
                        {
                            retval.Add(MessageTypeConstants.Error, string.Format(ValidationHelper.ErrorTextNameConfictsWithGeneratedCode, tableComponent.Parent.Name), this);
                        }
                    }

                    #endregion
                }

                return(retval);
            }
            catch (Exception ex)
            {
                throw;
            }
        }
		public override MessageCollection Verify()
		{
			try
			{
				var retval = new MessageCollection();
				retval.AddRange(base.Verify());

				//Check for duplicate names
				var nameList = new Hashtable();
				var referenceCollection = (ReferenceCollection)this.Object;
				foreach(Reference reference in referenceCollection)
				{
					var parameter = (Parameter)reference.Object;
					var name = parameter.Name.ToLower();
					if(nameList.ContainsKey(name))
						retval.Add(MessageTypeConstants.Error, string.Format(ValidationHelper.ErrorTextDuplicateName, name), parameter.Controller);
					else
						nameList.Add(name, string.Empty);
				}

				return retval;

			}
			catch(Exception ex)
			{
				throw;
			}
		}
Пример #19
0
        public override MessageCollection Verify()
        {
            try
            {
                var retval = new MessageCollection();
                retval.AddRange(base.Verify());

                if (!(((ReferenceCollection)this.Object).Parent is Table))
                {
                    return(retval);
                }

                var referenceCollection = (ReferenceCollection)this.Object;
                var columnList          = new List <Column>();
                foreach (Reference reference in referenceCollection)
                {
                    var column = (Column)reference.Object;
                    columnList.Add(column);
                }

                //Check for duplicate names
                var nameList = new Hashtable();
                foreach (var column in columnList)
                {
                    var name = column.Name.ToLower();
                    if (nameList.ContainsKey(name))
                    {
                        retval.Add(MessageTypeConstants.Error, string.Format(ValidationHelper.ErrorTextDuplicateName, column.Name), column.Controller);
                    }
                    else
                    {
                        nameList.Add(name, string.Empty);
                    }
                }

                if (retval.Count == 0)
                {
                    //Check for duplicate codefacades
                    nameList = new Hashtable();
                    foreach (var column in columnList)
                    {
                        var name = column.PascalName.ToLower();
                        if (nameList.ContainsKey(name))
                        {
                            retval.Add(MessageTypeConstants.Error, string.Format(ValidationHelper.ErrorTextDuplicateCodeFacade, column.Name), column.Controller);
                        }
                        else
                        {
                            nameList.Add(name, string.Empty);
                        }
                    }
                }

                //Check for a primary key
                var isPrimaryNull = false;
                foreach (var column in columnList)
                {
                    if (column.PrimaryKey)
                    {
                        //hasPrimary = true;
                        isPrimaryNull |= column.AllowNull;
                    }
                }

                //Check for field named created,modfied,timestamp as these are taken
                foreach (var column in columnList)
                {
                    var name = column.Name.ToLower().Replace("_", string.Empty);
                    var t    = (Table)column.ParentTableRef.Object;
                    if (t.AllowCreateAudit)
                    {
                        //If there is a CreateAudit then no fields can be named the predined values
                        if (string.Compare(name, ((ModelRoot)column.Root).Database.CreatedByColumnName.Replace("_", ""), true) == 0)
                        {
                            retval.Add(MessageTypeConstants.Error, string.Format(ValidationHelper.ErrorTextPreDefinedNameField, name), column.Controller);
                        }
                        else if (string.Compare(name, ((ModelRoot)column.Root).Database.CreatedDateColumnName.Replace("_", ""), true) == 0)
                        {
                            retval.Add(MessageTypeConstants.Error, string.Format(ValidationHelper.ErrorTextPreDefinedNameField, name), column.Controller);
                        }
                    }
                    if (t.AllowModifiedAudit)
                    {
                        if (string.Compare(name, ((ModelRoot)column.Root).Database.ModifiedByColumnName.Replace("_", ""), true) == 0)
                        {
                            retval.Add(MessageTypeConstants.Error, string.Format(ValidationHelper.ErrorTextPreDefinedNameField, name), column.Controller);
                        }
                        else if (string.Compare(name, ((ModelRoot)column.Root).Database.ModifiedDateColumnName.Replace("_", ""), true) == 0)
                        {
                            retval.Add(MessageTypeConstants.Error, string.Format(ValidationHelper.ErrorTextPreDefinedNameField, name), column.Controller);
                        }
                    }
                    if (t.AllowTimestamp)
                    {
                        if (string.Compare(name, ((ModelRoot)column.Root).Database.TimestampColumnName.Replace("_", ""), true) == 0)
                        {
                            retval.Add(MessageTypeConstants.Error, string.Format(ValidationHelper.ErrorTextPreDefinedNameField, name), column.Controller);
                        }
                    }
                }

                if (columnList.Count != 0)
                {
                    var parentTable = (Table)columnList[0].ParentTableRef.Object;
                    if (parentTable.Generated)
                    {
                        //Make sure all PK are generated
                        if (parentTable.PrimaryKeyColumns.Count != columnList.Count(x => x.Generated && x.PrimaryKey == true))
                        {
                            retval.Add(MessageTypeConstants.Error, ValidationHelper.ErrorTextNoPrimaryKey, parentTable.Controller);
                        }
                        else if (parentTable.PrimaryKeyColumns.Count == 0)
                        {
                            retval.Add(MessageTypeConstants.Error, ValidationHelper.ErrorTextNoPrimaryKey, parentTable.Controller);
                        }
                        else if (isPrimaryNull)
                        {
                            retval.Add(MessageTypeConstants.Error, ValidationHelper.ErrorTextPrimaryKeyNull, parentTable.Controller);
                        }
                    }
                }
                return(retval);
            }
            catch (Exception ex)
            {
                throw;
            }
            finally
            {
                Application.DoEvents();
            }
        }
Пример #20
0
		public override MessageCollection Verify()
		{
			try
			{
				var retval = new MessageCollection();
				retval.AddRange(base.Verify());

				var tableComponent = (TableComponent)this.Object;

				if (tableComponent.Generated)
				{

					#region Table Component must have PK for parent table
					var pkCount = 0;
					foreach (Reference reference in tableComponent.Columns)
					{
						var column = (Column)reference.Object;
						if (tableComponent.Parent.PrimaryKeyColumns.Contains(column))
							pkCount++;
					}

					if (pkCount != tableComponent.Parent.PrimaryKeyColumns.Count)
					{
						retval.Add(MessageTypeConstants.Error, String.Format(ValidationHelper.ErrorTextComponentMustHaveTablePK, tableComponent.Name), this);
					}
					#endregion

					#region Check valid name
					if (!ValidationHelper.ValidCodeIdentifier(tableComponent.PascalName))
						retval.Add(MessageTypeConstants.Error, string.Format(ValidationHelper.ErrorTextInvalidIdentifier, tableComponent.Parent.Name), this);
					#endregion

					#region Check that object does not have same name as project

					if (tableComponent.PascalName == ((ModelRoot)tableComponent.Parent.Root).ProjectName)
					{
						retval.Add(MessageTypeConstants.Error, string.Format(ValidationHelper.ErrorTextComponentProjectSameName, tableComponent.Parent.PascalName), 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 (tableComponent.PascalName.ToLower().EndsWith(ending))
						{
							retval.Add(MessageTypeConstants.Error, string.Format(ValidationHelper.ErrorTextNameConfictsWithGeneratedCode, tableComponent.Parent.Name), this);
						}
					}

					#endregion

				}

				return retval;

			}
			catch (Exception ex)
			{
				throw;
			}

		}
Пример #21
0
		public override MessageCollection Verify()
		{
			try
			{
				var retval = new MessageCollection();
				retval.AddRange(base.Verify());

				var package = (Package)this.Object;
				if(package.DisplayName.Trim() == "")
				{
					retval.Add(MessageTypeConstants.Error, ValidationHelper.ErrorTextPackageRequiresDisplayName, this);
				}

				return retval;
			}
			catch (Exception ex)
			{
				throw;
			}

		}
		public override MessageCollection Verify()
		{
			try
			{
				var retval = new MessageCollection();
				retval.AddRange(base.Verify());
				return retval;

			}
			catch (Exception ex)
			{
				throw;
			}

		}
		public override MessageCollection Verify()
		{
			try
			{
				var retval = new MessageCollection();
				retval.AddRange(base.Verify());

				var tableComponentCollection = (TableComponentCollection)this.Object;

				//Check for duplicate names
				var nameList = new Dictionary<string, TableComponent>();
				foreach (TableComponent component in tableComponentCollection)
				{
					var name = component.Name.ToLower();
					if (nameList.ContainsKey(name))
						retval.Add(MessageTypeConstants.Error, string.Format(ValidationHelper.ErrorTextDuplicateName, component.Name), component.Controller);
					else
						nameList.Add(name, component);
				}

				//Check to ensure all items have at least one column
				foreach (var component in tableComponentCollection.ToList())
				{
					if (component.Columns.Count == 0)
					{
						retval.Add(MessageTypeConstants.Error, string.Format(ValidationHelper.ErrorTextTableComponentNoColumns, component.Name), component.Controller);
					}
				}

				//Check for duplicate names with tables
				foreach (Table table in ((ModelRoot)tableComponentCollection.Root).Database.Tables)
				{
					if (nameList.ContainsKey(table.Name.ToLower()))
					{
						retval.Add(MessageTypeConstants.Error, string.Format(ValidationHelper.ErrorTextComponentTableDuplicateName, nameList[table.Name.ToLower()].Name), nameList[table.Name.ToLower()].Controller);
					}
				}

				return retval;

			}
			catch (Exception ex)
			{
				throw;
			}

		}
Пример #24
0
        public override MessageCollection Verify()
        {
            try
            {
                var retval = new MessageCollection();
                retval.AddRange(base.Verify());

                var table = (Table)this.Object;

                #region Remove invalid columns
                var deleteRelationList = new List <Relation>();
                foreach (var relation in ((ModelRoot)table.Root).Database.Relations.ToList())
                {
                    if (relation.ParentTableRef == null)
                    {
                        deleteRelationList.Add(relation);
                    }
                    else if (relation.FkColumns.Count() == 0)
                    {
                        deleteRelationList.Add(relation);
                    }
                    else if (relation.ChildTableRef == null)
                    {
                        deleteRelationList.Add(relation);
                    }
                    else if (relation.FkColumns.Count() == 0)
                    {
                        deleteRelationList.Add(relation);
                    }
                    else
                    {
                        foreach (var tempRelation in ((Table)relation.ChildTableRef.Object).ChildRoleRelations)
                        {
                            if (tempRelation.ChildTableRef == null)
                            {
                                deleteRelationList.Add(relation);
                            }
                            else if (tempRelation.ChildTableRef.Object == null)
                            {
                                deleteRelationList.Add(relation);
                            }
                            else if (tempRelation.ParentTableRef == null)
                            {
                                deleteRelationList.Add(relation);
                            }
                            else if (tempRelation.ParentTableRef.Object == null)
                            {
                                deleteRelationList.Add(relation);
                            }
                        }

                        foreach (var column in relation.FkColumns)
                        {
                            if (column.ParentTableRef == null)
                            {
                                deleteRelationList.Add(relation);
                            }
                        }
                    }
                }
                #endregion

                if (table.Generated)
                {
                    var heirList = table.GetTableHierarchy();

                    #region Check valid name
                    if (!ValidationHelper.ValidDatabaseIdenitifer(table.DatabaseName))
                    {
                        retval.Add(MessageTypeConstants.Error, string.Format(ValidationHelper.ErrorTextInvalidIdentifier, table.Name), this);
                    }
                    if (!ValidationHelper.ValidCodeIdentifier(table.PascalName) && (table.DatabaseName != table.PascalName))                     //Not same name
                    {
                        retval.Add(MessageTypeConstants.Error, string.Format(ValidationHelper.ErrorTextInvalidIdentifier, table.Name), this);
                    }
                    #endregion

                    #region Check that non-key relationships have a unique index on fields
                    foreach (var reference in table.Relationships.ToList())
                    {
                        var relation = (Relation)reference.Object;
                        if (!relation.IsPrimaryKeyRelation())
                        {
                            foreach (ColumnRelationship columnRelationship in relation.ColumnRelationships)
                            {
                                var parentColumn = (Column)columnRelationship.ParentColumnRef.Object;
                                if (!parentColumn.IsUnique)
                                {
                                    retval.Add(MessageTypeConstants.Error, string.Format(ValidationHelper.ErrorTextTableColumnNonPrimaryRelationNotUnique, parentColumn.DatabaseName, table.Name), this);
                                }
                            }
                        }
                    }
                    #endregion

                    #region Unit tests cannot be performed on base tables
                    if (table.AllowUnitTest != Table.UnitTestSettingsConstants.StubOnly)
                    {
                        if (table.Immutable)
                        {
                            retval.Add(MessageTypeConstants.Error, string.Format(ValidationHelper.ErrorTextTableDoesNotAllowModification, table.PascalName), this);
                        }
                    }
                    #endregion

                    #region Check that object has at least one generated column
                    if (table.GetColumns().Count(x => x.Generated) == 0)
                    {
                        retval.Add(MessageTypeConstants.Error, ValidationHelper.ErrorTextColumnsRequired, this);
                    }
                    #endregion

                    #region Clean up bogus references (in case this happened)
                    var delReferences = new ArrayList();

                    //Verify that no column has same name as table
                    foreach (var column in table.GetColumns())
                    {
                        if (string.Compare(column.PascalName, table.PascalName, true) == 0)
                        {
                            retval.Add(MessageTypeConstants.Error, ValidationHelper.ErrorTextTableColumnNameMatch + " (" + column.ToString() + ")", this);
                        }
                    }

                    //Verify relationships
                    foreach (var reference in table.Relationships.ToList())
                    {
                        var relation = (Relation)reference.Object;
                        if (relation != null)
                        {
                            foreach (var cRel in relation.ColumnRelationships.ToList())
                            {
                                var c1 = (Column)cRel.ParentColumnRef.Object;
                                var c2 = (Column)cRel.ChildColumnRef.Object;
                                if (c1.DataType != c2.DataType)
                                {
                                    retval.Add(MessageTypeConstants.Error, ValidationHelper.ErrorTextRelationshipTypeMismatch + " (" + c1.ToString() + " -> " + c2.ToString() + ")", this);
                                }
                            }
                        }
                    }

                    //Remove old relations
                    foreach (Reference reference in delReferences)
                    {
                        table.Relationships.Remove(reference);
                    }

                    //Verify that inheritance is setup correctly
                    if (!table.IsValidInheritance)
                    {
                        retval.Add(MessageTypeConstants.Error, string.Format(ValidationHelper.ErrorTextInvalidInheritance, table.Name), this);
                    }

                    #endregion

                    #region Check that table does not have same name as project

                    if (table.PascalName == ((ModelRoot)table.Root).ProjectName)
                    {
                        retval.Add(MessageTypeConstants.Error, string.Format(ValidationHelper.ErrorTextTableProjectSameName, table.PascalName), 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 (table.PascalName.ToLower().EndsWith(ending))
                        {
                            retval.Add(MessageTypeConstants.Error, string.Format(ValidationHelper.ErrorTextNameConfictsWithGeneratedCode, table.Name), this);
                        }
                    }

                    #endregion

                    #region Verify that child tables have a relation to their parent table

                    if (table.ParentTable != null)
                    {
                        var isValidRelation = true;
                        IEnumerable <Relation> relations = table.ParentTable.GetRelations().FindByChildTable(table);
                        foreach (var relation in relations)
                        {
                            if (relation.ColumnRelationships.Count == table.PrimaryKeyColumns.Count)
                            {
                                foreach (var columnRelationship in relation.ColumnRelationships.ToList())
                                {
                                    var parentColumn = (Column)columnRelationship.ParentColumnRef.Object;
                                    var childColumn  = (Column)columnRelationship.ChildColumnRef.Object;
                                    isValidRelation |= ((table.ParentTable.PrimaryKeyColumns.Contains(parentColumn)) && (!table.PrimaryKeyColumns.Contains(childColumn)));
                                }
                            }
                            else
                            {
                                isValidRelation = false;
                            }
                        }
                        if (!isValidRelation || relations.Count() == 0)
                        {
                            retval.Add(MessageTypeConstants.Error, string.Format(ValidationHelper.ErrorTextParentTableNoRelation, table.ParentTable.Name, table.Name), this);
                        }
                    }

                    #endregion

                    #region Check for inherit heirarchy that all tables are modifiable or not modifiable

                    //If this table is Mutable then make sure it is NOT derived from an Immutable table
                    if (!table.Immutable)
                    {
                        var   immutableCount = 0;
                        Table immutableTable = null;
                        foreach (var h in heirList)
                        {
                            if (h.Immutable)
                            {
                                if (immutableTable == null)
                                {
                                    immutableTable = h;
                                }
                                immutableCount++;
                            }
                        }

                        //If the counts are different then show errors
                        if (immutableCount > 0)
                        {
                            retval.Add(MessageTypeConstants.Error, string.Format(ValidationHelper.ErrorTextMutableInherit, table.Name, immutableTable.Name), this);
                        }
                    }

                    #endregion

                    #region Check that all tables in inheritance chain are generated

                    {
                        var   nonGenCount = 0;
                        Table nonGenTable = null;
                        foreach (var h in heirList)
                        {
                            if (!h.Generated)
                            {
                                if (nonGenTable == null)
                                {
                                    nonGenTable = h;
                                }
                                nonGenCount++;
                            }
                        }

                        //If the counts are different then show errors
                        if (nonGenCount > 0)
                        {
                            retval.Add(MessageTypeConstants.Error, string.Format(ValidationHelper.ErrorTextBaseTableNonGenerated, nonGenTable.Name, table.Name), this);
                        }
                    }

                    #endregion

                    #region Type Tables must be immutable

                    if (table.IsTypeTable & !table.Immutable)
                    {
                        retval.Add(MessageTypeConstants.Error, string.Format(ValidationHelper.ErrorTextTypeTableIsMutable, table.Name), this);
                    }

                    #endregion

                    #region Type Tables must have specific columns and data

                    if (table.IsTypeTable && (table.PrimaryKeyColumns.Count > 0))
                    {
                        //Mast have one PK that is integer type
                        if ((table.PrimaryKeyColumns.Count > 1) || !((Column)table.PrimaryKeyColumns[0]).IsIntegerType)
                        {
                            retval.Add(MessageTypeConstants.Error, string.Format(ValidationHelper.ErrorTextTypeTablePrimaryKey, table.Name), this);
                        }

                        //Must have static data
                        if (table.StaticData.Count == 0)
                        {
                            retval.Add(MessageTypeConstants.Error, string.Format(ValidationHelper.ErrorTextTypeTableNoData, table.CodeFacade), this);
                        }

                        //Must have a "Name" or "Description" field
                        var typeTableTextField = table.GetColumns().FirstOrDefault(x => x.Name.ToLower() == "name");
                        if (typeTableTextField == null)
                        {
                            typeTableTextField = table.GetColumns().FirstOrDefault(x => x.Name.ToLower() == "description");
                        }
                        if (typeTableTextField == null)
                        {
                            retval.Add(MessageTypeConstants.Error, string.Format(ValidationHelper.ErrorTextTypeTableTextField, table.Name), this);
                        }
                        else
                        {
                            //Verify that type tables have data
                            foreach (RowEntry row in table.StaticData)
                            {
                                //Primary key must be set
                                var cell = row.CellEntries[((Column)table.PrimaryKeyColumns[0]).Name];
                                if (cell == null)
                                {
                                    retval.Add(MessageTypeConstants.Error, string.Format(ValidationHelper.ErrorTextTypeTableStaticDataEmpty, table.Name), this);
                                }
                                else if (string.IsNullOrEmpty(cell.Value))
                                {
                                    retval.Add(MessageTypeConstants.Error, string.Format(ValidationHelper.ErrorTextTypeTableStaticDataEmpty, table.Name), this);
                                }

                                //Enum name must be set
                                cell = row.CellEntries[typeTableTextField.Name];
                                if (cell == null)
                                {
                                    retval.Add(MessageTypeConstants.Error, string.Format(ValidationHelper.ErrorTextTypeTableStaticDataEmpty, table.Name), this);
                                }
                                else if (string.IsNullOrEmpty(cell.Value))
                                {
                                    retval.Add(MessageTypeConstants.Error, string.Format(ValidationHelper.ErrorTextTypeTableStaticDataEmpty, table.Name), this);
                                }
                            }
                        }

                        //Verify that the static data is not duplicated
                        var staticDataIdentifierList = new List <string>();
                        foreach (RowEntry rowEntry in table.StaticData)
                        {
                            var id = rowEntry.GetCodeIdentifier(table);
                            if (!staticDataIdentifierList.Contains(id))
                            {
                                staticDataIdentifierList.Add(id);
                            }
                            else
                            {
                                retval.Add(MessageTypeConstants.Error, string.Format(ValidationHelper.ErrorTextDuplicateStaticData, id, table.Name), this);
                            }
                        }
                    }

                    #endregion

                    #region Audit Fields must go down to base table

                    //Ensure that audit fields are down in 1st base class
                    foreach (var t in heirList)
                    {
                        if (t.AllowCreateAudit != table.AllowCreateAudit)
                        {
                            retval.Add(MessageTypeConstants.Error, string.Format(ValidationHelper.ErrorTextAuditFieldMatchBase, table.Name), this);
                        }
                    }
                    foreach (var t in heirList)
                    {
                        if (t.AllowModifiedAudit != table.AllowModifiedAudit)
                        {
                            retval.Add(MessageTypeConstants.Error, string.Format(ValidationHelper.ErrorTextAuditFieldMatchBase, table.Name), this);
                        }
                    }
                    foreach (var t in heirList)
                    {
                        if (t.AllowTimestamp != table.AllowTimestamp)
                        {
                            retval.Add(MessageTypeConstants.Error, string.Format(ValidationHelper.ErrorTextAuditFieldMatchBase, table.Name), this);
                        }
                    }

                    #endregion

                    #region Self-ref table MUST have role name

                    #endregion

                    #region Self-ref table cannot map child column to PK field

                    foreach (Reference reference in table.Relationships)
                    {
                        var relation    = (Relation)reference.Object;
                        var parentTable = (Table)relation.ParentTableRef.Object;
                        var childTable  = (Table)relation.ChildTableRef.Object;
                        if (parentTable == childTable)
                        {
                            if (string.IsNullOrEmpty(relation.RoleName))
                            {
                                retval.Add(MessageTypeConstants.Error, string.Format(ValidationHelper.ErrorTextSelfRefMustHaveRole, table.Name), this);
                            }
                            else
                            {
                                foreach (ColumnRelationship columnRelationShip in relation.ColumnRelationships)
                                {
                                    if (table.PrimaryKeyColumns.Contains((Column)columnRelationShip.ChildColumnRef.Object))
                                    {
                                        retval.Add(MessageTypeConstants.Error, string.Format(ValidationHelper.ErrorTextSelfRefChildColumnPK, table.Name), this);
                                    }
                                }
                            }
                        }
                    }

                    #endregion

                    #region There can be only 1 self reference per table

                    if (table.AllRelationships.Count(x => x.ChildTableRef == x.ParentTableRef) > 1)
                    {
                        retval.Add(MessageTypeConstants.Error, string.Format(ValidationHelper.ErrorTextSelfRefOnlyOne, table.Name), this);
                    }

                    #endregion

                    #region Verify Relations

                    var relationList = new List <string>();
                    foreach (Relation relation in table.GetRelations())
                    {
                        var key         = string.Empty;
                        var parentTable = (Table)relation.ParentTableRef.Object;
                        var childTable  = (Table)relation.ChildTableRef.Object;
                        var foreignKeys = new List <Column>();
                        foreach (var columnRelationship in relation.ColumnRelationships.ToList())
                        {
                            var parentColumn = (Column)columnRelationship.ParentColumnRef.Object;
                            var childColumn  = (Column)columnRelationship.ChildColumnRef.Object;
                            if (!string.IsNullOrEmpty(key))
                            {
                                key += ", ";
                            }
                            key += parentTable.Name + "." + childColumn.Name + " -> " + childTable.Name + "." + parentColumn.Name;
                            if ((parentColumn.Identity == IdentityTypeConstants.Database) &&
                                (childColumn.Identity == IdentityTypeConstants.Database))
                            {
                                retval.Add(MessageTypeConstants.Error, string.Format(ValidationHelper.ErrorTextChildTableRelationIdentity, childTable.Name, parentTable.Name), this);
                            }

                            if (foreignKeys.Contains(childColumn))
                            {
                                retval.Add(MessageTypeConstants.Error, string.Format(ValidationHelper.ErrorTextMultiFieldRelationsMapDifferentFields, childTable.Name, parentTable.Name), this);
                            }
                            foreignKeys.Add(childColumn);

                            //Verify that field name does not match foreign table name
                            if (childColumn.PascalName == parentTable.PascalName)
                            {
                                retval.Add(MessageTypeConstants.Error, string.Format(ValidationHelper.ErrorTextRelationFieldNotMatchAssociatedTable, parentTable.Name, childTable.Name), this);
                            }
                        }

                        //Role names cannot start with number
                        if (relation.PascalRoleName.Length > 0)
                        {
                            var roleFirstChar = relation.PascalRoleName[0];
                            if ("0123456789".Contains(roleFirstChar))
                            {
                                retval.Add(MessageTypeConstants.Error, string.Format(ValidationHelper.ErrorTextRoleNoStartNumber, key), this);
                            }
                        }

                        //Verify that relations are not duplicated (T1.C1 -> T2.C2)
                        if (!relationList.Contains(relation.PascalRoleName + "|" + key))
                        {
                            relationList.Add(relation.PascalRoleName + "|" + key);
                        }
                        else
                        {
                            retval.Add(MessageTypeConstants.Error, string.Format(ValidationHelper.ErrorTextDuplicateRelation, key), this);
                        }
                    }

                    //Look for duplication relations based on child tables too
                    //Check the full table hierarchy for relations
                    relationList.Clear();
                    foreach (var relation in table.GetRelationsFullHierarchy().Where(x => !x.IsInherited && (x.ChildTableRef.Object != table)))
                    {
                        var key         = string.Empty;
                        var parentTable = (Table)relation.ParentTableRef.Object;
                        var childTable  = (Table)relation.ChildTableRef.Object;

                        if (!table.IsInheritedFrom(childTable))
                        {
                            if (relation.IsOneToOne)
                            {
                                key = relation.PascalRoleName + childTable.PascalName;
                            }
                            else
                            {
                                key = relation.PascalRoleName + childTable.PascalName + "List";
                            }

                            //Verify that relations are not duplicated (T1.C1 -> T2.C2)
                            if (!relationList.Contains(key))
                            {
                                relationList.Add(key);
                            }
                            else
                            {
                                retval.Add(MessageTypeConstants.Error, string.Format(ValidationHelper.ErrorTextDuplicateRelationFullHierarchy, table.Name, childTable.Name), this);
                            }
                        }
                    }

                    //Verify M:N relations have same role name on both sides
                    foreach (var relation in table.GetRelations().Where(x => x.IsManyToMany))
                    {
                        var relation2 = relation.GetAssociativeOtherRelation();
                        if (relation2 == null)
                        {
                            //TODO
                        }
                        else if (relation.RoleName != relation.GetAssociativeOtherRelation().RoleName)
                        {
                            retval.Add(MessageTypeConstants.Error, string.Format(ValidationHelper.ErrorTextRelationM_NRoleMismatch, relation.ChildTable.Name), this);
                        }
                    }

                    //Verify M:N relations do not map to same property names
                    //This can happen if 2 M:N tables are defined between the same two tables...(why people do this I do not know)
                    relationList.Clear();
                    foreach (var relation in table.GetRelations().Where(x => x.IsManyToMany))
                    {
                        var relation2 = relation.GetAssociativeOtherRelation();
                        if (relation2 == null)
                        {
                            //TODO
                        }
                        else
                        {
                            var mappedName = relation.RoleName + "|" + relation.GetSecondaryAssociativeTable().Name;
                            if (relationList.Contains(mappedName))
                            {
                                retval.Add(MessageTypeConstants.Error, string.Format(ValidationHelper.ErrorTextRelationM_NNameDuplication, table.Name, relation.GetSecondaryAssociativeTable().Name), this);
                            }
                            else
                            {
                                relationList.Add(mappedName);
                            }
                        }
                    }

                    {
                        //Verify that if related to an associative table I do not also have a direct link
                        var relatedTables = new List <string>();
                        foreach (var relation in table.GetRelations().ToList())
                        {
                            if (relation.IsManyToMany)
                            {
                                relatedTables.Add(relation.GetSecondaryAssociativeTable().PascalName + relation.RoleName);
                            }
                        }

                        //Now verify that I have no relation to them
                        var invalid = false;
                        foreach (var relation in table.GetRelations().ToList())
                        {
                            if (!relation.IsManyToMany)
                            {
                                if (relatedTables.Contains(relation.ChildTable.PascalName + relation.RoleName))
                                {
                                    invalid = true;
                                }
                            }
                        }

                        if (invalid)
                        {
                            retval.Add(MessageTypeConstants.Error, string.Format(ValidationHelper.ErrorTextRelationCausesNameConflict, table.Name, relatedTables.First()), this);
                        }
                    }

                    //Only 1 relation can exist from A->B on the same columns
                    {
                        var hashList = new List <string>();
                        var rList    = table.GetRelations().Where(x => x.ParentTable.Generated && x.ChildTable.Generated).ToList();
                        foreach (var r in rList)
                        {
                            if (!hashList.Contains(r.LinkHash))
                            {
                                hashList.Add(r.LinkHash);
                            }
                        }
                        if (rList.Count != hashList.Count)
                        {
                            retval.Add(MessageTypeConstants.Error, string.Format(ValidationHelper.ErrorTextRelationDuplicate, table.Name), this);
                        }
                    }

                    #endregion

                    #region Associative Tables

                    if (table.AssociativeTable)
                    {
                        var count = 0;
                        foreach (var relation in ((ModelRoot)_object.Root).Database.Relations.ToList())
                        {
                            if (relation.ChildTableRef.Object == table)
                            {
                                count++;
                            }
                        }
                        if (count != 2)
                        {
                            retval.Add(MessageTypeConstants.Error, string.Format(ValidationHelper.ErrorTextAssociativeTableMustHave2Relations, table.Name, count), this);
                        }

                        //Associative tables cannot be inherited
                        if (table.ParentTable != null)
                        {
                            retval.Add(MessageTypeConstants.Error, string.Format(ValidationHelper.ErrorTextAssociativeTableNotInherited, table.Name), this);
                        }
                    }

                    #endregion

                    #region There can be only 1 Identity per table

                    var identityCount = table.GetColumns().Count(x => x.Identity == IdentityTypeConstants.Database);
                    if (identityCount > 1)
                    {
                        //If there is an identity column, it can be the only PK
                        retval.Add(MessageTypeConstants.Error, string.Format(ValidationHelper.ErrorTextIdentityOnlyOnePerTable, table.Name), this);
                    }

                    #endregion

                    #region Identity PK can be only PK

                    var pkIdentityCount = table.PrimaryKeyColumns.Count(x => x.Identity != IdentityTypeConstants.None);
                    if ((pkIdentityCount > 0) && (table.PrimaryKeyColumns.Count != pkIdentityCount))
                    {
                        //If there is an identity column, it can be the only PK
                        retval.Add(MessageTypeConstants.Warning, string.Format(ValidationHelper.ErrorTextIdentityPKNotOnlyKey, table.Name), this);
                    }

                    #endregion

                    #region Associative table cannot be immutable

                    if (table.AssociativeTable & table.Immutable)
                    {
                        retval.Add(MessageTypeConstants.Error, ValidationHelper.ErrorTextAssociativeTableNotImmutable, this);
                    }

                    #endregion

                    #region Tables must have a non-identity column

                    if (!table.Immutable)
                    {
                        if (table.GetColumns().Count(x => x.Identity == IdentityTypeConstants.Database) == table.GetColumns().Count(x => x.Generated))
                        {
                            retval.Add(MessageTypeConstants.Error, string.Format(ValidationHelper.ErrorTextTableNotHave1IdentityOnly, table.Name), this);
                        }
                    }

                    #endregion

                    #region AllowAuditTracking

                    //if (table.AllowAuditTracking && table.AssociativeTable)
                    //{
                    //  retval.Add(MessageTypeConstants.Error, string.Format(ValidationHelper.ErrorTextTableAssociativeNoAuditTracking, table.Name), this);
                    //}

                    #endregion

                    #region Associative must have non-overlapping PK column

                    if (table.AssociativeTable)
                    {
                        var rlist = table.GetRelationsWhereChild().ToList();
                        if (rlist.Count == 2)
                        {
                            var r1 = rlist.First();
                            var r2 = rlist.Last();
                            if (table.PrimaryKeyColumns.Count != r1.ParentTable.PrimaryKeyColumns.Count + r2.ParentTable.PrimaryKeyColumns.Count)
                            {
                                retval.Add(MessageTypeConstants.Error, string.Format(ValidationHelper.ErrorTextTableAssociativeNeedsNonOverlappingColumns, table.Name), this);
                            }
                        }
                    }

                    #endregion

                    #region Verify Static Data
                    var dataValid = true;
                    foreach (var entry in table.StaticData.OfType <RowEntry>())
                    {
                        foreach (var cell in entry.CellEntries.OfType <CellEntry>())
                        {
                            if (!cell.IsDataValid())
                            {
                                dataValid = false;
                            }
                        }
                    }
                    if (!dataValid)
                    {
                        retval.Add(MessageTypeConstants.Error, string.Format(ValidationHelper.ErrorTextTableBadStaticData, table.Name), this);
                    }
                    #endregion
                }

                return(retval);
            }
            catch (Exception ex)
            {
                throw;
            }
            finally
            {
                Application.DoEvents();
            }
        }
		public override MessageCollection Verify()
		{
			try
			{
				var retval = new MessageCollection();
				retval.AddRange(base.Verify());

				//Check for duplicate names
				var nameList = new Hashtable();
				foreach(CustomView customView in (CustomViewCollection)this.Object)
				{
					if(customView.Generated)
					{
						var name = customView.Name.ToLower();
						if(nameList.ContainsKey(name))
							retval.Add(MessageTypeConstants.Error, string.Format(ValidationHelper.ErrorTextDuplicateName, name), this);
						else
							nameList.Add(name, string.Empty);
					}
				}

				return retval;

			}
			catch(Exception ex)
			{
				throw;
			}

		}
Пример #26
0
		public virtual MessageCollection Verify()
		{
			try
			{
				var retval = new MessageCollection();
				foreach (ModelObjectTreeNode node in this.Node.Nodes)
					retval.AddRange(((BaseModelObjectController)node.Controller).Verify());
				return retval;
			}
			catch (Exception ex)
			{
				throw;
			}
		}
Пример #27
0
		public override MessageCollection Verify()
		{
			try
			{
				var retval = new MessageCollection();
				retval.AddRange(base.Verify());

				var tableCollection = (TableCollection)this.Object;

				#region Check for zero tables
				if (tableCollection.Count == 0)
				{
					retval.Add(MessageTypeConstants.Error, ValidationHelper.ErrorTextNoTables, this);
				}
				#endregion

				#region Check for duplicate names
				var nameList = new Hashtable();
				foreach (Table table in tableCollection)
				{
					if (table.Generated)
					{
						var name = table.Name.ToLower();
						if (nameList.ContainsKey(name))
							retval.Add(MessageTypeConstants.Error, string.Format(ValidationHelper.ErrorTextDuplicateName, table.Name), table.Controller);
						else
							nameList.Add(name, string.Empty);
					}
				}
				#endregion

				#region Check for duplication relationship names

				var duplicateList = new Dictionary<string, RelationshipChecker>();
				foreach (Table table in tableCollection)
				{
					foreach (Reference reference in table.Relationships)
					{
						var relation = (Relation)reference.Object;
						var childTable = (Table)relation.ChildTableRef.Object;
						if (childTable != null)
						{
							var key = string.Empty;
							if (StringHelper.Match(table.Name, childTable.Name, true))
							{
								if (string.Compare(table.Name, childTable.Name, false) < 0)
									key = childTable.Name + "|" + relation.RoleName + "|" + table.Name;
								else
									key = table.Name + "|" + relation.RoleName + "|" + childTable.Name;
							}
							else
							{
								if (string.Compare(table.Name, childTable.Name, false) < 0)
									key = table.Name + "|" + relation.RoleName + "|" + childTable.Name;
								else
									key = childTable.Name + "|" + relation.RoleName + "|" + table.Name;
							}

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

					}

				}

				foreach (var key in duplicateList.Keys)
				{
					if (duplicateList[key].TableList.Count > 1)
					{
						var t1 = ((Table)duplicateList[key].Relationship.ChildTableRef.Object).Name;
						var t2 = ((Table)duplicateList[key].Relationship.ParentTableRef.Object).Name;
						retval.Add(MessageTypeConstants.Error, string.Format(ValidationHelper.ErrorTextConflictingRelationships, "'" + t1 + "' and '" + t2 + "'"), duplicateList[key].TableList[0].Controller);
					}
				}

				#endregion

				#region Check for duplicate codefacades
				if (retval.Count == 0)
				{
					nameList = new Hashtable();
					foreach (Table table in tableCollection)
					{
						if (table.Generated)
						{
							var name = table.PascalName.ToLower();
							if (nameList.ContainsKey(name))
								retval.Add(MessageTypeConstants.Error, string.Format(ValidationHelper.ErrorTextDuplicateCodeFacade, table.Name), table.Controller);
							else
								nameList.Add(name, string.Empty);
						}
					}
				}
				#endregion

				return retval;

			}
			catch (Exception ex)
			{
				throw;
			}
			finally
			{
				Application.DoEvents();
			}

		}
Пример #28
0
        public override MessageCollection Verify()
        {
            try
            {
                var retval = new MessageCollection();
                retval.AddRange(base.Verify());

                var tableCollection = (TableCollection)this.Object;

                #region Check for zero tables
                if (tableCollection.Count == 0)
                {
                    retval.Add(MessageTypeConstants.Error, ValidationHelper.ErrorTextNoTables, this);
                }
                #endregion

                #region Check for duplicate names
                var nameList = new Hashtable();
                foreach (Table table in tableCollection)
                {
                    if (table.Generated)
                    {
                        var name = table.Name.ToLower();
                        if (nameList.ContainsKey(name))
                        {
                            retval.Add(MessageTypeConstants.Error, string.Format(ValidationHelper.ErrorTextDuplicateName, table.Name), table.Controller);
                        }
                        else
                        {
                            nameList.Add(name, string.Empty);
                        }
                    }
                }
                #endregion

                #region Check for duplication relationship names

                var duplicateList = new Dictionary <string, RelationshipChecker>();
                foreach (Table table in tableCollection)
                {
                    foreach (Reference reference in table.Relationships)
                    {
                        var relation   = (Relation)reference.Object;
                        var childTable = (Table)relation.ChildTableRef.Object;
                        if (childTable != null)
                        {
                            var key = string.Empty;
                            if (StringHelper.Match(table.Name, childTable.Name, true))
                            {
                                if (string.Compare(table.Name, childTable.Name, false) < 0)
                                {
                                    key = childTable.Name + "|" + relation.RoleName + "|" + table.Name;
                                }
                                else
                                {
                                    key = table.Name + "|" + relation.RoleName + "|" + childTable.Name;
                                }
                            }
                            else
                            {
                                if (string.Compare(table.Name, childTable.Name, false) < 0)
                                {
                                    key = table.Name + "|" + relation.RoleName + "|" + childTable.Name;
                                }
                                else
                                {
                                    key = childTable.Name + "|" + relation.RoleName + "|" + table.Name;
                                }
                            }

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

                foreach (var key in duplicateList.Keys)
                {
                    if (duplicateList[key].TableList.Count > 1)
                    {
                        var t1 = ((Table)duplicateList[key].Relationship.ChildTableRef.Object).Name;
                        var t2 = ((Table)duplicateList[key].Relationship.ParentTableRef.Object).Name;
                        retval.Add(MessageTypeConstants.Error, string.Format(ValidationHelper.ErrorTextConflictingRelationships, "'" + t1 + "' and '" + t2 + "'"), duplicateList[key].TableList[0].Controller);
                    }
                }

                #endregion

                #region Check for duplicate codefacades
                if (retval.Count == 0)
                {
                    nameList = new Hashtable();
                    foreach (Table table in tableCollection)
                    {
                        if (table.Generated)
                        {
                            var name = table.PascalName.ToLower();
                            if (nameList.ContainsKey(name))
                            {
                                retval.Add(MessageTypeConstants.Error, string.Format(ValidationHelper.ErrorTextDuplicateCodeFacade, table.Name), table.Controller);
                            }
                            else
                            {
                                nameList.Add(name, string.Empty);
                            }
                        }
                    }
                }
                #endregion

                return(retval);
            }
            catch (Exception ex)
            {
                throw;
            }
            finally
            {
                Application.DoEvents();
            }
        }
		public override MessageCollection Verify()
		{
			try
			{
				var retval = new MessageCollection();
				retval.AddRange(base.Verify());

				//Check for duplicate names
				var nameList = new Hashtable();
				var referenceCollection = (ReferenceCollection)this.Object;
				foreach(Reference reference in referenceCollection)
				{
					var customViewColumn = (CustomViewColumn)reference.Object;
					var name = customViewColumn.Name.ToLower();
					if(nameList.ContainsKey(name))
						retval.Add(MessageTypeConstants.Error, string.Format(ValidationHelper.ErrorTextDuplicateName, name), customViewColumn.Controller);
					else
						nameList.Add(name, string.Empty);
				}

				//CustomViewColumn testCustomViewColumn = (CustomViewColumn)referenceCollection[0].Object;
				//if(!((CustomViewColumn)testCustomViewColumn.ParentViewRef.Object).Generated)
				//  return retval;

				return retval;

			}
			catch(Exception ex)
			{
				throw;
			}
		}
 /// <summary>
 /// Executes the send pipeline with all messages
 /// provided as inputs
 /// </summary>
 /// <param name="inputMessages">One or more input messages to the pipeline</param>
 /// <returns>The single output message</returns>
 public IBaseMessage Execute(params IBaseMessage[] inputMessages)
 {
    MessageCollection inputs = new MessageCollection();
    inputs.AddRange(inputMessages);
    return Execute(inputs);
 }
Пример #31
0
		public override MessageCollection Verify()
		{
			try
			{
				var retval = new MessageCollection();
				retval.AddRange(base.Verify());

				var customAggregate = (CustomAggregate)this.Object;
				if(customAggregate.Generated)
				{
					//Check valid name
					if (!ValidationHelper.ValidDatabaseIdenitifer(customAggregate.DatabaseName))
						retval.Add(MessageTypeConstants.Error, string.Format(ValidationHelper.ErrorTextInvalidIdentifier, customAggregate.Name), this);
					if (!ValidationHelper.ValidCodeIdentifier(customAggregate.PascalName))
						retval.Add(MessageTypeConstants.Error, string.Format(ValidationHelper.ErrorTextInvalidIdentifier, customAggregate.Name), this);

					//Check Aggregate SQL
					if (string.IsNullOrEmpty(customAggregate.SQL))
						retval.Add(MessageTypeConstants.Error, ValidationHelper.ErrorTextSQLRequired, this);

					//Check that object has at least one generated column
					if(customAggregate.GeneratedColumns.Count() == 0)
						retval.Add(MessageTypeConstants.Error, ValidationHelper.ErrorTextColumnsRequired, this);

				}

				return retval;

			}
			catch(Exception ex)
			{
				throw;
			}

		}
		public override MessageCollection Verify()
		{
			try
			{
				var retval = new MessageCollection();
				retval.AddRange(base.Verify());

				//Check for duplicate names
				var nameList = new Hashtable();
				var list = this.Object as CustomAggregateCollection;
				foreach (var item in list.Where(x => x.Generated))
				{
					var name = item.Name.ToLower();
					if (nameList.ContainsKey(name))
						retval.Add(MessageTypeConstants.Error, string.Format(ValidationHelper.ErrorTextDuplicateName, name), item.Controller);
					else
						nameList.Add(name, string.Empty);
				}

				return retval;

			}
			catch(Exception ex)
			{
				throw;
			}

		}