Esempio n. 1
0
        private void AppendGivenComponent(FzServiceComponent serviceComponent, StringBuilder outputText, int indent = 0)
        {
            // Get indent string
            var indentSpace = string.Empty;

            for (int i = 0; i < indent; i++)
            {
                indentSpace += " ";
            }

            // Append component text
            outputText.Append(indentSpace + "- " + serviceComponent.Name);

            if (!string.Empty.Equals(serviceComponent.OutboundUrl))
            {
                outputText.Append(" - " + serviceComponent.OutboundUrl);
            }

            outputText.Append("\r\n");
            indent += 4;

            // Add subcomponents
            foreach (var subComponent in serviceComponent.SubComponents)
            {
                AppendGivenComponent(subComponent, outputText, indent);
            }
        }
Esempio n. 2
0
        private void FindSubComponentsOfComponent(FzServiceComponent component, List <FzFile> flatFileCache)
        {
            // Find sub-component names
            // Find files that define those subcomponents
            // Add files of sub-components to current component
            // Call this function again with each subcomponent

            if (DateTime.Now > _deadline)
            {
                return;
            }

            var fileAndSubComponents = FindComponentNamesReferencedInFile(component);
            var subComponentFiles    = FindComponentFilesReferencedByName(fileAndSubComponents, component, flatFileCache);

            foreach (var subComponentFile in subComponentFiles)
            {
                var newSubComponent = new FzServiceComponent
                {
                    PreviousReferencedComponent = subComponentFile.ComponentNames.FirstOrDefault(),
                    File        = subComponentFile.File,
                    Name        = subComponentFile.File.FileName,
                    OutboundUrl = subComponentFile.File.Content.Contains("getRelativeUrl()") ? GetOutboundUrl(subComponentFile.File) : string.Empty
                };

                FindSubComponentsOfComponent(newSubComponent, flatFileCache);
                component.SubComponents.Add(newSubComponent);
            }
        }
Esempio n. 3
0
        private static void FindSubComponentsOfComponent(FzServiceComponent serviceComponent, FzFileCache fileCache)
        {
            var subComponents = GetComponentsUsedInComponent(serviceComponent);

            FillOutSourcesOfComponents(subComponents, fileCache);
            serviceComponent.SubComponents.AddRange(subComponents);

            foreach (var subComponent in serviceComponent.SubComponents)
            {
                FindSubComponentsOfComponent(subComponent, fileCache);
            }
        }
Esempio n. 4
0
        public static void FindAllComponents(FzServiceDirectory serviceDirectory, FzFileCache fileCache)
        {
            var taskList             = new List <Task>();
            var serviceComponentList = new List <FzServiceComponent>();

            // Setup each service component
            foreach (var serviceComponent in serviceDirectory.Services)
            {
                var newServiceComponent = new FzServiceComponent
                {
                    File        = serviceComponent.File,
                    Name        = serviceComponent.Name,
                    OutboundUrl = serviceComponent.OutboundUrl,
                    PreviousReferencedComponent = serviceComponent.PreviousReferencedComponent,
                    SubComponents = new List <FzServiceComponent>()
                };

                serviceComponentList.Add(newServiceComponent);
            }

            // Find each service component as a task
            foreach (var serviceComponent in serviceComponentList)
            {
                taskList.Add(Task.Run(() => FindSubComponentsOfComponent(serviceComponent, fileCache)));
            }

            // Await for each service to finish
            foreach (var runningTask in taskList)
            {
                runningTask.GetAwaiter().GetResult();
            }

            // Populate all finished service components back into the service directory
            foreach (var serviceDirectoryServiceComponent in serviceDirectory.Services)
            {
                foreach (var serviceComponent in serviceComponentList)
                {
                    if (serviceDirectoryServiceComponent.Name.Equals(serviceComponent.Name))
                    {
                        serviceDirectoryServiceComponent.SubComponents.AddRange(serviceComponent.SubComponents);
                    }
                }
            }
        }
Esempio n. 5
0
        private static List <FzServiceComponent> GetComponentsUsedInComponent(FzServiceComponent serviceComponent)
        {
            var newSubComponents = new List <FzServiceComponent>();

            // Find every @Resource component
            var resourceComponentMatches = Regex.Matches(serviceComponent.File.Content, @"@Resource\(name = ""(\w+)");

            foreach (Match resourceComponent in resourceComponentMatches)
            {
                var resourceComponentName = resourceComponent.Value.Substring(18);

                if ((resourceComponentName.Contains("Service") ||
                     resourceComponentName.Contains("Step")) &&
                    !IsComponentNameToBeIgnored(resourceComponentName))
                {
                    var newSubComponent = new FzServiceComponent {
                        Name = resourceComponentName
                    };
                    newSubComponents.Add(newSubComponent);
                }
            }

            // Find every inherited / extends component
            var inheritedComponentMatches = Regex.Matches(serviceComponent.File.Content, @"extends (\w+)");

            foreach (Match inheritedComponent in inheritedComponentMatches)
            {
                var inheritedComponentName = inheritedComponent.Value.Substring(8);

                if ((inheritedComponentName.Contains("Service") ||
                     inheritedComponentName.Contains("Step")) &&
                    !IsComponentNameToBeIgnored(inheritedComponentName))
                {
                    var newSubComponent = new FzServiceComponent {
                        Name = inheritedComponentName
                    };
                    newSubComponents.Add(newSubComponent);
                }
            }

            return(newSubComponents);
        }
Esempio n. 6
0
        private FzFileAndComponents FindComponentNamesReferencedInFile(FzServiceComponent serviceComponent)
        {
            var fileAndComponents = new FzFileAndComponents {
                File = serviceComponent.File
            };
            var flatFileContents = serviceComponent.File.Content.Replace("\r", "").Replace("\n", "").Replace("\t", "");

            // Find any @Resource component
            // @Resource(name = "retrieveServiceDefinitionsService")
            var resourceComponentMatches = Regex.Matches(flatFileContents, @"@Resource\(name = ""(\w+)");

            foreach (Match resourceComponent in resourceComponentMatches)
            {
                if ((resourceComponent.Value.Contains("Service") ||
                     resourceComponent.Value.Contains("Step")) &&
                    !serviceComponent.File.FileName.Equals("MitStepConfiguration.java")
                    )
                {
                    fileAndComponents.ComponentNames.Add(resourceComponent.Value.Substring(18));
                }
            }

            // Find any inherited / extends component
            var resourceInheritedMatches = Regex.Matches(serviceComponent.File.Content, @"extends (\w+)");

            foreach (Match resourceInherited in resourceInheritedMatches)
            {
                if (resourceInherited.Value.Contains("Service") ||
                    resourceInherited.Value.Contains("Step"))
                {
                    fileAndComponents.ComponentNames.Add(resourceInherited.Value.Substring(8));
                }
            }

            // Special case when inside the big step configuration file
            if (serviceComponent.File.FileName.Equals("MitStepConfiguration.java"))
            {
            }

            return(fileAndComponents);
        }
Esempio n. 7
0
        private List <FzFileAndComponents> FindComponentFilesReferencedByName(FzFileAndComponents fileAndComponents, FzServiceComponent serviceComponent, List <FzFile> flatFileCache)
        {
            var matchingSubComponentFiles = new List <FzFileAndComponents>();

            foreach (var subComponentName in fileAndComponents.ComponentNames)
            {
                foreach (var file in flatFileCache)
                {
                    // Ignore certain files
                    if (file.FileName.Equals("MitBaseStep.java") ||
                        file.FileName.Equals("MitBaseInnerServiceStep.java") ||
                        file.FileName.Equals("MitBaseCompoundStep.java") ||
                        file.FileName.Equals("MitBaseStepDecorator.java") ||
                        file.FileName.Equals("MitBasicServiceRecorderProxy.java") ||
                        file.FileName.Equals("MitNestedTransformerHttpJsonServiceAgentService.java") ||
                        file.FileName.Equals("MitBasicNestedTransformerHttpServiceAgentService.java") ||
                        file.FileName.Equals("MitBasicStepStateMachine.java") ||
                        file.FileName.Equals("MitBaseSimpleCachedStep.java") ||
                        file.FileName.Equals("MitNestedTransformerServiceAgentService.java"))
                    {
                        continue;
                    }

                    var flatFileContent = file.Content.Replace("\r", "").Replace("\n", "").Replace("\t", "");

                    // Find any @Component component
                    var componentComponentMatch = Regex.Match(file.Content, @"@Component(.*)""" + subComponentName + @"""");

                    if (componentComponentMatch.Success)
                    {
                        var matchedFileAndComponent = new FzFileAndComponents {
                            File = file
                        };

                        matchedFileAndComponent.ComponentNames.Add(subComponentName);
                        matchingSubComponentFiles.Add(matchedFileAndComponent);
                    }

                    // Find a @Component from a @Bean resource
                    var beanComponentMatch = Regex.Match(file.Content, @"@Component(.*)""" + serviceComponent.PreviousReferencedComponent + @"""");

                    if (beanComponentMatch.Success)
                    {
                        var matchedFileAndComponent = new FzFileAndComponents {
                            File = file
                        };

                        matchedFileAndComponent.ComponentNames.Add(subComponentName);
                        matchingSubComponentFiles.Add(matchedFileAndComponent);
                    }

                    // Find any base class used as a component
                    var baseClassComponentMatch = Regex.Match(flatFileContent, @"class " + subComponentName);

                    if (baseClassComponentMatch.Success)
                    {
                        var baseClassMatchedFileAndComponent = new FzFileAndComponents {
                            File = file
                        };

                        baseClassMatchedFileAndComponent.ComponentNames.Add(subComponentName);
                        matchingSubComponentFiles.Add(baseClassMatchedFileAndComponent);
                    }

                    // Find any @Bean match where the component is named after a method
                    var beanResource = BeanFinder.ExtractBeanResource(subComponentName, file);

                    if (beanResource != null)
                    {
                        matchingSubComponentFiles.Add(beanResource);
                    }


                    //var beanMethodComponentMatch = Regex.Match(file.Content, @"@Bean(\s+)public (\S+) " + subComponentName + @"\(\)(\s+){(\s+)return new (\S+)\((\w+)");

                    //if (beanMethodComponentMatch.Success)
                    //{
                    //    // Stop if step has caching
                    //    if (subComponentName.ToUpper().Contains("CACHING"))
                    //        continue;

                    //    // Get bean variable name
                    //    var beanVariableNameMatch = Regex.Match(beanMethodComponentMatch.Value, @"\((\w+)");
                    //    var beanVariableName = beanVariableNameMatch.Value.Substring(1);

                    //    // Get bean variable's corresponding resource name
                    //    var beanResourceDefinitionMatch = Regex.Match(file.Content, @"@Resource\(name = ""(\w+)""\)(\s+)private (\S+) " + beanVariableName);
                    //    var beanResourceNameMatch = Regex.Match(beanResourceDefinitionMatch.Value, @"""(\w+)""");
                    //    var beanResourceName = beanResourceNameMatch.Value.Substring(1, beanResourceNameMatch.Length - 2);

                    //    var beanClassMatchedFileAndComponent = new FzFileAndComponents { File = file };
                    //    beanClassMatchedFileAndComponent.ComponentNames.Add(beanResourceName);
                    //    matchingSubComponentFiles.Add(beanClassMatchedFileAndComponent);
                    //}



                    // Find any @Bean match where the component name is a method
                    //if (file.FileName.Equals("MitEmailConfirmationStepConfiguration.java") && subComponentName.Contains("Email"))
                    //{
                    //    var a = 1;
                    //}

                    //var beanMethodComponentMatch = Regex.Match(flatFileContent, @"@Beanpublic (\S*) " + subComponentName + @"\(\) {return new (\S*)\((\w+)(,|\))");

                    //if (beanMethodComponentMatch.Success)
                    //{
                    //    // Figure out the @Bean's resource variable name
                    //    var beanVariableName = Regex.Match(beanMethodComponentMatch.Value, @"(\w+)(,|\))");
                    //    var variableName = beanVariableName.Value.Substring(0, beanVariableName.Length - 1);

                    //    // Figure out the @Bean's resource name
                    //    var wholeResourceStatment = Regex.Match(flatFileContent, @"@Resource\(name = ""(\w+)""\)(\s*)private (\S*) " + variableName + ";");
                    //    var rawResourceName = Regex.Match(wholeResourceStatment.Value, @"""(\w+)""");

                    //    if (!wholeResourceStatment.Success)
                    //    {
                    //        continue;
                    //    }

                    //    var beanResourceName = rawResourceName.Value.Substring(1, rawResourceName.Value.Length - 2);

                    //    // Add matching component
                    //    var beanMethodMatchedFileAndComponent = new FzFileAndComponents { File = file };

                    //    beanMethodMatchedFileAndComponent.ComponentNames.Add(beanResourceName);
                    //    matchingSubComponentFiles.Add(beanMethodMatchedFileAndComponent);
                    //}
                }
            }

            return(matchingSubComponentFiles);
        }