Пример #1
0
        /// <summary>
        /// Updates the web.cloud.config with to auto-discover the cache role.
        /// </summary>
        /// <param name="roleName">The role name</param>
        /// <param name="cacheWorkerRoleName">The cache worker role name</param>
        /// <param name="azureService">The azure service instance for the role</param>
        private void UpdateWebConfig(string roleName, string cacheWorkerRoleName, string webConfigPath)
        {
            XDocument webConfig = XDocument.Load(webConfigPath);

            Dictionary <string, object> parameters = new Dictionary <string, object>();

            parameters[ScaffoldParams.RoleName] = cacheWorkerRoleName;
            string autoDiscoveryConfig = Scaffold.ReplaceParameter(Resources.CacheAutoDiscoveryConfig, parameters);

            // Adding the auto-discovery is sensetive to the placement of the nodes. The first node which is <configSections>
            // must be added at the first and the last node which is dataCacheClients must be added as last element.
            XElement autoDiscoverXElement = XElement.Parse(autoDiscoveryConfig);

            webConfig.Element("configuration").AddFirst(autoDiscoverXElement.FirstNode);
            webConfig.Element("configuration").Add(autoDiscoverXElement.LastNode);
            Debug.Assert(webConfig.Element("configuration").FirstNode.Ancestors("section").Attributes("name") != null);
            Debug.Assert(webConfig.Element("configuration").LastNode.Ancestors("tracing").Attributes("sinkType") != null);
            webConfig.Save(webConfigPath);
        }