/// <summary>
        ///
        /// </summary>
        public bool ClearTable <ItemType>()
            where ItemType : class, IDBPersistent
        {
            TracerHelper.TraceEntry(typeof(ItemType).Name);

            string tableName = _tablesTypeNames[typeof(ItemType)];

            _clearMutex.WaitOne();
            try
            {
                using (SQLiteConnection connection = GenerateConnection())
                {
                    using (SQLiteCommand command = new SQLiteCommand(connection))
                    {
                        connection.Open();

                        command.CommandText = "DELETE FROM " + tableName;
                        int result = command.ExecuteNonQuery();
                    }
                }
            }
            finally
            {
                _clearMutex.ReleaseMutex();
            }

            TracerHelper.TraceExit();
            return(true);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Prepare the object for operation. Access to this allows externals to use the 2
        /// step component registration process.
        /// Called to bring up a component for operation. Does not add the component
        /// permanently to the platform.
        /// </summary>
        public bool InitializeComponent(PlatformComponent component)
        {
            TracerHelper.Trace(component.Name);

            try
            {
                if (component.IsInitialized == false)
                {
                    Arbiter.AddClient(component);
                    // This allows the component to persist while initializing.
                    component.PersistenceDataUpdatedEvent += new GeneralHelper.GenericDelegate <IDBPersistent>(HandleComponentPersistenceDataUpdatedEvent);
                }

                if (component.IsInitialized || component.Initialize(this))
                {
                    return(true);
                }
            }
            catch (Exception ex)
            {
                SystemMonitor.Error(string.Format("Exception occured during initializing component [{0}, {1}]", component.Name, ex.Message));
            }

            // Failed to initialize component.
            component.PersistenceDataUpdatedEvent -= new GeneralHelper.GenericDelegate <IDBPersistent>(HandleComponentPersistenceDataUpdatedEvent);
            Arbiter.RemoveClient(component);
            return(false);
        }
Ejemplo n.º 3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="entity"></param>
        public void AddExecutionEntity(ExecutionEntity entity)
        {
            TracerHelper.TraceEntry();
            lock (this)
            {
                if (_pendingEntities.Count > _maxPendingExecutionItems)
                {
                    TracerHelper.TraceError("Too many pending entities in system. Some older entities are being dropped.");
                    if ((DateTime.Now - _maxPendingItemsWarningShownTime) > _warningsTimeSpan)
                    {
                        _maxPendingItemsWarningShownTime = DateTime.Now;
                        SystemMonitor.Error("Too many pending entities in system. Some older entities are being dropped.");
                    }

                    // Loose the oldest entity in line.
                    _timeOutMonitor.RemoveEntity(_pendingEntities[0]);
                    _pendingEntities.RemoveAt(0);
                }

                _timeOutMonitor.AddEntity(entity);
                _pendingEntities.Add(entity);
            }

            // Continue execution chain.
            UpdatePendingExecution();
        }
Ejemplo n.º 4
0
        ResponseMessage Receive(SubscribeToOperationalStateChangesMessage message)
        {
            bool result = false;

            lock (this)
            {
                if (message.Subscribe)
                {// Subscribe.
                    TracerHelper.TraceEntry("Subscribing - " + message.TransportInfo.OriginalSenderId.Value.Id.Name);

                    if (_operationStateChangeSubscribers.Contains(message.TransportInfo) == false)
                    {
                        _operationStateChangeSubscribers.Add(message.TransportInfo);
                        result = true;
                    }

                    // Send an initial notification.
                    this.SendResponding(message.TransportInfo, new ChangeOperationalStateMessage(this.OperationalState, false));
                }
                else
                {// Unsubscribe.
                    TracerHelper.TraceEntry("Unsubscribing - " + message.TransportInfo.OriginalSenderId.Value.Id.Name);
                    result = _operationStateChangeSubscribers.Remove(message.TransportInfo);
                }
            }

            if (message.RequestResponse)
            {
                return(new ResponseMessage(result));
            }
            else
            {
                return(null);
            }
        }
Ejemplo n.º 5
0
        void Receive(ChangeOperationalStateMessage message)
        {// Result can be returned to requestor.
            TracerHelper.TraceEntry();

            // Make sure to compare only the *original senders* as the rest is not guaranteed to be the same,
            // since remote status synchronization source is fed to class from outside.
            if (message.IsRequest == false)
            {     // This is a notification
                if (message.TransportInfo.OriginalSenderId.Equals(_remoteStatusSynchronizationSource.OriginalSenderId))
                { // Message received from status synch source, change state to synchronize.
                    if (StatusSynchronizationEnabled)
                    {
                        TracerHelper.Trace(this.GetType().Name + " is following its status synchronization source to new state [" + message.OperationalState.ToString() + "].");
                        ChangeOperationalState(message.OperationalState);
                    }
                    else
                    {
                        TracerHelper.Trace(this.GetType().Name + " is not following its status synchronization source to new state because synchronization is disabled.");
                    }
                }
                else
                {
                    SystemMonitor.Warning("Stat change notification received, but not from status source. Ignored.");
                }
            }
            else
            {
                TracerHelper.Trace(this.GetType().Name + " is following request from " + message.TransportInfo.CurrentTransportInfo.Value.SenderID.Value.Id.Name + " to " + message.OperationalState);

                bool result = OnChangeOperationalStateRequest(message.OperationalState);
                SystemMonitor.CheckWarning(result, "Component [" + this.Name + "] has not changed its operational state upon request.");
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Will unsubscribe to previous one.
        /// </summary>
        protected bool SetRemoteStatusSynchronizationSource(TransportInfo sourceTransportInfo)
        {
            lock (this)
            {
                if (_remoteStatusSynchronizationSource != null)
                {
                    SubscribeToOperationalStateChangesMessage message = new SubscribeToOperationalStateChangesMessage(false);
                    message.RequestResponse = false;
                    SendResponding(_remoteStatusSynchronizationSource, message);
                }

                _remoteStatusSynchronizationSource = sourceTransportInfo;
            }

            bool result = true;

            if (sourceTransportInfo != null)
            {
                ResponseMessage response = SendAndReceiveResponding <ResponseMessage>(sourceTransportInfo,
                                                                                      new SubscribeToOperationalStateChangesMessage(true));

                result = response != null && response.OperationResult;
            }

            TracerHelper.TraceEntry(this.GetType().Name + ", Remote synchronization source " + sourceTransportInfo.OriginalSenderId.Value.Id.Name + " assinged - " + result.ToString());
            return(result);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Change the component operational state.
        /// </summary>
        /// <param name="operationalState"></param>
        protected void ChangeOperationalState(OperationalStateEnum operationalState)
        {
            OperationalStateEnum previousState;

            lock (this)
            {
                if (operationalState == _operationalState)
                {
                    return;
                }

                previousState = _operationalState;
            }

            TracerHelper.Trace(this.GetType().Name + " is now " + operationalState.ToString() + " has [" + _operationStateChangeSubscribers.Count + "] subscribers.");

            _operationalState = operationalState;
            if (OperationalStateChangedEvent != null)
            {
                OperationalStateChangedEvent(this, previousState);
            }

            // Send to monitoring subscribers.
            lock (this)
            {
                foreach (TransportInfo info in _operationStateChangeSubscribers)
                {
                    TracerHelper.Trace("Sending operational state [" + operationalState.ToString() + "] to [" + info.OriginalSenderId.Value.Id.Print() + "].");
                    this.SendResponding(info, new ChangeOperationalStateMessage(this.OperationalState, false));
                }
            }
        }
Ejemplo n.º 8
0
        public void ServiceIdentifiers_MatchTracerInstanceSettings()
        {
            const string service = "unit-test";
            const string version = "1.0.0";
            const string env     = "staging";

            var settings = new TracerSettings()
            {
                ServiceName    = service,
                ServiceVersion = version,
                Environment    = env
            };
            var tracer = TracerHelper.Create(settings);

            Tracer.UnsafeSetTracerInstance(tracer);

            using (var parentScope = Tracer.Instance.StartActive("parent"))
                using (var childScope = Tracer.Instance.StartActive("child"))
                {
                    Assert.Equal(service, CorrelationIdentifier.Service);
                    Assert.Equal(version, CorrelationIdentifier.Version);
                    Assert.Equal(env, CorrelationIdentifier.Env);
                }

            Assert.Equal(service, CorrelationIdentifier.Service);
            Assert.Equal(version, CorrelationIdentifier.Version);
            Assert.Equal(env, CorrelationIdentifier.Env);
        }
        public void LockedTracerInstanceSwap()
        {
            var tracerOne = TracerHelper.Create();
            var tracerTwo = new LockedTracer();

            TracerRestorerAttribute.SetTracer(tracerOne);
            Tracer.Instance.Should().Be(tracerOne);
            Tracer.Instance.TracerManager.Should().Be(tracerOne.TracerManager);

            TracerRestorerAttribute.SetTracer(null);
            Tracer.Instance.Should().BeNull();

            // Set the locked tracer
            TracerRestorerAttribute.SetTracer(tracerTwo);
            Tracer.Instance.Should().Be(tracerTwo);
            Tracer.Instance.TracerManager.Should().Be(tracerTwo.TracerManager);

            // We test the locked tracer cannot be replaced.
#pragma warning disable CS0618 // Setter isn't actually obsolete, just should be internal
            Assert.Throws <InvalidOperationException>(() => Tracer.Instance = tracerOne);

            Assert.Throws <InvalidOperationException>(() => Tracer.Instance = null);

            Assert.Throws <InvalidOperationException>(() => TracerManager.ReplaceGlobalManager(null, TracerManagerFactory.Instance));
            Assert.Throws <InvalidOperationException>(() => TracerManager.ReplaceGlobalManager(null, new CITracerManagerFactory(CIVisibility.Settings)));
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Local execution. Expert to be executed locally, within the platform process
        /// space and on the platforms arbiter.
        /// </summary>
        protected ExpertHost(string name, Type expertType)
            : base(name, false)
        {
            TracerHelper.Trace(this.Name);
            _expertType = expertType;

            base.DefaultTimeOut = TimeSpan.FromSeconds(10);
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Name of the platform must be unique.
        /// </summary>
        public Platform(string name)
            : base(name, false)
        {
            TracerHelper.TraceEntry();

            Arbiter.Arbiter arbiter = new Arbiter.Arbiter("Platform");
            //TracerHelper.TracingEnabled = false;
            arbiter.AddClient(this);
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Constructor.
        /// </summary>
        public PlatformIndicator(string name, bool?isTradeable, bool?isScaledToQuotes, string[] resultSetNames)
            : base(name, isTradeable, isScaledToQuotes, resultSetNames)
        {
            TracerHelper.Trace(this.Name);

            _chartSeries = CreateChartSeries();
            // Needs immediate initialization since it will be added to chart.
            _chartSeries.Initialize(this);
        }
        public void One_Is_Allowed()
        {
            var traceContext = new TraceContext(TracerHelper.Create());
            var spanContext  = new SpanContext(null, traceContext, "Weeeee");
            var span         = new Span(spanContext, null);
            var rateLimiter  = new RateLimiter(maxTracesPerInterval: null);
            var allowed      = rateLimiter.Allowed(span);

            Assert.True(allowed);
        }