public static Task ExecuteAsync <T>(DbContext context, Type type, IList <T> entities, OperationType operationType, BulkConfig bulkConfig, Action <decimal> progress, CancellationToken cancellationToken) where T : class
        {
            using (ActivitySources.StartExecuteActivity((EFCore.BulkExtensions.OperationType)operationType, entities.Count))
            {
                if (operationType != OperationType.Truncate && entities.Count == 0)
                {
                    return(Task.CompletedTask);
                }

                TableInfo tableInfo = TableInfo.CreateInstance(context, type, entities, (EFCore.BulkExtensions.OperationType)operationType, bulkConfig);

                if (operationType == OperationType.Insert && !tableInfo.BulkConfig.SetOutputIdentity)
                {
                    return(SqlBulkOperation.InsertAsync(context, entities, tableInfo, progress, cancellationToken));
                }
                else if (operationType == OperationType.Read)
                {
                    return(SqlBulkOperation.ReadAsync(context, entities, tableInfo, progress, cancellationToken));
                }
                else if (operationType == OperationType.Truncate)
                {
                    return(SqlBulkOperation.TruncateAsync(context, tableInfo, cancellationToken));
                }
                else
                {
                    return(SqlBulkOperation.MergeAsync(context, entities, tableInfo, operationType, progress, cancellationToken));
                }
            }
        }
        public static void Execute(DbContext context, Type type, IList <object> entities, OperationType operationType, BulkConfig bulkConfig, Action <decimal> progress)
        {
            using (ActivitySources.StartExecuteActivity((EFCore.BulkExtensions.OperationType)operationType, entities.Count))
            {
                if (operationType != OperationType.Truncate && entities.Count == 0)
                {
                    return;
                }

                TableInfo tableInfo = TableInfo.CreateInstance(context, type, entities, (EFCore.BulkExtensions.OperationType)operationType, bulkConfig);

                if (operationType == OperationType.Insert && !tableInfo.BulkConfig.SetOutputIdentity)
                {
                    SqlBulkOperation.Insert(context, type, entities, tableInfo, progress);
                }
                else if (operationType == OperationType.Read)
                {
                    SqlBulkOperation.Read(context, type, entities, tableInfo, progress);
                }
                else if (operationType == OperationType.Truncate)
                {
                    SqlBulkOperation.Truncate(context, tableInfo);
                }
                else
                {
                    SqlBulkOperation.Merge(context, type, entities, tableInfo, operationType, progress);
                }
            }
        }
コード例 #3
0
        public void StartConsumeActivity_WhenActivitySourceListener_StartsActivityThroughSource()
        {
            using var listener = new TestActivityListener();

            var      envelope = CreateInboundEnvelope(new MessageHeaderCollection());
            Activity activity = ActivitySources.StartConsumeActivity(envelope);

            listener.Activites.Should().Contain(activity);
        }
コード例 #4
0
        public void StartConsumeActivity_WithoutActivityHeaders_ActivityIsNotModified()
        {
            var envelope = CreateInboundEnvelope(new MessageHeaderCollection());

            Activity activity = ActivitySources.StartConsumeActivity(envelope);

            activity.TraceStateString.Should().BeNull();
            activity.Baggage.Should().BeEmpty();
        }
コード例 #5
0
        public void StartConsumeActivity_WithStateHeader_ActivityStateIsSet()
        {
            var headers = new MessageHeaderCollection
            {
                { DefaultMessageHeaders.TraceId, "00-0af7651916cd43dd8448eb211c80319c-b7ad6b7169203331-01" },
                { DefaultMessageHeaders.TraceState, "key1=value1" }
            };

            var      envelope = CreateInboundEnvelope(headers);
            Activity activity = ActivitySources.StartConsumeActivity(envelope);

            activity.TraceStateString.Should().Be("key1=value1");
        }
コード例 #6
0
        public void StartConsumeActivity_WithBaggageHeader_ActivityBaggageIsSet()
        {
            var headers = new MessageHeaderCollection
            {
                { DefaultMessageHeaders.TraceId, "00-0af7651916cd43dd8448eb211c80319c-b7ad6b7169203331-01" },
                { DefaultMessageHeaders.TraceBaggage, "key1=value1" }
            };

            var      envelope = CreateInboundEnvelope(headers);
            Activity activity = ActivitySources.StartConsumeActivity(envelope);

            activity.Baggage.Should().ContainEquivalentOf(new KeyValuePair <string, string>("key1", "value1"));
        }
コード例 #7
0
        public void StartConsumeActivity_WithoutStateAndBaggageHeaders_ActivityStateAndBaggageAreNotSet()
        {
            var headers = new MessageHeaderCollection
            {
                { DefaultMessageHeaders.TraceId, "00-0af7651916cd43dd8448eb211c80319c-b7ad6b7169203331-01" }
            };

            var      envelope = CreateInboundEnvelope(headers);
            Activity activity = ActivitySources.StartConsumeActivity(envelope);

            activity.TraceStateString.Should().BeNull();
            activity.Baggage.Should().BeEmpty();
        }
コード例 #8
0
    /// <summary>
    /// Initializes a new instance of the <see cref="TracerSettings"/> class
    /// using the specified <see cref="IConfigurationSource"/> to initialize values.
    /// </summary>
    /// <param name="source">The <see cref="IConfigurationSource"/> to use when retrieving configuration values.</param>
    private TracerSettings(IConfigurationSource source)
        : base(source)
    {
        TracesExporter         = ParseTracesExporter(source);
        ConsoleExporterEnabled = source.GetBool(ConfigurationKeys.Traces.ConsoleExporterEnabled) ?? false;

        var instrumentations        = new Dictionary <string, TracerInstrumentation>();
        var enabledInstrumentations = source.GetString(ConfigurationKeys.Traces.Instrumentations);

        if (enabledInstrumentations != null)
        {
            foreach (var instrumentation in enabledInstrumentations.Split(Separator))
            {
                if (Enum.TryParse(instrumentation, out TracerInstrumentation parsedType))
                {
                    instrumentations[instrumentation] = parsedType;
                }
                else
                {
                    throw new FormatException($"The \"{instrumentation}\" is not recognized as supported trace instrumentation and cannot be enabled");
                }
            }
        }

        var disabledInstrumentations = source.GetString(ConfigurationKeys.Traces.DisabledInstrumentations);

        if (disabledInstrumentations != null)
        {
            foreach (var instrumentation in disabledInstrumentations.Split(Separator))
            {
                instrumentations.Remove(instrumentation);
            }
        }

        EnabledInstrumentations = instrumentations.Values.ToList();

        var providerPlugins = source.GetString(ConfigurationKeys.Traces.ProviderPlugins);

        if (providerPlugins != null)
        {
            foreach (var pluginAssemblyQualifiedName in providerPlugins.Split(DotNetQualifiedNameSeparator))
            {
                TracerPlugins.Add(pluginAssemblyQualifiedName);
            }
        }

        var additionalSources = source.GetString(ConfigurationKeys.Traces.AdditionalSources);

        if (additionalSources != null)
        {
            foreach (var sourceName in additionalSources.Split(Separator))
            {
                ActivitySources.Add(sourceName);
            }
        }

        var legacySources = source.GetString(ConfigurationKeys.Traces.LegacySources);

        if (legacySources != null)
        {
            foreach (var sourceName in legacySources.Split(Separator))
            {
                LegacySources.Add(sourceName);
            }
        }

        TraceEnabled        = source.GetBool(ConfigurationKeys.Traces.Enabled) ?? true;
        LoadTracerAtStartup = source.GetBool(ConfigurationKeys.Traces.LoadTracerAtStartup) ?? true;
        Integrations        = new IntegrationSettingsCollection(source);
    }