Esempio n. 1
0
        private void GenerateOnConfiguring(string connectionString)
        {
            _sb.AppendLine("protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)");
            _sb.AppendLine("{");

            using (_sb.Indent())
            {
                _sb.AppendLine("if (!optionsBuilder.IsConfigured)");
                _sb.AppendLine("{");

                using (_sb.Indent())
                {
                    _sb.DecrementIndent()
                    .DecrementIndent()
                    .DecrementIndent()
                    .DecrementIndent()
                    .AppendLine("#warning " + DesignStrings.SensitiveInformationWarning)
                    .IncrementIndent()
                    .IncrementIndent()
                    .IncrementIndent()
                    .IncrementIndent();

                    _sb.AppendLine($"optionsBuilder{_providerCodeGenerator.GenerateUseProvider(connectionString, Language)};");
                }

                _sb.AppendLine("}");
            }
            _sb.AppendLine("}");

            _sb.AppendLine();
        }
        /// <summary>
        /// Generate OnConfiguring method.
        /// </summary>
        /// <param name="connectionString">Database connection string.</param>
        /// <param name="suppressConnectionStringWarning">Suppress connection string warning.</param>
        protected virtual void GenerateOnConfiguring(
            string connectionString,
            bool suppressConnectionStringWarning)
        {
            if (connectionString == null)
            {
                throw new ArgumentNullException(nameof(connectionString));
            }

            var sb = new IndentedStringBuilder();

            using (sb.Indent())
            {
                sb.IncrementIndent();
                sb.AppendLine("protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)");
                sb.AppendLine("{");

                using (sb.Indent())
                {
                    sb.AppendLine("if (!optionsBuilder.IsConfigured)");
                    sb.AppendLine("{");

                    using (sb.Indent())
                    {
                        if (!suppressConnectionStringWarning)
                        {
                            sb.DecrementIndent()
                            .DecrementIndent()
                            .DecrementIndent()
                            .DecrementIndent()
                            .AppendLine("#warning " + DesignStrings.SensitiveInformationWarning)
                            .IncrementIndent()
                            .IncrementIndent()
                            .IncrementIndent()
                            .IncrementIndent();
                        }

                        sb.Append("optionsBuilder")
                        .Append(
                            _providerConfigurationCodeGenerator != null
                                    ? _code.Fragment(
                                _providerConfigurationCodeGenerator.GenerateUseProvider(connectionString))
#pragma warning disable CS0618 // Type or member is obsolete
                                    : _legacyProviderCodeGenerator.GenerateUseProvider(connectionString, Language))
#pragma warning restore CS0618 // Type or member is obsolete
                        .AppendLine(";");
                    }

                    sb.AppendLine("}");
                }
                sb.AppendLine("}");

                var onConfiguring = sb.ToString();
                _templateData.Add("on-configuring", onConfiguring);
            }
        }
        /// <summary>
        ///     This API supports the Entity Framework Core infrastructure and is not intended to be used
        ///     directly from your code. This API may change or be removed in future releases.
        /// </summary>
        protected virtual void GenerateOnConfiguring(
            [NotNull] string connectionString,
            bool suppressConnectionStringWarning)
        {
            Check.NotNull(connectionString, nameof(connectionString));

            _sb.AppendLine("protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)");
            _sb.AppendLine("{");

            using (_sb.Indent())
            {
                _sb.AppendLine("if (!optionsBuilder.IsConfigured)");
                _sb.AppendLine("{");

                using (_sb.Indent())
                {
                    if (!suppressConnectionStringWarning)
                    {
                        _sb.DecrementIndent()
                        .DecrementIndent()
                        .DecrementIndent()
                        .DecrementIndent()
                        .AppendLine("#warning " + DesignStrings.SensitiveInformationWarning)
                        .IncrementIndent()
                        .IncrementIndent()
                        .IncrementIndent()
                        .IncrementIndent();
                    }

                    _sb.Append("optionsBuilder")
                    .Append(
                        _providerConfigurationCodeGenerator != null
                                ? _code.Fragment(
                            _providerConfigurationCodeGenerator.GenerateUseProvider(connectionString))
#pragma warning disable CS0618 // Type or member is obsolete
                                : _legacyProviderCodeGenerator.GenerateUseProvider(connectionString, Language))
#pragma warning restore CS0618 // Type or member is obsolete
                    .AppendLine(";");
                }

                _sb.AppendLine("}");
            }

            _sb.AppendLine("}");

            _sb.AppendLine();
        }
        /// <summary>
        /// Generate OnConfiguring method.
        /// </summary>
        /// <param name="connectionString">Database connection string.</param>
        protected virtual void GenerateOnConfiguring(string connectionString)
        {
            if (connectionString == null)
            {
                throw new ArgumentNullException(nameof(connectionString));
            }

            var sb = new IndentedStringBuilder();

            using (sb.Indent())
            {
                sb.IncrementIndent();
                sb.AppendLine("protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)");
                sb.AppendLine("{");

                using (sb.Indent())
                {
                    sb.AppendLine("if (!optionsBuilder.IsConfigured)");
                    sb.AppendLine("{");

                    using (sb.Indent())
                    {
                        sb.DecrementIndent()
                        .DecrementIndent()
                        .DecrementIndent()
                        .DecrementIndent()
                        .AppendLine("#warning " + DesignStrings.SensitiveInformationWarning)
                        .IncrementIndent()
                        .IncrementIndent()
                        .IncrementIndent()
                        .IncrementIndent();

                        sb.AppendLine($"optionsBuilder{_providerCodeGenerator.GenerateUseProvider(connectionString, Language)};");
                    }

                    sb.AppendLine("}");
                }
                sb.AppendLine("}");

                //_sb.AppendLine();

                var onConfiguring = sb.ToString();
                _templateData.Add("on-configuring", onConfiguring);
            }
        }
Esempio n. 5
0
        /// <summary>
        ///     This API supports the Entity Framework Core infrastructure and is not intended to be used
        ///     directly from your code. This API may change or be removed in future releases.
        /// </summary>
        protected virtual void GenerateOnConfiguring(
            [NotNull] string connectionString)
        {
            Check.NotNull(connectionString, nameof(connectionString));

            _sb.AppendLine("protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)");
            _sb.AppendLine("{");

            using (_sb.Indent())
            {
                _sb.AppendLine("if (!optionsBuilder.IsConfigured)");
                _sb.AppendLine("{");

                using (_sb.Indent())
                {
                    _sb.DecrementIndent()
                    .DecrementIndent()
                    .DecrementIndent()
                    .DecrementIndent()
                    .AppendLine("#warning " + DesignStrings.SensitiveInformationWarning)
                    .IncrementIndent()
                    .IncrementIndent()
                    .IncrementIndent()
                    .IncrementIndent();

                    var useProviderMethod = _providerCodeGenerator?.UseProviderMethod;

                    _sb.AppendLine(
                        useProviderMethod != null
                           ? $"optionsBuilder.{useProviderMethod}({_cSharpUtilities.GenerateVerbatimStringLiteral(connectionString)});"
#pragma warning disable CS0618 // Type or member is obsolete
                           : $"optionsBuilder{_legacyProviderCodeGenerator.GenerateUseProvider(connectionString, Language)};");
#pragma warning restore CS0618 // Type or member is obsolete
                }

                _sb.AppendLine("}");
            }
            _sb.AppendLine("}");

            _sb.AppendLine();
        }