Ejemplo n.º 1
0
 public void ConvertContract()
 {
     //Convert data model logic
     DataModelConverter.ConvertLogic();
     //Add enum and struct definitions to the main contract
     mainSolidityContract.AddComponents(DataModelConverter.GetMainContractComponents());
     //Convert all processes and add their logic to the main contract
     foreach (var processConverter in processConverters.Values)
     {
         processConverter.ConvertProcess();
         mainSolidityContract.AddComponents(processConverter.GetGeneratedSolidityComponents());
     }
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Iterates through the process model and creates the parsed solidity structure
        /// BFS algorithm is used to go through the model.
        /// !!! This approach is not very efficient and may create further issues if expanded upon.
        /// I have chosen it for simplicity, better solution would probably be recreating the given process model
        /// into a graph with references as links between each element. That would allow more flexibility for the converter
        /// objects, which is quite limited in the current implementation.
        /// </summary>
        /// <param name="process">The BPMN process model</param>
        void IterateProcess()
        {
            var flagged = new HashSet <string>();
            var toVisit = new Queue <ProcessElement>();
            //Find the startEvent
            var startEvent = FindStartEvent();

            toVisit.Enqueue(startEvent);
            flagged.Add(startEvent.Id);
            //BFS - go through every element
            while (toVisit.Count > 0)
            {
                var current      = toVisit.Dequeue();
                var nextElements = new List <ElementConverter>();
                //Iterate through all outgoing sequence flow ids of this element
                foreach (var outSequenceFlowId in current.Outgoing)
                {
                    //Convert the sequence flow id to its target element
                    var nextElement = GetSequenceFlowTarget(outSequenceFlowId);
                    nextElements.Add(ConverterFactory.CreateConverter(nextElement));
                    //Add to queue if not visited yet and flag it
                    if (!flagged.Contains(nextElement.Id))
                    {
                        toVisit.Enqueue(nextElement);
                        flagged.Add(nextElement.Id);
                    }
                }
                //Create converter for the current element and use it to generate code elements
                var elementConverter = ConverterFactory.CreateConverter(current);
                var elementCode      = elementConverter.GetElementCode(nextElements, SeqFlowIdToObject(current.Outgoing), dataModel);
                solidityContract.AddComponents(elementCode);
            }
        }