Esempio n. 1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="MainEntry"/> class.
        /// </summary>
        /// <param name="config">The configuration.</param>
        public MainEntry(MainConfiguration config)
        {
            _config        = config;
            ClientWrappers = new List <ClientWrapper>();
            ClientNames    = new List <string>();

            RefreshStatus = new RefreshStatus(DateTime.Now, DateTime.Now + TimeSpan.FromMinutes(RefreshInterval))
            {
                TimeTillNextRefresh = DateTime.Now + TimeSpan.FromMinutes(RefreshInterval) - DateTime.Now
            };
            if (config.LocalDatabases?.Count > 0)
            {
                FetchAllClientsFromLocalDb();
                _testMode = true;
            }
            else
            {
                _sharpClient = new TeamCitySharpClient(_config.Host, _config.UserName, _config.Password);
                _restClient  = new RestSharpHelper(_config.Host, _config.UserName, _config.Password);
                new Task(Initialise).Start();
                SetUpdateInterval(60);
            }

            StartRefreshTimer();
        }
Esempio n. 2
0
        /// <summary>
        /// Fetches all fleets.
        /// </summary>
        private void FetchAllClients()
        {
            if (!_initialFetch)
            {
                ClientWrappers.RemoveAll(x => ClientNames.Contains(x.Name));
            }

            foreach (var client in ClientNames)
            {
                var found = _restClient.GetDatabase(client);

                if (found.ToLower().Contains("error"))
                {
                    continue;;
                }

                var fleets = JsonConvert.DeserializeObject(found);

                if (fleets == null)
                {
                    continue;
                }

                ClientWrappers.Add(new ClientWrapper(client, fleets, RefreshStatus));
                RefreshStatus = new RefreshStatus(DateTime.Now, DateTime.Now + TimeSpan.FromMinutes(RefreshInterval))
                {
                    TimeTillNextRefresh = DateTime.Now + TimeSpan.FromMinutes(RefreshInterval) - DateTime.Now
                };
            }

            _initialFetch = false;
        }