Beispiel #1
0
        private void WriteEndpointAddressClosed(Hashtable regex2Values, XmlElement endPtNode)
        {
            var endPtAddrAttr = endPtNode.Attributes["address"];

            //implies the a contract with no end point address whatsoever.
            if (string.IsNullOrWhiteSpace(endPtAddrAttr?.Value))
            {
                return;
            }

            AddEndpointNodeToTransform(
                endPtAddrAttr.Value,
                endPtNode.Attributes["binding"]?.Value,
                endPtNode.Attributes["bindingConfiguration"]?.Value,
                endPtNode.Attributes["contract"]?.Value,
                endPtNode.Attributes["name"]?.Value);

            if (!RegexCatalog.AreAnyRegexMatch(endPtAddrAttr.Value, regex2Values.Keys.Cast <string>().ToArray()))
            {
                var addUri = new UriBuilder(endPtAddrAttr.Value)
                {
                    Host = "localhost"
                };

                endPtAddrAttr.Value = addUri.ToString();
            }
            else
            {
                AppropriateAllRegex(endPtAddrAttr, regex2Values);
            }
        }
Beispiel #2
0
        public void TestAreAnyRegexMatch()
        {
            var testResult = RegexCatalog.AreAnyRegexMatch("www.TheDomainName.com",
                                                           Regex2Values.Keys.Cast <string>().ToArray());

            Assert.IsTrue(testResult);

            testResult = RegexCatalog.AreAnyRegexMatch("net.tcp://224.11.89.55:1060/OrNotToWankAdminUIController/",
                                                       Regex2Values.Keys.Cast <string>().ToArray());

            Assert.IsTrue(testResult);

            testResult = RegexCatalog.AreAnyRegexMatch("ContractDocument", new[] { "Contract", "Client", "Location" });
            Assert.IsTrue(testResult);
        }
Beispiel #3
0
        internal void SplitClientServiceModelNodes(Hashtable regex2Values)
        {
            var svcClientNode = _xmlDocument.SelectSingleNode("//system.serviceModel/client");

            if (svcClientNode == null || !svcClientNode.HasChildNodes)
            {
                return;
            }

            _xmlWriter.WriteStartElement("client");

            foreach (var node in svcClientNode.ChildNodes)
            {
                var endPtNode = node as XmlElement;
                var addrAttr  = endPtNode?.Attributes["address"];
                if (addrAttr == null)
                {
                    continue;
                }

                if (!Uri.IsWellFormedUriString(addrAttr.Value, UriKind.RelativeOrAbsolute))
                {
                    continue;
                }

                AddEndpointNodeToTransform(
                    endPtNode.Attributes["address"]?.Value,
                    endPtNode.Attributes["binding"]?.Value,
                    endPtNode.Attributes["bindingConfiguration"]?.Value,
                    endPtNode.Attributes["contract"]?.Value,
                    endPtNode.Attributes["name"]?.Value);

                if (!RegexCatalog.AreAnyRegexMatch(addrAttr.Value, regex2Values.Keys.Cast <string>().ToArray()))
                {
                    var addUri = new UriBuilder(addrAttr.Value)
                    {
                        Host = "localhost"
                    };

                    addrAttr.Value = addUri.ToString();
                }
                else
                {
                    AppropriateAllRegex(addrAttr, regex2Values);
                }
            }
            _xmlWriter.WriteEndElement();
        }
Beispiel #4
0
        internal void SplitAppSettings(Hashtable regex2Values, bool swapConnStrs)
        {
            var appSettingsNodes = _xmlDocument.SelectSingleNode("//appSettings");

            if (appSettingsNodes == null || !appSettingsNodes.HasChildNodes)
            {
                return;
            }

            _xmlWriter.WriteStartElement("appSettings");

            foreach (var node in appSettingsNodes)
            {
                var cnode = node as XmlElement;
                if (cnode == null)
                {
                    continue;
                }
                var appValAttr = cnode.Attributes["value"];
                var appKeyAttr = cnode.Attributes["key"];
                if (appValAttr == null || appKeyAttr == null)
                {
                    continue;
                }
                var originalVal = appValAttr.Value;

                if (swapConnStrs && IsConnectionString(appValAttr.Value))
                {
                    AddAppSettingAddNodeToTransform(appKeyAttr.Value, appValAttr.Value);
                    appValAttr.Value = NfConfig.SqlServerDotNetConnString;
                    continue;
                }

                if (!RegexCatalog.AreAnyRegexMatch(appValAttr.Value, regex2Values.Keys.Cast <string>().ToArray()))
                {
                    continue;
                }

                AppropriateAllRegex(appValAttr, regex2Values);

                AddAppSettingAddNodeToTransform(appKeyAttr.Value, originalVal);
            }

            _xmlWriter.WriteEndElement();
        }
Beispiel #5
0
        private void WriteServiceHostNodeClosed(Hashtable regex2Values, XmlNode hostNode)
        {
            _xmlWriter.WriteStartElement("host");
            _xmlWriter.WriteAttributeString("Transform", XML_TRANSFORM_NS,
                                            "Replace");

            _xmlWriter.WriteStartElement("baseAddresses");
            foreach (var nodeV in hostNode.ChildNodes)
            {
                var bAddrNode = nodeV as XmlElement;
                if (bAddrNode == null)
                {
                    continue;
                }
                var baseAddrAttr = bAddrNode.Attributes["baseAddress"];
                if (string.IsNullOrEmpty(baseAddrAttr?.Value) ||
                    !Uri.IsWellFormedUriString(baseAddrAttr.Value, UriKind.RelativeOrAbsolute))
                {
                    _xmlWriter.WriteEndElement();
                    _xmlWriter.WriteEndElement();
                    continue;
                }

                _xmlWriter.WriteStartElement("add");
                _xmlWriter.WriteAttributeString("baseAddress", baseAddrAttr.Value);


                if (!RegexCatalog.AreAnyRegexMatch(baseAddrAttr.Value, regex2Values.Keys.Cast <string>().ToArray()))
                {
                    var bAddrUri = new UriBuilder(baseAddrAttr.Value)
                    {
                        Host = "localhost"
                    };
                    baseAddrAttr.Value = bAddrUri.ToString();
                }
                else
                {
                    AppropriateAllRegex(baseAddrAttr, regex2Values);
                }
                _xmlWriter.WriteEndElement();
            }
            _xmlWriter.WriteEndElement(); //end baseAddresses node
            _xmlWriter.WriteEndElement(); //end host node
        }
Beispiel #6
0
        internal void SplitConnectionStringNodes(Hashtable regex2Values, bool swapConnStrs)
        {
            var connectionStringNodes = _xmlDocument.SelectSingleNode("//connectionStrings");

            if (connectionStringNodes == null || !connectionStringNodes.HasChildNodes)
            {
                return;
            }
            _xmlWriter.WriteStartElement("connectionStrings");
            foreach (var node in connectionStringNodes.ChildNodes)
            {
                var constr = node as XmlElement;
                if (constr == null)
                {
                    continue;
                }
                var conStrAttr     = constr.Attributes["connectionString"];
                var conStrNameAttr = constr.Attributes["name"];

                if (conStrAttr == null)
                {
                    continue;
                }

                var conStrVal = conStrAttr.Value;

                if (swapConnStrs ||
                    !RegexCatalog.AreAnyRegexMatch(conStrAttr.Value, regex2Values.Keys.Cast <string>().ToArray()))
                {
                    conStrAttr.Value = NfConfig.SqlServerDotNetConnString;

                    AddConnStringNodeToTransform(conStrNameAttr.Value, conStrVal);

                    continue;
                }

                AppropriateAllRegex(conStrAttr, regex2Values);

                AddConnStringNodeToTransform(conStrNameAttr.Value, conStrVal);
            }
            _xmlWriter.WriteEndElement();
        }