Example #1
0
 public static void isValid_HasPersistentOrder(RelationEnd obj, PropertyIsValidEventArgs e)
 {
     if (obj.HasPersistentOrder && obj.Multiplicity != Multiplicity.ZeroOrMore)
     {
         e.IsValid = false;
         e.Error = String.Format("Can only require persistent order when multiplicity is ZeroOrMore, but multiplicity is {0}", obj.Multiplicity);
     }
 }
Example #2
0
 public static void isValid_NextStates(StateChangeDefinition obj, PropertyIsValidEventArgs e)
 {
     // Check if next states are member of the same workflow definition
     if (obj.StateDefinition != null)
     {
         var invalidNextStates = obj.NextStates.Where(ns => ns.WFDefinition != obj.StateDefinition.WFDefinition).ToList();
         e.IsValid = invalidNextStates.Count == 0;
         e.Error   = e.IsValid ? string.Empty : "At least one next state does not belong to the same workflow. These states are: " + string.Join(", ", invalidNextStates.Select(ns => ns.Name).ToArray());
     }
 }
Example #3
0
 public static void isValid_InvokedByActions(StateChangeDefinition obj, PropertyIsValidEventArgs e)
 {
     // Check if actions invoke only one state change
     if (obj.StateDefinition != null)
     {
         var allOtherActions = obj.StateDefinition.StateChanges.Except(new[] { obj }).SelectMany(sc => sc.InvokedByActions);
         var actions         = allOtherActions.Intersect(obj.InvokedByActions).ToList();
         e.IsValid = actions.Count == 0;
         e.Error   = e.IsValid ? string.Empty : "A Action is invoking more than one state change. This state change is one of it. Actions found: " + string.Join(", ", actions.Select(a => a.Action.Name).ToArray());
     }
 }
Example #4
0
 public static void isValid_FulfillmentDate(Receipt obj, PropertyIsValidEventArgs e)
 {
     if (obj.FulfillmentDate.HasValue && obj.Status.In(ReceiptStatus.Open, ReceiptStatus.Canceled))
     {
         e.IsValid = false;
         e.Error   = "Current status does not allow a fullfillment date";
     }
     else if (!obj.FulfillmentDate.HasValue && obj.Status.In(ReceiptStatus.Fulfilled, ReceiptStatus.Partial, ReceiptStatus.WriteOff))
     {
         e.IsValid = false;
         e.Error   = "Current status requieres a Fulfillment date";
     }
     else
     {
         e.IsValid = true;
     }
 }
Example #5
0
 public static void isValid_DatumVon(Task obj, PropertyIsValidEventArgs e)
 {
     e.IsValid = !obj.IsInitialized("DatumBis") || obj.DatumBis >= obj.DatumVon || obj.DatumBis == null;
     e.Error = e.IsValid ? string.Empty : "Falsches Zeitalter";
 }
Example #6
0
 public static void isValid_Aufwand(Task obj, PropertyIsValidEventArgs e)
 {
     e.IsValid = obj.Aufwand >= 0;
     e.Error = e.IsValid ? string.Empty : "Ungültiger Aufwand";
 }
Example #7
0
 public static void isValid_KickOffBis(Projekt obj, PropertyIsValidEventArgs e)
 {
     e.IsValid = obj.KickOffBis == null || obj.KickOffBis >= obj.KickOffAm;
     e.Error = e.IsValid ? string.Empty : "Bis-Datum ist leer oder liegt vor dem Von-Datum";
 }
Example #8
0
 public static void isValid_DatumBis(Task obj, PropertyIsValidEventArgs e)
 {
     e.IsValid = !obj.IsInitialized("DatumVon") || obj.DatumBis >= obj.DatumVon || obj.DatumBis == null;
     e.Error   = e.IsValid ? string.Empty : "Falsches Zeitalter";
 }
Example #9
0
 public static void isValid_Aufwand(Task obj, PropertyIsValidEventArgs e)
 {
     e.IsValid = obj.Aufwand >= 0;
     e.Error   = e.IsValid ? string.Empty : "Ungültiger Aufwand";
 }
Example #10
0
        public static void isValid_Name(Property obj, PropertyIsValidEventArgs e)
        {
            e.IsValid = true;
            var dataType = obj.ObjectClass;
            while (dataType != null)
            {
                if (dataType.Properties.Where(p => p != obj && p.Name == obj.Name).Count() > 0)
                {
                    e.IsValid = false;
                }

                var cls = dataType as ObjectClass;
                if (cls != null)
                {
                    dataType = cls.BaseObjectClass;
                }
                else
                {
                    break;
                }
            }
            e.Error = e.IsValid ? string.Empty : "Propertyname is not unique";
        }
Example #11
0
        public static void isValid_DefaultSortPriority(Property obj, PropertyIsValidEventArgs e)
        {
            var cls = obj.ObjectClass;
            if (cls == null || obj.DefaultSortPriority == null)
            {
                e.IsValid = true;
                return;
            }

            var other = cls.Properties
                                .Except(new[] { obj })
                                .Where(p => p.DefaultSortPriority == obj.DefaultSortPriority)
                                .ToList();
            e.IsValid = other.Count == 0;
            e.Error = e.IsValid
                ? string.Empty
                : string.Format("{0} other property/ies have the same default sort priority: {1}", other.Count, string.Join(", ", other.Select(p => p.Name)));
        }
Example #12
0
        public static void isValid_Storage(Relation obj, PropertyIsValidEventArgs e)
        {
            var rel = obj;
            if (rel.A != null && rel.B != null)
            {
                if (rel.A.Multiplicity == 0 || rel.B.Multiplicity == 0)
                {
                    e.IsValid = false;
                    e.Error = "Incomplete Relation (Multiplicity is missing)";
                    return;
                }
                var aUpper = rel.A.Multiplicity.UpperBound();
                var bUpper = rel.B.Multiplicity.UpperBound();

                switch (rel.Storage)
                {
                    case StorageType.MergeIntoA:
                        e.IsValid = bUpper <= 1;
                        if (!e.IsValid) e.Error = "B side could be more than one. Not able to merge foreign key into A";
                        break;
                    case StorageType.MergeIntoB:
                        e.IsValid = aUpper <= 1;
                        if (!e.IsValid) e.Error = "A side could be more than one. Not able to merge foreign key into B";
                        break;
                    case StorageType.Separate:
                        e.IsValid = aUpper > 1 && bUpper > 1;
                        if (!e.IsValid)
                        {
                            if (aUpper <= 1 && bUpper <= 1)
                            {
                                e.Error = "A side is only one-ary. Please use MergeIntoA or MergeIntoB";
                            }
                            else if (aUpper <= 1)
                            {
                                e.Error = "A side is only one-ary. Please use MergeIntoB";
                            }
                            else if (bUpper <= 1)
                            {
                                e.Error = "B side is only one-ary. Please use MergeIntoA";
                            }
                        }
                        break;
                    case StorageType.Replicate:
                    default:
                        e.IsValid = false;
                        e.Error = String.Format("StorageType.{0} not implemented.", rel.Storage);
                        break;
                }
            }
            else
            {
                e.IsValid = false;
                e.Error = "Incomplete Relation (A or B missing)";
            }
        }
Example #13
0
        public static void isValid_Containment(Relation obj, PropertyIsValidEventArgs e)
        {
            var rel = obj;
            if (rel.A != null && rel.B != null)
            {
                if (rel.A.Multiplicity == 0 || rel.B.Multiplicity == 0)
                {
                    e.IsValid = false;
                    e.Error = "Incomplete Relation (A.Multiplicity or B.Multiplicity missing)";
                    return;
                }

                var relType = rel.GetRelationType();

                switch (rel.Containment)
                {
                    case ContainmentSpecification.AContainsB:
                        if (relType == RelationType.n_m)
                        {
                            e.IsValid = false;
                            e.Error = "N:M relations cannot be containment relations";
                        }
                        else if (relType == RelationType.one_n)
                        {
                            e.IsValid = rel.B.Multiplicity.UpperBound() > 1;
                            if (!e.IsValid) e.Error = "Can only contain the N-side of a 1:N relationship (which is A).";
                        }
                        else if (relType == RelationType.one_one)
                        {
                            e.IsValid = true;
                        }
                        else
                        {
                            e.IsValid = false;
                            e.Error = String.Format("RelationType.{0} not implemented.", relType);
                        }
                        break;
                    case ContainmentSpecification.BContainsA:
                        if (relType == RelationType.n_m)
                        {
                            e.IsValid = false;
                            e.Error = "N:M relations cannot be containment relations";
                        }
                        else if (relType == RelationType.one_n)
                        {
                            e.IsValid = rel.A.Multiplicity.UpperBound() > 1;
                            if (!e.IsValid) e.Error = "Can only contain the N-side of a 1:N relationship (which is B).";
                        }
                        else if (relType == RelationType.one_one)
                        {
                            e.IsValid = true;
                        }
                        else
                        {
                            e.IsValid = false;
                            e.Error = String.Format("RelationType.{0} not implemented.", relType);
                        }
                        break;
                    case ContainmentSpecification.Independent:
                        e.IsValid = true;
                        break;
                    default:
                        {
                            e.IsValid = false;
                            e.Error = String.Format("ContainmentType.{0} not implemented.", rel.Containment);
                            break;
                        }
                }
            }
            else
            {
                e.IsValid = false;
                e.Error = "Incomplete Relation (A or B missing)";
            }
        }
Example #14
0
 public static void isValid_TableMapping(ObjectClass obj, PropertyIsValidEventArgs e)
 {
     e.IsValid = obj.TableMapping == null || (obj.TableMapping != null && obj.BaseObjectClass == null);
     e.Error = e.IsValid ? string.Empty : "TableMapping is valid only on base classes.";
 }
Example #15
0
        public static void isValid_Navigator(RelationEnd obj, PropertyIsValidEventArgs e)
        {
            var relEnd = obj;
            var rel = relEnd.GetParent();
            if (rel == null)
            {
                e.IsValid = false;
                e.Error = "No Relation assigned to Relation end";
                return;
            }
            var otherEnd = rel.GetOtherEnd(relEnd);
            var orp = obj.Navigator;

            e.IsValid = true;

            if (orp != null)
            {
                if (orp.ObjectClass == null)
                {
                    e.IsValid = false;
                    e.Error = String.Format("Navigator should be attached to {0}", relEnd.Type);
                }
                if (orp.ObjectClass != relEnd.Type)
                {
                    e.IsValid = false;
                    e.Error = String.Format("Navigator is attached to {0} but should be attached to {1}",
                                orp.ObjectClass,
                                relEnd.Type);
                }

                switch (otherEnd.Multiplicity)
                {
                    case Multiplicity.One:
                        if(orp.Constraints.OfType<NotNullableConstraint>().Count() == 0)
                        {
                            e.IsValid = false;
                            e.Error = "Navigator should have NotNullableConstraint because Multiplicity of opposite RelationEnd is One";
                        }
                        break;
                    case Multiplicity.ZeroOrMore:
                        if(orp.Constraints.OfType<NotNullableConstraint>().Count() > 0)
                        {
                            e.IsValid = false;
                            e.Error = "Navigator should not have NotNullableConstraint because Multiplicity of opposite RelationEnd is ZeroOrMore";
                        }
                        break;
                    case Multiplicity.ZeroOrOne:
                        if(orp.Constraints.OfType<NotNullableConstraint>().Count() > 0)
                        {
                            e.IsValid = false;
                            e.Error = "Navigator should not have NotNullableConstraint because Multiplicity of opposite RelationEnd is ZeroOrOne";
                        }
                        break;
                }
            }
        }
Example #16
0
 public static void isValid_KickOffBis(Projekt obj, PropertyIsValidEventArgs e)
 {
     e.IsValid = obj.KickOffBis == null || obj.KickOffBis >= obj.KickOffAm;
     e.Error   = e.IsValid ? string.Empty : "Bis-Datum ist leer oder liegt vor dem Von-Datum";
 }