private CodeNamespaceCollection GenerateProcessVariablesNamespaces(TibcoBWProcess tibcoBwProcessToGenerate)
        {
            var processVariableNameNamespaces = new CodeNamespaceCollection();

            if (tibcoBwProcessToGenerate.ProcessVariables != null)
            {
                foreach (var item in tibcoBwProcessToGenerate.ProcessVariables)
                {
                    if (!CodeDomUtils.IsBasicType(item.Parameter.Type))
                    {
                        try
                        {
                            processVariableNameNamespaces.Add(
                                this.xsdClassGenerator.Build(item.ObjectXNodes, TargetAppNameSpaceService.myAppName() + "." + tibcoBwProcessToGenerate.VariablesNameSpace));
                        }
                        catch (Exception e)
                        {
                            Log.Error(
                                "unable to generate Process Variable object class for this process: "
                                + tibcoBwProcessToGenerate.ProcessName,
                                e);
                        }
                    }
                }
            }

            return(processVariableNameNamespaces);
        }
        public override List <CodeNamespaceImport> GenerateImports(Activity activity)
        {
            var import4Activities   = new List <CodeNamespaceImport>();
            var callProcessActivity = (CallProcessActivity)activity;

            import4Activities.Add(new CodeNamespaceImport(TargetAppNameSpaceService.myAppName() + "." + TargetAppNameSpaceService.RemoveFirstDot(callProcessActivity.TibcoProcessToCall.ShortNameSpace)));
            if (IsTheProcessInputRequiresAnImport(callProcessActivity))
            {
                import4Activities.Add(new CodeNamespaceImport(TargetAppNameSpaceService.myAppName() + "." + TargetAppNameSpaceService.RemoveFirstDot(callProcessActivity.TibcoProcessToCall.InputAndOutputNameSpace)));
            }

            return(import4Activities);
        }
        public CodeNamespace GenerateProcessInterface(TibcoBWProcess tibcoBwProcessToGenerate, CodeTypeDeclaration tibcoBwProcessClassModel)
        {
            var namespaceName      = TargetAppNameSpaceService.myAppName() + "." + tibcoBwProcessToGenerate.ShortNameSpace;
            var interfaceNameSpace = InterfaceExtractorFromClass.Extract(tibcoBwProcessClassModel, TargetAppNameSpaceService.myAppName() + "." + tibcoBwProcessToGenerate.ShortNameSpace);

            if ((tibcoBwProcessToGenerate.StartActivity != null && tibcoBwProcessToGenerate.StartActivity.Parameters != null) || (tibcoBwProcessToGenerate.EndActivity != null && tibcoBwProcessToGenerate.EndActivity.Parameters != null))
            {
                interfaceNameSpace.Imports.Add(new CodeNamespaceImport(TargetAppNameSpaceService.myAppName() + "." + tibcoBwProcessToGenerate.InputAndOutputNameSpace));
            }

            interfaceNameSpace.Imports.AddRange(this.GenerateXsdImports(tibcoBwProcessToGenerate).ToArray());

            ModuleBuilder.AddServiceToRegister(namespaceName + "." + interfaceNameSpace.Types[0].Name, namespaceName + "." + tibcoBwProcessClassModel.Name);
            return(interfaceNameSpace);
        }
        private List <CodeNamespaceImport> GenerateXsdImports(TibcoBWProcess tibcoBwProcessToGenerate)
        {
            var imports = new List <CodeNamespaceImport>();

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

            return(imports);
        }
        /// <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.xmlToolsNameSpace()),
                new CodeNamespaceImport(TargetAppNameSpaceService.loggerNameSpace())
            };

            if ((tibcoBwProcessToGenerate.StartActivity != null && tibcoBwProcessToGenerate.StartActivity.Parameters != null) ||
                (tibcoBwProcessToGenerate.EndActivity != null && tibcoBwProcessToGenerate.EndActivity.Parameters != null))
            {
                imports.Add(new CodeNamespaceImport(TargetAppNameSpaceService.myAppName() + "." + tibcoBwProcessToGenerate.InputAndOutputNameSpace));
            }

            imports.AddRange(this.GenerateXsdImports(tibcoBwProcessToGenerate));

            return(imports.ToArray());
        }
        public override List <CodeMemberMethod> GenerateMethods(Activity activity, Dictionary <string, string> variables)
        {
            var activityMethod = base.GenerateMethods(activity, variables);

            var callProcessActivity      = (CallProcessActivity)activity;
            var invocationCodeCollection = new CodeStatementCollection();

            // Add the mapping
            if (IsTheProcessInputRequiresAnImport(callProcessActivity))
            {
                invocationCodeCollection.AddRange(
                    this.xslBuilder.Build(
                        TargetAppNameSpaceService.myAppName() + "." + callProcessActivity.TibcoProcessToCall.InputAndOutputNameSpace,
                        callProcessActivity.InputBindings));
            }
            else
            {
                invocationCodeCollection.AddRange(
                    this.xslBuilder.Build(callProcessActivity.InputBindings));
            }

            // Add the invocation
            var processToCallReference = new CodeFieldReferenceExpression(new CodeThisReferenceExpression(), VariableHelper.ToVariableName(callProcessActivity.TibcoProcessToCall.ProcessName));

            var parameters = GenerateParameters(callProcessActivity);

            var methodInvocation = new CodeMethodInvokeExpression(processToCallReference, GetCalledProcess(activity).StartActivity.Name, parameters);

            if (this.GetReturnType(activity) == CSharpTypeConstant.SystemVoid)
            {
                invocationCodeCollection.Add(methodInvocation);
            }
            else
            {
                var code = new CodeMethodReturnStatement(methodInvocation);
                invocationCodeCollection.Add(code);
            }

            activityMethod[0].Statements.AddRange(invocationCodeCollection);

            return(activityMethod);
        }
Exemple #7
0
        // TODO : refacto to split the 2 generation method in 2 sub-service
        public CodeNamespace Build(string fileName)
        {
            var xsdCodeNamespace            = new CodeNamespace();
            var convertXsdImportToNameSpace = TargetAppNameSpaceService.myAppName() + "." + TargetAppNameSpaceService.ConvertXsdImportToNameSpace(fileName);

            try
            {
                var stream = new FileStream(fileName, FileMode.Open, FileAccess.Read);

                xsdCodeNamespace = this.GeneratedClassFromStream(stream, convertXsdImportToNameSpace);
            }
            catch (Exception e)
            {
                Log.Warn("Switching mode to generate class from XSD file because it contains custom element:" + fileName);
                XElement allFileElement = XElement.Load(fileName);
                xsdCodeNamespace = this.Build(this.Parse(allFileElement, convertXsdImportToNameSpace), convertXsdImportToNameSpace);
            }

            return(xsdCodeNamespace);
        }
        public CodeStatementCollection GenerateEndActivityInvocationCode(TibcoBWProcess tibcoBwProcessToGenerate)
        {
            var statements = new CodeStatementCollection();

            var returnType = this.GenerateStartMethodReturnType(tibcoBwProcessToGenerate);

            if (returnType.BaseType != CSharpTypeConstant.SystemVoid)
            {
                //statements.AddRange(DefaultActivityBuilder.LogActivity(tibcoBwProcessToGenerate.EndActivity));
                statements.AddRange(new XslBuilder(new XpathBuilder()).Build(TargetAppNameSpaceService.myAppName() + "." + tibcoBwProcessToGenerate.InputAndOutputNameSpace, tibcoBwProcessToGenerate.EndActivity.InputBindings));
                var returnName = tibcoBwProcessToGenerate.EndActivity.Parameters[0].Name;

                var returnStatement = new CodeMethodReturnStatement(new CodeVariableReferenceExpression(returnName));
                statements.Add(returnStatement);
            }
            else
            {
                statements.Add(new CodeMethodReturnStatement());
            }

            return(statements);
        }
        public CodeCompileUnit Build(TibcoBWProcess tibcoBwProcessToGenerate)
        {
            if (tibcoBwProcessToGenerate == null)
            {
                return(null);
            }
            Log.Info("Starting Generation of process:" + tibcoBwProcessToGenerate.FullProcessName);

            var activityNameToServiceNameDictionnary = new Dictionary <string, CodeStatementCollection>();

            var targetUnit = new CodeCompileUnit();

            // create the namespace
            var processNamespace = new CodeNamespace(TargetAppNameSpaceService.myAppName() + "." + tibcoBwProcessToGenerate.ShortNameSpace);

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


            var tibcoBwProcessClassModel = this.GenerateSqueletonClassModel(tibcoBwProcessToGenerate);

            var processVariablesDictionary = this.GetProcessVariableDictionary(tibcoBwProcessToGenerate);

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

            processNamespace.Types.Add(tibcoBwProcessClassModel);

            targetUnit.Namespaces.Add(processNamespace);

            // 7 Mappe les classes des activity


            foreach (var activity in tibcoBwProcessToGenerate.Activities)
            {
                try
                {
                    var activityBuilder = this.activityBuilderFactory.Get(activity.Type);
                    targetUnit.Namespaces.AddRange(activityBuilder.GenerateClassesToGenerate(activity, processVariablesDictionary));
                    activityNameToServiceNameDictionnary.Add(activity.Name, activityBuilder.GenerateInvocationCode(activity, processVariablesDictionary));
                    var codeMemberMethod = activityBuilder.GenerateMethods(activity, processVariablesDictionary);
                    if (codeMemberMethod != null)
                    {
                        tibcoBwProcessClassModel.Members.AddRange(codeMemberMethod.ToArray());
                    }
                    processNamespace.Imports.AddRange(activityBuilder.GenerateImports(activity).ToArray());
                    tibcoBwProcessClassModel.Members.AddRange(activityBuilder.GenerateFields(activity).ToArray());
                }
                catch (Exception e)
                {
                    Log.Error("An error occurred:--" + e);
                }
            }

            // Same for the starter
            if (tibcoBwProcessToGenerate.StarterActivity != null)
            {
                var activityBuilder = this.activityBuilderFactory.Get(tibcoBwProcessToGenerate.StarterActivity.Type);
                targetUnit.Namespaces.AddRange(activityBuilder.GenerateClassesToGenerate(tibcoBwProcessToGenerate.StarterActivity, processVariablesDictionary));
                processNamespace.Imports.AddRange(activityBuilder.GenerateImports(tibcoBwProcessToGenerate.StarterActivity).ToArray());
                tibcoBwProcessClassModel.Members.AddRange(activityBuilder.GenerateFields(tibcoBwProcessToGenerate.StarterActivity).ToArray());
            }

            // Add the reduction on fields
            this.RemoveDuplicateFields(tibcoBwProcessClassModel);

            // Generate ouput and input classes from start and End Activity
            try
            {
                targetUnit.Namespaces.Add(this.GenerateInputOutputClasses(tibcoBwProcessToGenerate.EndActivity, TargetAppNameSpaceService.myAppName() + "." + tibcoBwProcessToGenerate.InputAndOutputNameSpace));
                targetUnit.Namespaces.Add(this.GenerateInputOutputClasses(tibcoBwProcessToGenerate.StartActivity, TargetAppNameSpaceService.myAppName() + "." + tibcoBwProcessToGenerate.InputAndOutputNameSpace));
            }
            catch (Exception ex)
            {
                Console.WriteLine("An error occurred:--" + ex);
                Log.Error("An error occurred:--" + ex);
            }

            // Add the invocation code of the End if any
            if (tibcoBwProcessToGenerate.EndActivity != null)
            {
                activityNameToServiceNameDictionnary.Add(tibcoBwProcessToGenerate.EndActivity.Name, this.GenerateEndActivityInvocationCode(tibcoBwProcessToGenerate));
            }

            targetUnit.Namespaces.AddRange(this.GenerateProcessVariablesNamespaces(tibcoBwProcessToGenerate));
            // 8 la methode start avec input starttype et return du endtype
            tibcoBwProcessClassModel.Members.AddRange(this.GenerateMethod(tibcoBwProcessToGenerate, activityNameToServiceNameDictionnary));

            var interfaceNameSpace = this.GenerateProcessInterface(tibcoBwProcessToGenerate, tibcoBwProcessClassModel);

            targetUnit.Namespaces.Add(interfaceNameSpace);

            return(targetUnit);
        }
 private static CodeTypeReference GetServiceFieldType(CallProcessActivity callProcessActivity)
 {
     return(new CodeTypeReference(TargetAppNameSpaceService.myAppName() + "." + callProcessActivity.TibcoProcessToCall.ShortNameSpace + ".I" + VariableHelper.ToClassName(callProcessActivity.TibcoProcessToCall.ProcessName)));
 }