private void Init(bool doDeserializationInit = false)
        {
            if (_initialized)
                return;

            ProcessResultsSynchronously = _userProcessResultsSynchronously != null && _userProcessResultsSynchronously.Value;

            if (_userStackTraceBreadCrumbConfiguration == null)
                StackTraceBreadCrumbConfiguration = _userStackTraceBreadCrumbConfiguration ?? new StackTraceBreadCrumbConfiguration();
            else
            {
                StackTraceBreadCrumbConfiguration = _userStackTraceBreadCrumbConfiguration;
                if (doDeserializationInit)
                    ((IRequiresInitAfterDeserialization)StackTraceBreadCrumbConfiguration).InitAfterDeserialization();
            }

            if (doDeserializationInit)
            {
                var requiresInitAfterDeserialization = ProfilerResultProcessorConfiguration as IRequiresInitAfterDeserialization;
                if (requiresInitAfterDeserialization != null)
                    requiresInitAfterDeserialization.InitAfterDeserialization();
            }

            _initialized = true;
        }
        public SqlClientProfilerConfiguration(bool isEnabled, IProfilerResultProcessorConfiguration profilerResultProcessorConfiguration,
            bool? processResultsSynchronously = false, StackTraceBreadCrumbConfiguration stackTraceBreadCrumbConfiguration = null)
        {
            IsEnabled = isEnabled;
            _userStackTraceBreadCrumbConfiguration = stackTraceBreadCrumbConfiguration;
            _userProcessResultsSynchronously = processResultsSynchronously;
            ProfilerResultProcessorConfiguration = profilerResultProcessorConfiguration;

            Init();
        }
        //[TestMethod]
        //This is only here to help regenerate the config section.
        public void CreateConfigurationXml()
        {
            var breadCrumb = new Config.StackTraceBreadCrumbConfiguration(true);
            var parameterInsert = new Config.SqlParameterInsertConfiguration(true, "ProfileItemId", "insert into SqlProfileItemParameter(ProfileItemId, Name, Value, OutputValue, DbType, Size, ParameterDirection) values(@ProfileItemId, @Name, @Value, @OutputValue, @DbType, @Size, @ParameterDirection)");
            var resultProcessor = new Config.SqlServerProfilerResultProcessorConfiguration("NorthwindConnectionString", "insert into SqlProfileItem(CommandText, ExecuteType, StartDateTime, TotalElapsedTicks, TotalElapsedMilliseconds, FirstFetchElapsedTicks, FirstFetchElapsedMilliseconds, StackTraceBreadCrumb, ParameterSummary) values(@ProfileItemId, @CommandText, @ExecuteType, @StartDateTime, @TotalElapsedTicks, @TotalElapsedMilliseconds, @FirstFetchElapsedTicks, @FirstFetchElapsedMilliseconds, @StackTraceBreadCrumb, @ParameterSummary) select @@identity", null, parameterInsert);
            var profilerConfig = new Config.SqlClientProfilerConfiguration(true, resultProcessor, true, breadCrumb);

            var serializer = new DataContractSerializer(typeof(Config.SqlClientProfilerConfiguration));
            using (var fs = new FileStream(@"..\..\..\Generated.config", FileMode.Create))
            {
                serializer.WriteObject(fs, profilerConfig);
            }
        }