Exemplo n.º 1
0
        protected internal void DeployAppConfig()
        {
            IOUtil.FindAndWriteResourceToFile(this.GetType().Assembly, "app.config", ExecutablePath + ".config");

            Configuration.Configuration config = ConfigurationManager.OpenExeConfiguration(ExecutablePath);
#if !ClientSKUFramework
            if (AstoriaTestProperties.Host == Host.WebServiceHost)
            {
                BindingsSection bindingsSection = config.GetSection("system.serviceModel/bindings") as BindingsSection;
                WebHttpBindingCollectionElement webHttpBindingCollectionElement;
                WebHttpBindingElement           webHttpBindingElement;
                foreach (BindingCollectionElement bindingCollectionElement in bindingsSection.BindingCollections)
                {
                    // find WebHttpBinding element "higherMessageSize" and modify its settings
                    if (bindingCollectionElement.BindingType.ToString().Equals("System.ServiceModel.WebHttpBinding"))
                    {
                        webHttpBindingCollectionElement = bindingCollectionElement as WebHttpBindingCollectionElement;
                        webHttpBindingElement           = webHttpBindingCollectionElement.Bindings["higherMessageSize"];

                        if (webHttpBindingElement != null)
                        {
                            // webHttpBinding -> binding -> security ->transport
                            WebHttpSecurityElement webHttpSecurityElement = webHttpBindingElement.Security;
                            switch (AstoriaTestProperties.HostAuthenicationMethod.ToLower())
                            {
                            case "windows":
                                webHttpSecurityElement.Transport.ClientCredentialType = System.ServiceModel.HttpClientCredentialType.Windows;
                                webHttpSecurityElement.Transport.ProxyCredentialType  = System.ServiceModel.HttpProxyCredentialType.Windows;
                                break;

                            default:
                                webHttpSecurityElement.Transport.ClientCredentialType = System.ServiceModel.HttpClientCredentialType.None;
                                webHttpSecurityElement.Transport.ProxyCredentialType  = System.ServiceModel.HttpProxyCredentialType.None;
                                break;
                            }
                        }
                    }
                }
            }
#endif

            if (Database != null)
            {
                // fixup config files
                config.ConnectionStrings.ConnectionStrings.Clear();
                config.ConnectionStrings.ConnectionStrings.Add(this.Workspace.GetConnectionStringSettingsForProvider(this, this.Database.DatabaseConnectionString));
            }

            config.Save();

            if (AstoriaTestProperties.WebServiceHostTargetFramework != null)
            {
                //Would rather do this through the API but unsure how
                string contents         = File.ReadAllText(ExecutablePath + ".config");
                int    configurationPos = contents.IndexOf("<configuration>");
                string startupStr       = string.Format("<startup><supportedRuntime version=\"{0}\"/></startup>", AstoriaTestProperties.WebServiceHostTargetFramework);
                contents = contents.Insert(configurationPos + 16, startupStr);
                File.WriteAllText(ExecutablePath + ".config", contents);
            }
        }