Example #1
0
        private static void WipeSqlServerCredentials(string webRootPath)
        {
            var pathToConnectionStringsConfig = webRootPath.PathCombine("App_Config").PathCombine("ConnectionStrings.config");

            var connectionStringsDocument = new XmlDocumentEx();

            connectionStringsDocument.Load(pathToConnectionStringsConfig);

            var connectionsStringsElement = new XmlElementEx(connectionStringsDocument.DocumentElement, connectionStringsDocument);

            var connectionStrings = new ConnectionStringCollection(connectionsStringsElement);

            connectionStrings.AddRange(connectionsStringsElement.Element.ChildNodes.OfType <XmlElement>().Select(element => new ConnectionString(element, connectionsStringsElement.Document)));

            foreach (var connectionString in connectionStrings)
            {
                if (!connectionString.IsSqlConnectionString)
                {
                    continue;
                }

                var builder = new SqlConnectionStringBuilder(connectionString.Value)
                {
                    DataSource = string.Empty,
                    UserID     = string.Empty,
                    Password   = string.Empty
                };
                connectionString.Value = builder.ToString();
            }

            connectionStrings.Save();
        }
        protected override void Process(ImportArgs args)
        {
            var pathToConnectionStringsConfig = args._RootPath.PathCombine("Website").PathCombine("App_Config").PathCombine("ConnectionStrings.config");
            var connectionStringsDocument     = new XmlDocumentEx();

            connectionStringsDocument.Load(pathToConnectionStringsConfig);
            var connectionsStringsElement = new XmlElementEx(connectionStringsDocument.DocumentElement, connectionStringsDocument);
            ConnectionStringCollection connStringCollection = GetConnectionStringCollection(connectionsStringsElement);

            foreach (var conn in connStringCollection)
            {
                if (conn.IsSqlConnectionString)
                {
                    var builder = new SqlConnectionStringBuilder(conn.Value)
                    {
                        IntegratedSecurity = false,
                        DataSource         = args._ConnectionString.DataSource,
                        UserID             = args._ConnectionString.UserID,
                        Password           = args._ConnectionString.Password
                    };

                    if (args._DatabaseNameAppend != -1)
                    {
                        builder.InitialCatalog = $"{builder.InitialCatalog}_{args._DatabaseNameAppend}";
                    }
                    else
                    {
                        builder.InitialCatalog = builder.InitialCatalog;
                    }

                    conn.Value = builder.ToString();
                }
                else if (conn.IsMongoConnectionString)
                {
                    var builder = new MongoUrlBuilder(conn.Value);

                    foreach (var database in args.ExtractedMongoDatabases)
                    {
                        if (database.OriginalName == builder.DatabaseName)
                        {
                            builder.DatabaseName = database.FinalName;
                            conn.Value           = builder.ToString();
                            break;
                        }
                    }
                }
            }

            connStringCollection.Save();
        }
        protected override void Process(ImportArgs args)
        {
            var pathToConnectionStringsConfig = args.rootPath.PathCombine("Website").PathCombine("App_Config").PathCombine("ConnectionStrings.config");
            var connectionStringsDocument     = new XmlDocumentEx();

            connectionStringsDocument.Load(pathToConnectionStringsConfig);
            var connectionsStringsElement = new XmlElementEx(connectionStringsDocument.DocumentElement, connectionStringsDocument);
            ConnectionStringCollection connStringCollection = this.GetConnectionStringCollection(connectionsStringsElement);

            foreach (var conn in connStringCollection)
            {
                if (conn.IsSqlConnectionString)
                {
                    var builder = new SqlConnectionStringBuilder(conn.Value)
                    {
                        IntegratedSecurity = false,
                        DataSource         = args.connectionString.DataSource,
                        UserID             = args.connectionString.UserID,
                        Password           = args.connectionString.Password
                    };

                    if (args.databaseNameAppend != -1)
                    {
                        builder.InitialCatalog = builder.InitialCatalog + "_" + args.databaseNameAppend.ToString();
                    }
                    else
                    {
                        builder.InitialCatalog = builder.InitialCatalog;
                    }

                    conn.Value = builder.ToString();
                }
            }

            connStringCollection.Save();
        }
        private static void WipeSqlServerCredentials(string webRootPath)
        {
            var pathToConnectionStringsConfig = webRootPath.PathCombine("App_Config").PathCombine("ConnectionStrings.config");

              var connectionStringsDocument = new XmlDocumentEx();
              connectionStringsDocument.Load(pathToConnectionStringsConfig);

              var connectionsStringsElement = new XmlElementEx(connectionStringsDocument.DocumentElement, connectionStringsDocument);

              var connectionStrings = new ConnectionStringCollection(connectionsStringsElement);
              connectionStrings.AddRange(connectionsStringsElement.Element.ChildNodes.OfType<XmlElement>().Select(element => new ConnectionString(element, connectionsStringsElement.Document)));

              foreach (var connectionString in connectionStrings)
              {
            if (!connectionString.IsSqlConnectionString)
            {
              continue;
            }

            var builder = new SqlConnectionStringBuilder(connectionString.Value)
            {
              DataSource = string.Empty,
              UserID = string.Empty,
              Password = string.Empty
            };
            connectionString.Value = builder.ToString();
              }

              connectionStrings.Save();
        }