public void Remove(AgentRecord agent)
 {
     if (_agentList.Any(a => a.Hostname == agent.Hostname))
     {
         _agentList.RemoveAll(a => a.Hostname == agent.Hostname);
     }
 }
 public void SaveOrUpdate(AgentRecord agent)
 {
     using (var session = _documentStore.OpenSession())
     {
         session.Store(agent);
         session.SaveChanges();
     }
 }
 public void Remove(AgentRecord agent)
 {
     using (var session = _documentStore.OpenSession())
     {
         session.Delete(agent);
         session.SaveChanges();
     }
 }
 public void SaveOrUpdate(AgentRecord agent)
 {
     using (var session = _documentStore.OpenSession())
     {
         session.Advanced.UseOptimisticConcurrency = true;
         session.Store(agent);
         session.SaveChanges();
     }
 }
Exemple #5
0
        public AgentRecord RegisterAgent(string hostname)
        {
            if (_ravenSession.Load<AgentRecord>(hostname) != null)
                throw new InvalidOperationException("Agent already registered");

            var agent = new AgentRecord(hostname);
            _ravenSession.Store(agent);

            return agent;
        }
 public void Remove(AgentRecord agent)
 {
     using (var session = _documentStore.OpenSession())
     using (var transaction = new TransactionScope())
     {
         session.Delete(agent);
         session.SaveChanges();
         transaction.Complete();
     }
 }
Exemple #7
0
        public void RegisterAgentAndGetStatus(string hostname)
        {
            if (_agentRepository.List().Any(a=>a.Hostname == hostname))
            {
                throw new InvalidOperationException("Agent already registered");
            }

            AgentRecord agent = new AgentRecord() { Hostname = hostname };
            new TaskFactory().StartNew(() => UpdateAgentStatus(agent));
            _agentRepository.SaveOrUpdate(agent);
        }
 public void SaveOrUpdate(AgentRecord agent)
 {
     var existing = _agentList.SingleOrDefault(a => a.Hostname == agent.Hostname);
     if (existing != null)
     {
         _agentList[_agentList.IndexOf(existing)] = agent;
         existing = null;
     }
     else
     {
         _agentList.Add(agent);
     }
 }
Exemple #9
0
        private void SetAgentStatus(AgentStatusReport agentStatus, AgentRecord agent)
        {
            if (agentStatus.packages != null)
            {

                _ravenSession.Advanced.GetEtagFor(agent);
                agent.Packages = agentStatus.packages
                    .Where(p => p.AvailableVersions != null)
                    .Select(p => new PackageViewModel
                                     {
                                         availableVersions = p.AvailableVersions.ToArray(),
                                         currentTask = p.CurrentTask,
                                         installedVersion = p.InstalledVersion,
                                         packageId = p.PackageId,
                                         installed = p.Installed,
                                         installationResult = p.InstallationResult
                                     }).ToList();
            }
            agent.CurrentTasks = agentStatus.currentTasks;
                agent.AvailableVersions = agentStatus.availableVersions;
            agent.Environment = agentStatus.environment;
            agent.Contacted = true;
            agent.LastContact = DateTime.Now;
            agent.Updating = agentStatus.updating ?? new List<string>();
            if (agent.Updating.Count > 0)
            {
                agent.ShowUpdatingStatusUntil = DateTime.Now.AddSeconds(5);
            }
            _ravenSession.Store(agent);
            System.Diagnostics.Debug.WriteLine("Update agent");

            try
            {
                _ravenSession.SaveChanges();
            } catch (ConcurrencyException)
            {
                _logger.Debug("agent status update was rejected because etag was old");
            }
        }
Exemple #10
0
 private void UpdateAgentStatus(AgentRecord agent)
 {
     AgentStatusReport agentStatus = null;
     try
     {
         agentStatus = _agentRemoteService.GetAgentStatus(agent.Hostname);
         agent.Packages = agentStatus.packages;
         agent.CurrentTasks = agentStatus.currentTasks;
         agent.AvailableVersions = agentStatus.availableVersions;
         agent.Environment = agentStatus.environment;
         agent.Contacted = true;
         _agentRepository.SaveOrUpdate(agent);
     }
     catch (Exception ex)
     {
         _logger.Warn("Failed to get agent status", ex);
         agent.Contacted = false;
     }
 }