/// <summary>
 /// Initializes a new instance of the <see cref="PersistenceChannel"/> class.
 /// </summary>
 /// <param name="storageFolderName">
 /// A folder 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 storageFolderName, int sendersCount = 1)
 {   
     this.TelemetryBuffer = new TelemetryBuffer();
     this.storage = ServiceLocator.GetService<BaseStorageService>();
     this.storage.Init(storageFolderName);
     this.Transmitter = new PersistenceTransmitter(this.storage, sendersCount);
     this.flushManager = new FlushManager(this.storage, this.TelemetryBuffer);
     this.EndpointAddress = TelemetryServiceEndpoint;
     this.developerMode = false;
 }
Beispiel #2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="PersistenceChannel"/> class.
 /// </summary>
 /// <param name="storageFolderName">
 /// A folder 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 storageFolderName, int sendersCount = 1)
 {
     this.TelemetryBuffer = new TelemetryBuffer();
     this.storage         = ServiceLocator.GetService <BaseStorageService>();
     this.storage.Init(storageFolderName);
     this.Transmitter     = new PersistenceTransmitter(this.storage, sendersCount);
     this.flushManager    = new FlushManager(this.storage, this.TelemetryBuffer);
     this.EndpointAddress = TelemetryServiceEndpoint;
     this.developerMode   = false;
 }
Beispiel #3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="PersistenceTransmitter"/> class.
 /// </summary>
 /// <param name="storage">The transmissions storage.</param>
 /// <param name="sendersCount">The number of senders to create.</param>
 /// <param name="createSenders">A boolean value that indicates if this class should try and create senders. This is a workaround for unit tests purposes only.</param>
 internal PersistenceTransmitter(BaseStorageService storage, int sendersCount, bool createSenders = true)
 {
     this.storage = storage;
     if (createSenders)
     {
         for (int i = 0; i < sendersCount; i++)
         {
             this.senders.Add(new Sender(this.storage, this));
         }
     }
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="PersistenceTransmitter"/> class.
 /// </summary>
 /// <param name="storage">The transmissions storage.</param>
 /// <param name="sendersCount">The number of senders to create.</param>
 /// <param name="createSenders">A boolean value that indicates if this class should try and create senders. This is a workaround for unit tests purposes only.</param>
 internal PersistenceTransmitter(BaseStorageService storage, int sendersCount, bool createSenders = true)
 {
     this.storage = storage;
     if (createSenders)
     {
         for (int i = 0; i < sendersCount; i++)
         {
             this.senders.Add(new Sender(this.storage, this));
         }
     }
 }
        /// <summary>
        /// Initializes a new instance of the <see cref="FlushManager"/> class.
        /// </summary>        
        /// <param name="storage">The storage that persists the telemetries.</param>
        /// <param name="telemetryBuffer">In memory buffer that holds telemetries.</param>
        /// <param name="supportAutoFlush">A boolean value that determines if flush will happen automatically. Used by unit tests.</param>
        internal FlushManager(BaseStorageService storage, TelemetryBuffer telemetryBuffer, bool supportAutoFlush = true)
        {
            this.storage = storage;
            this.telemetryBuffer = telemetryBuffer;
            this.telemetryBuffer.OnFull = this.OnTelemetryBufferFull;
            this.FlushDelay = TimeSpan.FromSeconds(30);

            if (supportAutoFlush)
            {
                Task.Factory.StartNew(this.FlushLoop, TaskCreationOptions.LongRunning)
                    .ContinueWith(t => CoreEventSource.Log.LogVerbose("FlushManager: Failure in FlushLoop: Exception: " + t.Exception.ToString()), TaskContinuationOptions.OnlyOnFaulted);
            }
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="FlushManager"/> class.
        /// </summary>
        /// <param name="storage">The storage that persists the telemetries.</param>
        /// <param name="telemetryBuffer">In memory buffer that holds telemetries.</param>
        /// <param name="supportAutoFlush">A boolean value that determines if flush will happen automatically. Used by unit tests.</param>
        internal FlushManager(BaseStorageService storage, TelemetryBuffer telemetryBuffer, bool supportAutoFlush = true)
        {
            this.storage                = storage;
            this.telemetryBuffer        = telemetryBuffer;
            this.telemetryBuffer.OnFull = this.OnTelemetryBufferFull;
            this.FlushDelay             = TimeSpan.FromSeconds(30);

            if (supportAutoFlush)
            {
                Task.Factory.StartNew(this.FlushLoop, TaskCreationOptions.LongRunning)
                .ContinueWith(t => CoreEventSource.Log.LogVerbose("FlushManager: Failure in FlushLoop: Exception: " + t.Exception.ToString()), TaskContinuationOptions.OnlyOnFaulted);
            }
        }
Beispiel #7
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)
        {
            this.stopped = false;
            this.DelayHandler = new AutoResetEvent(false);
            this.stoppedHandler = new AutoResetEvent(false);
            this.drainingTimeout = TimeSpan.FromSeconds(100);
            this.defaultSendingInterval = TimeSpan.FromSeconds(5);

            // TODO: instead of a circualr reference, pass the TelemetryConfiguration.
            this.transmitter = transmitter;
            this.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(this.SendLoop, CancellationToken.None, TaskCreationOptions.LongRunning, TaskScheduler.Default)
                    .ContinueWith(t => CoreEventSource.Log.LogVerbose("Sender: Failure in SendLoop: Exception: " + t.Exception.ToString()), TaskContinuationOptions.OnlyOnFaulted);
            }
        }
Beispiel #8
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)
        {
            this.stopped                = false;
            this.DelayHandler           = new AutoResetEvent(false);
            this.stoppedHandler         = new AutoResetEvent(false);
            this.drainingTimeout        = TimeSpan.FromSeconds(100);
            this.defaultSendingInterval = TimeSpan.FromSeconds(5);

            // TODO: instead of a circualr reference, pass the TelemetryConfiguration.
            this.transmitter = transmitter;
            this.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(this.SendLoop, CancellationToken.None, TaskCreationOptions.LongRunning, TaskScheduler.Default)
                .ContinueWith(t => CoreEventSource.Log.LogVerbose("Sender: Failure in SendLoop: Exception: " + t.Exception.ToString()), TaskContinuationOptions.OnlyOnFaulted);
            }
        }
Beispiel #9
0
 internal SenderUnderTest(BaseStorageService storage, PersistenceTransmitter transmitter)
     : base(storage, transmitter, false)
 {
 }