public static void CodeBasedCheck()

in src/CTA.FeatureDetection.Common/WCFConfigUtils/WCFBindingAndTransportUtil.cs [155:253]


        public static void CodeBasedCheck(ProjectWorkspace project, Dictionary<string, BindingConfiguration> bindingsTransportMap)
        {
            IEnumerable<InvocationExpression> addEndpointInvocations = project.GetInvocationExpressionsByMethodName(Constants.AddServiceEndpointType);

            foreach (var addEndpointInvocation in addEndpointInvocations)
            {
                var argumentCount = addEndpointInvocation.Arguments.Count();

                if (argumentCount == 1)
                {
                    var endpointIdentifier = addEndpointInvocation.Arguments.First();

                    IEnumerable<ObjectCreationExpression> serviceEndpointObjectExpressions = project.GetObjectCreationExpressionBySemanticClassType(Constants.ServiceEndpointClass);

                    var endpointArgumentObjects = serviceEndpointObjectExpressions.
                        SelectMany(s => s.GetObjectCreationExpressionBySemanticNamespace(Constants.SystemServiceModelClass));

                    var bindingArgumentObjects = endpointArgumentObjects.Where(e => e.SemanticClassType != Constants.EndpointAddressType);

                    foreach(var binding in bindingArgumentObjects)
                    {
                        var bindingName = binding.SemanticClassType;
                        var bindingNameFormatted = bindingName.ToString().ToLower();

                        bindingsTransportMap[bindingName] = new BindingConfiguration
                        {
                            Mode = GetModeFromObjectArguments(binding.Arguments),
                            EndpointAddress = GetEndpointFromInvocationArguments(addEndpointInvocation.Arguments)
                        };
                    }
                }

                var bindingArgument = addEndpointInvocation.Arguments.Where(a => a.SemanticType.ToLower().Contains("binding"));

                var objectDeclarations = addEndpointInvocation.GetObjectCreationExpressionBySemanticNamespace(Constants.SystemServiceModelClass);

                ObjectCreationExpression objectCreationExpression;

                if(objectDeclarations.IsNullOrEmpty())
                {
                    if(!bindingArgument.IsNullOrEmpty())
                    {
                        var bindingName = bindingArgument.First().SemanticType;

                        var objectCreationExpressionList = project.GetObjectCreationExpressionBySemanticClassType(bindingName);

                        if(!objectCreationExpressionList.IsNullOrEmpty())
                        {
                            objectCreationExpression = objectCreationExpressionList.First();
                        }
                        else
                        {
                            bindingsTransportMap[bindingName] = new BindingConfiguration();
                            return;
                        }
                    }
                    else
                    { 
                        break; 
                    }
                }
                else
                {
                    objectCreationExpression = objectDeclarations.First();
                }

                if (objectCreationExpression != null)
                {
                    var bindingName = objectCreationExpression.SemanticClassType.ToLower();

                    bindingsTransportMap[bindingName] = new BindingConfiguration
                    {
                        Mode = GetModeFromObjectArguments(objectCreationExpression.Arguments),
                        EndpointAddress = GetEndpointFromInvocationArguments(addEndpointInvocation.Arguments)
                    };
                }
            }

            var webConfig = WebConfigManager.LoadWebConfigAsXDocument(project.ProjectRootPath);
            var appConfig = WebConfigManager.LoadAppConfigAsXDocument(project.ProjectRootPath);
            
            if (webConfig != null && webConfig.ContainsElement(Constants.WCFBindingElementPath))
            {
                BindingTagCheck(webConfig, bindingsTransportMap);
            }
            else if (appConfig != null && appConfig.ContainsElement(Constants.WCFBindingElementPath))
            {
                BindingTagCheck(appConfig, bindingsTransportMap);
            }

            if (webConfig != null && webConfig.ContainsElement(Constants.WCFProtocolMappingElement))
            {
                ProtocolTagCheck(webConfig, bindingsTransportMap);
            }
            else if (appConfig != null && appConfig.ContainsElement(Constants.WCFProtocolMappingElement))
            {
                ProtocolTagCheck(appConfig, bindingsTransportMap);
            }
        }