public void SetUp()
        {
            tibcoBWProcessBuilder = new TibcoProcessClassesBuilder ();

            tibcoBWProcess = new TibcoBWProcess ("MyNamespace/myProcessTest.process");
            tibcoBWProcess.Activities = new List<Activity> ();
        }
        public CodeCompileUnit Build(TibcoBWProcess tibcoBwProcessToGenerate)
        {
            var targetUnit = new CodeCompileUnit();

            //create the namespace
            CodeNamespace processNamespace = new CodeNamespace(tibcoBwProcessToGenerate.ShortNameSpace);

            processNamespace.Imports.AddRange(this.GenerateImport(tibcoBwProcessToGenerate));

            var tibcoBwProcessClassModel = new CodeTypeDeclaration(tibcoBwProcessToGenerate.ProcessName);
            tibcoBwProcessClassModel.IsClass = true;
            tibcoBwProcessClassModel.TypeAttributes = TypeAttributes.Public;

            tibcoBwProcessClassModel.Comments.Add(new CodeCommentStatement(tibcoBwProcessToGenerate.Description));

            // 3 les membres privee : les activité injecte
            tibcoBwProcessClassModel.Members.AddRange(this.GeneratePrivateFields(tibcoBwProcessToGenerate));

            // 4 le ctor avec injection des activités + logger
            tibcoBwProcessClassModel.Members.AddRange(this.GenerateConstructors(tibcoBwProcessToGenerate, tibcoBwProcessClassModel));

            processNamespace.Types.Add(tibcoBwProcessClassModel);

            targetUnit.Namespaces.Add(processNamespace);

            //7 Mappe les classes des activity
            targetUnit.Namespaces.AddRange(this.GenerateActivityClasses(tibcoBwProcessToGenerate.Activities));

            if (tibcoBwProcessToGenerate.EndActivity != null && tibcoBwProcessToGenerate.EndActivity.ObjectXNodes != null)
            {
                targetUnit.Namespaces.Add(this.xsdClassGenerator.Build(tibcoBwProcessToGenerate.EndActivity.ObjectXNodes, tibcoBwProcessToGenerate.InputAndOutputNameSpace));
            }
            if (tibcoBwProcessToGenerate.StartActivity != null && tibcoBwProcessToGenerate.StartActivity.ObjectXNodes != null)
            {
                targetUnit.Namespaces.Add(this.xsdClassGenerator.Build(tibcoBwProcessToGenerate.StartActivity.ObjectXNodes, tibcoBwProcessToGenerate.InputAndOutputNameSpace));
            }
            targetUnit.Namespaces.AddRange(this.GenerateProcessVariablesNamespaces(tibcoBwProcessToGenerate));
            //7 la methode start avec input starttype et return du endtype
            tibcoBwProcessClassModel.Members.AddRange(this.GenerateMethod(tibcoBwProcessToGenerate));

            return targetUnit;
        }
 private CodeTypeReference GenerateStartMethodReturnType(TibcoBWProcess tibcoBwProcessToGenerate)
 {
     string returnType;
     if (tibcoBwProcessToGenerate.EndActivity == null || tibcoBwProcessToGenerate.EndActivity.Parameters == null)
     {
         returnType = "System.Void";
     }
     else
     {
         returnType = tibcoBwProcessToGenerate.EndActivity.Parameters[0].Type;
     }
     return new CodeTypeReference(returnType);
 }
 private void GenerateStartMethodInputParameters(TibcoBWProcess tibcoBwProcessToGenerate, CodeMemberMethod startMethod)
 {
     if (tibcoBwProcessToGenerate.StartActivity.Parameters != null)
     {
         foreach (var parameter in tibcoBwProcessToGenerate.StartActivity.Parameters)
         {
             startMethod.Parameters.Add(new CodeParameterDeclarationExpression
             {
                 Name = parameter.Name,
                 Type = new CodeTypeReference(parameter.Type)
             });
         }
     }
 }
 CodeNamespaceCollection GenerateProcessVariablesNamespaces(TibcoBWProcess tibcoBwProcessToGenerate)
 {
     CodeNamespaceCollection processVariableNameNamespaces = new CodeNamespaceCollection();
     if (tibcoBwProcessToGenerate.ProcessVariables != null)
     {
         foreach (var item in tibcoBwProcessToGenerate.ProcessVariables)
         {
             if (!IsBasicType(item.Parameter.Type))
             {
                 processVariableNameNamespaces.Add(this.xsdClassGenerator.Build(item.ObjectXNodes, tibcoBwProcessToGenerate.NameSpace));
             }
         }
     }
     return processVariableNameNamespaces;
 }
 private List<CodeMemberField> GenerateFieldForProcessVariables(TibcoBWProcess tibcoBwProcessToGenerate)
 {
     var fields = new List<CodeMemberField>();
     if (tibcoBwProcessToGenerate.ProcessVariables != null)
     {
         foreach (var variable in tibcoBwProcessToGenerate.ProcessVariables)
         {
             fields.Add(new CodeMemberField
             {
                 Type = new CodeTypeReference(tibcoBwProcessToGenerate.NameSpace + "." + variable.Parameter.Type),
                 Name = VariableHelper.ToVariableName(variable.Parameter.Name),
                 Attributes = MemberAttributes.Private
             });
         }
     }
     return fields;
 }
 public void GenerateStartMethodBody(TibcoBWProcess tibcoBwProcessToGenerate, CodeMemberMethod startMethod)
 {
     if (tibcoBwProcessToGenerate.Transitions != null)
     {
         startMethod.Statements.AddRange(this.coreProcessBuilder.GenerateStartCodeStatement(tibcoBwProcessToGenerate.Transitions, tibcoBwProcessToGenerate.StartActivity.Name, null, this.activityNameToServiceNameDictionnary));
         // TODO VC : integrate the following section in in CoreProcessBuilder
         if (startMethod.ReturnType.BaseType != "System.Void")
         {
             var returnName = VariableHelper.ToVariableName(tibcoBwProcessToGenerate.EndActivity.Parameters[0].Name);
             var objectCreate = new CodeObjectCreateExpression(startMethod.ReturnType);
             startMethod.Statements.Add(new CodeVariableDeclarationStatement(startMethod.ReturnType, returnName, objectCreate));
             CodeMethodReturnStatement returnStatement = new CodeMethodReturnStatement(new CodeVariableReferenceExpression(returnName));
             startMethod.Statements.Add(returnStatement);
         }
     }
 }
        public CodeMemberMethod GenerateStartMethod(TibcoBWProcess tibcoBwProcessToGenerate)
        {
            var startMethod = new CodeMemberMethod();
            if (tibcoBwProcessToGenerate.StartActivity == null)
            {
                return startMethod;
            }

            startMethod.Attributes = MemberAttributes.Public | MemberAttributes.Final;
            startMethod.Name = tibcoBwProcessToGenerate.StartActivity.Name;
            startMethod.ReturnType = this.GenerateStartMethodReturnType(tibcoBwProcessToGenerate);

            this.GenerateStartMethodInputParameters(tibcoBwProcessToGenerate, startMethod);

            this.GenerateStartMethodBody(tibcoBwProcessToGenerate, startMethod);

            return startMethod;
        }
        public CodeMemberField[] GeneratePrivateFields(TibcoBWProcess tibcoBwProcessToGenerate)
        {
            var fields = new List<CodeMemberField>();

            fields.Add(new CodeMemberField
            {
                Type = new CodeTypeReference("ILogger"),
                Name = "logger",
                Attributes = MemberAttributes.Private
            });

            fields.AddRange(this.GenerateFieldForProcessVariables(tibcoBwProcessToGenerate));

            fields.AddRange(this.GenerateFieldsForActivityServices(tibcoBwProcessToGenerate.Activities));

            return fields.ToArray();
        }
 public CodeMemberMethod[] GenerateMethod(TibcoBWProcess tibcoBwProcessToGenerate)
 {
     return new List<CodeMemberMethod> { GenerateStartMethod(tibcoBwProcessToGenerate) }.ToArray();
 }
        /// <summary>
        /// Generates the import.
        /// </summary>
        /// <returns>The import.</returns>
        /// <param name="tibcoBwProcessToGenerate">Tibco bw process to generate.</param>
        public CodeNamespaceImport[] GenerateImport(TibcoBWProcess tibcoBwProcessToGenerate)
        {
            var imports = new List<CodeNamespaceImport> {
                new CodeNamespaceImport ("System"),
                new CodeNamespaceImport (TargetAppNameSpaceService.domainContractNamespaceName),
                new CodeNamespaceImport (tibcoBwProcessToGenerate.InputAndOutputNameSpace),
                new CodeNamespaceImport (TargetAppNameSpaceService.loggerNameSpace)
            };

            if (tibcoBwProcessToGenerate.XsdImports != null)
            {
                foreach (var xsdImport in tibcoBwProcessToGenerate.XsdImports)
                {
                    imports.Add(new CodeNamespaceImport(ConvertXsdImportToNameSpace(xsdImport.SchemaLocation)));
                }
            }

            var import4Activities = GenerateImport4Activities(tibcoBwProcessToGenerate.Activities);

            imports.AddRange(import4Activities);
            return imports.ToArray();
        }
        public CodeConstructor[] GenerateConstructors(TibcoBWProcess tibcoBwProcessToGenerate, CodeTypeDeclaration classModel)
        {
            var constructor = new CodeConstructor();
            constructor.Attributes = MemberAttributes.Public;
            foreach (CodeMemberField field in classModel.Members)
            {
                if (this.IsNotAProcessVariable(field.Name, tibcoBwProcessToGenerate.ProcessVariables))
                {
                    constructor.Parameters.Add(new CodeParameterDeclarationExpression(
                        field.Type, field.Name));

                    var parameterReference = new CodeFieldReferenceExpression(
                        new CodeThisReferenceExpression(), field.Name);

                    constructor.Statements.Add(new CodeAssignStatement(parameterReference,
                        new CodeArgumentReferenceExpression(field.Name)));
                }
            }

            return new List<CodeConstructor> { constructor }.ToArray();
        }
        public void Should_Return_Simple_Start_Method_Body()
        {
            var expected = @"this.step1Service.ExecuteQuery();
            ";
            var tibcoBWProcess = new TibcoBWProcess("MyTestProcess");
            tibcoBWProcess.StartActivity = new Activity("start", ActivityType.startType);
            tibcoBWProcess.EndActivity = new Activity("End", ActivityType.endType);
            tibcoBWProcess.Transitions = this.simpleProcessTransitions;

            var codeStatementCollection = this.builder.GenerateStartCodeStatement (tibcoBWProcess.Transitions, tibcoBWProcess.StartActivity.Name, null, activitiesToServiceMapping);

            var classesInString = TestCodeGeneratorUtils.GenerateCode (codeStatementCollection);

            Assert.AreEqual (expected, classesInString);
        }