Esempio n. 1
0
        private RestrictionDefinition EnsureRestrictionExists(FileModel file)
        {
            var name = $"EntityTypeRestriction";

            var r = file.Parent.Models.GetRestrictionDefinition(name);

            if (r == null)
            {
                string error = "Failed to evaluate '!ibase.name' with the restriction !name -> '!rule'";

                var r2 = new RestrictionDefinition()
                {
                    File          = file,
                    Description   = $"Autogenerated restriction validate the specified name is an Entity name",
                    Name          = name,
                    ErrorMessage  = error,
                    AutoGenerated = true,
                    Kind          = RestrictionKindEnum.TypeRestriction,
                    Value         = $"de:*",
                }.SetRule();

                this._parent.Add(r2);

                return(r2);
            }

            return(r);
        }
Esempio n. 2
0
        public override void RegisterFinal(ProcessDefinition pd, List <WorkflowBlock> blocks)
        {
            base.RegisterFinal(pd, blocks);

            //transitions
            var commands = this["Commands"] as List <SimpleCommand>;

            if (commands != null)
            {
                var restrictions = new List <RestrictionDefinition>();
                if (this["_actorRestrictions"] is ActorDefinition)
                {
                    restrictions.Add(RestrictionDefinition.Create(RestrictionType.Allow, (ActorDefinition)this["_actorRestrictions"]));
                }

                foreach (var c in commands)
                {
                    var pdCommand = pd.Commands.Where(pdc => pdc.Name == c.Name).FirstOrDefault();
                    if (pdCommand == null)
                    {
                        pdCommand = CommandDefinition.Create(c.Name);

                        ParameterDefinition pdParameterComment = pd.Parameters.Where(p => p.Name == "Comment").FirstOrDefault();
                        if (pdParameterComment == null)
                        {
                            pdParameterComment = ParameterDefinition.Create("Comment", typeof(string), ParameterPurpose.Temporary, null);
                            pd.Parameters.Add(pdParameterComment);
                        }

                        pdCommand.InputParameters.Add(new ParameterDefinitionReference()
                        {
                            Name      = "Comment",
                            Parameter = pdParameterComment
                        });
                        pd.Commands.Add(pdCommand);
                    }

                    pd.Transitions.Add(new TransitionDefinition()
                    {
                        Name       = string.Format("{0}_{1}_{2}", Name, c.ToBlock.Name, c.Name),
                        Classifier = c.Classifier,
                        From       = (ActivityDefinition)this["_currentActivity"],
                        To         = (ActivityDefinition)c.ToBlock["_currentActivity"],
                        Trigger    = new TriggerDefinition(TriggerType.Command)
                        {
                            Command = pdCommand
                        },
                        Conditions = new List <ConditionDefinition>()
                        {
                            ConditionDefinition.Always
                        },
                        Restrictions = restrictions
                    });
                }
            }
        }
Esempio n. 3
0
        internal void RemoveDefinition(RestrictionDefinition item)
        {
            var type = item.GetType();

            if (!_definitions.TryGetValue(type, out Dictionary <string, IBase> dic))
            {
                _definitions.Add(type, (dic = new Dictionary <string, IBase>()));
            }
            if (dic.ContainsKey(item.Name))
            {
                dic.Remove(item.Name);
            }
        }
Esempio n. 4
0
        internal void Add(RestrictionDefinition item)
        {
            var type = item.GetType();

            if (!_definitions.TryGetValue(type, out Dictionary <string, IBase> dic))
            {
                dic = new Dictionary <string, IBase>();
                _definitions.Add(type, dic);
            }

            if (dic.ContainsKey(item.Name))
            {
                var oldDefinition = dic[item.Name];
                dic[item.Name] = item;
                //PropagateFileChanged(item);
                return;
            }

            dic.Add(item.Name, item);
            //PropagateFileChanged(item);
        }
Esempio n. 5
0
        private RestrictionDefinition EnsureRestrictionExists(FileModel file, IBase entity, string prefix)
        {
            string _prefix = string.Empty;

            if (prefix == "de")
            {
                _prefix = "Definition";
            }

            else if (prefix == "de")
            {
                _prefix = "Referential";
            }

            var name = $"{entity.Name}Type{_prefix}Restriction";

            var r = file.Parent.Models.GetRestrictionDefinition(name);

            if (r == null)
            {
                string error = "Failed to evaluate '!ibase.name' with the restriction !name -> '!rule'";

                var r2 = new RestrictionDefinition()
                {
                    File          = file,
                    Description   = $"Autogenerated restriction on the {entity.Name} entities",
                    Name          = name,
                    ErrorMessage  = error,
                    AutoGenerated = true,
                    Kind          = RestrictionKindEnum.TypeRestriction,
                    Value         = $"{prefix}:{entity.Name}",
                }.SetRule();

                this._parent.Add(r2);

                return(r2);
            }

            return(r);
        }
Esempio n. 6
0
        public override IEnumerable <TransitionDefinition> ParseTransitions(XElement schemeMedium, IEnumerable <ActorDefinition> actorDefinitions, IEnumerable <CommandDefinition> commandDefinitions, IEnumerable <ActionDefinition> actionDefinitions, IEnumerable <ActivityDefinition> activityDefinitions, IEnumerable <TimerDefinition> timerDefinitions)
        {
            if (schemeMedium == null)
            {
                throw new ArgumentNullException("schemeMedium");
            }
            if (commandDefinitions == null)
            {
                throw new ArgumentNullException("commandDefinitions");
            }
            if (actionDefinitions == null)
            {
                throw new ArgumentNullException("actionDefinitions");
            }
            if (activityDefinitions == null)
            {
                throw new ArgumentNullException("activityDefinitions");
            }
            var transitionElements = schemeMedium.SingleOrDefault("Transitions");

            if (transitionElements == null)
            {
                throw new ArgumentNullException("");
            }

            var commandDefinitionsList  = commandDefinitions.ToList();
            var actionDefinitionsList   = actionDefinitions.ToList();
            var activityDefinitionsList = activityDefinitions.ToList();
            var actorDefinitionsList    = actorDefinitions.ToList();
            var timerDefinitionsList    = timerDefinitions.ToList();

            var transitions = new List <TransitionDefinition>();

            foreach (var transitionElement in transitionElements.Elements().ToList())
            {
                var fromActivity = activityDefinitionsList.Single(ad => ad.Name == GetFrom(transitionElement));
                var toActivity   = activityDefinitionsList.Single(ad => ad.Name == GetTo(transitionElement));

                TriggerDefinition trigger = null;
                var triggersElement       = transitionElement.Element("Triggers");
                if (triggersElement != null)
                {
                    var triggerElement = triggersElement.Element("Trigger");
                    if (triggerElement != null)
                    {
                        trigger = TriggerDefinition.Create(GetType(triggerElement));
                        if (trigger.Type == TriggerType.Command)
                        {
                            (trigger as CommandTriggerDefinition).Command =
                                commandDefinitionsList.Single(cd => cd.Name == GetNameRef(triggerElement));
                        }
                        else if (trigger.Type == TriggerType.Timer)
                        {
                            (trigger as TimerTriggerDefinition).Timer =
                                timerDefinitionsList.Single(cd => cd.Name == GetNameRef(triggerElement));
                        }
                    }
                }

                ConditionDefinition condition = null;
                var conditionsElement         = transitionElement.Element("Conditions");
                if (conditionsElement != null)
                {
                    var conditionElement = conditionsElement.Element("Condition");
                    if (conditionElement != null)
                    {
                        condition = !string.IsNullOrEmpty(GetNameRefNullable(conditionElement))
                                        ? ConditionDefinition.Create(GetType(conditionElement), actionDefinitionsList.Single(ad => ad.Name == GetNameRef(conditionElement)), GetResultOnPreExecution(conditionElement))
                                        : ConditionDefinition.Create(GetType(conditionElement), GetResultOnPreExecution(conditionElement));
                    }
                }

                var transition = TransitionDefinition.Create(GetName(transitionElement), GetClassifier(transitionElement), fromActivity,
                                                             toActivity, trigger, condition);

                var restrictionsElement = transitionElement.Element("Restrictions");
                if (restrictionsElement != null)
                {
                    foreach (var element in restrictionsElement.Elements("Restriction"))
                    {
                        transition.AddRestriction(RestrictionDefinition.Create(GetType(element), actorDefinitionsList.Single(ad => ad.Name == GetNameRef(element))));
                    }
                }

                var onErrorsElement = transitionElement.Element("OnErrors");
                if (onErrorsElement != null)
                {
                    foreach (var element in onErrorsElement.Elements("OnError"))
                    {
                        //TODO Only One Type Of OnErrorHandler
                        transition.AddOnError(OnErrorDefinition.CreateSetActivityOnError(GetName(element), GetNameRef(element), GetPriority(element), GetTypeName(element) /*, GetIsExecuteImplementation(element),GetIsRethrow(element)*/));
                    }
                }
                transitions.Add(transition);
            }


            return(transitions);
        }
Esempio n. 7
0
        public override void RegisterFinal(ProcessDefinition pd, List <WorkflowBlock> blocks)
        {
            //transitions
            var commands = this["Commands"] as List <SimpleCommand>;

            if (commands != null)
            {
                var restrictions = new List <RestrictionDefinition>();
                if (this["_actorRestrictions"] is ActorDefinition)
                {
                    restrictions.Add(RestrictionDefinition.Create(RestrictionType.Allow, (ActorDefinition)this["_actorRestrictions"]));
                }

                foreach (var c in commands)
                {
                    var pdCommand = pd.Commands.Where(pdc => pdc.Name == c.Name).FirstOrDefault();
                    if (pdCommand == null)
                    {
                        pdCommand = CommandDefinition.Create(c.Name);
                        pd.Commands.Add(pdCommand);
                    }

                    if (c.Classifier == TransitionClassifier.Direct)
                    {
                        //CA
                        pd.Transitions.Add(new TransitionDefinition()
                        {
                            Name       = string.Format("{0}_{1}_{2}", Name, c.ToBlock.Name, c.Name),
                            Classifier = c.Classifier,
                            From       = (ActivityDefinition)this["_currentActivity"],
                            To         = (ActivityDefinition)this["_currentActivity"],
                            Trigger    = new TriggerDefinition(TriggerType.Command)
                            {
                                Command = pdCommand
                            },
                            Conditions = new List <ConditionDefinition>()
                            {
                                ConditionDefinition.Always
                            },
                            Restrictions = restrictions
                        });

                        //AC
                        pd.Transitions.Add(new TransitionDefinition()
                        {
                            Name       = string.Format("{0}_{1}_{2}", Name, c.ToBlock.Name, "Auto"),
                            Classifier = c.Classifier,
                            From       = (ActivityDefinition)this["_currentActivity"],
                            To         = (ActivityDefinition)c.ToBlock["_currentActivity"],
                            Trigger    = new TriggerDefinition(TriggerType.Auto),
                            Conditions = new List <ConditionDefinition>()
                            {
                                ConditionDefinition.Create("Action", ActionDefinitionReference.Create("BudgetItemIsLegalEntitySignsComplete", "0", Name), "false", "true")
                            }
                        });
                    }
                    else
                    {
                        pd.Transitions.Add(new TransitionDefinition()
                        {
                            Name       = string.Format("{0}_{1}_{2}", Name, c.ToBlock.Name, c.Name),
                            Classifier = c.Classifier,
                            From       = (ActivityDefinition)this["_currentActivity"],
                            To         = (ActivityDefinition)c.ToBlock["_currentActivity"],
                            Trigger    = new TriggerDefinition(TriggerType.Command)
                            {
                                Command = pdCommand
                            },
                            Conditions = new List <ConditionDefinition>()
                            {
                                ConditionDefinition.Always
                            },
                            Restrictions = restrictions
                        });
                    }
                }
            }
        }
Esempio n. 8
0
        private Transactionfile LoadMetaDefinitions(JObject payload, FileModel file)
        {
            Transactionfile result = new Transactionfile();

            JsonSerializer serializer = new JsonSerializer();

            var model = (MetaDefinitions)serializer.Deserialize(new JTokenReader(payload), typeof(MetaDefinitions));

            var itemRestrictions = this._parent.CollectContentOfFile <RestrictionDefinition>(file).Where(c => !c.AutoGenerated).ToList();

            foreach (var restriction in model.Restrictions)
            {
                restriction.File = file;

                try
                {
                    this._parent.Add(restriction);
                    var p = itemRestrictions.RemoveWhere(c => c.Name == restriction.Name);
                    if (p.Count == 0)
                    {
                        result.Added.Add(restriction);
                    }
                    else
                    {
                        result.Updated.Add(restriction);
                    }
                }
                catch (System.Exception e1)
                {
                    _parent.Diagnostic.Append(
                        new DiagnositcMessage()
                    {
                        Severity  = SeverityEnum.Error,
                        File      = file.FullPath,
                        Exception = e1,
                        Text      = $"Failed to adding entity definition {model.Name}"
                    }
                        );
                }
            }
            foreach (var item in itemRestrictions)
            {
                if (!item.AutoGenerated)
                {
                    this._parent.RemoveDefinition(item);
                    result.Deleted.Add(item);
                }
            }

            var itemEntities = this._parent.CollectContentOfFile <EntityDefinition>(file).ToList();

            foreach (EntityDefinition entity in model.Entities)
            {
                entity.File = file;
                entity.Properties.Insert(0, Property(nameof(ReferentialEntity.Description), "entity's Description", "Specify the description for this entity", string.Empty));
                entity.Properties.Insert(0, Property(nameof(ReferentialEntity.Label), "Label of the entity", "Specify the label for this entity", string.Empty, true));
                entity.Properties.Insert(0, Property(nameof(ReferentialBase.Name), "entity'name", "Specify the functional name of the entity", this._parent.Config.RestrictionNamePattern, true));
                entity.Properties.Insert(0, Property(nameof(ReferentialBase.Id), "entity'key", "Specify the key of the entity", string.Empty, true));

                EnsureRestrictionExists(file, entity, "e");     // create a restriction on the type for use in relation referential

                try
                {
                    this._parent.Add(entity);
                    var p = itemEntities.RemoveWhere(c => c.Name == entity.Name);
                    if (p.Count == 0)
                    {
                        result.Added.Add(entity);
                    }
                    else
                    {
                        result.Updated.Add(entity);
                    }
                }
                catch (System.Exception e1)
                {
                    _parent.Diagnostic.Append(
                        new DiagnositcMessage()
                    {
                        Severity  = SeverityEnum.Error,
                        File      = file.FullPath,
                        Exception = e1,
                        Text      = $"Failed to adding entity definition {model.Name}"
                    }
                        );
                }
            }

            foreach (var item in itemEntities)
            {
                this._parent.RemoveDefinition(item);
                result.Deleted.Add(item);
            }

            var itemLinks = this._parent.CollectContentOfFile <RelationshipDefinition>(file).ToList();

            foreach (RelationshipDefinition relationship in model.Relationships)
            {
                relationship.File = file;
                relationship.Properties.Insert(0, Property(nameof(ReferentialRelationship.Description), "relationship's Description", "Specify the description for this relationship", string.Empty));
                relationship.Properties.Insert(0, Property(nameof(ReferentialRelationship.Label), "Label of the relationship", "Specify the label for this relationship", string.Empty, true));
                relationship.Properties.Insert(0, Property(nameof(ReferentialBase.Name), "entity'key", "Specify the functional name of the entity", this._parent.Config.RestrictionNamePattern, true));
                relationship.Properties.Insert(0, Property(nameof(ReferentialBase.Id), "entity'key", "Specify the key of the entity", string.Empty, true));

                relationship.Origin.Properties.Insert(0, Property(nameof(ModelDefinition.Name), "reference of the entity", "Specify the origin reference.", this._parent.Config.RestrictionNamePattern, true));
                relationship.Target.Properties.Insert(0, Property(nameof(ModelDefinition.Name), "reference of the entity", "Specify the target reference", this._parent.Config.RestrictionNamePattern, true));

                // Add restriction on the name of origin et target
                RestrictionDefinition r = EnsureRestrictionExists(file);
                relationship.Origin.Restrictions.Add(r.Name);
                relationship.Target.Restrictions.Add(r.Name);

                try
                {
                    this._parent.Add(relationship);
                    var p = itemLinks.RemoveWhere(c => c.Name == relationship.Name);
                    if (p.Count == 0)
                    {
                        result.Added.Add(relationship);
                    }
                    else
                    {
                        result.Updated.Add(relationship);
                    }
                }
                catch (System.Exception e)
                {
                    _parent.Diagnostic.Append(
                        new DiagnositcMessage()
                    {
                        Severity  = SeverityEnum.Error,
                        File      = file.FullPath,
                        Exception = e,
                        Text      = $"Failed to adding relationship definition {relationship.Name}"
                    }
                        );
                }
            }

            foreach (var item in itemLinks)
            {
                this._parent.RemoveDefinition(item);
                result.Deleted.Add(item);
            }

            return(result);
        }