Exemplo n.º 1
0
        public static Dictionary <string, BindingConfiguration> GetBindingsTransportMap(string projectDir)
        {
            Dictionary <string, BindingConfiguration> bindingsTransportMap = new Dictionary <string, BindingConfiguration>();

            WCFBindingAndTransportUtil.ConfigBasedCheck(projectDir, bindingsTransportMap);

            return(bindingsTransportMap);
        }
Exemplo n.º 2
0
        public static Dictionary <string, BindingConfiguration> GetBindingsTransportMap(ProjectWorkspace project)
        {
            Dictionary <string, BindingConfiguration> bindingsTransportMap = new Dictionary <string, BindingConfiguration>();

            WCFBindingAndTransportUtil.CodeBasedCheck(project, bindingsTransportMap);

            return(bindingsTransportMap);
        }
Exemplo n.º 3
0
        public bool IsWCFCodeService(AnalyzerResult analyzerResult)
        {
            // For Code Based, look for Service Interface

            var project = analyzerResult.ProjectResult;

            Tuple <string, string> serviceInterfaceAndClass = WCFBindingAndTransportUtil.GetServiceInterfaceAndClass(project);

            return(serviceInterfaceAndClass != null);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Determines if a project is a CoreWCF Compatible Config based Service based on the following :-
        ///     If it has a web.config or App.config based configuaration, and has a service tag
        ///     in the nested configuration/system.serviceModel tag.
        ///     The service should also have atleast one binding and transport mode compatible with CoreWCF.
        /// </summary>
        /// <param name="analyzerResult"></param>
        /// <returns>Whether a project is a CoreWCF Compatible Config based Service or not</returns>
        public override bool IsPresent(AnalyzerResult analyzerResult)
        {
            if (!IsWCFConfigService(analyzerResult))
            {
                return(false);
            }

            Dictionary <string, BindingConfiguration> bindingsTransportMap = WCFBindingAndTransportUtil.GetBindingAndTransport(analyzerResult);

            return(CoreWCFParityCheck.HasCoreWCFParity(bindingsTransportMap));
        }
Exemplo n.º 5
0
        /// <summary>
        /// Given existing Startup.cs template file, generate new Startup.cs based on configuration.
        /// </summary>
        /// <param name="startupFilePath">Path to existing Startup.cs template</param>
        /// <returns>New Startup.cs contents</returns>
        public string ReplaceStartupFile(string startupFilePath)
        {
            var startupFileContents = File.ReadAllText(startupFilePath);

            if (_projectType == ProjectType.WCFConfigBasedService)
            {
                string configPath = Path.Combine(_projectPath, Constants.PortedConfigFileName);

                if (HasBehavioursTag())
                {
                    startupFileContents = HandleBehaviorsTag(startupFilePath);
                }

                return(startupFileContents.Replace(Constants.XMLPathPlaceholder, "@\"" + configPath + "\""));
            }
            else
            {
                string addService             = Constants.AddServiceFormat;
                string endpointConfigTemplate = Constants.AddServiceEndpointFormat;
                string endpointConfigs        = "";

                ProjectWorkspace project = _analyzerResult.ProjectResult;

                Dictionary <string, BindingConfiguration> bindingTransportMap = GetBindingsTransportMap(project);

                Tuple <string, string> serviceInterfaceAndClass = WCFBindingAndTransportUtil.GetServiceInterfaceAndClass(project);

                var serviceInterfaceName = serviceInterfaceAndClass.Item1 ?? Constants.DefaultServiceInterface;
                var serviceClassName     = serviceInterfaceAndClass.Item2 ?? Constants.DefaultServiceClass;

                endpointConfigs += String.Format(addService, serviceClassName);

                foreach (KeyValuePair <string, BindingConfiguration> keyValuePair in bindingTransportMap)
                {
                    var binding         = keyValuePair.Key;
                    var mode            = keyValuePair.Value.Mode;
                    var endpointAddress = keyValuePair.Value.EndpointAddress ?? String.Join("", "\"", "/", binding.ToLower(), "\"");

                    if (mode.ToLower() == Constants.TransportMode.ToLower())
                    {
                        mode = Constants.TransportMode;
                    }
                    else if (mode.ToLower() == Constants.TransportMessageCredentialsMode.ToLower())
                    {
                        mode = Constants.TransportMessageCredentialsMode;
                    }

                    if (binding == Constants.HttpProtocol)
                    {
                        endpointConfigs += String.Format(endpointConfigTemplate, serviceClassName, serviceInterfaceName,
                                                         mode == Constants.NoneMode ? "new BasicHttpBinding()" : "new BasicHttpBinding(BasicHttpSecurityMode." + mode + ")", endpointAddress);
                    }
                    else if (binding == Constants.NettcpProtocol)
                    {
                        endpointConfigs += String.Format(endpointConfigTemplate, serviceClassName, serviceInterfaceName,
                                                         mode == Constants.NoneMode ? "new NetTcpBinding()" : "new NetTcpBinding(SecurityMode." + mode + ")", endpointAddress);
                    }
                    else if (binding == Constants.WSHttpProtocol)
                    {
                        endpointConfigs += String.Format(endpointConfigTemplate, serviceClassName, serviceInterfaceName,
                                                         mode == Constants.NoneMode ? "new WSHttpBinding()" : "new WSHttpBinding(SecurityMode." + mode + ")", endpointAddress);
                    }
                    else if (binding == Constants.HttpsProtocol)
                    {
                        endpointConfigs += String.Format(endpointConfigTemplate, serviceClassName, serviceInterfaceName, "new BasicHttpBinding(BasicHttpSecurityMode.Transport)", endpointAddress);
                    }
                    else if (binding == Constants.NethttpProtocol)
                    {
                        endpointConfigs += String.Format(endpointConfigTemplate, serviceClassName, serviceInterfaceName,
                                                         mode == Constants.NoneMode ? "new NetHttpBinding()" : "new NetHttpBinding(BasicHttpSecurityMode." + mode + ")", endpointAddress);
                    }
                }

                return(startupFileContents.Replace(Constants.EndpointPlaceholder, endpointConfigs));
            }
        }