<commit_before>﻿
using System;
using System.Collections.Generic;
using System.IO;
using System.Threading.Tasks;
using NServiceBus;
using NServiceBus.Performance.TimeToBeReceived;
using NServiceBus.Routing;
using NServiceBus.Settings;
using NServiceBus.Transports;

#region TransportDefinition
public class FileTransport : TransportDefinition
{
    /// <summary>
    /// Used by implementations to control if a connection string is necessary.
    /// </summary>
    public override bool RequiresConnectionString => false;

    /// <summary>
    /// Gets an example connection string to use when reporting lack of configured connection string to the user.
    /// </summary>
    public override string ExampleConnectionStringForErrorMessage { get; } = "";

    /// <summary>
    /// Gets the highest supported transaction mode for the this transport.
    /// </summary>
    public override TransportTransactionMode GetSupportedTransactionMode() => TransportTransactionMode.SendsAtomicWithReceive;

    /// <summary>
    /// Will be called if the transport has indicated that it has native support for pub sub.
    /// Creates a transport address for the input queue defined by a logical address.
    /// </summary>
    public override IManageSubscriptions GetSubscriptionManager()
    {
        throw new NotImplementedException();
    }

    /// <summary>
    /// Returns the discriminator for this endpoint instance.
    /// </summary>
    public override EndpointInstance BindToLocalEndpoint(EndpointInstance instance, ReadOnlySettings settings)
    {
        return instance;
    }

    /// <summary>
    /// Configures transport for receiving.
    /// </summary>
    protected override TransportReceivingConfigurationResult ConfigureForReceiving(TransportReceivingConfigurationContext context)
    {
        return new TransportReceivingConfigurationResult(() => new FileTransportMessagePump(), () => new FileTransportQueueCreator(), () => Task.FromResult(StartupCheckResult.Success));
    }

    /// <summary>
    /// Configures transport for sending.
    /// </summary>
    protected override TransportSendingConfigurationResult ConfigureForSending(TransportSendingConfigurationContext context)
    {
        return new TransportSendingConfigurationResult(() => new Dispatcher(), () => Task.FromResult(StartupCheckResult.Success));
    }

    /// <summary>
    /// Returns the list of supported delivery constraints for this transport.
    /// </summary>
    public override IEnumerable<Type> GetSupportedDeliveryConstraints()
    {
        return new List<Type>
            {
                typeof(DiscardIfNotReceivedBefore)
            };
    }

    /// <summary>
    /// Converts a given logical address to the transport address.
    /// </summary>
    /// <param name="logicalAddress">The logical address.</param>
    /// <returns>The transport address.</returns>
    public override string ToTransportAddress(LogicalAddress logicalAddress)
    {
        return Path.Combine(logicalAddress.EndpointInstance.Endpoint.ToString(),
            logicalAddress.EndpointInstance.Discriminator ?? "",
            logicalAddress.Qualifier ?? "");
    }

    /// <summary>
    /// Returns the outbound routing policy selected for the transport.
    /// </summary>
    public override OutboundRoutingPolicy GetOutboundRoutingPolicy(ReadOnlySettings settings)
    {
        return new OutboundRoutingPolicy(OutboundRoutingType.Unicast, OutboundRoutingType.Unicast, OutboundRoutingType.Unicast);
    }
}
#endregion<commit_msg>update file transport to new TransportDefinition<commit_after>﻿
using System;
using System.Collections.Generic;
using System.IO;
using System.Threading.Tasks;
using NServiceBus;
using NServiceBus.Performance.TimeToBeReceived;
using NServiceBus.Routing;
using NServiceBus.Settings;
using NServiceBus.Transports;

#region TransportDefinition
public class FileTransport : TransportDefinition
{
    public override bool RequiresConnectionString => false;

    protected override TransportInfrastructure Initialize(SettingsHolder settings, string connectionString)
    {
        return new FileTransportInfrastructure();
    }

    public override string ExampleConnectionStringForErrorMessage { get; } = "";
}

public class FileTransportInfrastructure : TransportInfrastructure
{
    public override TransportReceiveInfrastructure ConfigureReceiveInfrastructure()
    {
        return new TransportReceiveInfrastructure(() => new FileTransportMessagePump(), () => new FileTransportQueueCreator(), () => Task.FromResult(StartupCheckResult.Success));
    }

    public override TransportSendInfrastructure ConfigureSendInfrastructure()
    {
        return new TransportSendInfrastructure(() => new Dispatcher(), () => Task.FromResult(StartupCheckResult.Success));
    }

    public override TransportSubscriptionInfrastructure ConfigureSubscriptionInfrastructure()
    {
        throw new NotImplementedException();
    }

    public override EndpointInstance BindToLocalEndpoint(EndpointInstance instance)
    {
        return instance;
    }

    public override string ToTransportAddress(LogicalAddress logicalAddress)
    {
        return Path.Combine(logicalAddress.EndpointInstance.Endpoint.ToString(),
            logicalAddress.EndpointInstance.Discriminator ?? "",
            logicalAddress.Qualifier ?? "");
    }

    public override IEnumerable<Type> DeliveryConstraints
    {
        get { yield return typeof(DiscardIfNotReceivedBefore);}
    }

    public override TransportTransactionMode TransactionMode => TransportTransactionMode.SendsAtomicWithReceive;

    public override OutboundRoutingPolicy OutboundRoutingPolicy => new OutboundRoutingPolicy(OutboundRoutingType.Unicast, OutboundRoutingType.Unicast, OutboundRoutingType.Unicast);
}
#endregion
{'fraction_non_alphanumeric': 0.08553654743390357, 'fraction_numerical': 0.0, 'mean_word_length': 3.8313856427378963, 'pattern_counts': {'":': 0, '<': 30, '<?xml version=': 0, '>': 45, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6717907', 'n_tokens_mistral': 1362, 'n_tokens_neox': 1354, 'n_words': 365}