Beispiel #1
0
        public override void ConvertElementLogic()
        {
            processReturnFunction = CreateProcessReturnFunction();
            mainFunction          = new SolidityFunction(GetElementCallName(), SolidityVisibility.Internal);
            mainFunction.AddParameters(processConverter.GetIdentifiersAsParameters());
            var calledStartEventConverter = processConverter.ContractConverter.GetStartEventConverter(callActivity);
            var callSubprocessStatement   = calledStartEventConverter.GetStatementForPrevious(callActivity);

            stateTracker = new SolidityStatement($"uint256 {ConversionTemplates.CallActivityCounter(GetElementCallName())}");
            switch (callActivity.InstanceType)
            {
            case InstanceType.Single:
                //Call the subprocess.
                mainFunction.AddToBody(callSubprocessStatement);
                break;

            case InstanceType.Sequential:
                //Call the subprocess and create a counter.
                mainFunction.AddToBody(new SolidityStatement($"{ConversionTemplates.CallActivityCounter(GetElementCallName())} = 0"));
                mainFunction.AddToBody(callSubprocessStatement);
                break;

            case InstanceType.Parallel:
                //Call all of the subprocesses using an identifier, create a counter.
                mainFunction.AddToBody(new SolidityStatement($"{ConversionTemplates.CallActivityCounter(GetElementCallName())} = 0"));
                var solidityForLoop = new SolidityFor(GetLoopVariable(), GetCountTarget(callActivity));
                solidityForLoop.AddToBody(callSubprocessStatement);
                mainFunction.AddToBody(solidityForLoop);
                break;
            }
        }
        SolidityFunction CreateElementMainFunction()
        {
            SolidityFunction function = new SolidityFunction(GetElementCallName(), SolidityVisibility.Public);

            function.AddModifier($"{ConversionTemplates.StateGuardModifierName(GetElementCallName())}({processConverter.GetIdentifierNames()})");
            function.AddParameters(processConverter.GetIdentifiersAsParameters());

            /*
             * if (IsAddressGuardRequired())
             *  function.AddModifier($"{ConversionTemplates.AddressGuardModifierName(GetElementCallName())}({processConverter.GetIdentifierNames()})");
             */

            boundaryEventCalls.ForEach(c => function.AddToBody(c));

            function.AddToBody(new SolidityStatement(userTaskElement.ValidationScript, false));


            if (userTaskElement.Form.Fields != null)
            {
                foreach (var field in userTaskElement.Form.Fields)
                {
                    //TODO: throw exception if no property has been found
                    var propertyAndEntity       = processConverter.GetPropertyAndEntity(field.PropertyExpression);
                    var property                = propertyAndEntity.Item1;
                    var entity                  = propertyAndEntity.Item2;
                    var formPropertyDisplayName = Helpers.ToLowerCamelCase(field.DisplayName);


                    function.AddParameter(new SolidityParameter(Helpers.PropertyTypeToString(property, processConverter.ContractConverter), formPropertyDisplayName));
                }
            }

            function.AddToBody(CreateCallNextBody());
            return(function);
        }
Beispiel #3
0
        SolidityFunction CreateMainFunction()
        {
            var logicFunction = new SolidityFunction($"{GetElementCallName()}", SolidityVisibility.Internal);
            var body          = CreateCallsToOutgoing();

            logicFunction.AddParameters(processConverter.GetIdentifiersAsParameters());

            if (gatewayElement.Incoming.Count == 1)
            {
                logicFunction.AddToBody(body);
            }
            else
            {
                //Increment the incoming variable
                logicFunction.AddToBody(new SolidityStatement($"{incrementVariableName} += 1"));

                var    ifElseBlock     = new SolidityIfElse();
                string ifElseCondition = $"{incrementVariableName}=={gatewayElement.Incoming.Count}";
                //reset the incoming flow count
                body.Add(incrementVariableName + " = 0");
                ifElseBlock.AddConditionBlock(ifElseCondition, body);
                logicFunction.AddToBody(ifElseBlock);
            }

            return(logicFunction);
        }
        SolidityFunction CreateElementMainFunction()
        {
            SolidityFunction function = new SolidityFunction(GetElementCallName(), SolidityVisibility.Public);

            function.AddModifier($"{ConversionTemplates.StateGuardModifierName(GetElementCallName())}({processConverter.GetIdentifierNames()})");
            function.AddParameters(processConverter.GetIdentifiersAsParameters());

            /*
             * if (IsAddressGuardRequired())
             *  function.AddModifier($"{ConversionTemplates.AddressGuardModifierName(GetElementCallName())}({processConverter.GetIdentifierNames()})");
             */

            boundaryEventCalls.ForEach(c => function.AddToBody(c));

            function.AddToBody(new SolidityStatement(userTaskElement.ValidationScript, false));

            foreach (var fieldGroup in userTaskElement.Form.FieldGroups)
            {
                foreach (var field in fieldGroup.Fields)
                {
                    //var property = processConverter.GetProperty(field.ParamBind);
                    var formPropertyDisplayName = Helpers.ToLowerCamelCase(field.Label);
                    function.AddParameter(new SolidityParameter(Helpers.FormFieldToDataType(field), formPropertyDisplayName));
                }
            }

            function.AddToBody(CreateCallNextBody());
            return(function);
        }
Beispiel #5
0
        private SolidityFunction CreateTaskFunction()
        {
            SolidityFunction function = new SolidityFunction(GetElementCallName(), SolidityVisibility.Internal);

            function.AddParameters(processConverter.GetIdentifiersAsParameters());
            //Add the script logic
            function.AddToBody(new SolidityStatement(scriptTaskElement.Script, false));
            //Get the delegation logic of the next connected element
            function.AddToBody(processConverter.GetStatementOfNextElement(scriptTaskElement));
            return(function);
        }
        SolidityFunction CreateGetStateFunction()
        {
            var functionName     = ConversionTemplates.ActiveStatesFunctionName(Id);
            var getStateFunction = new SolidityFunction(functionName, SolidityVisibility.Public, "bool", true);

            getStateFunction.AddToBody(new SolidityStatement($"return " +
                                                             $"{ConversionTemplates.ActiveStateAssignment(ConverterConfig.STATE_PARAMETER_NAME, Id, InstanceIdentifiers, true)}"));
            //Add the potential process identifiers
            getStateFunction.AddParameters(GetIdentifiersAsParameters());
            getStateFunction.AddParameter(new SolidityParameter("string", ConverterConfig.STATE_PARAMETER_NAME));
            return(getStateFunction);
        }
Beispiel #7
0
        SolidityFunction CreateTouchFunction(TaskConverter attachedToConverter)
        {
            var function = new SolidityFunction($"touch{GetElementCallName()}", SolidityVisibility.Public, "bool");

            function.AddParameters(processConverter.GetIdentifiersAsParameters());
            function.AddModifier($"{ConversionTemplates.StateGuardModifierName(attachedToConverter.GetElementCallName())}({processConverter.GetIdentifierNames()})");

            var solidityCondition = new SolidityIfElse();

            solidityCondition.AddConditionBlock($"now > {GetTimerCondition()}", CreateTouchFunctionLogic(attachedToConverter));
            function.AddToBody(solidityCondition);
            function.AddToBody(new SolidityStatement("return true"));
            return(function);
        }
Beispiel #8
0
        private SolidityFunction CreateTaskFunction()
        {
            SolidityFunction function = new SolidityFunction(GetElementCallName(), SolidityVisibility.Internal);

            function.AddParameters(processConverter.GetIdentifiersAsParameters());
            //Add the calls of the decision function in the right order
            var declarations = GetDecisionFunctionDeclarations();

            foreach (var declaration in declarations)
            {
                function.AddToBody(declaration);
            }
            //Get the delegation logic of the next connected element
            function.AddToBody(processConverter.GetStatementOfNextElement(BusinessRuleTaskElement));
            return(function);
        }
        SolidityFunction CreateLogicFunction()
        {
            var logicFunction = new SolidityFunction($"{GetElementCallName()}", SolidityVisibility.Internal);

            logicFunction.AddParameters(processConverter.GetIdentifiersAsParameters());
            var outgoingSequenceFlows = processConverter.GetOutgoingSequenceFlows(gatewayElement);

            if (outgoingSequenceFlows.Count == 1)
            {
                ElementConverter nextConverter = processConverter.GetConverterOfElement(outgoingSequenceFlows.First().TargetId);
                logicFunction.AddToBody(nextConverter.GetStatementForPrevious(gatewayElement));
            }
            else
            {
                logicFunction.AddToBody(CreateIfElseBlock(outgoingSequenceFlows));
            }

            return(logicFunction);
        }
Beispiel #10
0
        SolidityFunction CreateProcessReturnFunction()
        {
            var function = new SolidityFunction(ConversionTemplates.CallActivityReturnFunctionName(GetElementCallName()), SolidityVisibility.Internal);

            function.AddParameters(processConverter.GetIdentifiersAsParameters());

            var nextElementStatement      = CreateNextElementStatement();
            var incrementStatement        = new SolidityStatement($"{ConversionTemplates.CallActivityCounter(GetElementCallName())}++");
            var checkConditionBlock       = new SolidityIfElse();
            var calledStartEventConverter = processConverter.ContractConverter.GetStartEventConverter(callActivity);
            var callSubprocessStatement   = calledStartEventConverter.GetStatementForPrevious(callActivity);

            checkConditionBlock.AddConditionBlock($"{ConversionTemplates.CallActivityCounter(GetElementCallName())} >= {GetCountTarget(callActivity)}",
                                                  nextElementStatement);

            switch (callActivity.InstanceType)
            {
            case InstanceType.Single:
                function.AddToBody(nextElementStatement);
                break;

            case InstanceType.Sequential:
                //increment the counter, check if counter reached limit.
                //If counter reached limit, then call the next element. If not, call the subprocess again.
                function.AddToBody(incrementStatement);

                checkConditionBlock.AddConditionBlock("", callSubprocessStatement);
                function.AddToBody(checkConditionBlock);

                break;

            case InstanceType.Parallel:
                //increment the counter, check if counter reached limit.
                //If counter reached limit, then call the next element. If not, do nothing.
                function.AddToBody(incrementStatement);
                function.AddToBody(checkConditionBlock);
                break;
            }
            return(function);
        }