Ejemplo n.º 1
0
        /// <summary>
        /// Lift the current instance to the static instance.
        /// </summary>
        public void Bind()
        {
            if (Instance != null)
            {
                _logger.LogWarning("A new session is being started but one already exists.");
            }

            Session = new AlgorithmSession
            {
                Name                   = Configuration.Configuration.Instance.EnabledAlgorithm.Algorithm.Name,
                CreatedTimestamp       = DateTimeOffset.Now.ToUnixTimeMilliseconds(),
                ContainerId            = Environment.MachineName,
                AlgorithmConfiguration = JsonConvert.SerializeObject(Configuration.Configuration.Instance.EnabledAlgorithm.AlgorithmConfiguration),
                Active                 = true,
            };

            _sources.Add(_allocation.Subscribe(new ConfigurableObserver <Portfolio>(
                                                   () => { },
                                                   _ => { },
                                                   OnNext)));

            lock (Lock)
            {
                _database.Sessions.Add(Session);
                _database.SaveChanges();
            }

            var prev = Instance;

            Instance = this;
            prev?.Dispose();
        }