Example #1
0
        /// <summary>
        /// Adds a new client to the database by running a query from CI with a given client name.
        /// </summary>
        /// <param name="name">The name of the client.</param>
        /// <returns></returns>
        public string AddClientByName(string name)
        {
            //TODO This is temporary for testing with local DB
            if (_sharpClient == null)
            {
                return("Error : TeamCitySharpClient has not been initialised. Probably running local DB");
            }

            var retrieved = _sharpClient.GetDatabaseJsonByConfigName(name);

            if (retrieved.ToLower().Contains("error"))
            {
                return($"Error : Failed to find {name} client .");
            }

            var fleets = JsonConvert.DeserializeObject(retrieved);

            if (fleets == null)
            {
                return($"Error : Failed to retrieve {name} database from TeamCity");
            }

            if (!ClientWrappers.Any(x => x.Name.ToLower().Equals(name)))
            {
                ClientWrappers.Add(new ClientWrapper(name, fleets,
                                                     new RefreshStatus(RefreshStatus.LastRefresh,
                                                                       RefreshStatus.NextRefresh)));
            }

            return("");
        }
Example #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;
        }
Example #3
0
        /// <summary>
        /// Fetches all clients from local database.Test
        /// </summary>
        private void FetchAllClientsFromLocalDb()
        {
            foreach (var local in _config.LocalDatabases)
            {
                var fleets = JsonConvert.DeserializeObject(File.ReadAllText(local.Value));

                if (fleets == null)
                {
                    continue;
                }

                ClientWrappers.Add(new ClientWrapper(local.Key, fleets, RefreshStatus));
            }
        }
Example #4
0
        /// <summary>
        /// Refreshes the client database.
        /// </summary>
        /// <param name="clientName">Name of the client.</param>
        /// <returns></returns>
        public List <ClientWrapper> RefreshClientDatabase(string clientName)
        {
            // TODO remove after testing
            if (_testMode)
            {
                return(ClientWrappers);
            }

            var found = ClientWrappers.FirstOrDefault(x => x.Name.ToLower().Equals(clientName.ToLower()));

            if (found == null)
            {
                return(ClientWrappers);
            }

            found.Fleets = JsonConvert.DeserializeObject(_restClient.GetDatabase(clientName));

            return(ClientWrappers);
        }