Пример #1
0
 /// <summary>
 ///     Initializes a new instance of the <see cref="PersistenceChannel" /> class.
 /// </summary>
 /// <param name="storageDirectoryPath">
 ///     Full path of a directory name. Under this folder all the transmissions will be saved.
 ///     Setting this value groups channels, even from different processes.
 ///     If 2 (or more) channels has the same <c>storageFolderName</c> only one channel will perform the sending even if the
 ///     channel is in a different process/AppDomain/Thread.
 /// </param>
 /// <param name="sendersCount">
 ///     Defines the number of senders. A sender is a long-running thread that sends telemetry batches in intervals defined
 ///     by <see cref="SendingInterval" />.
 ///     So the amount of senders also defined the maximum amount of http channels opened at the same time.
 /// </param>
 public PersistenceChannel(string storageDirectoryPath = null, int sendersCount = 1)
 {
     _storage = new StorageService();
     _storage.Init(storageDirectoryPath);
     _transmitter    = new PersistenceTransmitter(_storage, sendersCount);
     _flushManager   = new FlushManager(_storage);
     EndpointAddress = TelemetryServiceEndpoint;
 }
Пример #2
0
        /// <summary>
        ///     Initializes a new instance of the <see cref="Sender" /> class.
        /// </summary>
        /// <param name="storage">The storage that holds the transmissions to send.</param>
        /// <param name="transmitter">
        ///     The persistence transmitter that manages this Sender.
        ///     The transmitter will be used as a configuration class, it exposes properties like SendingInterval that will be read
        ///     by Sender.
        /// </param>
        /// <param name="startSending">
        ///     A boolean value that determines if Sender should start sending immediately. This is only
        ///     used for unit tests.
        /// </param>
        internal Sender(BaseStorageService storage, PersistenceTransmitter transmitter, bool startSending = true)
        {
            _stopped                = false;
            DelayHandler            = new AutoResetEvent(false);
            _stoppedHandler         = new AutoResetEvent(false);
            _drainingTimeout        = TimeSpan.FromSeconds(100);
            _defaultSendingInterval = TimeSpan.FromSeconds(5);

            _transmitter = transmitter;
            _storage     = storage;

            if (startSending)
            {
                // It is currently possible for the long - running task to be executed(and thereby block during WaitOne) on the UI thread when
                // called by a task scheduled on the UI thread. Explicitly specifying TaskScheduler.Default
                // when calling StartNew guarantees that Sender never blocks the main thread.
                Task.Factory.StartNew(SendLoop, CancellationToken.None, TaskCreationOptions.LongRunning,
                                      TaskScheduler.Default)
                .ContinueWith(
                    t => PersistenceChannelDebugLog.WriteException(t.Exception, "Sender: Failure in SendLoop"),
                    TaskContinuationOptions.OnlyOnFaulted);
            }
        }